git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@792960 13f79535-47bb-0310-9956-ffa450edef68master
@@ -749,6 +749,10 @@ Other changes: | |||||
optional prefix and suffix attributes. | optional prefix and suffix attributes. | ||||
Bugzilla Report 45625 | 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 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
============================================= | ============================================= | ||||
@@ -155,6 +155,20 @@ to a value other than its default, <code>"add"</code>.</b></p> | |||||
false.</td> | false.</td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </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> | <tr> | ||||
<td valign="top">update</td> | <td valign="top">update</td> | ||||
<td valign="top">indicates whether to update or overwrite | <td valign="top">indicates whether to update or overwrite | ||||
@@ -204,6 +204,20 @@ to a value other than its default, <code>"add"</code>.</b></p> | |||||
false.</td> | false.</td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </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> | <tr> | ||||
<td valign="top">manifestencoding</td> | <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">The encoding used to read the JAR manifest, when a manifest file is specified.</td> | ||||
@@ -119,6 +119,9 @@ public class Jar extends Zip { | |||||
/** jar index is JDK 1.3+ only */ | /** jar index is JDK 1.3+ only */ | ||||
private boolean index = false; | 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 | * whether to really create the archive in createEmptyZip, will | ||||
* get set in getResourcesToAdd. | * get set in getResourcesToAdd. | ||||
@@ -223,6 +226,25 @@ public class Jar extends Zip { | |||||
index = flag; | index = flag; | ||||
} | } | ||||
/** | |||||
* 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. | * The character encoding to use in the manifest file. | ||||
* | * | ||||
@@ -972,7 +994,9 @@ public class Jar extends Zip { | |||||
// looks like nothing from META-INF should be added | // looks like nothing from META-INF should be added | ||||
// and the check is not case insensitive. | // and the check is not case insensitive. | ||||
// see sun.misc.JarIndex | // 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; | continue; | ||||
} | } | ||||
// name newline | // name newline | ||||
@@ -1064,9 +1088,6 @@ public class Jar extends Zip { | |||||
org.apache.tools.zip.ZipEntry ze = | org.apache.tools.zip.ZipEntry ze = | ||||
(org.apache.tools.zip.ZipEntry) entries.nextElement(); | (org.apache.tools.zip.ZipEntry) entries.nextElement(); | ||||
String name = ze.getName(); | String name = ze.getName(); | ||||
// META-INF would be skipped anyway, avoid index for | |||||
// manifest-only jars. | |||||
if (!name.startsWith("META-INF/")) { | |||||
if (ze.isDirectory()) { | if (ze.isDirectory()) { | ||||
dirSet.add(name); | dirSet.add(name); | ||||
} else if (name.indexOf("/") == -1) { | } else if (name.indexOf("/") == -1) { | ||||
@@ -1079,7 +1100,6 @@ public class Jar extends Zip { | |||||
dirSet.add(name.substring(0, | dirSet.add(name.substring(0, | ||||
name.lastIndexOf("/") + 1)); | name.lastIndexOf("/") + 1)); | ||||
} | } | ||||
} | |||||
} | } | ||||
dirs.addAll(dirSet); | dirs.addAll(dirSet); | ||||
} finally { | } finally { | ||||
@@ -60,4 +60,30 @@ | |||||
</jar> | </jar> | ||||
<au:assertLogDoesntContain text="skipping jar archive"/> | <au:assertLogDoesntContain text="skipping jar archive"/> | ||||
</target> | </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> | </project> |