5050import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
5151import org .apache .maven .plugin .MojoExecutionException ;
5252import org .apache .maven .plugin .MojoFailureException ;
53- import org .apache .maven .plugins .annotations .Component ;
5453import org .apache .maven .plugins .annotations .LifecyclePhase ;
5554import org .apache .maven .plugins .annotations .Mojo ;
5655import org .apache .maven .plugins .annotations .Parameter ;
5756import org .apache .maven .plugins .annotations .ResolutionScope ;
58- import org .codehaus .plexus .archiver .Archiver ;
5957import org .codehaus .plexus .archiver .jar .JarArchiver ;
58+ import javax .inject .Inject ;
59+ import javax .inject .Named ;
6060
6161/**
6262 * Assemble a kar archive from a features.xml file
@@ -75,7 +75,8 @@ public class KarMojo extends MojoSupport {
7575 /**
7676 * The Jar archiver.
7777 */
78- @ Component (role = Archiver .class , hint ="jar" )
78+ @ Inject
79+ @ Named ("jar" )
7980 private JarArchiver jarArchiver = null ;
8081
8182 /**
@@ -264,6 +265,7 @@ private File createArchive(List<Artifact> bundles, File featuresFile, String gro
264265 // configure for Reproducible Builds based on outputTimestamp value
265266 archiver .configureReproducible (outputTimestamp );
266267
268+ List <File > tempMetadataFiles = new ArrayList <>();
267269 try {
268270 //TODO should .kar be a bundle?
269271// archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName());
@@ -345,12 +347,7 @@ private File createArchive(List<Artifact> bundles, File featuresFile, String gro
345347 }
346348
347349 jarArchiver .addFile (metadataTmp , repositoryPath + layout .pathOf (artifact ).substring (0 , layout .pathOf (artifact ).lastIndexOf ('/' )) + "/maven-metadata-local.xml" );
348-
349- try {
350- metadataTmp .delete ();
351- } catch (final Exception ex ) {
352- getLog ().warn ("Cannot delete temporary created file." , ex );
353- }
350+ tempMetadataFiles .add (metadataTmp );
354351 }
355352
356353 String targetFileName = repositoryPath + layout .pathOf (artifact );
@@ -362,6 +359,16 @@ private File createArchive(List<Artifact> bundles, File featuresFile, String gro
362359 }
363360 archiver .createArchive (mavenSession , project , archive );
364361
362+ for (File tempMetadataFile : tempMetadataFiles ) {
363+ try {
364+ if (!tempMetadataFile .delete ()) {
365+ getLog ().warn ("Cannot delete temporary created file: " + tempMetadataFile .getAbsolutePath ());
366+ }
367+ } catch (final Exception ex ) {
368+ getLog ().warn ("Cannot delete temporary created file: " + tempMetadataFile .getAbsolutePath (), ex );
369+ }
370+ }
371+
365372 return archiveFile ;
366373 } catch (Exception e ) {
367374 throw new MojoExecutionException ("Failed to create archive" , e );
0 commit comments