git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@799650 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -415,6 +415,11 @@ Fixed bugs: | |||||
| * AntClassLoader didn't set the proper CodeSource for loaded classes. | * AntClassLoader didn't set the proper CodeSource for loaded classes. | ||||
| Bugzilla Report 20174. | Bugzilla Report 20174. | ||||
| * AntClassLoader.getResourceAsStream would return streams to | |||||
| resources it didn't return with getResource and to classes it | |||||
| failed to load. | |||||
| Bugzilla Report 44103. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| * The get task now also follows redirects from http to https | * The get task now also follows redirects from http to https | ||||
| @@ -705,6 +705,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
| InputStream resourceStream = null; | InputStream resourceStream = null; | ||||
| if (isParentFirst(name)) { | if (isParentFirst(name)) { | ||||
| resourceStream = loadBaseResource(name); | resourceStream = loadBaseResource(name); | ||||
| } | |||||
| if (resourceStream != null) { | if (resourceStream != null) { | ||||
| log("ResourceStream for " + name | log("ResourceStream for " + name | ||||
| + " loaded from parent loader", Project.MSG_DEBUG); | + " loaded from parent loader", Project.MSG_DEBUG); | ||||
| @@ -715,17 +716,16 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
| + " loaded from ant loader", Project.MSG_DEBUG); | + " loaded from ant loader", Project.MSG_DEBUG); | ||||
| } | } | ||||
| } | } | ||||
| } else { | |||||
| resourceStream = loadResource(name); | |||||
| if (resourceStream != null) { | |||||
| log("ResourceStream for " + name + " loaded from ant loader", Project.MSG_DEBUG); | |||||
| if (resourceStream == null && !isParentFirst(name)) { | |||||
| if (ignoreBase) { | |||||
| resourceStream = getRootLoader() == null ? null : getRootLoader().getResourceAsStream(name); | |||||
| } else { | } else { | ||||
| resourceStream = loadBaseResource(name); | resourceStream = loadBaseResource(name); | ||||
| } | |||||
| if (resourceStream != null) { | if (resourceStream != null) { | ||||
| log("ResourceStream for " + name + " loaded from parent loader", | log("ResourceStream for " + name + " loaded from parent loader", | ||||
| Project.MSG_DEBUG); | Project.MSG_DEBUG); | ||||
| } | } | ||||
| } | |||||
| } | } | ||||
| if (resourceStream == null) { | if (resourceStream == null) { | ||||
| log("Couldn't load ResourceStream for " + name, Project.MSG_DEBUG); | log("Couldn't load ResourceStream for " + name, Project.MSG_DEBUG); | ||||
| @@ -766,7 +766,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener { | |||||
| * the resource cannot be found. | * the resource cannot be found. | ||||
| */ | */ | ||||
| private InputStream loadBaseResource(String name) { | private InputStream loadBaseResource(String name) { | ||||
| return parent == null ? getSystemResourceAsStream(name) : parent.getResourceAsStream(name); | |||||
| return parent == null ? super.getResourceAsStream(name) : parent.getResourceAsStream(name); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -0,0 +1,83 @@ | |||||
| <?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 xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> | |||||
| <import file="../antunit-base.xml"/> | |||||
| <target name="setUp"> | |||||
| <mkdir dir="${input}"/> | |||||
| <mkdir dir="${output}"/> | |||||
| </target> | |||||
| <target name="testGetResource" | |||||
| description="https://issues.apache.org/bugzilla/show_bug.cgi?id=44103" | |||||
| depends="setUp"> | |||||
| <echo file="${input}/A.java"><![CDATA[ | |||||
| public class A { | |||||
| public static void main(String[] args) { | |||||
| if (A.class.getClassLoader().getResource("org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.class") != null) { | |||||
| throw new RuntimeException("Didn't expect to find DocumenBuilderImpl"); | |||||
| } | |||||
| } | |||||
| } | |||||
| ]]></echo> | |||||
| <javac srcdir="${input}" destdir="${output}"/> | |||||
| <java classname="A" failonerror="true" fork="false"> | |||||
| <classpath location="${output}"/> | |||||
| </java> | |||||
| </target> | |||||
| <target name="testLoadClass" | |||||
| description="https://issues.apache.org/bugzilla/show_bug.cgi?id=44103" | |||||
| depends="setUp"> | |||||
| <echo file="${input}/A.java"><![CDATA[ | |||||
| public class A { | |||||
| public static void main(String[] args) { | |||||
| try { | |||||
| A.class.getClassLoader().loadClass("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); | |||||
| throw new RuntimeException("Didn't expect to find DocumenBuilderImpl"); | |||||
| } catch (ClassNotFoundException cnfe) { | |||||
| } | |||||
| } | |||||
| } | |||||
| ]]></echo> | |||||
| <javac srcdir="${input}" destdir="${output}"/> | |||||
| <java classname="A" failonerror="true" fork="false"> | |||||
| <classpath location="${output}"/> | |||||
| </java> | |||||
| </target> | |||||
| <target name="testGetResourceAsStream" | |||||
| description="https://issues.apache.org/bugzilla/show_bug.cgi?id=44103" | |||||
| depends="setUp"> | |||||
| <echo file="${input}/A.java"><![CDATA[ | |||||
| public class A { | |||||
| public static void main(String[] args) { | |||||
| if (A.class.getClassLoader().getResourceAsStream("org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.class") != null) { | |||||
| throw new RuntimeException("Didn't expect to find DocumenBuilderImpl"); | |||||
| } | |||||
| } | |||||
| } | |||||
| ]]></echo> | |||||
| <javac srcdir="${input}" destdir="${output}"/> | |||||
| <java classname="A" failonerror="true" fork="false"> | |||||
| <classpath location="${output}"/> | |||||
| </java> | |||||
| </target> | |||||
| </project> | |||||