ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r792960 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/ear.html docs/manual/CoreTasks/jar.html src/main/org/apache/tools/ant/taskdefs/Jar.java src/tests/antunit/taskdefs/jar-test.xml
Date Fri, 10 Jul 2009 14:24:30 GMT
Author: bodewig
Date: Fri Jul 10 14:24:29 2009
New Revision: 792960

URL: http://svn.apache.org/viewvc?rev=792960&view=rev
Log:
add a new indexMetaInf attribute to <jar>.  PR 47457.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/ear.html
    ant/core/trunk/docs/manual/CoreTasks/jar.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
    ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=792960&r1=792959&r2=792960&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Jul 10 14:24:29 2009
@@ -749,6 +749,10 @@
    optional prefix and suffix attributes.
    Bugzilla Report 45625
 
+ * <jar> has a new attribute to enable indexing of META-INF
+   directories which is desabled for backwards compatibility reasons.
+   Bugzilla Report 47457
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/ear.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/ear.html?rev=792960&r1=792959&r2=792960&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/ear.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/ear.html Fri Jul 10 14:24:29 2009
@@ -156,6 +156,20 @@
     <td valign="top" align="center">No</td>
   </tr>
   <tr>
+    <td valign="top">indexMetaInf</td>
+    <td valign="top">whether to include META-INF and its children in
+      the index.  Doesn't have any effect if <em>index</em> is
+      false.<br/>
+      Sun's jar implementation used to skip the META-INF directory and
+      Ant followed that example.  The behavior has been changed with
+      <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526">Java
+      5</a>.  In order to avoid problems with Ant generated jars on
+      Java 1.4 or earlier Ant will not include META-INF unless
+      explicitly asked to.<br/>
+      <em>Ant 1.8.0</em> - Defaults to false.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
     <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>

Modified: ant/core/trunk/docs/manual/CoreTasks/jar.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/jar.html?rev=792960&r1=792959&r2=792960&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/jar.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/jar.html Fri Jul 10 14:24:29 2009
@@ -205,6 +205,20 @@
     <td valign="top" align="center">No</td>
   </tr>
   <tr>
+    <td valign="top">indexMetaInf</td>
+    <td valign="top">whether to include META-INF and its children in
+      the index.  Doesn't have any effect if <em>index</em> is
+      false.<br/>
+      Sun's jar implementation used to skip the META-INF directory and
+      Ant followed that example.  The behavior has been changed with
+      <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526">Java
+      5</a>.  In order to avoid problems with Ant generated jars on
+      Java 1.4 or earlier Ant will not include META-INF unless
+      explicitly asked to.<br/>
+      <em>Ant 1.8.0</em> - Defaults to false.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
     <td valign="top">manifestencoding</td>
     <td valign="top">The encoding used to read the JAR manifest, when a manifest file
is specified.</td>
     <td valign="top" align="center">No, defaults to the platform encoding.</td>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?rev=792960&r1=792959&r2=792960&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 Fri Jul 10 14:24:29 2009
@@ -119,6 +119,9 @@
     /** jar index is JDK 1.3+ only */
     private boolean index = false;
 
+    /** Whether to index META-INF/ and its children */
+    private boolean indexMetaInf = false;
+
     /**
      * whether to really create the archive in createEmptyZip, will
      * get set in getResourcesToAdd.
@@ -224,6 +227,25 @@
     }
 
     /**
+     * Set whether or not to add META-INF and its children to the index.
+     *
+     * <p>Doesn't have any effect if index is false.</p>
+     *
+     * <p>Sun's jar implementation used to skip the META-INF directory
+     * and Ant followed that example.  The behavior has been changed
+     * with Java 5.  In order to avoid problems with Ant generated
+     * jars on Java 1.4 or earlier Ant will not include META-INF
+     * unless explicitly asked to.</p>
+     *
+     * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526
+     * @since Ant 1.8.0
+     * @param flag a <code>boolean</code> value, defaults to false
+     */
+    public void setIndexMetaInf(boolean flag) {
+        indexMetaInf = flag;
+    }
+
+    /**
      * The character encoding to use in the manifest file.
      *
      * @param manifestEncoding the character encoding
@@ -972,7 +994,9 @@
             // looks like nothing from META-INF should be added
             // and the check is not case insensitive.
             // see sun.misc.JarIndex
-            if (dir.startsWith("META-INF")) {
+            // see also 
+            // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4408526
+            if (!indexMetaInf && dir.startsWith("META-INF")) {
                 continue;
             }
             // name newline
@@ -1064,9 +1088,6 @@
                 org.apache.tools.zip.ZipEntry ze =
                     (org.apache.tools.zip.ZipEntry) entries.nextElement();
                 String name = ze.getName();
-                // META-INF would be skipped anyway, avoid index for
-                // manifest-only jars.
-                if (!name.startsWith("META-INF/")) {
                     if (ze.isDirectory()) {
                         dirSet.add(name);
                     } else if (name.indexOf("/") == -1) {
@@ -1079,7 +1100,6 @@
                         dirSet.add(name.substring(0,
                                                   name.lastIndexOf("/") + 1));
                     }
-                }
             }
             dirs.addAll(dirSet);
         } finally {

Modified: ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml?rev=792960&r1=792959&r2=792960&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/jar-test.xml Fri Jul 10 14:24:29 2009
@@ -60,4 +60,30 @@
     </jar>
     <au:assertLogDoesntContain text="skipping jar archive"/>
   </target>
+
+  <target name="-metainf-setup">
+    <mkdir dir="${input}/services"/>
+    <touch file="${input}/services/foo"/>
+    <mkdir dir="${output}"/>
+  </target>
+
+  <target name="testIndexNoMetaInf" depends="-metainf-setup">
+    <jar index="true" destfile="${output}/test.jar">
+      <metainf dir="${input}"/>
+    </jar>
+    <unjar src="${output}/test.jar" dest="${output}"/>
+    <au:assertFileExists file="${output}/META-INF/INDEX.LIST"/>
+    <au:assertResourceDoesntContain value="META-INF"
+                                    resource="${output}/META-INF/INDEX.LIST"/>
+  </target>
+
+  <target name="testIndexMetaInf" depends="-metainf-setup">
+    <jar index="true" destfile="${output}/test.jar" indexMetaInf="true">
+      <metainf dir="${input}"/>
+    </jar>
+    <unjar src="${output}/test.jar" dest="${output}"/>
+    <au:assertFileExists file="${output}/META-INF/INDEX.LIST"/>
+    <au:assertResourceContains value="META-INF"
+                               resource="${output}/META-INF/INDEX.LIST"/>
+  </target>
 </project>



Mime
View raw message