You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2010/09/27 16:33:08 UTC

svn commit: r1001756 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/helper/ProjectHelper2.java src/main/org/apache/tools/ant/launch/Locator.java src/tests/antunit/taskdefs/taskdef-test.xml

Author: bodewig
Date: Mon Sep 27 14:33:08 2010
New Revision: 1001756

URL: http://svn.apache.org/viewvc?rev=1001756&view=rev
Log:
according to the javadocs of JarURLConnection the separator is !/ not ! - this allows dealing with jars in directories that contain a ! in their name, as long as it is not at the end of the directory name.  PR 50007

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/taskdef-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1001756&r1=1001755&r2=1001756&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Sep 27 14:33:08 2010
@@ -153,6 +153,10 @@ Fixed bugs:
  * runant.py would swallow the first argument if CLASSPATH wasn't set.
    Bugzilla Report 49963.
 
+ * <taskdef> failed to load resources from jar files contained in a
+   directory that has a "!" in its name.
+   Bugzilla Report 50007.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java?rev=1001756&r1=1001755&r2=1001756&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Mon Sep 27 14:33:08 2010
@@ -279,7 +279,7 @@ public class ProjectHelper2 extends Proj
                 uri = url.toString();
                 int pling = -1;
                 if (uri.startsWith("jar:file")
-                    && (pling = uri.indexOf("!")) > -1) {
+                    && (pling = uri.indexOf("!/")) > -1) {
                     zf = new ZipFile(org.apache.tools.ant.launch.Locator
                                      .fromJarURI(uri), "UTF-8");
                     inputStream =

Modified: ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java?rev=1001756&r1=1001755&r2=1001756&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/launch/Locator.java Mon Sep 27 14:33:08 2010
@@ -281,7 +281,7 @@ public final class Locator {
      * @since Ant1.7.1
      */
     public static String fromJarURI(String uri) {
-        int pling = uri.indexOf('!');
+        int pling = uri.indexOf("!/");
         String jarName = uri.substring("jar:".length(), pling);
         return fromURI(jarName);
     }

Added: ant/core/trunk/src/tests/antunit/taskdefs/taskdef-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/taskdef-test.xml?rev=1001756&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/taskdef-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/taskdef-test.xml Mon Sep 27 14:33:08 2010
@@ -0,0 +1,107 @@
+<?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" />
+
+  <target name="setUp">
+    <mkdir dir="${input}/org/example"/>
+    <echoxml file="${input}/org/example/antlib.xml">
+      <antlib>
+        <taskdef name="echooo"
+                 classname="org.apache.tools.ant.taskdefs.Echo"/>
+      </antlib>
+    </echoxml>
+  </target>
+
+  <target name="testPlainDir" depends="setUp">
+    <tempfile property="jar" deleteonexit="true"
+              destdir="${java.io.tmpdir}" prefix="test" suffix=".jar"/>
+    <jar destfile="${jar}">
+      <fileset dir="${input}"/>
+    </jar>
+    <taskdef resource="org/example/antlib.xml"
+             classpath="${jar}"
+             uri="urn:test:plain"/>
+    <echooo xmlns="urn:test:plain">Hello</echooo>
+    <au:assertLogContains text="Hello"/>
+  </target>
+
+  <target name="testDirWithPling" depends="setUp"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50007">
+    <property name="dir" location="${java.io.tmpdir}/pl!ng"/>
+    <mkdir dir="${dir}"/>
+    <tempfile property="jar" deleteonexit="true" destdir="${dir}"
+              prefix="test" suffix=".jar"/>
+    <jar destfile="${jar}">
+      <fileset dir="${input}"/>
+    </jar>
+    <taskdef resource="org/example/antlib.xml"
+             classpath="${jar}"
+             uri="urn:test:indir"/>
+    <echooo xmlns="urn:test:indir">Hello</echooo>
+    <au:assertLogContains text="Hello"/>
+  </target>
+
+  <!-- fails because URLConnection.connect() fails on the JAR URL returned
+       by ClassLoader.getResources() -->
+  <target name="NOtestDirWithPlingAtEnd" depends="setUp"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50007">
+    <property name="dir" location="${java.io.tmpdir}/pling!"/>
+    <mkdir dir="${dir}"/>
+    <tempfile property="jar" deleteonexit="true" destdir="${dir}"
+              prefix="test" suffix=".jar"/>
+    <jar destfile="${jar}">
+      <fileset dir="${input}"/>
+    </jar>
+    <taskdef resource="org/example/antlib.xml"
+             classpath="${jar}"
+             uri="urn:test:atend"/>
+    <echooo xmlns="urn:test:atend">Hello</echooo>
+    <au:assertLogContains text="Hello"/>
+  </target>
+
+  <target name="testPlingInJar" depends="setUp">
+    <tempfile property="jar" deleteonexit="true"
+              destdir="${java.io.tmpdir}" prefix="test" suffix=".jar"/>
+    <move file="${input}/org/example/antlib.xml"
+          tofile="${input}/org/examp!e/antlib.xml"/>
+    <jar destfile="${jar}">
+      <fileset dir="${input}"/>
+    </jar>
+    <taskdef resource="org/examp!e/antlib.xml"
+             classpath="${jar}"
+             uri="urn:test:injar"/>
+    <echooo xmlns="urn:test:injar">Hello</echooo>
+    <au:assertLogContains text="Hello"/>
+  </target>
+
+  <target name="testPlingInJarAtEnd" depends="setUp">
+    <tempfile property="jar" deleteonexit="true"
+              destdir="${java.io.tmpdir}" prefix="test" suffix=".jar"/>
+    <move file="${input}/org/example/antlib.xml"
+          tofile="${input}/org/example!/antlib.xml"/>
+    <jar destfile="${jar}">
+      <fileset dir="${input}"/>
+    </jar>
+    <taskdef resource="org/example!/antlib.xml"
+             classpath="${jar}"
+             uri="urn:test:injaratend"/>
+    <echooo xmlns="urn:test:injaratend">Hello</echooo>
+    <au:assertLogContains text="Hello"/>
+  </target>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/taskdef-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Re: svn commit: r1001756 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/helper/ProjectHelper2.java src/main/org/apache/tools/ant/launch/Locator.java src/tests/antunit/taskdefs/taskdef-test.xml

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-09-27, Jesse Glick wrote:

> On 09/27/2010 10:49 AM, Stefan Bodewig wrote:
>>   (2) The new tests create JARs that will be loaded by a classloader -
>>     which means Ant cannot delete them because they remain locked until
>>     the JVM has exited.

> Can't this at least use something inside ${build.dir}, rather than
> ${java.io.tmpdir}?

Done.

> (And AntClassLoader should probably implement Closeable to match
> URLClassLoader

AntClassLoader5 could and in fact now does.

Stefan

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


Re: svn commit: r1001756 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/helper/ProjectHelper2.java src/main/org/apache/tools/ant/launch/Locator.java src/tests/antunit/taskdefs/taskdef-test.xml

Posted by Jesse Glick <je...@oracle.com>.
On 09/27/2010 10:49 AM, Stefan Bodewig wrote:
>   (2) The new tests create JARs that will be loaded by a classloader -
>     which means Ant cannot delete them because they remain locked until
>     the JVM has exited.

Can't this at least use something inside ${build.dir}, rather than ${java.io.tmpdir}?

Maybe <classloader reset="true" ...> could be used, if the to-do comment in it to close the old loader were implemented? Or a project when finishing a build could close 
all of its outstanding class loader references automatically?

(And AntClassLoader should probably implement Closeable to match URLClassLoader and "automatic resource management" <https://docs.google.com/View?id=ddv8ts74_3fs7483dp> 
in JDK 7!)


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


Re: svn commit: r1001756 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/helper/ProjectHelper2.java src/main/org/apache/tools/ant/launch/Locator.java src/tests/antunit/taskdefs/taskdef-test.xml

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-09-27, <bo...@apache.org> wrote:

> according to the javadocs of JarURLConnection the separator is !/ not
> ! - this allows dealing with jars in directories that contain a ! in
> their name, as long as it is not at the end of the directory name.

This deals with splitting jar:file:somwhere/jar.file!/some/resource into
the jar's URL and the relative resource.  We used to split at
indexOf("!") and the code now splits at indexOf("!/") which is the
official separator.

Two things to note:

 (1) there is a disabled testcase for when "somewhere" in the URL above
   ends with a "!".  Classloader.getResources("something") happily
   returns an URL that JarURLConnection cannot deal with - it looks as
   if Sun's code was performing the same naive indexOf("!/") that our
   code now uses.

   I'm not conviced that we can fix that (we could try to figure out the
   file part in special cases like the <taskdef> test and perform
   %-escaping if that works) or that we even want to.

 (2) The new tests create JARs that will be loaded by a classloader -
   which means Ant cannot delete them because they remain locked until
   the JVM has exited.  This means the tests accumulate a lot of garbage
   in ${TEMP} over time.

Stefan

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