You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by jk...@apache.org on 2005/10/02 22:04:44 UTC

svn commit: r293157 - in /ant/core/trunk: build.xml docs/manual/CoreTasks/jar.html src/main/org/apache/tools/ant/taskdefs/Jar.java

Author: jkf
Date: Sun Oct  2 13:04:39 2005
New Revision: 293157

URL: http://svn.apache.org/viewcvs?rev=293157&view=rev
Log:
Updated the Jar task to have an whenmanifestonly attribute, 
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

Modified:
    ant/core/trunk/build.xml
    ant/core/trunk/docs/manual/CoreTasks/jar.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java

Modified: ant/core/trunk/build.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/build.xml?rev=293157&r1=293156&r2=293157&view=diff
==============================================================================
--- ant/core/trunk/build.xml (original)
+++ ant/core/trunk/build.xml Sun Oct  2 13:04:39 2005
@@ -777,7 +777,8 @@
     </manifest>
 
     <jar destfile="${build.lib}/${name}-launcher.jar"
-      basedir="${build.classes}">
+      basedir="${build.classes}"
+      whenmanifestonly="fail">
       <selector refid="ant.launcher"/>
       <manifest>
         <attribute name="Main-Class" value="org.apache.tools.ant.launch.Launcher"/>
@@ -786,7 +787,8 @@
 
     <jar destfile="${build.lib}/${name}.jar"
       basedir="${build.classes}"
-      manifest="${manifest}">
+      manifest="${manifest}"
+      whenmanifestonly="fail">
       <not>
         <selector id="non-core">
           <or>
@@ -835,7 +837,8 @@
 
     <jar destfile="${build.lib}/${bootstrap.jar}"
       basedir="${build.classes}"
-      manifest="${manifest}">
+      manifest="${manifest}"
+      whenmanifestonly="fail">
       <include name="${ant.package}/Main.class"/>
       <metainf dir="${build.dir}">
         <include name="LICENSE.txt"/>
@@ -849,7 +852,8 @@
 
     <jar destfile="${build.lib}/ant-nodeps.jar"
       basedir="${build.classes}"
-      manifest="${manifest.tmp}">
+      manifest="${manifest.tmp}"
+      whenmanifestonly="skip">
       <and>
         <selector refid="non-core"/>
         <not>
@@ -895,7 +899,8 @@
       <sequential>
         <jar destfile="${build.lib}/${optional.jars.prefix}-@{dep}.jar"
           basedir="${build.classes}"
-          manifest="${manifest.tmp}">
+	  manifest="${manifest.tmp}"
+	  whenmanifestonly="skip">
           <selector refid="needs.@{dep}"/>
         </jar>
       </sequential>
@@ -928,7 +933,8 @@
 
     <jar destfile="${build.lib}/${optional.jars.prefix}-weblogic.jar"
       basedir="${build.classes}"
-      manifest="${manifest.tmp}">
+      manifest="${manifest.tmp}"
+      whenmanifestonly="skip">
       <or>
         <selector refid="needs.weblogic.ejbc"/>
         <selector refid="needs.weblogic.ddcreator"/>

Modified: ant/core/trunk/docs/manual/CoreTasks/jar.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/jar.html?rev=293157&r1=293156&r2=293157&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/jar.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/jar.html Sun Oct  2 13:04:39 2005
@@ -43,6 +43,13 @@
 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>
 
+<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.
 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
@@ -153,6 +160,11 @@
     <td valign="top">update</td>
     <td valign="top">indicates whether to update or overwrite
       the destination file if it already exists.  Default is &quot;false&quot;.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">whenmanifestonly</td>
+    <td valign="top">behavior when no files match.  Valid values are &quot;fail&quot;, &quot;skip&quot;, and &quot;create&quot;.  Default is &quot;create&quot;.</td>
     <td valign="top" align="center">No</td>
   </tr>
   <tr>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?rev=293157&r1=293156&r2=293157&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java Sun Oct  2 13:04:39 2005
@@ -140,6 +140,8 @@
     private ZipExtraField[] JAR_MARKER = new ZipExtraField[] {
         JarMarker.getInstance()
     };
+    
+    protected String emptyBehavior = "create";
 
     /** constructor */
     public Jar() {
@@ -161,6 +163,16 @@
     }
 
     /**
+     * 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.
      * @param jarFile the destination file
      * @deprecated Use setDestFile(File) instead
@@ -677,6 +689,18 @@
             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;
         try {
             log("Building MANIFEST-only jar: "
@@ -737,6 +761,7 @@
      */
     public void reset() {
         super.reset();
+        emptyBehavior = "create";
         configuredManifest = null;
         filesetManifestConfig = null;
         mergeManifestsMain = false;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: svn commit: r293157 - in /ant/core/trunk: build.xml docs/manual/CoreTasks/jar.html src/main/org/apache/tools/ant/taskdefs/Jar.java

Posted by Stefan Bodewig <bo...@apache.org>.
On Sun, 02 Oct 2005, <jk...@apache.org> wrote:

> Updated the Jar task to have an whenmanifestonly attribute, 
> 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

This last part breaks Gump.

In the dist-ant project we declare a couple of optional dependencies
(for our optional tasks).  Since they are optional we don't know
whether they will be present at runtime - but have to declare all
output jars.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org