bodewig 2003/03/12 03:23:28
Modified: src/main/org/apache/tools/ant/taskdefs Jar.java Zip.java
Log:
Fix the bug.
PR: 17780
Revision Changes Path
1.71 +5 -3 ant/src/main/org/apache/tools/ant/taskdefs/Jar.java
Index: Jar.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- Jar.java 17 Feb 2003 14:00:34 -0000 1.70
+++ Jar.java 12 Mar 2003 11:23:27 -0000 1.71
@@ -531,11 +531,12 @@
* out-of-date. Subclasses overriding this method are supposed to
* set this value correctly in their call to
* super.getResourcesToAdd.
- * @return an array of resources to add for each fileset passed in.
+ * @return an array of resources to add for each fileset passed in as well
+ * as a flag that indicates whether the archive is uptodate.
*
* @exception BuildException if it likes
*/
- protected Resource[][] getResourcesToAdd(FileSet[] filesets,
+ protected ArchiveState getResourcesToAdd(FileSet[] filesets,
File zipFile,
boolean needsUpdate)
throws BuildException {
@@ -581,7 +582,8 @@
ZipOutputStream zOut = null;
try {
- log("Building jar: " + getDestFile().getAbsolutePath());
+ log("Building MANIFEST-only jar: "
+ + getDestFile().getAbsolutePath());
zOut = new ZipOutputStream(new FileOutputStream(getDestFile()));
zOut.setEncoding(getEncoding());
1.101 +64 -11 ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
Index: Zip.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -r1.100 -r1.101
--- Zip.java 7 Mar 2003 11:23:03 -0000 1.100
+++ Zip.java 12 Mar 2003 11:23:27 -0000 1.101
@@ -344,7 +344,11 @@
// we don't need to update if the original file doesn't exist
addingNewFiles = true;
- doUpdate = doUpdate && zipFile.exists();
+ if (doUpdate && !zipFile.exists()) {
+ doUpdate = false;
+ log("ignoring update attribute as " + archiveType
+ + " doesn't exist.", Project.MSG_DEBUG);
+ }
// Add the files found in groupfileset to fileset
for (int i = 0; i < groupfilesets.size(); i++) {
@@ -381,14 +385,16 @@
vfss.copyInto(fss);
boolean success = false;
try {
- Resource[][] addThem = getResourcesToAdd(fss, zipFile, false);
+ // can also handle empty archives
+ ArchiveState state = getResourcesToAdd(fss, zipFile, false);
// quick exit if the target is up to date
- // can also handle empty archives
- if (isEmpty(addThem)) {
+ if (!state.isOutOfDate()) {
return;
}
+ Resource[][] addThem = state.getResourcesToAdd();
+
if (doUpdate) {
renamedFile =
fileUtils.createTempFile("zip", ".tmp",
@@ -687,17 +693,38 @@
* out-of-date. Subclasses overriding this method are supposed to
* set this value correctly in their call to
* super.getResourcesToAdd.
- * @return an array of resources to add for each fileset passed in.
+ * @return an array of resources to add for each fileset passed in as well
+ * as a flag that indicates whether the archive is uptodate.
*
* @exception BuildException if it likes
*/
- protected Resource[][] getResourcesToAdd(FileSet[] filesets,
+ protected ArchiveState getResourcesToAdd(FileSet[] filesets,
File zipFile,
boolean needsUpdate)
throws BuildException {
Resource[][] initialResources = grabResources(filesets);
if (isEmpty(initialResources)) {
+ if (needsUpdate && doUpdate) {
+ /*
+ * This is a rather hairy case.
+ *
+ * One of our subclasses knows that we need to update the
+ * archive, but at the same time, there are no resources
+ * known to us that would need to be added. Only the
+ * subclass seems to know what's going on.
+ *
+ * This happens if <jar> detects that the manifest has changed,
+ * for example. The manifest is not part of any resources
+ * because of our support for inline <manifest>s.
+ *
+ * If we invoke createEmptyZip like Ant 1.5.2 did,
+ * we'll loose all stuff that has been in the original
+ * archive (bugzilla report 17780).
+ */
+ return new ArchiveState(true, initialResources);
+ }
+
if (emptyBehavior.equals("skip")) {
if (doUpdate) {
log(archiveType + " archive " + zipFile
@@ -717,16 +744,18 @@
// Create.
createEmptyZip(zipFile);
}
- return initialResources;
+ return new ArchiveState(needsUpdate, initialResources);
}
+ // initialResources is not empty
+
if (!zipFile.exists()) {
- return initialResources;
+ return new ArchiveState(true, initialResources);
}
if (needsUpdate && !doUpdate) {
// we are recreating the archive, need all resources
- return initialResources;
+ return new ArchiveState(true, initialResources);
}
Resource[][] newerResources = new Resource[filesets.length][];
@@ -794,10 +823,10 @@
if (needsUpdate && !doUpdate) {
// we are recreating the archive, need all resources
- return initialResources;
+ return new ArchiveState(true, initialResources);
}
- return newerResources;
+ return new ArchiveState(needsUpdate, newerResources);
}
/**
@@ -1094,6 +1123,30 @@
public static class Duplicate extends EnumeratedAttribute {
public String[] getValues() {
return new String[] {"add", "preserve", "fail"};
+ }
+ }
+
+ /**
+ * Holds the up-to-date status and the out-of-date resources of
+ * the original archive.
+ *
+ * @since Ant 1.5.3
+ */
+ public static class ArchiveState {
+ private boolean outOfDate;
+ private Resource[][] resourcesToAdd;
+
+ ArchiveState(boolean state, Resource[][] r) {
+ outOfDate = state;
+ resourcesToAdd = r;
+ }
+
+ public boolean isOutOfDate() {
+ return outOfDate;
+ }
+
+ public Resource[][] getResourcesToAdd() {
+ return resourcesToAdd;
}
}
}
|