Skip to content

Commit 56c95b2

Browse files
committed
Fix the way to deal with temp files in the KarMojo
1 parent 523e631 commit 56c95b2

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

  • tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling

tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/KarMojo.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
5151
import org.apache.maven.plugin.MojoExecutionException;
5252
import org.apache.maven.plugin.MojoFailureException;
53-
import org.apache.maven.plugins.annotations.Component;
5453
import org.apache.maven.plugins.annotations.LifecyclePhase;
5554
import org.apache.maven.plugins.annotations.Mojo;
5655
import org.apache.maven.plugins.annotations.Parameter;
5756
import org.apache.maven.plugins.annotations.ResolutionScope;
58-
import org.codehaus.plexus.archiver.Archiver;
5957
import 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

Comments
 (0)