creating the possibility to skip jar files that would otherwise only contain a jar file. Also started to use this for the optional tasks in the build.xml git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@293157 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -777,7 +777,8 @@ | |||||
| </manifest> | </manifest> | ||||
| <jar destfile="${build.lib}/${name}-launcher.jar" | <jar destfile="${build.lib}/${name}-launcher.jar" | ||||
| basedir="${build.classes}"> | |||||
| basedir="${build.classes}" | |||||
| whenmanifestonly="fail"> | |||||
| <selector refid="ant.launcher"/> | <selector refid="ant.launcher"/> | ||||
| <manifest> | <manifest> | ||||
| <attribute name="Main-Class" value="org.apache.tools.ant.launch.Launcher"/> | <attribute name="Main-Class" value="org.apache.tools.ant.launch.Launcher"/> | ||||
| @@ -786,7 +787,8 @@ | |||||
| <jar destfile="${build.lib}/${name}.jar" | <jar destfile="${build.lib}/${name}.jar" | ||||
| basedir="${build.classes}" | basedir="${build.classes}" | ||||
| manifest="${manifest}"> | |||||
| manifest="${manifest}" | |||||
| whenmanifestonly="fail"> | |||||
| <not> | <not> | ||||
| <selector id="non-core"> | <selector id="non-core"> | ||||
| <or> | <or> | ||||
| @@ -835,7 +837,8 @@ | |||||
| <jar destfile="${build.lib}/${bootstrap.jar}" | <jar destfile="${build.lib}/${bootstrap.jar}" | ||||
| basedir="${build.classes}" | basedir="${build.classes}" | ||||
| manifest="${manifest}"> | |||||
| manifest="${manifest}" | |||||
| whenmanifestonly="fail"> | |||||
| <include name="${ant.package}/Main.class"/> | <include name="${ant.package}/Main.class"/> | ||||
| <metainf dir="${build.dir}"> | <metainf dir="${build.dir}"> | ||||
| <include name="LICENSE.txt"/> | <include name="LICENSE.txt"/> | ||||
| @@ -849,7 +852,8 @@ | |||||
| <jar destfile="${build.lib}/ant-nodeps.jar" | <jar destfile="${build.lib}/ant-nodeps.jar" | ||||
| basedir="${build.classes}" | basedir="${build.classes}" | ||||
| manifest="${manifest.tmp}"> | |||||
| manifest="${manifest.tmp}" | |||||
| whenmanifestonly="skip"> | |||||
| <and> | <and> | ||||
| <selector refid="non-core"/> | <selector refid="non-core"/> | ||||
| <not> | <not> | ||||
| @@ -895,7 +899,8 @@ | |||||
| <sequential> | <sequential> | ||||
| <jar destfile="${build.lib}/${optional.jars.prefix}-@{dep}.jar" | <jar destfile="${build.lib}/${optional.jars.prefix}-@{dep}.jar" | ||||
| basedir="${build.classes}" | basedir="${build.classes}" | ||||
| manifest="${manifest.tmp}"> | |||||
| manifest="${manifest.tmp}" | |||||
| whenmanifestonly="skip"> | |||||
| <selector refid="needs.@{dep}"/> | <selector refid="needs.@{dep}"/> | ||||
| </jar> | </jar> | ||||
| </sequential> | </sequential> | ||||
| @@ -928,7 +933,8 @@ | |||||
| <jar destfile="${build.lib}/${optional.jars.prefix}-weblogic.jar" | <jar destfile="${build.lib}/${optional.jars.prefix}-weblogic.jar" | ||||
| basedir="${build.classes}" | basedir="${build.classes}" | ||||
| manifest="${manifest.tmp}"> | |||||
| manifest="${manifest.tmp}" | |||||
| whenmanifestonly="skip"> | |||||
| <or> | <or> | ||||
| <selector refid="needs.weblogic.ejbc"/> | <selector refid="needs.weblogic.ejbc"/> | ||||
| <selector refid="needs.weblogic.ddcreator"/> | <selector refid="needs.weblogic.ddcreator"/> | ||||
| @@ -43,6 +43,13 @@ note that ZIP files store file modification times with a granularity | |||||
| of two seconds. If a file is less than two seconds newer than the | of two seconds. If a file is less than two seconds newer than the | ||||
| entry in the archive, Ant will not consider it newer.</p> | entry in the archive, Ant will not consider it newer.</p> | ||||
| <p>The <code>whenmanifestonly</code> parameter controls what happens when no | |||||
| files, apart from the manifest file, match. | |||||
| If <code>skip</code>, the JAR is not created and a warning is issued. | |||||
| If <code>fail</code>, the JAR is not created and the build is halted with an error. | |||||
| If <code>create</code>, (default) an empty JAR file (only containing a manifest) | |||||
| is created.</p> | |||||
| <p>(The Jar task is a shortcut for specifying the manifest file of a JAR file. | <p>(The Jar task is a shortcut for specifying the manifest file of a JAR file. | ||||
| The same thing can be accomplished by using the <i>fullpath</i> | The same thing can be accomplished by using the <i>fullpath</i> | ||||
| attribute of a zipfileset in a Zip task. The one difference is that if the | attribute of a zipfileset in a Zip task. The one difference is that if the | ||||
| @@ -155,6 +162,11 @@ to a value other than its default, <code>"add"</code>.</b></p> | |||||
| the destination file if it already exists. Default is "false".</td> | the destination file if it already exists. Default is "false".</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">whenmanifestonly</td> | |||||
| <td valign="top">behavior when no files match. Valid values are "fail", "skip", and "create". Default is "create".</td> | |||||
| <td valign="top" align="center">No</td> | |||||
| </tr> | |||||
| <tr> | <tr> | ||||
| <td valign="top">duplicate</td> | <td valign="top">duplicate</td> | ||||
| <td valign="top">behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add". </td> | <td valign="top">behavior when a duplicate file is found. Valid values are "add", "preserve", and "fail". The default value is "add". </td> | ||||
| @@ -140,6 +140,8 @@ public class Jar extends Zip { | |||||
| private ZipExtraField[] JAR_MARKER = new ZipExtraField[] { | private ZipExtraField[] JAR_MARKER = new ZipExtraField[] { | ||||
| JarMarker.getInstance() | JarMarker.getInstance() | ||||
| }; | }; | ||||
| protected String emptyBehavior = "create"; | |||||
| /** constructor */ | /** constructor */ | ||||
| public Jar() { | public Jar() { | ||||
| @@ -160,6 +162,16 @@ public class Jar extends Zip { | |||||
| Project.MSG_WARN); | Project.MSG_WARN); | ||||
| } | } | ||||
| /** | |||||
| * Not used for jar files. | |||||
| * @param we not used | |||||
| * @ant.attribute ignore="true" | |||||
| */ | |||||
| public void setWhenmanifestonly(WhenEmpty we) { | |||||
| emptyBehavior = we.getValue(); | |||||
| } | |||||
| /** | /** | ||||
| * Set the destination file. | * Set the destination file. | ||||
| * @param jarFile the destination file | * @param jarFile the destination file | ||||
| @@ -677,6 +689,18 @@ public class Jar extends Zip { | |||||
| return true; | return true; | ||||
| } | } | ||||
| if (emptyBehavior.equals("skip")) { | |||||
| log("Warning: skipping " + archiveType + " archive " | |||||
| + zipFile + " because no files were included.", | |||||
| Project.MSG_WARN); | |||||
| return true; | |||||
| } else if (emptyBehavior.equals("fail")) { | |||||
| throw new BuildException("Cannot create " + archiveType | |||||
| + " archive " + zipFile | |||||
| + ": no files were included.", | |||||
| getLocation()); | |||||
| } | |||||
| ZipOutputStream zOut = null; | ZipOutputStream zOut = null; | ||||
| try { | try { | ||||
| log("Building MANIFEST-only jar: " | log("Building MANIFEST-only jar: " | ||||
| @@ -737,6 +761,7 @@ public class Jar extends Zip { | |||||
| */ | */ | ||||
| public void reset() { | public void reset() { | ||||
| super.reset(); | super.reset(); | ||||
| emptyBehavior = "create"; | |||||
| configuredManifest = null; | configuredManifest = null; | ||||
| filesetManifestConfig = null; | filesetManifestConfig = null; | ||||
| mergeManifestsMain = false; | mergeManifestsMain = false; | ||||