bodewig 2003/01/17 04:50:28 Modified: . Tag: ANT_15_BRANCH WHATSNEW src/etc/testcases/taskdefs Tag: ANT_15_BRANCH jar.xml src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH Jar.java src/testcases/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH JarTest.java Log: merge fix for bug 12651 from HEAD Revision Changes Path No revision No revision 1.263.2.111 +1 -0 jakarta-ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/jakarta-ant/WHATSNEW,v retrieving revision 1.263.2.110 retrieving revision 1.263.2.111 diff -u -r1.263.2.110 -r1.263.2.111 --- WHATSNEW 16 Jan 2003 12:08:00 -0000 1.263.2.110 +++ WHATSNEW 17 Jan 2003 12:50:27 -0000 1.263.2.111 @@ -61,6 +61,7 @@ it to once again accept URLs. This should not affect current FIle based usage unless you are extending the Signjar task. +* <jar update="true"> would remove the original manifest. Other changes: -------------- No revision No revision 1.4.2.1 +21 -3 jakarta-ant/src/etc/testcases/taskdefs/jar.xml Index: jar.xml =================================================================== RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/jar.xml,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- jar.xml 8 Jan 2002 09:46:26 -0000 1.4 +++ jar.xml 17 Jan 2003 12:50:27 -0000 1.4.2.1 @@ -2,6 +2,9 @@ <project name="jar-test" basedir="." default="test1"> + <property name="tmp.jar" location="tmp.jar"/> + <property name="tmp.dir" location="jartmp"/> + <target name="test1"> <jar/> </target> @@ -22,7 +25,7 @@ <target name="test4"> <jar - destfile="tmp.jar" + destfile="${tmp.jar}" basedir="." includes="jar.xml" /> @@ -31,14 +34,29 @@ <!-- This test is to make sure upToDate is working --> <target name="test5"> <jar - destfile="tmp.jar" + destfile="${tmp.jar}" basedir="." includes="jar.xml" /> </target> + <target name="testManifestStaysIntact"> + <mkdir dir="${tmp.dir}"/> + <manifest file="${tmp.dir}/manifest"> + <attribute name="Foo" value="bar"/> + </manifest> + <jar destfile="${tmp.jar}" basedir="." includes="jar.xml" + manifest="${tmp.dir}/manifest"/> + <sleep seconds="3"/> + <touch file="jar.xml"/> + <jar destfile="${tmp.jar}" basedir="." includes="jar.xml" + update="true"/> + <unjar src="${tmp.jar}" dest="${tmp.dir}"/> + </target> + <target name="cleanup"> - <delete file="tmp.jar" /> + <delete file="${tmp.jar}" /> + <delete dir="${tmp.dir}"/> </target> </project> No revision No revision 1.51.2.12 +56 -18 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java Index: Jar.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v retrieving revision 1.51.2.11 retrieving revision 1.51.2.12 diff -u -r1.51.2.11 -r1.51.2.12 --- Jar.java 19 Jul 2002 18:36:25 -0000 1.51.2.11 +++ Jar.java 17 Jan 2003 12:50:28 -0000 1.51.2.12 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -72,7 +72,8 @@ import java.io.OutputStreamWriter; import java.io.InputStreamReader; import java.util.Enumeration; - +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; /** * Creates a JAR archive. @@ -97,6 +98,12 @@ /** merged manifests added through filesets */ private Manifest filesetManifest; + /** + * Manifest of original archive, will be set to null if not in + * update mode. + */ + private Manifest originalManifest; + /** * whether to merge fileset manifests; * value is true if filesetmanifest is 'merge' or 'mergewithoutmain' @@ -152,6 +159,36 @@ } /** + * Override to get hold of the original Manifest (if present and + * only if updating ... + * + * @since Ant 1.5.2 + */ + public void setDestFile(File jarFile) { + super.setDestFile(jarFile); + if (jarFile.exists()) { + try { + ZipFile zf = new ZipFile(jarFile); + + // must not use getEntry as "well behaving" applications + // must accept the manifest in any capitalization + Enumeration enum = zf.entries(); + while (enum.hasMoreElements()) { + ZipEntry ze = (ZipEntry) enum.nextElement(); + if (ze.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) { + originalManifest = + getManifest(new InputStreamReader(zf + .getInputStream(ze))); + } + } + } catch (Throwable t) { + log("error while reading original manifest: " + t.getMessage(), + Project.MSG_WARN); + } + } + } + + /** * Set whether or not to create an index list for classes. * This may speed up classloading in some cases. */ @@ -275,6 +312,10 @@ private Manifest createManifest() throws IOException, BuildException { try { + if (!isInUpdateMode()) { + originalManifest = null; + } + Manifest finalManifest = Manifest.getDefaultManifest(); if (manifest == null) { @@ -282,24 +323,21 @@ // if we haven't got the manifest yet, attempt to // get it now and have manifest be the final merge manifest = getManifest(manifestFile); - finalManifest.merge(filesetManifest); - finalManifest.merge(configuredManifest); - finalManifest.merge(manifest, !mergeManifestsMain); - } else if (configuredManifest != null) { - // configuredManifest is the final merge - finalManifest.merge(filesetManifest); - finalManifest.merge(configuredManifest, - !mergeManifestsMain); - } else if (filesetManifest != null) { - // filesetManifest is the final (and only) merge - finalManifest.merge(filesetManifest, !mergeManifestsMain); } - } else { - // manifest is the final merge - finalManifest.merge(filesetManifest); - finalManifest.merge(configuredManifest); - finalManifest.merge(manifest, !mergeManifestsMain); } + + /* + * Precedence: manifestFile wins over inline manifest, + * over manifests read from the filesets over the original + * manifest. + * + * merge with null argument is a no-op + */ + + finalManifest.merge(originalManifest); + finalManifest.merge(filesetManifest); + finalManifest.merge(configuredManifest); + finalManifest.merge(manifest, !mergeManifestsMain); return finalManifest; No revision No revision 1.8.2.1 +13 -7 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java Index: JarTest.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JarTest.java,v retrieving revision 1.8 retrieving revision 1.8.2.1 diff -u -r1.8 -r1.8.2.1 --- JarTest.java 10 Jan 2002 10:13:12 -0000 1.8 +++ JarTest.java 17 Jan 2003 12:50:28 -0000 1.8.2.1 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,7 +54,9 @@ package org.apache.tools.ant.taskdefs; +import java.io.IOException; import java.io.File; +import java.io.FileReader; import java.util.Date; import org.apache.tools.ant.BuildFileTest; @@ -63,7 +65,6 @@ */ public class JarTest extends BuildFileTest { - private static long jarModifiedDate; private static String tempJar = "tmp.jar"; public JarTest(String name) { @@ -94,12 +95,17 @@ executeTarget("test4"); File jarFile = new File(getProjectDir(), tempJar); assertTrue(jarFile.exists()); - jarModifiedDate = jarFile.lastModified(); } - public void XXXtest5() { - executeTarget("test5"); - File jarFile = new File(getProjectDir(), tempJar); - assertEquals(jarModifiedDate, jarFile.lastModified()); + public void testManifestStaysIntact() + throws IOException, ManifestException { + executeTarget("testManifestStaysIntact"); + Manifest mf1 = + new Manifest(new FileReader(getProject() + .resolveFile("jartmp/manifest"))); + Manifest mf2 = + new Manifest(new FileReader(getProject() + .resolveFile("jartmp/META-INF/MANIFEST.MF"))); + assertEquals(mf1, mf2); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>