ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Lévy-Lambert <anto...@antbuild.com>
Subject Re: New Launcher and JPackage RPMs
Date Thu, 15 Jan 2004 17:42:53 GMT
I am +1 to get this into ant 1.6.1.
Cheers,

Antoine

Peter Reilly wrote:

> Antoine Lévy-Lambert wrote:
>
>> Hi Peter,
>>
>> can we improve the new classloader so that the work of inspecting the 
>> jars does not happen each time an <antcall/> is done ?
>
>
> Yes by keeping a static map of file->manifest class path.
>
> With the following:
> <project default="call-all">
>  <taskdef resource="net/sf/antcontrib/antcontrib.properties" />
>  <taskdef resource="cpptasks.tasks"/>
>  <typedef resource="cpptasks.types"/>
>  <target name="call-all">
>    <foreach list="1,2,3,4,5,6,7,8,9,10" param="name" target="doit"/>
>    <echo>Done</echo>
>  </target>
>  <target name="doit">
>    <foreach list="1,2,3,4,5,6,7,8,9,10" param="name" target="doit2"/>
>  </target>
>  <target name="doit2"/>
> </project>
>
> and the included patch, the time is reduced from 6 seconds to 3 
> seconds - not
> a great improvement considering that there is 100 ant-calls, but it is 
> a improvement!
>
> Peter
>
>------------------------------------------------------------------------
>
>Index: src/main/org/apache/tools/ant/loader/AntClassLoader2.java
>===================================================================
>RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/loader/AntClassLoader2.java,v
>retrieving revision 1.7
>diff -u -r1.7 AntClassLoader2.java
>--- src/main/org/apache/tools/ant/loader/AntClassLoader2.java	17 Jul 2003 10:36:27 -0000
1.7
>+++ src/main/org/apache/tools/ant/loader/AntClassLoader2.java	15 Jan 2004 17:34:19 -0000
>@@ -1,7 +1,7 @@
> /*
>  * The Apache Software License, Version 1.1
>  *
>- * Copyright (c) 2003 The Apache Software Foundation.  All rights
>+ * Copyright (c) 2003-2004 The Apache Software Foundation.  All rights
>  * reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>@@ -68,6 +68,9 @@
> import java.net.URL;
> import java.net.MalformedURLException;
> import java.util.zip.ZipEntry;
>+import java.util.Collections;
>+import java.util.HashMap;
>+import java.util.Map;
> import java.util.StringTokenizer;
> import org.apache.tools.ant.util.FileUtils;
> 
>@@ -81,6 +84,9 @@
>     /** Instance of a utility class to use for file operations. */
>     private FileUtils fileUtils;
> 
>+    /** Static map of jar file/time to manifiest class-path entries */
>+    private static Map pathMap = Collections.synchronizedMap(new HashMap());
>+
>     /**
>      * Constructor
>      */
>@@ -272,36 +278,46 @@
>             return;
>         }
> 
>+        String absPathPlusTimeAndLength =
>+            pathComponent.getAbsolutePath() + pathComponent.lastModified() + "-"
>+            + pathComponent.length();
>         String classpath = null;
>-        ZipFile jarFile = null;
>-        InputStream manifestStream = null;
>-        try {
>-            jarFile = new ZipFile(pathComponent);
>-            manifestStream
>-                = jarFile.getInputStream(new ZipEntry("META-INF/MANIFEST.MF"));
>-
>-            if (manifestStream == null) {
>-                return;
>-            }
>-            Reader manifestReader
>-                = new InputStreamReader(manifestStream, "UTF-8");
>-            org.apache.tools.ant.taskdefs.Manifest manifest
>-                = new org.apache.tools.ant.taskdefs.Manifest(manifestReader);
>-            classpath
>-                = manifest.getMainSection().getAttributeValue("Class-Path");
>+                classpath = (String) pathMap.get(absPathPlusTimeAndLength);
>+        if (classpath == null) {
>+            ZipFile jarFile = null;
>+            InputStream manifestStream = null;
>+            try {
>+                jarFile = new ZipFile(pathComponent);
>+                manifestStream
>+                    = jarFile.getInputStream(new ZipEntry("META-INF/MANIFEST.MF"));
>+
>+                if (manifestStream == null) {
>+                    return;
>+                }
>+                Reader manifestReader
>+                    = new InputStreamReader(manifestStream, "UTF-8");
>+                org.apache.tools.ant.taskdefs.Manifest manifest
>+                    = new org.apache.tools.ant.taskdefs.Manifest(manifestReader);
>+                classpath
>+                    = manifest.getMainSection().getAttributeValue("Class-Path");
> 
>-        } catch (org.apache.tools.ant.taskdefs.ManifestException e) {
>-            // ignore
>-        } finally {
>-            if (manifestStream != null) {
>-                manifestStream.close();
>+            } catch (org.apache.tools.ant.taskdefs.ManifestException e) {
>+                // ignore
>+            } finally {
>+                if (manifestStream != null) {
>+                    manifestStream.close();
>+                }
>+                if (jarFile != null) {
>+                    jarFile.close();
>+                }
>             }
>-            if (jarFile != null) {
>-                jarFile.close();
>+            if (classpath == null) {
>+                classpath = "";
>             }
>+            pathMap.put(absPathPlusTimeAndLength, classpath);
>         }
> 
>-        if (classpath != null) {
>+        if (!"".equals(classpath)) {
>             URL baseURL = fileUtils.getFileURL(pathComponent);
>             StringTokenizer st = new StringTokenizer(classpath);
>             while (st.hasMoreTokens()) {
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>For additional commands, e-mail: dev-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message