Author: peterreilly
Date: Mon Sep 4 15:39:06 2006
New Revision: 440199
URL: http://svn.apache.org/viewvc?view=rev&rev=440199
Log:
Bugzilla 38747: isolate resources in antclassloader when requested
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java
ant/core/trunk/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=440199&r1=440198&r2=440199
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Sep 4 15:39:06 2006
@@ -14,6 +14,7 @@
* Invalid hash code of Target causes XmlLogger to fail.
Bugzilla report 40207.
* Macro element did not include top level Text. Bugzilla report 36803.
+* AntClassLoader did not isolate resources when isolate was set. Bugzilla
report 38747.
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?view=diff&rev=440199&r1=440198&r2=440199
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/AntClassLoader.java Mon Sep 4
15:39:06 2006
@@ -33,6 +33,7 @@
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
@@ -205,7 +206,7 @@
*
* @see #setIsolated(boolean)
*/
- private boolean ignoreBase = false;
+ private boolean isolated = false;
/**
* The parent class loader, if one is given or can be determined.
@@ -601,7 +602,7 @@
* isolated mode.
*/
public synchronized void setIsolated(boolean isolated) {
- ignoreBase = isolated;
+ this.isolated = isolated;
}
/**
@@ -883,8 +884,6 @@
// designated to use a specific loader first
// (this one or the parent one)
- // XXX - shouldn't this always return false in isolated mode?
-
boolean useParentFirst = parentFirst;
for (Enumeration e = systemPackages.elements(); e.hasMoreElements();) {
@@ -1076,7 +1075,7 @@
log("Class " + classname + " loaded from ant loader",
Project.MSG_DEBUG);
} catch (ClassNotFoundException cnfe) {
- if (ignoreBase) {
+ if (isolated) {
throw cnfe;
}
theClass = findBaseClass(classname);
@@ -1540,7 +1539,8 @@
}
/**
- * Override ClassLoader.getResources() to handle the reverse case.
+ * Override ClassLoader.getResources() to handle the reverse case
+ * and the isolate case.
* @param name The resource name to seach for.
* @return an enumeration of URLs for the resources
* @exception IOException if I/O errors occurs.
@@ -1554,8 +1554,23 @@
parentEnum = new ClassLoader(){}.getResources(name);
}
Enumeration mine = findResources(name);
- return isParentFirst(name)
- ? CollectionUtils.append(parentEnum, mine)
- : CollectionUtils.append(mine, parentEnum);
+ boolean parentEnumFirst = isParentFirst(name);
+
+ if (isolated && !parentEnumFirst) {
+ return mine;
+ } else if (parentEnumFirst) {
+ return CollectionUtils.append(parentEnum, mine);
+ } else {
+ return CollectionUtils.append(mine, parentEnum);
+ }
}
+
+ /**
+ * Accessor for derived classloaders to access the path components.
+ * @return the pathcomponents.
+ */
+ protected List getPathComponents() {
+ return pathComponents;
+ }
+
}
Modified:
ant/core/trunk/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java?view=diff&rev=440199&r1=440198&r2=440199
==============================================================================
---
ant/core/trunk/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
(original)
+++
ant/core/trunk/src/testcases/org/apache/tools/ant/AntClassLoaderDelegationTest.java
Mon Sep 4 15:39:06 2006
@@ -77,6 +77,22 @@
Arrays.asList(new URL[] {urlFromPath, urlFromParent}),
enum2List(acl.getResources(TEST_RESOURCE)));
}
+
+ public void testFindIsolateResources() throws Exception {
+ String buildTestcases = System.getProperty("build.tests");
+ assertNotNull("defined ${build.tests}", buildTestcases);
+ assertTrue("have a dir " + buildTestcases, new
File(buildTestcases).isDirectory());
+ Path path = new Path(p, buildTestcases);
+ // A special parent loader which is not the system class loader:
+ ClassLoader parent = new ParentLoader();
+
+ URL urlFromPath = new URL(FILE_UTILS.toURI(buildTestcases) +
TEST_RESOURCE);
+ AntClassLoader acl = new AntClassLoader(parent, p, path, false);
+ acl.setIsolated(true);
+ assertEquals("correct resources (reverse delegation order)",
+ Arrays.asList(new URL[] {urlFromPath}),
+ enum2List(acl.getResources(TEST_RESOURCE)));
+ }
private static List enum2List(Enumeration e) {
// JDK 1.4: return Collections.list(e);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]