diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java index e8f6e0b31..9f6edbabe 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java +++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java @@ -78,6 +78,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute; * * @author Conor MacNeill * @author Stefan Bodewig + * @author Jose Alberto Fernandez * * @ant.task category="java" */ @@ -1027,17 +1028,19 @@ public class Manifest extends Task { } Manifest toWrite = getDefaultManifest(); + Manifest current = null; + BuildException error = null; - if (mode.getValue().equals("update") && manifestFile.exists()) { + if (manifestFile.exists()) { FileReader f = null; try { f = new FileReader(manifestFile); - toWrite.merge(new Manifest(f)); + current = new Manifest(f); } catch (ManifestException m) { - throw new BuildException("Existing manifest " + manifestFile + error = new BuildException("Existing manifest " + manifestFile + " is invalid", m, location); } catch (IOException e) { - throw new BuildException("Failed to read " + manifestFile, + error = new BuildException("Failed to read " + manifestFile, e, location); } finally { if (f != null) { @@ -1049,11 +1052,25 @@ public class Manifest extends Task { } try { + if (mode.getValue().equals("update") && manifestFile.exists()) { + if (current != null) { + toWrite.merge(current); + } + else if (error != null) { + throw error; + } + } + toWrite.merge(this); } catch (ManifestException m) { throw new BuildException("Manifest is invalid", m, location); } + if (toWrite.equals(current)) { + log("Manifest has not changed, do not recreate", project.MSG_VERBOSE); + return; + } + PrintWriter w = null; try { w = new PrintWriter(new FileWriter(manifestFile));