Browse Source

add a new indexMetaInf attribute to <jar>. PR 47457.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@792960 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
7f24568899
5 changed files with 83 additions and 5 deletions
  1. +4
    -0
      WHATSNEW
  2. +14
    -0
      docs/manual/CoreTasks/ear.html
  3. +14
    -0
      docs/manual/CoreTasks/jar.html
  4. +25
    -5
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  5. +26
    -0
      src/tests/antunit/taskdefs/jar-test.xml

+ 4
- 0
WHATSNEW View File

@@ -749,6 +749,10 @@ Other changes:
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
=============================================



+ 14
- 0
docs/manual/CoreTasks/ear.html View File

@@ -155,6 +155,20 @@ to a value other than its default, <code>&quot;add&quot;</code>.</b></p>
false.</td>
<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


+ 14
- 0
docs/manual/CoreTasks/jar.html View File

@@ -204,6 +204,20 @@ to a value other than its default, <code>"add"</code>.</b></p>
false.</td>
<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>


+ 25
- 5
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -119,6 +119,9 @@ public class Jar extends Zip {
/** 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.
@@ -223,6 +226,25 @@ public class Jar extends Zip {
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.
*
@@ -972,7 +994,9 @@ public class Jar extends Zip {
// 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 @@ public class Jar extends Zip {
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 @@ public class Jar extends Zip {
dirSet.add(name.substring(0,
name.lastIndexOf("/") + 1));
}
}
}
dirs.addAll(dirSet);
} finally {


+ 26
- 0
src/tests/antunit/taskdefs/jar-test.xml View File

@@ -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>

Loading…
Cancel
Save