[jboss-cvs] JBossAS SVN: r111993 - in projects/jboss-cl/branches/Branch_2_0: classloader/src/main/java/org/jboss/classloader/spi/base and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 10 20:41:21 EDT 2011
Author: bmaxwell
Date: 2011-08-10 20:41:20 -0400 (Wed, 10 Aug 2011)
New Revision: 111993
Added:
projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824DefaultTestCase.java
projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824EnabledTestCase.java
projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824TestBase.java
Modified:
projects/jboss-cl/branches/Branch_2_0/
projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
projects/jboss-cl/branches/Branch_2_0/pom.xml
Log:
[JBPAPP-6824] adding system property -Dorg.jboss.classloader.honor.resource.delegation=true to allow resource delegation to work
Property changes on: projects/jboss-cl/branches/Branch_2_0
___________________________________________________________________
Modified: svn:mergeinfo
- /projects/jboss-cl/trunk:111484
+ /projects/jboss-cl/branches/2.0.9.GA_JBPAPP-6927:111894
/projects/jboss-cl/trunk:111484
Modified: projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java 2011-08-10 20:54:27 UTC (rev 111992)
+++ projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java 2011-08-11 00:41:20 UTC (rev 111993)
@@ -84,7 +84,18 @@
/** Keep track of the added order */
private int order = 0;
-
+
+ // JBPAPP-6824 - getResource when parent-first=true returns resource from child
+ private static final Boolean honorResourceDelegation = java.security.AccessController.doPrivileged (
+ new java.security.PrivilegedAction<Boolean>()
+ {
+ public Boolean run()
+ {
+ return Boolean.valueOf ( System.getProperty("org.jboss.classloader.honor.resource.delegation", "false") );
+ }
+ }
+ );
+
/**
* Flush the internal caches
*/
@@ -411,12 +422,22 @@
{
boolean trace = log.isTraceEnabled();
+ URL result = null;
+
+ if( honorResourceDelegation == true )
+ {
+ // Try the before attempt
+ result = beforeGetResource(name);
+ if (result != null)
+ return result;
+ }
+
// Try the classloader first
if (classLoader != null)
{
if (trace)
log.trace(this + " trying to get resource " + name + " from requesting " + classLoader);
- URL result = classLoader.getResourceLocally(name);
+ result = classLoader.getResourceLocally(name);
if (result != null)
{
if (trace)
@@ -428,21 +449,25 @@
if (getClassLoaderSystem() == null)
throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
- // Try the before attempt
- URL result = beforeGetResource(name);
- if (result != null)
- return result;
+ if( ! honorResourceDelegation )
+ {
+ // Try the before attempt
+ result = beforeGetResource(name);
+ if (result != null)
+ return result;
+ }
// Work out the rules
ClassLoaderInformation info = null;
- BaseClassLoaderPolicy policy;
+ BaseClassLoaderPolicy policy;
+
if (classLoader != null)
{
policy = classLoader.getPolicy();
info = infos.get(classLoader);
if (policy.isImportAll())
allExports = true;
- }
+ }
// Next we try the old "big ball of mud" model
if (allExports)
Added: projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824DefaultTestCase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824DefaultTestCase.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824DefaultTestCase.java 2011-08-11 00:41:20 UTC (rev 111993)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classloader.resources.tests;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.test.classloader.domain.support.MockLoader;
+import org.jboss.test.classloader.domain.test.ParentPolicyUnitTestCase;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+// extending base class, this is because maven will not run tests in a testcase in a separate jvm which is needed to test system property
+public class JBPAPP6824DefaultTestCase extends JBPAPP6824TestBase
+{
+ private String SYSTEM_PROPERTY = "org.jboss.classloader.honor.resource.delegation";
+ private ClassLoader previousClassLoader;
+
+ public JBPAPP6824DefaultTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(JBPAPP6824DefaultTestCase.class);
+ }
+
+ // from org.jboss.test.classloader.resources.tests.ResourceUnitTestCase extends org.jboss.test.classloader.AbstractClassLoaderTestWithSecurity
+ public void testGetResourceFromParentBefore() throws Exception
+ {
+ System.out.println("property: " + getSystemProperty());
+ setSystemProperty(SYSTEM_PROPERTY, "false");
+ System.out.println("property after set: " + getSystemProperty());
+
+ try
+ {
+ // prefix is only on MockClassLoaderPolicy, it looks like it is just used to verify where the resource was found. So there will be two
+ // testResources in the same package but will be prefixed with a (parent) and b (child)
+ // The testResources are packaged in the resources directory, the policy is overriding getResource and prepending the prefix
+ ClassLoaderSystem system = createClassLoaderSystem();
+ ClassLoaderDomain parent = system.createAndRegisterDomain("parent");
+ MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
+ policy.setPrefix("a/");
+ policy.setPath("com/acme/p1");
+ policy.setPackageNames(new String[] { "com.acme.p1" } );
+ system.registerClassLoaderPolicy(parent, policy);
+
+ ClassLoaderDomain child = system.createAndRegisterDomain("child", ParentPolicy.BEFORE, parent);
+ MockClassLoaderPolicy policy2 = createMockClassLoaderPolicy();
+ policy2.setPrefix("b/");
+ policy2.setPath("com/acme/p1");
+ ClassLoader classLoader = system.registerClassLoaderPolicy(child, policy2);
+
+ assertGetResource("b/", "com/acme/p1/testResource", classLoader);
+ }
+ finally
+ {
+ }
+ }
+}
Added: projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824EnabledTestCase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824EnabledTestCase.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824EnabledTestCase.java 2011-08-11 00:41:20 UTC (rev 111993)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classloader.resources.tests;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.test.classloader.domain.support.MockLoader;
+import org.jboss.test.classloader.domain.test.ParentPolicyUnitTestCase;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+// extending base class, this is because maven will not run tests in a testcase in a separate jvm which is needed to test system property
+public class JBPAPP6824EnabledTestCase extends JBPAPP6824TestBase
+{
+ private String SYSTEM_PROPERTY = "org.jboss.classloader.honor.resource.delegation";
+ private ClassLoader previousClassLoader;
+
+ public JBPAPP6824EnabledTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(JBPAPP6824EnabledTestCase.class);
+ }
+
+ // base on org.jboss.test.classloader.resources.tests.ResourceUnitTestCase extends org.jboss.test.classloader.AbstractClassLoaderTestWithSecurity
+ public void testGetResourceFromParentBeforeJBPAPP682() throws Exception
+ {
+ System.out.println("property: " + getSystemProperty());
+ setSystemProperty(SYSTEM_PROPERTY, "true");
+ System.out.println("property after: " + getSystemProperty());
+ System.out.println("Classloader type: " + Thread.currentThread().getContextClassLoader().getClass());
+
+ try
+ {
+ // prefix is only on MockClassLoaderPolicy, it looks like it is just used to verify where the resource was found. So there will be two
+ // testResources in the same package but will be prefixed with a (parent) and b (child)
+ // The testResources are packaged in the resources directory, the policy is overriding getResource and prepending the prefix
+ ClassLoaderSystem system = createClassLoaderSystem();
+ ClassLoaderDomain parent = system.createAndRegisterDomain("parent");
+ MockClassLoaderPolicy policy = createMockClassLoaderPolicy();
+ policy.setPrefix("a/");
+ policy.setPath("com/acme/p1");
+ policy.setPackageNames(new String[] { "com.acme.p1" } );
+ system.registerClassLoaderPolicy(parent, policy);
+
+ ClassLoaderDomain child = system.createAndRegisterDomain("child", ParentPolicy.BEFORE, parent);
+ MockClassLoaderPolicy policy2 = createMockClassLoaderPolicy();
+ policy2.setPrefix("b/");
+ policy2.setPath("com/acme/p1");
+ ClassLoader classLoader = system.registerClassLoaderPolicy(child, policy2);
+
+ assertGetResource("a/", "com/acme/p1/testResource", classLoader);
+ }
+ finally
+ {
+ setSystemProperty(SYSTEM_PROPERTY, "false");
+ }
+ }
+}
Added: projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824TestBase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824TestBase.java (rev 0)
+++ projects/jboss-cl/branches/Branch_2_0/classloader/src/test/java/org/jboss/test/classloader/resources/tests/JBPAPP6824TestBase.java 2011-08-11 00:41:20 UTC (rev 111993)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.classloader.resources.tests;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.test.classloader.domain.support.MockLoader;
+import org.jboss.test.classloader.domain.test.ParentPolicyUnitTestCase;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+public class JBPAPP6824TestBase extends org.jboss.test.classloader.AbstractClassLoaderTestWithSecurity
+{
+ private String SYSTEM_PROPERTY = "org.jboss.classloader.honor.resource.delegation";
+ private ClassLoader previousClassLoader;
+
+ public JBPAPP6824TestBase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(JBPAPP6824TestBase.class);
+ }
+
+ protected void setSystemProperty(final String key, final String value)
+ {
+ SecurityManager sm = suspendSecurity();
+ try
+ {
+ java.security.AccessController.doPrivileged
+ (
+ new java.security.PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.setProperty(key, value);
+ }
+ }
+ );
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ }
+
+ protected Boolean getSystemProperty()
+ {
+ SecurityManager sm = suspendSecurity();
+
+ try
+ {
+ Boolean useCorrectParentFirstResourceLoading =
+ java.security.AccessController.doPrivileged
+ (
+ new java.security.PrivilegedAction<Boolean>()
+ {
+ public Boolean run()
+ {
+ Boolean value = Boolean.valueOf ( System.getProperty(SYSTEM_PROPERTY, "false") );
+ return value;
+ }
+ }
+ );
+ return useCorrectParentFirstResourceLoading;
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ }
+
+ protected URL assertGetResource(String prefix, String resourcePath, ClassLoader classLoader) throws Exception
+ {
+ URL url = classLoader.getResource(resourcePath);
+ assertNotNull("Should have got resource prefix=" + prefix + " resourcePath " + resourcePath + " from " + classLoader, url);
+ SecurityManager sm = suspendSecurity();
+ try
+ {
+ InputStream is = url.openStream();
+ try
+ {
+ InputStreamReader reader = new InputStreamReader(is);
+ char[] chars = new char[1000];
+ int count = 0;
+ int read = reader.read(chars);
+ while (read != -1)
+ {
+ count += read;
+ read = reader.read(chars, read, 1000 - read);
+ }
+ String string = new String(chars, 0, count);
+ assertEquals("Should have read the correct resource", prefix + resourcePath, string);
+ }
+ finally
+ {
+ is.close();
+ }
+ }
+ finally
+ {
+ resumeSecurity(sm);
+ }
+ return url;
+ }
+}
Modified: projects/jboss-cl/branches/Branch_2_0/pom.xml
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/pom.xml 2011-08-10 20:54:27 UTC (rev 111992)
+++ projects/jboss-cl/branches/Branch_2_0/pom.xml 2011-08-11 00:41:20 UTC (rev 111993)
@@ -89,9 +89,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <version>2.4.3</version>
+ <version>2.9</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <forkMode>always</forkMode>
+ <forkedProcessTimeoutInSeconds>10</forkedProcessTimeoutInSeconds>
<includes>
<include>org/jboss/test/**/*TestCase.java</include>
</includes>
More information about the jboss-cvs-commits
mailing list