diff --git a/docs/manual/CoreTasks/ear.html b/docs/manual/CoreTasks/ear.html index dc4a05d44..9b3b0e912 100644 --- a/docs/manual/CoreTasks/ear.html +++ b/docs/manual/CoreTasks/ear.html @@ -31,7 +31,7 @@ attributes of zipfilesets in a Zip or Jar task.)

appxml The deployment descriptor to use (META-INF/application.xml). - Yes + Yes, unless update is set to true basedir diff --git a/docs/manual/CoreTasks/war.html b/docs/manual/CoreTasks/war.html index 65e8aedbd..1e29b8b64 100644 --- a/docs/manual/CoreTasks/war.html +++ b/docs/manual/CoreTasks/war.html @@ -33,7 +33,7 @@ attributes of zipfilesets in a Zip or Jar task.)

webxml The deployment descriptor to use (WEB-INF/web.xml). - Yes + Yes, unless update is set to true basedir diff --git a/src/main/org/apache/tools/ant/taskdefs/Ear.java b/src/main/org/apache/tools/ant/taskdefs/Ear.java index e9b3d0c1d..bff4f0ab5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Ear.java +++ b/src/main/org/apache/tools/ant/taskdefs/Ear.java @@ -111,7 +111,7 @@ public class Ear extends Jar { throws IOException, BuildException { // If no webxml file is specified, it's an error. - if (deploymentDescriptor == null) { + if (deploymentDescriptor == null && !isInUpdateMode()) { throw new BuildException("appxml attribute is required", location); } diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java index 417a805dd..918b36f40 100644 --- a/src/main/org/apache/tools/ant/taskdefs/War.java +++ b/src/main/org/apache/tools/ant/taskdefs/War.java @@ -119,7 +119,7 @@ public class War extends Jar { throws IOException, BuildException { // If no webxml file is specified, it's an error. - if (deploymentDescriptor == null) { + if (deploymentDescriptor == null && !isInUpdateMode()) { throw new BuildException("webxml attribute is required", location); } diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index 8cbc4bb96..050663a33 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -76,6 +76,7 @@ import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.ZipFileSet; import org.apache.tools.ant.types.ZipScanner; +import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.SourceFileScanner; import org.apache.tools.ant.util.MergingMapper; import org.apache.tools.zip.ZipOutputStream; @@ -165,6 +166,13 @@ public class Zip extends MatchingTask { doUpdate = c; } + /** + * Are we updating an existing archive? + */ + public boolean isInUpdateMode() { + return doUpdate; + } + /** * Adds a set of files (nested fileset attribute). */ @@ -228,23 +236,12 @@ public class Zip extends MatchingTask { // we don't need to update if the original file doesn't exist addingNewFiles = true; - boolean reallyDoUpdate = false; - if (doUpdate && zipFile.exists()) + doUpdate = doUpdate && zipFile.exists(); + if (doUpdate) { - reallyDoUpdate = true; - - int i; - for (i=0; i < 1000; i++) - { - renamedFile = new File(zipFile.getParent(), "tmp."+i); - - if (!renamedFile.exists()) { - break; - } - } - if (i == 1000) { - throw new BuildException("Can't find available temporary filename to which to rename old file."); - } + FileUtils fileUtils = FileUtils.newFileUtils(); + renamedFile = fileUtils.createTempFile("zip", ".tmp", + fileUtils.getParentFile(zipFile)); try { @@ -277,7 +274,7 @@ public class Zip extends MatchingTask { return; } - String action = reallyDoUpdate ? "Updating " : "Building "; + String action = doUpdate ? "Updating " : "Building "; log(action + archiveType +": "+ zipFile.getAbsolutePath()); @@ -300,7 +297,7 @@ public class Zip extends MatchingTask { } // Add the explicit filesets to the archive. addFiles(filesets, zOut); - if (reallyDoUpdate) { + if (doUpdate) { addingNewFiles = false; ZipFileSet oldFiles = new ZipFileSet(); oldFiles.setSrc(renamedFile); @@ -345,7 +342,7 @@ public class Zip extends MatchingTask { msg += " (and the archive is probably corrupt but I could not delete it)"; } - if (reallyDoUpdate) { + if (doUpdate) { if (!renamedFile.renameTo(zipFile)) { msg+=" (and I couldn't rename the temporary file "+ renamedFile.getName()+" back)"; @@ -358,7 +355,7 @@ public class Zip extends MatchingTask { } // If we've been successful on an update, delete the temporary file - if (success && reallyDoUpdate) { + if (success && doUpdate) { if (!renamedFile.delete()) { log ("Warning: unable to delete temporary file " + renamedFile.getName(), Project.MSG_WARN);