Fixed logging. Don't generate temporary file from /tmp. Fixed bug: the target bundle was not deleted before copy
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@898309 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/mvn/AnnotationMojo.java b/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/mvn/AnnotationMojo.java
index 3b9e410..802f4cc 100644
--- a/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/mvn/AnnotationMojo.java
+++ b/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/mvn/AnnotationMojo.java
@@ -19,6 +19,7 @@
package org.apache.felix.dm.annotation.plugin.mvn;
import java.io.File;
+import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
@@ -98,10 +99,7 @@
{
jar.putResource(entry.getKey(), entry.getValue());
}
- output = File.createTempFile(getClass().getName(), m_artifactExtension);
- jar.write(output);
- jar.close();
- output.renameTo(target);
+ copy(jar, target);
}
// Check if some errors have to be logged.
@@ -119,7 +117,7 @@
{
for (Iterator<String> e = analyzer.getWarnings().iterator(); e.hasNext();)
{
- getLog().warn(e.next());
+ getLog().info(e.next());
}
}
}
@@ -139,7 +137,7 @@
{
if (output != null && output.exists())
{
- output.delete();
+ //output.delete();
}
if (jar != null)
@@ -159,4 +157,37 @@
return new File(build.getDirectory() + File.separator + build.getFinalName() + "."
+ m_artifactExtension);
}
+
+ /**
+ * Copy the generated jar into our target bundle.
+ * @param jar the jar with the generated component descriptors
+ * @param target our target bundle
+ * @throws MojoExecutionException on any errors
+ * @throws Exception on any error
+ */
+ private void copy(Jar jar, File target) throws MojoExecutionException, Exception
+ {
+ File tmp = new File(getBundleName() + ".tmp");
+ try
+ {
+ if (tmp.exists())
+ {
+ if (! tmp.delete()) {
+ throw new MojoExecutionException("Could not remove " + tmp);
+ }
+ }
+ jar.write(tmp);
+ jar.close();
+
+ if (!tmp.renameTo(target))
+ {
+ throw new MojoExecutionException("Could not rename " + tmp + " to " + target);
+ }
+ }
+ finally
+ {
+ jar.close();
+ tmp.delete();
+ }
+ }
}
\ No newline at end of file