diff --git a/WHATSNEW b/WHATSNEW index 1acdb84e7..ca4dcef50 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -56,6 +56,11 @@ Fixed bugs: * caused a NullPointerException when no destdir was set. Bugzilla Report 55949 + * would still include the + Main section of the fileset manifests if there was no nested + manifest or manifest attribute. + Bugzilla Report 54171 + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index 91a49fa4b..d351627b2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -516,8 +516,6 @@ public class Jar extends Zip { private Manifest createManifest() throws BuildException { try { - Manifest finalManifest = Manifest.getDefaultManifest(); - if (manifest == null) { if (manifestFile != null) { // 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, * over manifests read from the filesets over the original @@ -537,7 +554,9 @@ public class Jar extends Zip { if (isInUpdateMode()) { finalManifest.merge(originalManifest, false, mergeClassPaths); } - finalManifest.merge(filesetManifest, false, mergeClassPaths); + if (!mergeFileSetFirst) { + finalManifest.merge(filesetManifest, false, mergeClassPaths); + } finalManifest.merge(configuredManifest, !mergeManifestsMain, mergeClassPaths); finalManifest.merge(manifest, !mergeManifestsMain, diff --git a/src/tests/antunit/taskdefs/jar-test.xml b/src/tests/antunit/taskdefs/jar-test.xml index 87c5d726a..c2c8834eb 100644 --- a/src/tests/antunit/taskdefs/jar-test.xml +++ b/src/tests/antunit/taskdefs/jar-test.xml @@ -226,4 +226,27 @@ Main-Class: MyClass resource="${output}/META-INF/MANIFEST.MF"/> + + + + + + + + + + + + + + + + + + +