Browse Source

merge filesetmanifest=mergewithoutmain even if no explicit manifest has been specified. PR 54171

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1555355 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
a17032a42a
3 changed files with 50 additions and 3 deletions
  1. +5
    -0
      WHATSNEW
  2. +22
    -3
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  3. +23
    -0
      src/tests/antunit/taskdefs/jar-test.xml

+ 5
- 0
WHATSNEW View File

@@ -56,6 +56,11 @@ Fixed bugs:
* <javadoc> caused a NullPointerException when no destdir was set. * <javadoc> caused a NullPointerException when no destdir was set.
Bugzilla Report 55949 Bugzilla Report 55949


* <jar filesetmanifest="mergewithoutmain"> would still include the
Main section of the fileset manifests if there was no nested
manifest or manifest attribute.
Bugzilla Report 54171

Other changes: Other changes:
-------------- --------------




+ 22
- 3
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -516,8 +516,6 @@ public class Jar extends Zip {
private Manifest createManifest() private Manifest createManifest()
throws BuildException { throws BuildException {
try { try {
Manifest finalManifest = Manifest.getDefaultManifest();

if (manifest == null) { if (manifest == null) {
if (manifestFile != null) { if (manifestFile != null) {
// if we haven't got the manifest yet, attempt to // if we haven't got the manifest yet, attempt to
@@ -526,6 +524,25 @@ public class Jar extends Zip {
} }
} }


// fileset manifest must come even before the default
// manifest if mergewithoutmain is selected and there is
// no explicit manifest specified - otherwise the Main
// section of the fileset manifest is still merged to the
// final manifest.
boolean mergeFileSetFirst = !mergeManifestsMain
&& filesetManifest != null
&& configuredManifest == null && manifest == null;

Manifest finalManifest;
if (mergeFileSetFirst) {
finalManifest = new Manifest();
finalManifest.merge(filesetManifest, false, mergeClassPaths);
finalManifest.merge(Manifest.getDefaultManifest(),
true, mergeClassPaths);
} else {
finalManifest = Manifest.getDefaultManifest();
}

/* /*
* Precedence: manifestFile wins over inline manifest, * Precedence: manifestFile wins over inline manifest,
* over manifests read from the filesets over the original * over manifests read from the filesets over the original
@@ -537,7 +554,9 @@ public class Jar extends Zip {
if (isInUpdateMode()) { if (isInUpdateMode()) {
finalManifest.merge(originalManifest, false, mergeClassPaths); finalManifest.merge(originalManifest, false, mergeClassPaths);
} }
finalManifest.merge(filesetManifest, false, mergeClassPaths);
if (!mergeFileSetFirst) {
finalManifest.merge(filesetManifest, false, mergeClassPaths);
}
finalManifest.merge(configuredManifest, !mergeManifestsMain, finalManifest.merge(configuredManifest, !mergeManifestsMain,
mergeClassPaths); mergeClassPaths);
finalManifest.merge(manifest, !mergeManifestsMain, finalManifest.merge(manifest, !mergeManifestsMain,


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

@@ -226,4 +226,27 @@ Main-Class: MyClass
resource="${output}/META-INF/MANIFEST.MF"/> resource="${output}/META-INF/MANIFEST.MF"/>
</target> </target>


<target name="testMergeWithoutMainWithoutExplicitManifest"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54171">
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<jar destfile="${input}/input.jar">
<manifest>
<attribute name="Foo" value="Main Section"/>
</manifest>
<fileset dir="."/>
</jar>
<jar destfile="${input}/test.jar"
filesetmanifest="mergewithoutmain">
<zipgroupfileset dir="${input}">
<include name="input.jar"/>
</zipgroupfileset>
</jar>
<unjar src="${input}/test.jar" dest="${output}"/>
<au:assertFileExists file="${output}/META-INF/MANIFEST.MF"/>
<au:assertResourceDoesntContain
value="Foo: Main Section"
resource="${output}/META-INF/MANIFEST.MF"/>
</target>

</project> </project>

Loading…
Cancel
Save