Browse Source

deal more gracefully with non-JARs on the CLASSPATH - PR 53964

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1554758 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
9bd753321a
4 changed files with 43 additions and 5 deletions
  1. +5
    -0
      WHATSNEW
  2. +14
    -1
      src/main/org/apache/tools/ant/AntClassLoader.java
  3. +20
    -0
      src/tests/antunit/taskdefs/optional/junit/junit-test.xml
  4. +4
    -4
      src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java

+ 5
- 0
WHATSNEW View File

@@ -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:
--------------



+ 14
- 1
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -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 ClassLoader implements SubBuildListener {
} 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;


+ 20
- 0
src/tests/antunit/taskdefs/optional/junit/junit-test.xml View File

@@ -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>

+ 4
- 4
src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java View File

@@ -168,13 +168,13 @@ public class AntClassLoaderTest extends BuildFileTest {
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);
}


Loading…
Cancel
Save