git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1554758 13f79535-47bb-0310-9956-ffa450edef68master
@@ -40,6 +40,11 @@ Fixed bugs: | |||||
explicitly disable caching to avoid problems with reloading jars. | explicitly disable caching to avoid problems with reloading jars. | ||||
Bugzilla Report 54473 | 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: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -41,6 +41,7 @@ import java.util.jar.Attributes.Name; | |||||
import java.util.jar.JarEntry; | import java.util.jar.JarEntry; | ||||
import java.util.jar.JarFile; | import java.util.jar.JarFile; | ||||
import java.util.jar.Manifest; | import java.util.jar.Manifest; | ||||
import java.util.zip.ZipException; | |||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
import org.apache.tools.ant.util.CollectionUtils; | import org.apache.tools.ant.util.CollectionUtils; | ||||
import org.apache.tools.ant.util.FileUtils; | import org.apache.tools.ant.util.FileUtils; | ||||
@@ -1003,7 +1004,19 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
} else { | } else { | ||||
if (jarFile == null) { | if (jarFile == null) { | ||||
if (file.exists()) { | 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); | jarFiles.put(file, jarFile); | ||||
} else { | } else { | ||||
return null; | return null; | ||||
@@ -345,4 +345,24 @@ public class BTest extends TestCase { | |||||
<test name="T2" methods="ok" /> | <test name="T2" methods="ok" /> | ||||
</junit> | </junit> | ||||
</target> | </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> | </project> |
@@ -168,13 +168,13 @@ public class AntClassLoaderTest extends BuildFileTest { | |||||
System.setErr(err); | System.setErr(err); | ||||
loader.getResource("foo.txt"); | loader.getResource("foo.txt"); | ||||
String log = getLog(); | String log = getLog(); | ||||
int startMessage = log.indexOf("Unable to obtain resource from "); | |||||
int startMessage = log.indexOf("CLASSPATH element "); | |||||
assertTrue(startMessage >= 0); | assertTrue(startMessage >= 0); | ||||
assertTrue(log.indexOf("foo.jar", startMessage) > 0); | |||||
assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0); | |||||
log = errBuffer.toString(); | log = errBuffer.toString(); | ||||
startMessage = log.indexOf("Unable to obtain resource from "); | |||||
startMessage = log.indexOf("CLASSPATH element "); | |||||
assertTrue(startMessage >= 0); | assertTrue(startMessage >= 0); | ||||
assertTrue(log.indexOf("foo.jar", startMessage) > 0); | |||||
assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0); | |||||
} finally { | } finally { | ||||
System.setErr(sysErr); | System.setErr(sysErr); | ||||
} | } | ||||