bodewig 2004/05/13 00:13:53 Modified: . Tag: ANT_16_BRANCH WHATSNEW docs/manual/CoreTasks Tag: ANT_16_BRANCH jar.html src/etc/testcases/filters Tag: ANT_16_BRANCH concat.xml src/etc/testcases/taskdefs Tag: ANT_16_BRANCH defaultexcludes.xml src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH Jar.java src/testcases/org/apache/tools/ant/filters Tag: ANT_16_BRANCH ConcatFilterTest.java src/testcases/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH DefaultExcludesTest.java Log: merge Revision Changes Path No revision No revision 1.503.2.90 +4 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.503.2.89 retrieving revision 1.503.2.90 diff -u -r1.503.2.89 -r1.503.2.90 --- WHATSNEW 28 Apr 2004 11:45:22 -0000 1.503.2.89 +++ WHATSNEW 13 May 2004 07:13:47 -0000 1.503.2.90 @@ -122,6 +122,10 @@ run all tests in a single forked JVM reducing the overhead of VM creation a lot. Bugzilla Report 24697. +* <jar> can now optionally create an index for jars different than the + one it currently builds as well. See the new <indexjars> element + for details. Bugzilla Report 14255. + Changes from Ant 1.6.0 to Ant 1.6.1 =================================== No revision No revision 1.28.2.3 +33 -1 ant/docs/manual/CoreTasks/jar.html Index: jar.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/jar.html,v retrieving revision 1.28.2.2 retrieving revision 1.28.2.3 diff -u -r1.28.2.2 -r1.28.2.3 --- jar.html 9 Feb 2004 22:12:07 -0000 1.28.2.2 +++ jar.html 13 May 2004 07:13:50 -0000 1.28.2.3 @@ -161,7 +161,13 @@ </tr> <tr> <td valign="top">index</td> - <td valign="top">whether to create an <A HREF="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">index list</A> to speed up classloading. This is a JDK 1.3+ specific feature. Defaults to false. </td> + <td valign="top">whether to create an <A + HREF="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index">index + list</A> to speed up classloading. This is a JDK 1.3+ specific + feature. Unless you specify additional jars with nested <a + href="#indexjars"><code>indexjars</code></a> elements, only the + contents of this jar will be included in the index. Defaults to + false.</td> <td valign="top" align="center">No</td> </tr> <tr> @@ -196,6 +202,32 @@ If the manifest values have changed the jar will be updated or rebuilt, as appropriate. </p> + +<a name="indexjars"><h4>indexjars</h4></a> + +<p><em>since ant 1.6.2</em></p> + +<p>The nested <code>indexjars</code> element specifies a <a +href="../using.html#path">PATH like structure</a>. Its content is +completely ignored unless you set the index attribute of the task to +true.</p> + +<p>The index created by this task will contain indices for the +archives contained in this path, the names used for the archioves +depend on your manifest:</p> +<ul> + <li>If the generated jar's manifest contains no Class-Path + attribute, the file name without any leading directory path will be + used and all parts of the path will get indexed.</li> + <li>If the manifest contains a Class-Path attribute, this task will + try to guess which part of the Class-Path belongs to a given + archive. If it cannot guess a name, the archive will be skipped, + otherwise tha name listed inside the Class-PAth attribute will be + used.</li> +</ul> + +<p>This task will not create any index entries for archives that are +empty or only contain files inside the META-INF directory.</p> <h3>Examples</h3> <pre> <jar destfile="${dist}/lib/app.jar" basedir="${build}/classes"/></pre> No revision No revision 1.2.2.3 +2 -0 ant/src/etc/testcases/filters/concat.xml Index: concat.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/filters/concat.xml,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- concat.xml 25 Sep 2003 06:19:51 -0000 1.2.2.2 +++ concat.xml 13 May 2004 07:13:51 -0000 1.2.2.3 @@ -7,6 +7,8 @@ <echo file="result/append.txt" message="this-should-be-the-last-line${line.separator}"/> <copy file="input/head-tail.test" tofile="input/concatfilter.test"/> <fixcrlf srcDir="input" includes="concatfilter.test"/> + <!-- to be consistent on MacOS X. fixcrlf uses CR while line.sep is LF --> + <fixcrlf srcDir="result" includes="append.txt,prepend.txt"/> </target> <target name="cleanup"> No revision No revision 1.2.2.1 +4 -0 ant/src/etc/testcases/taskdefs/defaultexcludes.xml Index: defaultexcludes.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/defaultexcludes.xml,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- defaultexcludes.xml 21 Jul 2003 10:52:19 -0000 1.2 +++ defaultexcludes.xml 13 May 2004 07:13:51 -0000 1.2.2.1 @@ -2,6 +2,10 @@ <project name="echo-test" basedir="." default="test1"> + <target name="cleanup"> + <defaultexcludes default="true"/> + </target> + <target name="test1"> <defaultexcludes echo="true"/> </target> No revision No revision 1.81.2.5 +201 -27 ant/src/main/org/apache/tools/ant/taskdefs/Jar.java Index: Jar.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v retrieving revision 1.81.2.4 retrieving revision 1.81.2.5 diff -u -r1.81.2.4 -r1.81.2.5 --- Jar.java 9 Mar 2004 17:01:33 -0000 1.81.2.4 +++ Jar.java 13 May 2004 07:13:53 -0000 1.81.2.5 @@ -29,7 +29,15 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; +import java.util.TreeMap; import java.util.Vector; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -37,10 +45,10 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.ZipFileSet; import org.apache.tools.zip.ZipOutputStream; - /** * Creates a JAR archive. * @@ -115,6 +123,13 @@ */ private Vector rootEntries; + /** + * Path containing jars that shall be indexed in addition to this archive. + * + * @since Ant 1.6.2 + */ + private Path indexJars; + /** constructor */ public Jar() { super(); @@ -304,6 +319,16 @@ super.addFileset(fs); } + /** + * @since Ant 1.6.2 + */ + public void addConfiguredIndexJars(Path p) { + if (indexJars == null) { + indexJars = new Path(getProject()); + } + indexJars.append(p); + } + protected void initZipOutputStream(ZipOutputStream zOut) throws IOException, BuildException { @@ -384,7 +409,7 @@ /** * Create the index list to speed up classloading. * This is a JDK 1.3+ specific feature and is enabled by default. See - * <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR+Index"> + * <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#JAR%20Index"> * the JAR index specification</a> for more details. * * @param zOut the zip stream representing the jar being built. @@ -404,34 +429,38 @@ // header newline writer.println(zipFile.getName()); - // JarIndex is sorting the directories by ascending order. - // it's painful to do in JDK 1.1 and it has no value but cosmetic - // since it will be read into a hashtable by the classloader. - Enumeration e = addedDirs.keys(); - while (e.hasMoreElements()) { - String dir = (String) e.nextElement(); + writeIndexLikeList(new ArrayList(addedDirs.keySet()), + rootEntries, writer); + writer.println(); - // try to be smart, not to be fooled by a weird directory name - // @fixme do we need to check for directories starting by ./ ? - dir = dir.replace('\\', '/'); - int pos = dir.lastIndexOf('/'); - if (pos != -1) { - dir = dir.substring(0, pos); + if (indexJars != null) { + Manifest mf = createManifest(); + Manifest.Attribute classpath = + mf.getMainSection().getAttribute(Manifest.ATTRIBUTE_CLASSPATH); + String[] cpEntries = null; + if (classpath != null) { + StringTokenizer tok = new StringTokenizer(classpath.getValue(), + " "); + cpEntries = new String[tok.countTokens()]; + int c = 0; + while (tok.hasMoreTokens()) { + cpEntries[c++] = tok.nextToken(); + } } - - // 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")) { - continue; + String[] indexJarEntries = indexJars.list(); + for (int i = 0; i < indexJarEntries.length; i++) { + String name = findJarName(indexJarEntries[i], cpEntries); + if (name != null) { + ArrayList dirs = new ArrayList(); + ArrayList files = new ArrayList(); + grabFilesAndDirs(indexJarEntries[i], dirs, files); + if (dirs.size() + files.size() > 0) { + writer.println(name); + writeIndexLikeList(dirs, files, writer); + writer.println(); + } + } } - // name newline - writer.println(dir); - } - - e = rootEntries.elements(); - while (e.hasMoreElements()) { - writer.println(e.nextElement()); } writer.flush(); @@ -670,6 +699,151 @@ public static class FilesetManifestConfig extends EnumeratedAttribute { public String[] getValues() { return new String[] {"skip", "merge", "mergewithoutmain"}; + } + } + + /** + * Writes the directory entries from the first and the filenames + * from the second list to the given writer, one entry per line. + * + * @since Ant 1.6.2 + */ + protected final void writeIndexLikeList(List dirs, List files, + PrintWriter writer) + throws IOException { + // JarIndex is sorting the directories by ascending order. + // it has no value but cosmetic since it will be read into a + // hashtable by the classloader, but we'll do so anyway. + Collections.sort(dirs); + Collections.sort(files); + Iterator iter = dirs.iterator(); + while (iter.hasNext()) { + String dir = (String) iter.next(); + + // try to be smart, not to be fooled by a weird directory name + dir = dir.replace('\\', '/'); + if (dir.startsWith("./")) { + dir = dir.substring(2); + } + while (dir.startsWith("/")) { + dir = dir.substring(1); + } + int pos = dir.lastIndexOf('/'); + if (pos != -1) { + dir = dir.substring(0, pos); + } + + // 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")) { + continue; + } + // name newline + writer.println(dir); + } + + iter = files.iterator(); + while (iter.hasNext()) { + writer.println(iter.next()); + } + } + + /** + * try to guess the name of the given file. + * + * <p>If this jar has a classpath attribute in its manifest, we + * can assume that it will only require an index of jars listed + * there. try to find which classpath entry is most likely the + * one the given file name points to.</p> + * + * <p>In the absence of a classpath attribute, assume the other + * files will be placed inside the same directory as this jar and + * use their basename.</p> + * + * <p>if there is a classpath and the given file doesn't match any + * of its entries, return null.</p> + * + * @since Ant 1.7 + */ + protected static final String findJarName(String fileName, + String[] classpath) { + if (classpath == null) { + return (new File(fileName)).getName(); + } + fileName = fileName.replace(File.separatorChar, '/'); + TreeMap matches = new TreeMap(new Comparator() { + // longest match comes first + public int compare(Object o1, Object o2) { + if (o1 instanceof String && o2 instanceof String) { + return ((String) o2).length() + - ((String) o1).length(); + } + return 0; + } + }); + + for (int i = 0; i < classpath.length; i++) { + if (fileName.endsWith(classpath[i])) { + matches.put(classpath[i], classpath[i]); + } else { + int slash = classpath[i].indexOf("/"); + String candidate = classpath[i]; + while (slash > -1) { + candidate = candidate.substring(slash + 1); + if (fileName.endsWith(candidate)) { + matches.put(candidate, classpath[i]); + break; + } + slash = candidate.indexOf("/"); + } + } + } + + return matches.size() == 0 + ? null : (String) matches.get(matches.firstKey()); + } + + /** + * Grab lists of all root-level files and all directories + * contained in the given archive. + * + * @since Ant 1.7 + */ + protected static final void grabFilesAndDirs(String file, List dirs, + List files) + throws IOException { + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(file, "utf-8"); + Enumeration entries = zf.getEntries(); + HashSet dirSet = new HashSet(); + while (entries.hasMoreElements()) { + 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) { + files.add(name); + } else { + // a file, not in the root + // since the jar may be one without directory + // entries, add the parent dir of this file as + // well. + dirSet.add(name.substring(0, + name.lastIndexOf("/") + 1)); + } + } + } + dirs.addAll(dirSet); + } finally { + if (zf != null) { + zf.close(); + } } } } No revision No revision 1.2.2.9 +3 -1 ant/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java Index: ConcatFilterTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java,v retrieving revision 1.2.2.8 retrieving revision 1.2.2.9 diff -u -r1.2.2.8 -r1.2.2.9 --- ConcatFilterTest.java 9 Mar 2004 17:02:01 -0000 1.2.2.8 +++ ConcatFilterTest.java 13 May 2004 07:13:53 -0000 1.2.2.9 @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.util.FileUtils; /** @@ -29,7 +30,8 @@ public class ConcatFilterTest extends BuildFileTest { private static FileUtils fu = FileUtils.newFileUtils(); - private static final String lSep = System.getProperty("line.separator"); + private static final String lSep = + Os.isFamily("mac") ? "\r" : System.getProperty("line.separator"); private static final String FILE_PREPEND_WITH = "this-should-be-the-first-line" + lSep No revision No revision 1.3.2.5 +4 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java Index: DefaultExcludesTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java,v retrieving revision 1.3.2.4 retrieving revision 1.3.2.5 diff -u -r1.3.2.4 -r1.3.2.5 --- DefaultExcludesTest.java 9 Mar 2004 17:02:01 -0000 1.3.2.4 +++ DefaultExcludesTest.java 13 May 2004 07:13:53 -0000 1.3.2.5 @@ -32,6 +32,10 @@ configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml"); } + public void tearDown() { + project.executeTarget("cleanup"); + } + // Output the default excludes public void test1() { String[] expected = {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]