[jboss-cvs] JBossAS SVN: r104734 - in projects/jboss-cl/trunk/classloading/src: test/java/org/jboss/test/classloading/dependency/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 12 13:59:39 EDT 2010
Author: alesj
Date: 2010-05-12 13:59:38 -0400 (Wed, 12 May 2010)
New Revision: 104734
Modified:
projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java
projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java
Log:
[JBCL-161]; properly handle package requirement filtering.
Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-12 17:38:56 UTC (rev 104733)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/dependency/policy/ClassLoaderPolicyModule.java 2010-05-12 17:59:38 UTC (rev 104734)
@@ -27,16 +27,12 @@
import java.util.List;
import org.jboss.classloader.plugins.loader.ClassLoaderToLoaderAdapter;
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.ClassLoaderPolicyFactory;
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.classloader.spi.DelegateLoader;
-import org.jboss.classloader.spi.Loader;
-import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.*;
import org.jboss.classloader.spi.base.BaseClassLoader;
import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
import org.jboss.classloader.spi.filter.LazyFilteredDelegateLoader;
import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
import org.jboss.classloading.spi.dependency.Domain;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
@@ -50,6 +46,7 @@
* ClassLoaderPolicyModule.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public abstract class ClassLoaderPolicyModule extends ClassLoadingMetaDataModule implements ClassLoaderPolicyFactory
@@ -263,7 +260,18 @@
Controller controller = context.getController();
DynamicClassLoaderPolicyFactory factory = new DynamicClassLoaderPolicyFactory(controller, domain, item);
- return new LazyFilteredDelegateLoader(factory);
+
+ Requirement requirement = item.getRequirement();
+ if (requirement instanceof PackageRequirement)
+ {
+ PackageRequirement pr = (PackageRequirement) requirement;
+ PackageClassFilter filter = PackageClassFilter.createPackageClassFilter(pr.getName());
+ return new FilteredDelegateLoader(factory, filter);
+ }
+ else
+ {
+ return new LazyFilteredDelegateLoader(factory);
+ }
}
@Override
@@ -278,7 +286,16 @@
return policy;
}
};
- PackageClassFilter filter = PackageClassFilter.createPackageClassFilter(determinePackageNames(true));
+ PackageClassFilter filter;
+ if (requirement instanceof PackageRequirement)
+ {
+ PackageRequirement pr = (PackageRequirement) requirement;
+ filter = PackageClassFilter.createPackageClassFilter(pr.getName());
+ }
+ else
+ {
+ filter = PackageClassFilter.createPackageClassFilter(determinePackageNames(true));
+ }
return new FilteredDelegateLoader(clpf, filter);
}
Modified: projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java 2010-05-12 17:38:56 UTC (rev 104733)
+++ projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/DynamicPackageUnitTestCase.java 2010-05-12 17:59:38 UTC (rev 104734)
@@ -21,18 +21,23 @@
*/
package org.jboss.test.classloading.dependency.test;
-import junit.framework.Test;
-
+import org.jboss.classloader.spi.ImportType;
import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.helpers.AbstractRequirement;
import org.jboss.classloading.spi.version.VersionRange;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+import junit.framework.Test;
+
/**
* ReExportPackageUnitTestCase.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class DynamicPackageUnitTestCase extends AbstractMockClassLoaderUnitTest
@@ -115,4 +120,83 @@
}
assertNoClassLoader(contextA1);
}
+
+ // deploy A first, B second
+ public void testDynamicImportAexportAandB1() throws Exception
+ {
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+
+ Requirement aPackage = factory.createRequirePackage(A.class.getPackage().getName(), null, false, false, true);
+ ((AbstractRequirement)aPackage).setImportType(ImportType.AFTER);
+
+ a.getRequirements().addRequirement(aPackage);
+ a.setPaths(A.class);
+ KernelControllerContext contextA = install(a);
+ try
+ {
+ MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+ b.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+ b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+ b.setPathsAndPackageNames(A.class, B.class);
+ KernelControllerContext contextB = install(b);
+ try
+ {
+ assertClassLoader(contextB); // force install
+
+ ClassLoader clA = assertClassLoader(contextA);
+ assertLoadClassFail(B.class, clA);
+ }
+ finally
+ {
+ uninstall(contextB);
+ }
+ assertNoClassLoader(contextB);
+ }
+ finally
+ {
+ uninstall(contextA);
+ }
+ assertNoClassLoader(contextA);
+ }
+
+ // deploy B first, then A
+ public void testDynamicImportAexportAandB2() throws Exception
+ {
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+ MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+ b.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+ b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+ b.setPathsAndPackageNames(A.class, B.class);
+ KernelControllerContext contextB = install(b);
+ try
+ {
+ assertClassLoader(contextB); // force CL install
+
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+
+ Requirement aPackage = factory.createRequirePackage(A.class.getPackage().getName(), null, false, false, true);
+ ((AbstractRequirement)aPackage).setImportType(ImportType.AFTER);
+
+ a.getRequirements().addRequirement(aPackage);
+ a.setPaths(A.class);
+ KernelControllerContext contextA = install(a);
+ try
+ {
+ ClassLoader clA = assertClassLoader(contextA);
+ assertLoadClassFail(B.class, clA);
+ }
+ finally
+ {
+ uninstall(contextA);
+ }
+ assertNoClassLoader(contextA);
+ }
+ finally
+ {
+ uninstall(contextB);
+ }
+ assertNoClassLoader(contextB);
+ }
}
Modified: projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java 2010-05-12 17:38:56 UTC (rev 104733)
+++ projects/jboss-cl/trunk/classloading/src/test/java/org/jboss/test/classloading/dependency/test/PackageDependencyUnitTestCase.java 2010-05-12 17:59:38 UTC (rev 104734)
@@ -21,8 +21,6 @@
*/
package org.jboss.test.classloading.dependency.test;
-import junit.framework.Test;
-
import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
import org.jboss.classloading.spi.version.VersionRange;
@@ -30,10 +28,13 @@
import org.jboss.test.classloading.dependency.support.a.A;
import org.jboss.test.classloading.dependency.support.b.B;
+import junit.framework.Test;
+
/**
* PackageDependencyUnitTestCase.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class PackageDependencyUnitTestCase extends AbstractMockClassLoaderUnitTest
@@ -168,4 +169,39 @@
}
assertNoClassLoader(contextA);
}
+
+ public void testImportAexportAandB() throws Exception
+ {
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+ MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+ b.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+ b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+ b.setPathsAndPackageNames(A.class, B.class);
+ KernelControllerContext contextB = install(b);
+ try
+ {
+ assertClassLoader(contextB); // force CL install
+
+ MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+ a.getRequirements().addRequirement(factory.createRequirePackage(A.class.getPackage().getName()));
+ a.setPaths(A.class);
+ KernelControllerContext contextA = install(a);
+ try
+ {
+ ClassLoader clA = assertClassLoader(contextA);
+ assertLoadClassFail(B.class, clA);
+ }
+ finally
+ {
+ uninstall(contextA);
+ }
+ assertNoClassLoader(contextA);
+ }
+ finally
+ {
+ uninstall(contextB);
+ }
+ assertNoClassLoader(contextB);
+ }
}
More information about the jboss-cvs-commits
mailing list