git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@690714 13f79535-47bb-0310-9956-ffa450edef68master
@@ -316,6 +316,10 @@ Other changes: | |||
manual page for details. | |||
Bugzilla Report 37241. | |||
* The Jar task now supports the addition of a jar index file in update mode. | |||
Previously the absence of the index was not enough to trigger the rebuild; | |||
some other update was necessary. Bugzilla report 45098. | |||
Changes from Ant 1.7.0 TO Ant 1.7.1 | |||
============================================= | |||
@@ -340,6 +340,29 @@ public class Jar extends Zip { | |||
return newManifest; | |||
} | |||
private boolean jarHasIndex(File jarFile) throws IOException { | |||
ZipFile zf = null; | |||
try { | |||
zf = new ZipFile(jarFile); | |||
Enumeration e = zf.entries(); | |||
while (e.hasMoreElements()) { | |||
ZipEntry ze = (ZipEntry) e.nextElement(); | |||
if (ze.getName().equalsIgnoreCase(INDEX_NAME)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} finally { | |||
if (zf != null) { | |||
try { | |||
zf.close(); | |||
} catch (IOException e) { | |||
// XXX - log an error? throw an exception? | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Behavior when a Manifest is found in a zipfileset or zipgroupfileset file. | |||
* Valid values are "skip", "merge", and "mergewithoutmain". | |||
@@ -593,7 +616,7 @@ public class Jar extends Zip { | |||
} | |||
} else if (INDEX_NAME.equalsIgnoreCase(vPath) && index) { | |||
log("Warning: selected " + archiveType | |||
+ " files include a META-INF/INDEX.LIST which will" | |||
+ " files include a " + INDEX_NAME + " which will" | |||
+ " be replaced by a newly generated one.", Project.MSG_WARN); | |||
} else { | |||
if (index && vPath.indexOf("/") == -1) { | |||
@@ -734,6 +757,14 @@ public class Jar extends Zip { | |||
} | |||
createEmpty = needsUpdate; | |||
if (!needsUpdate && index) { | |||
try { | |||
needsUpdate = !jarHasIndex(zipFile); | |||
} catch (IOException e) { | |||
//if we couldn't read it, we might as well recreate it? | |||
needsUpdate = true; | |||
} | |||
} | |||
return super.getResourcesToAdd(rcs, zipFile, needsUpdate); | |||
} | |||
@@ -0,0 +1,52 @@ | |||
<?xml version="1.0"?> | |||
<!-- | |||
Licensed to the Apache Software Foundation (ASF) under one or more | |||
contributor license agreements. See the NOTICE file distributed with | |||
this work for additional information regarding copyright ownership. | |||
The ASF licenses this file to You under the Apache License, Version 2.0 | |||
(the "License"); you may not use this file except in compliance with | |||
the License. You may obtain a copy of the License at | |||
http://www.apache.org/licenses/LICENSE-2.0 | |||
Unless required by applicable law or agreed to in writing, software | |||
distributed under the License is distributed on an "AS IS" BASIS, | |||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
See the License for the specific language governing permissions and | |||
limitations under the License. | |||
--> | |||
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> | |||
<import file="../antunit-base.xml" /> | |||
<property name="index.jar" location="index.jar" /> | |||
<target name="tearDown"> | |||
<delete file="${index.jar}" /> | |||
</target> | |||
<target name="testIndexOnlyUpdate"> | |||
<jar destfile="${index.jar}" index="false"> | |||
<fileset dir="${basedir}" includes="*-test.xml" /> | |||
</jar> | |||
<au:assertTrue> | |||
<resourcecount count="0"> | |||
<restrict> | |||
<zipentry zipfile="${index.jar}" name="META-INF/INDEX.LIST" /> | |||
<exists /> | |||
</restrict> | |||
</resourcecount> | |||
</au:assertTrue> | |||
<jar destfile="${index.jar}" index="true" update="true"> | |||
<fileset dir="${basedir}" includes="*-test.xml" /> | |||
</jar> | |||
<au:assertTrue> | |||
<resourcecount count="1"> | |||
<restrict> | |||
<zipentry zipfile="${index.jar}" name="META-INF/INDEX.LIST" /> | |||
<exists /> | |||
</restrict> | |||
</resourcecount> | |||
</au:assertTrue> | |||
</target> | |||
</project> |