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 2014/01/02 08:22:39 UTC

svn commit: r1554758 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/AntClassLoader.java src/tests/antunit/taskdefs/optional/junit/junit-test.xml src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java

Author: bodewig
Date: Thu Jan  2 07:22:39 2014
New Revision: 1554758

URL: http://svn.apache.org/r1554758
Log:
deal more gracefully with non-JARs on the CLASSPATH - PR 53964

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java
    ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1554758&r1=1554757&r2=1554758&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Jan  2 07:22:39 2014
@@ -40,6 +40,11 @@ Fixed bugs:
    explicitly disable caching to avoid problems with reloading jars.
    Bugzilla Report 54473
 
+ * AntClassloader will now ignore files that are part of the classpath but
+   not valid zip files when scanning for resources.  It used to throw
+   an exception.
+   Bugzilla Report 53964
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java?rev=1554758&r1=1554757&r2=1554758&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java Thu Jan  2 07:22:39 2014
@@ -41,6 +41,7 @@ import java.util.jar.Attributes.Name;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
+import java.util.zip.ZipException;
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.util.CollectionUtils;
 import org.apache.tools.ant.util.FileUtils;
@@ -1003,7 +1004,19 @@ public class AntClassLoader extends Clas
             } else {
                 if (jarFile == null) {
                     if (file.exists()) {
-                        jarFile = new JarFile(file);
+                        try {
+                            jarFile = new JarFile(file);
+                        } catch (ZipException notAJar) {
+                            // raised if a file that is not a ZIP
+                            // happens to be part of the classpath -
+                            // this obviously cannot contain the
+                            // resource
+                            String msg = "CLASSPATH element " + file
+                                + " is not a JAR.";
+                            log(msg, Project.MSG_WARN);
+                            System.err.println(msg);
+                            return null;
+                        }
                         jarFiles.put(file, jarFile);
                     } else {
                         return null;

Modified: ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml?rev=1554758&r1=1554757&r2=1554758&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/optional/junit/junit-test.xml Thu Jan  2 07:22:39 2014
@@ -345,4 +345,24 @@ public class BTest extends TestCase {
       <test name="T2" methods="ok" />
     </junit>
   </target>
+
+  <target name="testClasspathBuildingSurvivesNonZips" depends="setUp"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53964">
+    <empty-test classname="ATest" package="org.apache.ant.test" />
+    <javac srcdir="${input}" destdir="${output}">
+      <classpath refid="junit" />
+    </javac>
+    <junit fork="true" printsummary="true" haltonerror="true">
+      <classpath>
+        <pathelement location="${output}" />
+        <pathelement location="${ant.file}" />
+        <path refid="junit" />
+      </classpath>
+      <batchtest>
+        <fileset dir="${output}">
+          <include name="**/*Test.class" />
+        </fileset>
+      </batchtest>
+    </junit>
+  </target>
 </project>

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java?rev=1554758&r1=1554757&r2=1554758&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java Thu Jan  2 07:22:39 2014
@@ -168,13 +168,13 @@ public class AntClassLoaderTest extends 
             System.setErr(err);
             loader.getResource("foo.txt");
             String log = getLog();
-            int startMessage = log.indexOf("Unable to obtain resource from ");
+            int startMessage = log.indexOf("CLASSPATH element ");
             assertTrue(startMessage >= 0);
-            assertTrue(log.indexOf("foo.jar", startMessage) > 0);
+            assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
             log = errBuffer.toString();
-            startMessage = log.indexOf("Unable to obtain resource from ");
+            startMessage = log.indexOf("CLASSPATH element ");
             assertTrue(startMessage >= 0);
-            assertTrue(log.indexOf("foo.jar", startMessage) > 0);
+            assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0);
         } finally {
             System.setErr(sysErr);
         }



Re: svn commit: r1554758 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/AntClassLoader.java src/tests/antunit/taskdefs/optional/junit/junit-test.xml src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 2014-01-02, Jesse Glick wrote:

> On Thu, Jan 2, 2014 at 2:22 AM,  <bo...@apache.org> wrote:
>+                        try {
>+                            jarFile = new JarFile(file);
>+                        } catch (ZipException notAJar) {
>+                            // raised if a file that is not a ZIP

> Would also be thrown if the file _is_ a ZIP file but there was some
> (potentially significant) error opening it.

Right.

> Could consider checking the file header for the magic sequence {0x50,
> 0x4b, 0x03, 0x04} and rethrowing the exception. (Have observed {0x50,
> 0x4b, 0x05, 0x06} in empty archives as well,

or PK00.  I know, I spent some time with the format :-)

You are right, of course, will port over ZipArchiveInputStream#matches
from Commons Compress.

Stefan

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


Re: svn commit: r1554758 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/AntClassLoader.java src/tests/antunit/taskdefs/optional/junit/junit-test.xml src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java

Posted by Jesse Glick <ty...@gmail.com>.
On Thu, Jan 2, 2014 at 2:22 AM,  <bo...@apache.org> wrote:
> +                        try {
> +                            jarFile = new JarFile(file);
> +                        } catch (ZipException notAJar) {
> +                            // raised if a file that is not a ZIP

Would also be thrown if the file _is_ a ZIP file but there was some
(potentially significant) error opening it. Could consider checking
the file header for the magic sequence {0x50, 0x4b, 0x03, 0x04} and
rethrowing the exception. (Have observed {0x50, 0x4b, 0x05, 0x06} in
empty archives as well, so maybe just check for {0x50, 0x4b} i.e.
"PK".)

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