Browse Source

make update="true" and filesetmanifest="merge" work together. PR 30751

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@794630 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
8df1ef0ecf
3 changed files with 72 additions and 2 deletions
  1. +4
    -0
      WHATSNEW
  2. +35
    -2
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  3. +33
    -0
      src/tests/antunit/taskdefs/jar-test.xml

+ 4
- 0
WHATSNEW View File

@@ -404,6 +404,10 @@ Fixed bugs:
* <record> didn't work properly with nested builds.
Bugzilla Report 41368.

* <jar> with filesetmanifest different from skip didn't work if the
update attribute has been set to true.
Bugzilla Report 30751.

Other changes:
--------------
* The get task now also follows redirects from http to https


+ 35
- 2
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -47,6 +47,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Manifest.Section;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
@@ -778,6 +779,14 @@ public class Jar extends Zip {
boolean needsUpdate)
throws BuildException {

if (skipWriting) {
// this pass is only there to construct the merged
// manifest this means we claim an update was needed and
// only include the manifests, skipping any uptodate
// checks here defering them for the second run
return new ArchiveState(true, grabManifests(rcs));
}

// need to handle manifest as a special check
if (zipFile.exists()) {
// if it doesn't exist, it will get created anyway, don't
@@ -786,13 +795,13 @@ public class Jar extends Zip {
try {
originalManifest = getManifestFromJar(zipFile);
if (originalManifest == null) {
logOnFirstPass("Updating jar since the current jar has"
log("Updating jar since the current jar has"
+ " no manifest", Project.MSG_VERBOSE);
needsUpdate = true;
} else {
Manifest mf = createManifest();
if (!mf.equals(originalManifest)) {
logOnFirstPass("Updating jar since jar manifest has"
log("Updating jar since jar manifest has"
+ " changed", Project.MSG_VERBOSE);
needsUpdate = true;
}
@@ -1117,6 +1126,30 @@ public class Jar extends Zip {
}
}

private Resource[][] grabManifests(ResourceCollection[] rcs) {
Resource[][] manifests = new Resource[rcs.length][];
for (int i = 0; i < rcs.length; i++) {
Resource[][] resources = null;
if (rcs[i] instanceof FileSet) {
resources = grabResources(new FileSet[] {(FileSet) rcs[i]});
} else {
resources = grabNonFileSetResources(new ResourceCollection[] {
rcs[i]
});
}
for (int j = 0; j < resources[0].length; j++) {
if (resources[0][j].getName().equalsIgnoreCase(MANIFEST_NAME)) {
manifests[i] = new Resource[] {resources[0][j]};
break;
}
}
if (manifests[i] == null) {
manifests[i] = new Resource[0];
}
}
return manifests;
}

/** The strict enumerated type. */
public static class StrictMode extends EnumeratedAttribute {
/** Public no arg constructor. */


+ 33
- 0
src/tests/antunit/taskdefs/jar-test.xml View File

@@ -146,4 +146,37 @@
</jar>
</au:expectfailure>
</target>

<target name="test-update-and-filesetmanifest"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=30751">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<jar destfile="${input}/manifest.jar">
<manifest>
<attribute name="Origin" value="manifest.jar"/>
</manifest>
</jar>

<touch file="${input}/foo"/>
<jar destfile="${output}/test.jar">
<fileset dir="${input}" excludes="*.jar"/>
<manifest>
<attribute name="Second-Origin" value="test.jar"/>
</manifest>
</jar>

<touch file="${input}/bar"/>
<jar destfile="${output}/test.jar" update="true" filesetmanifest="merge">
<fileset dir="${input}" excludes="*.jar"/>
<zipgroupfileset dir="${input}" includes="*.jar"/>
</jar>

<unjar src="${output}/test.jar" dest="${output}"/>
<au:assertFileExists file="${output}/foo"/>
<au:assertFileExists file="${output}/bar"/>
<au:assertResourceContains value="Origin: manifest.jar"
resource="${output}/META-INF/MANIFEST.MF"/>
<au:assertResourceContains value="Second-Origin: test.jar"
resource="${output}/META-INF/MANIFEST.MF"/>
</target>
</project>

Loading…
Cancel
Save