[jboss-cvs] JBossAS SVN: r91561 - in projects/jboss-classpool/trunk: src and 39 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 22 11:18:01 EDT 2009
Author: flavia.rainone at jboss.com
Date: 2009-07-22 11:17:59 -0400 (Wed, 22 Jul 2009)
New Revision: 91561
Added:
projects/jboss-classpool/trunk/pom.xml
projects/jboss-classpool/trunk/src/
projects/jboss-classpool/trunk/src/main/
projects/jboss-classpool/trunk/src/main/java/
projects/jboss-classpool/trunk/src/main/java/org/
projects/jboss-classpool/trunk/src/main/java/org/jboss/
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolDomain.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractIsLocalResourcePlugin.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractParentDelegationStrategy.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPoolDomain.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassLoaderUtils.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomain.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomainRegistry.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolSearchStrategy.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdapter.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdaptorFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePlugin.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassPoolToClassPoolDomainAdaptorFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultParentDelegationStrategy.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DelegatingClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePlugin.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactoryRegistry.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/NonDelegatingClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ParentDelegationStrategy.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/SecurityActions.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossDelegatingClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePlugin.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePluginFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/LoaderRepositoryUrlUtil.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedJBossClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedRepositoryClassLoaderHelper.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/SecurityActions.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvoker.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvokerPoolReference.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/DomainRegistry.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/RegisterModuleCallback.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ScopedJBoss5ClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/SecurityActions.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvoker.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvokerPoolReference.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/VFSClassLoaderDomainRegistry.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolDomain.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdapter.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdaptorFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClParentDelegationStrategy.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/SecurityActions.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPool.java
projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPoolFactory.java
projects/jboss-classpool/trunk/src/main/resources/
projects/jboss-classpool/trunk/src/main/resources/jbossorg-eula.txt
projects/jboss-classpool/trunk/src/test/
projects/jboss-classpool/trunk/src/test/java/
projects/jboss-classpool/trunk/src/test/java/org/
projects/jboss-classpool/trunk/src/test/java/org/jboss/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/common/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/common/ClassFactory.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalDomainSanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalParentLoaderSanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportModuleSanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportPackageSanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithRepositorySanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithUsesPackageSanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalDomainTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalParentLoaderTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithModuleDependencyTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithPackageDependencyTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportModuleTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportPackageTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReplaceReferencesTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithUsesPackageTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTest.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestDelegate.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestSuite.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/AlwaysWritablePermissionCollectionTestPolicyPlugin.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/BundleInfoBuilder.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/CapabilityInfo.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ModuleOrPackageInfo.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/NoMatchClassFilter.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/RequirementInfo.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/Result.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactory.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactoryFactory.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderPolicyModule.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/a/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/a/A.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/b/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/b/B.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/a/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/a/A.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/b/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/b/B.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/c/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/c/C.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/Invoked.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/Child.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/ChildCaller.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/Parent.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/ParentCaller.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTest.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTestDelegate.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/DelegatingClassPoolTestSuite.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/IsLocalResourcePluginFactoryTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentFirstDelegatingClassPoolTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentLastDelegatingClassPoolTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/SimpleDelegatingClassPoolTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/support/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassLoaderSanityTestCase.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestSuite.java
projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclDelegatingClassPoolTestCase.java
projects/jboss-classpool/trunk/src/test/resources/
projects/jboss-classpool/trunk/src/test/resources/log4j.xml
projects/jboss-classpool/trunk/src/test/resources/org/
projects/jboss-classpool/trunk/src/test/resources/org/jboss/
projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/
projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/
projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/
projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml
Modified:
projects/jboss-classpool/trunk/
Log:
Initial version of JBoss ClassPool project.
This project contains the classpool classes that were originally at the jboss-aop project. These classes have been adapted in such a way that there are no dependencies to JBoss AOP-related stuff.
Property changes on: projects/jboss-classpool/trunk
___________________________________________________________________
Name: svn:ignore
+ target
.settings
Added: projects/jboss-classpool/trunk/pom.xml
===================================================================
--- projects/jboss-classpool/trunk/pom.xml (rev 0)
+++ projects/jboss-classpool/trunk/pom.xml 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,284 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-classpool</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>JBoss ClassPool</name>
+ <url>http://www.jboss.org/jbossreflect</url>
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-classpool/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-classpool/trunk/</developerConnection>
+ <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/jboss-classpool/trunk/</url>
+ </scm>
+ <properties>
+ <version.jboss.common.core>2.2.12.GA</version.jboss.common.core>
+ <version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
+ <version.jboss.logging.log4j>2.0.5.GA</version.jboss.logging.log4j>
+ <version.javassist>3.10.0.GA</version.javassist>
+ <version.org.jboss.test>1.0.3.GA</version.org.jboss.test>
+ <version.junit>3.8</version.junit>
+ <version.jboss.profiler.jvmti>1.0.0.CR5</version.jboss.profiler.jvmti>
+ <version.org.jboss.cl>2.0.3.GA</version.org.jboss.cl>
+ <version.org.jboss.microcontainer.jboss-dependency>2.0.4.GA</version.org.jboss.microcontainer.jboss-dependency>
+ <version.org.jboss.mdr>2.0.1.GA</version.org.jboss.mdr>
+ <version.org.jboss.jbossas>5.1.0.GA</version.org.jboss.jbossas>
+ </properties>
+
+ <build>
+ <finalName>${artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ <executions>
+ <execution>
+ <id>test-jar</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <excludes>
+ <exclude>org/jboss/aop/junit/**</exclude>
+ <exclude>org/jboss/test/classpool/support/excluded/**</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.3</version>
+ <configuration>
+ <!-- <useSystemClassLoader>true</useSystemClassLoader> -->
+ <testFailureIgnore>true</testFailureIgnore>
+ <forkMode>always</forkMode>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <includes>
+ <include>org/jboss/test/**/*TestCase.class</include>
+ <include>org/jboss/test/**/*Test.class</include>
+ </includes>
+ <excludes>
+ <exclude>org/jboss/test/aop/integration/complex/test/ComplexImportMultipleVersionsUnitTestCase.class</exclude>
+ <!-- <exclude>org/jboss/test/**/*JBossClClassPoolTest.class</exclude> -->
+ </excludes>
+ <systemProperties>
+ <property>
+ <name>build.testlog</name>
+ <value>target/surefire-reports/tests.log</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <version>2.4.3</version>
+ <executions>
+ <execution>
+ <id>surefire-report</id>
+ <goals>
+ <goal>report-only</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.2</version>
+ <executions>
+ <execution>
+ <id>create-test-jars</id>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <phase>process-test-classes</phase>
+ <configuration>
+ <tasks>
+ <property name="test.jar.suffix" value="-test-classpool-"/>
+ <!-- <jar destfile="${project.build.directory}/${artifactId}${test.jar.suffix}a1.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/a/*.class"/> -->
+ <jar destfile="${project.build.directory}/a1.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/a/*.class"/>
+ <jar destfile="${project.build.directory}/a2.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/a/*.class"/>
+ <jar destfile="${project.build.directory}/b1.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/b/*.class"/>
+ <jar destfile="${project.build.directory}/b2.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/b/*.class"/>
+ <jar destfile="${project.build.directory}/c1.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/c/*.class"/>
+ <jar destfile="${project.build.directory}/c2.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/classpool/support/excluded/c/*.class"/>
+ <jar destfile="${project.build.directory}/replacereferences-parent.jar">
+ <fileset dir="${project.build.testOutputDirectory}">
+ <include name="org/jboss/test/classpool/support/excluded/replacereferences/**"/>
+ <exclude name="org/jboss/test/classpool/support/excluded/replacereferences/child/*.class"/>
+ </fileset>
+ </jar>
+ <jar destfile="${project.build.directory}/replacereferences-child.jar">
+ <fileset dir="${project.build.testOutputDirectory}">
+ <include name="org/jboss/test/classpool/support/excluded/replacereferences/**"/>
+ <exclude name="org/jboss/test/classpool/support/excluded/replacereferences/parent/ParentCaller.class"/>
+ </fileset>
+ </jar>
+ <delete dir="${project.build.testOutputDirectory}/org/jboss/test/classpool/support/excluded"/>
+
+ <jar destfile="${project.build.directory}/test-weaving-target.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/aop/classpool/jbosscl/weaving/support/excluded/target/*.class"/>
+ <jar destfile="${project.build.directory}/test-weaving-aspects.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/aop/classpool/jbosscl/weaving/support/excluded/aspects/*.class"/>
+ <jar destfile="${project.build.directory}/test-weaving-interceptions.jar"
+ basedir="${project.build.testOutputDirectory}"
+ includes="org/jboss/test/aop/classpool/jbosscl/weaving/support/excluded/interceptions/*.class"/>
+ <delete dir="${project.build.testOutputDirectory}/org/jboss/test/aop/classpool/jbosscl/weaving/support/excluded"/>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>${version.javassist}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <version>2.1.3.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>pluggable-instrumentor</artifactId>
+ <version>2.1.3.GA</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop-asintegration-core</artifactId>
+ <version>2.1.3.GA</version>
+ </dependency> -->
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>${version.jboss.logging.spi}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-mdr</artifactId>
+ <version>${version.org.jboss.mdr}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-dependency</artifactId>
+ <version>${version.org.jboss.microcontainer.jboss-dependency}</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloader</artifactId>
+ <version>${version.jboss.classloader}</version>
+ </dependency> -->
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ <version>${version.org.jboss.cl}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cl</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ <version>${version.org.jboss.cl}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-system-jmx</artifactId>
+ <version>${version.org.jboss.jbossas}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-main</artifactId>
+ <version>${version.org.jboss.jbossas}</version>
+ </dependency>
+ <!-- <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-j2se</artifactId>
+ <version>${version.org.jboss.jbossas}</version>
+ </dependency> -->
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>${version.org.jboss.test}</version>
+ <!-- <scope>compile</scope> -->
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit}</version>
+ <!-- <scope>compile</scope> -->
+ </dependency> <!-- <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>2.2.11.GA</version>
+ </dependency> -->
+ </dependencies>
+
+ <!-- site stuff -->
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.2</version>
+ <configuration>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
+ </links>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <developers>
+ <developer>
+ <name>Kabir Khan</name>
+ </developer>
+ <developer>
+ <name>Adrian Brock</name>
+ </developer>
+ <developer>
+ <name>Bill Burke</name>
+ </developer>
+ <developer>
+ <name>Flavia Rainone</name>
+ </developer>
+ </developers>
+</project>
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,411 @@
+package org.jboss.classpool;
+
+import java.util.Map;
+import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision: 1.1 $
+ *
+ */
+/**
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision: 86930 $
+ */
+public class AbstractClassPool extends ScopedClassPool
+{
+ protected final Logger logger = Logger.getLogger(this.getClass());
+
+ /** Classnames of classes that will be created - we do not want to look for these in other pools.
+ * The main use for this is when a class is created in a parent pool, and we then want to
+ * create a class with the same name in a parent-last child pool. As part of the create process
+ * javassist.ClassPool will check if that class is frozen (which in turn will call getCached()
+ * and get0()). If the classname exists in this map, get0() and getCached() should return null;
+ */
+ protected final ConcurrentHashMap<String, String> generatedClasses = new ConcurrentHashMap<String, String>();
+
+ protected final ConcurrentHashMap<String, Boolean> localResources = new ConcurrentHashMap<String, Boolean>();
+
+ /** Classnames of classes that have been loaded, but were not woven */
+ protected final ConcurrentHashMap<String, Boolean> loadedButNotWovenClasses = new ConcurrentHashMap<String, Boolean>();
+
+ /** Causes the AbstractClassPool.getCached() method to search all ClassPools registered in the repository */
+ public static final Class<SearchAllRegisteredLoadersSearchStrategy> SEARCH_ALL_STRATEGY = SearchAllRegisteredLoadersSearchStrategy.class;
+
+ /** Causes the AbstractClassPool.getCached() method to search only itself */
+ public static final Class<SearchLocalLoaderLoaderSearchStrategy> SEARCH_LOCAL_ONLY_STRATEGY = SearchLocalLoaderLoaderSearchStrategy.class;
+
+ private final ClassPoolSearchStrategy searchStrategy;
+
+ private final Map<AbstractClassPool, Boolean> children = new WeakHashMap<AbstractClassPool, Boolean>();
+
+ static
+ {
+ ClassPool.doPruning = false;
+ ClassPool.releaseUnmodifiedClassFile = false;
+ }
+
+ public AbstractClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ this(cl, src, repository, false);
+ }
+
+ protected AbstractClassPool(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ this(null, src, repository, true);
+ }
+
+ private AbstractClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, boolean isTemp)
+ {
+ this(cl, src, repository, SEARCH_ALL_STRATEGY, isTemp);
+ }
+
+ public AbstractClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, Class<? extends ClassPoolSearchStrategy> searchStrategy)
+ {
+ this(cl, src, repository, searchStrategy, false);
+ }
+
+ public AbstractClassPool(ClassPool src, ScopedClassPoolRepository repository, Class<? extends ClassPoolSearchStrategy> searchStrategy)
+ {
+ this(null, src, repository, searchStrategy, true);
+ }
+
+ private AbstractClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, Class<? extends ClassPoolSearchStrategy> searchStrategy, boolean isTemp)
+ {
+ super(cl, src, repository, isTemp);
+ if (searchStrategy == SEARCH_ALL_STRATEGY)
+ {
+ this.searchStrategy = new SearchAllRegisteredLoadersSearchStrategy();
+ }
+ else if (searchStrategy == SEARCH_LOCAL_ONLY_STRATEGY)
+ {
+ this.searchStrategy = new SearchLocalLoaderLoaderSearchStrategy();
+ }
+ else
+ {
+ try
+ {
+ this.searchStrategy = searchStrategy.newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error instantiating search strategy class " + searchStrategy, e);
+ }
+ }
+ if (logger.isTraceEnabled()) logger.trace(this + " creating pool for loader " + cl + " searchStrategy:" + this.searchStrategy + " isTemp:" + isTemp);
+
+ registerWithParent();
+ }
+
+ private void registerWithParent()
+ {
+ if (parent != null && parent instanceof AbstractClassPool)
+ {
+ ((AbstractClassPool)parent).children.put(this, Boolean.TRUE);
+ }
+ }
+
+ private void unregisterWithParent()
+ {
+ if (parent != null && parent instanceof AbstractClassPool)
+ {
+ ((AbstractClassPool)parent).children.remove(this);
+ }
+ }
+
+ public void registerGeneratedClass(String className)
+ {
+ generatedClasses.put(className, className);
+ }
+
+ public boolean isGeneratedClass(String className)
+ {
+ return generatedClasses.containsKey(className);
+ }
+
+ public void doneGeneratingClass(String className)
+ {
+ generatedClasses.remove(className);
+ }
+
+ public void close()
+ {
+ super.close();
+ unregisterWithParent();
+ repository.unregisterClassLoader(getClassLoader());
+// for (Iterator<AbstractClassPool> it = children.keySet().iterator() ; it.hasNext() ; )
+// {
+// AbstractClassPool child = it.next();
+// it.remove();
+// ClassLoader loader = child.getClassLoader();
+// if (loader != null)
+// {
+// AspectManager.instance().unregisterClassLoader(loader);
+// }
+// }
+ }
+
+ public CtClass getCached(String classname)
+ {
+ return searchStrategy.getCached(classname);
+ }
+
+ /**
+ * Make createCtClass public so that we can override it
+ */
+// @Override
+// public CtClass createCtClass(String classname, boolean useCache)
+// {
+// boolean trace = logger.isTraceEnabled();
+//
+// if (trace) logger.trace(this + " attempting to create CtClass " + classname);
+// CtClass clazz = super.createCtClass(classname, useCache);
+// if (trace) logger.trace(this + " created CtClass " + getClassPoolLogStringForClass(clazz));
+//
+// return clazz;
+// }
+
+ @Override
+ public void cacheCtClass(String classname, CtClass c, boolean dynamic)
+ {
+ boolean trace = logger.isTraceEnabled();
+ if (trace) logger.trace(this + " caching " + classname);
+ // TODO remove this true when ready
+ super.cacheCtClass(classname, c, true);
+ if (dynamic)
+ {
+ if (trace) logger.trace(this + " registering dynamic class " + classname);
+ doneGeneratingClass(classname);
+ String resourcename = getResourceName(classname);
+ localResources.put(resourcename, Boolean.TRUE);
+ }
+ }
+
+ protected boolean includeInGlobalSearch()
+ {
+ return true;
+ }
+
+ protected String getResourceName(String classname)
+ {
+ return ClassLoaderUtils.getResourceName(classname);
+ }
+
+ protected final boolean isLocalResource(String resourceName, boolean trace)
+ {
+ String classResourceName = resourceName;
+ Boolean isLocal = localResources.get(classResourceName);
+ if (isLocal != null)
+ {
+ if (trace) logger.trace(this + " " + resourceName + " is local " + isLocal);
+
+ return isLocal.booleanValue();
+ }
+ boolean localResource = isLocalClassLoaderResource(classResourceName);
+ localResources.put(classResourceName, localResource ? Boolean.TRUE : Boolean.FALSE);
+
+ if (trace) logger.trace(this + " " + resourceName + " is local " + localResource);
+
+ return localResource;
+ }
+
+ protected boolean isLocalClassLoaderResource(String classResourceName)
+ {
+ return getClassLoader().getResource(classResourceName) != null;
+ }
+
+// @Override
+// public synchronized CtClass getLocally(String classname)
+// throws NotFoundException
+// {
+// boolean trace = logger.isTraceEnabled();
+// if (trace) logger.trace(this + " attempting local get for " + classname);
+// softcache.remove(classname);
+// CtClass clazz = (CtClass) classes.get(classname);
+// if (trace && clazz != null)
+// {
+// logger.trace(this + " found " + classname + " in cache");
+// }
+// if (clazz == null)
+// {
+// clazz = createCtClass(classname, true);
+// if (clazz == null) throw new NotFoundException(classname);
+// lockInCache(clazz);//Avoid use of the softclasscache
+// }
+//
+// return clazz;
+// }
+
+// @Override
+// protected CtClass getCachedLocally(String classname)
+// {
+// if (logger.isTraceEnabled()) logger.trace(this + " checking local cache for " + classname);
+// return super.getCachedLocally(classname);
+// }
+
+// @Override
+// public void lockInCache(CtClass c)
+// {
+// if (logger.isTraceEnabled()) logger.trace(this + " locking in cache " + c.getName());
+// super.lockInCache(c);
+// }
+
+// public void setClassLoadedButNotWoven(String classname)
+// {
+// loadedButNotWovenClasses.put(classname, Boolean.TRUE);
+// }
+//
+// public boolean isClassLoadedButNotWoven(String classname)
+// {
+// return loadedButNotWovenClasses.get(classname) == Boolean.TRUE;
+// }
+
+// public static AbstractClassPool createAOPClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+// {
+// return (AbstractClassPool)AspectManager.getClassPoolFactory().create(cl, src, repository);
+// }
+//
+// public static AbstractClassPool createAOPClassPool(ClassPool src, ScopedClassPoolRepository repository)
+// {
+// return (AbstractClassPool)AspectManager.getClassPoolFactory().create(src, repository);
+// }
+
+ public String toString()
+ {
+ ClassLoader cl = null;
+ try
+ {
+ cl = getClassLoader();
+ }
+ catch(IllegalStateException ignore)
+ {
+ }
+ return this.getClass().getName() + "@" + System.identityHashCode(this) + " " + super.toString() + " - dcl:" + cl;
+ }
+
+ /* public CtClass getClass(String classname) {
+ CtClass clazz;
+ if (classname.charAt(0) == '[')
+ {
+ try
+ {
+ return Descriptor.toCtClass(classname, this);
+ }
+ catch (NotFoundException nfe)
+ {
+ throw new UnreachableStatementException(nfe.getMessage());
+ }
+ }
+ if (classname == null)
+ return null;
+ else
+ clazz = get0(classname, true);
+
+ if (clazz != null)
+ {
+ //clazz.incGetCounter();
+ }
+ return clazz;
+ }*/
+
+
+// public CtClass internalGet0(String classname, boolean useCache) throws NotFoundException
+// {
+// return super.get0(classname, useCache);
+// }
+
+ protected String getClassPoolLogStringForClass(CtClass clazz)
+ {
+ if (clazz == null)
+ {
+ return null;
+ }
+ if (clazz.getClassPool() == null)
+ {
+ return null;
+ }
+ return clazz.getClassPool().toString();
+ }
+
+ /**
+ * Contains the original AbstractClassPool.getCached()
+ *
+ */
+ // NOTE: identical to ScopedClassPoolRepository, with two differences:
+ // 1. This method uses the shortcuts isLocalResource and getResourceName
+ // 2. This method uses the Repository.includeInGlobalSearch method
+ private class SearchAllRegisteredLoadersSearchStrategy implements ClassPoolSearchStrategy
+ {
+ Logger logger = Logger.getLogger(this.getClass());
+ public CtClass getCached(String classname)
+ {
+ boolean trace = logger.isTraceEnabled();
+
+ if (trace) logger.trace(this + " " + AbstractClassPool.this + " searching all pools for " + classname);
+
+ CtClass clazz = getCachedLocally(classname);
+ if (clazz == null && getClassLoader0() != null &&
+ !isLocalResource(getResourceName(classname), trace) &&
+ !generatedClasses.containsKey(classname))
+ {
+ Map<ClassLoader, ClassPool> registeredCLs = repository.getRegisteredCLs();
+ synchronized (registeredCLs)
+ {
+ for(ClassPool pl : registeredCLs.values())
+ {
+ AbstractClassPool pool = (AbstractClassPool) pl;
+ if (pool.isUnloadedClassLoader())
+ {
+ if (trace) logger.trace(this + " pool is unloaded " + pool);
+ repository.unregisterClassLoader(pool.getClassLoader());
+ continue;
+ }
+
+ //Do not check classpools for scoped classloaders
+ if (!pool.includeInGlobalSearch())
+ {
+ if (trace) logger.trace(this + " pool is scoped " + pool);
+ continue;
+ }
+
+ if (trace) logger.trace(this + " " + AbstractClassPool.this + " searching for " + classname + " in " + pool);
+ clazz = pool.getCachedLocally(classname);
+ if (clazz != null)
+ {
+ break;
+ }
+ }
+ }
+ }
+ if (trace) logger.trace(this + " " + AbstractClassPool.this + " found " + classname + " in pool" + getClassPoolLogStringForClass(clazz));
+ return clazz;
+ }
+ }
+
+ /**
+ * Checks only the ClassPool's cache
+ */
+ private class SearchLocalLoaderLoaderSearchStrategy implements ClassPoolSearchStrategy
+ {
+ Logger logger = Logger.getLogger(this.getClass());
+
+ public CtClass getCached(String classname)
+ {
+ boolean trace = logger.isTraceEnabled();
+
+ if (trace) logger.trace(this + " " + AbstractClassPool.this + " searching just this pool for " + classname);
+ CtClass clazz = getCachedLocally(classname);
+ if (trace) logger.trace(this + " " + AbstractClassPool.this + " found " + classname + " in pool" + getClassPoolLogStringForClass(clazz));
+ return clazz;
+ }
+ }
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolDomain.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolDomain.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolDomain.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,124 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import org.jboss.logging.Logger;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+
+
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractClassPoolDomain implements ClassPoolDomain
+{
+ protected final Logger logger = Logger.getLogger(this.getClass());
+
+ abstract CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, boolean create);
+
+ abstract CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace);
+
+ abstract CtClass getCachedOrCreateFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace);
+
+ abstract void addClassPool(DelegatingClassPool pool);
+
+ abstract void removeClassPool(DelegatingClassPool pool);
+
+
+ protected CtClass getCachedOrCreateFromPoolParent(BaseClassPool initiatingPool, String classname, boolean create, boolean trace)
+ {
+ if (initiatingPool == null)
+ {
+ if (trace) logger.trace(this + " get cached or create " + classname + " from pool parent - no initiating pool");
+ return null;
+ }
+ ClassPool parentPool = initiatingPool.getParent();
+ if (parentPool == null)
+ {
+ if (trace) logger.trace(this + " get cached or create " + classname + " from pool parent - no parent pool");
+ return null;
+ }
+
+ return getCachedOrCreateFromPool(parentPool, classname, create, trace);
+ }
+
+
+ protected CtClass getCachedOrCreateFromPool(ClassPool pool, String classname, boolean create, boolean trace)
+ {
+ if (pool instanceof BaseClassPool)
+ {
+ return getCachedOrCreateFromPool((BaseClassPool)pool, classname, create, trace);
+ }
+ try
+ {
+ //This will check the parents
+ if (trace) logger.trace(this + " get cached or create " + classname + " from non-BaseClassPool pool " + pool);
+ CtClass clazz = pool.get(classname);
+ if (trace) logger.trace(this + " got cached or create " + classname + " from non-BaseClassPool pool " + clazz.getClassPool());
+ return clazz;
+ }
+ catch(NotFoundException e)
+ {
+ return null;
+ }
+ }
+
+ protected CtClass getCachedOrCreateFromPool(BaseClassPool pool, String classname, boolean create, boolean trace)
+ {
+ if (pool == null)
+ {
+ if (trace) logger.trace(this + " get cached or create " + classname + " from BaseClassPool - no pool");
+ return null;
+ }
+
+ CtClass clazz = null;
+ if (!pool.childFirstLookup)
+ {
+ if (trace) logger.trace(this + " get cached or create " + classname + " from BaseClassPool - checking parent (parentFirst)");
+ clazz = getCachedOrCreateFromPoolParent(pool, classname, create, trace);
+ }
+
+ if (clazz == null)
+ {
+ //We can use the exposed methods directly to avoid the overhead of NotFoundException
+ if (trace) logger.trace(this + " get cached or create " + classname + " from BaseClassPool - checking cache");
+ clazz = pool.getCached(classname);
+ if (clazz == null && create)
+ {
+ if (trace) logger.trace(this + " get cached or create " + classname + " from BaseClassPool - creating");
+ clazz = pool.createCtClass(classname, true);
+ }
+ }
+
+ if (clazz == null && pool.childFirstLookup)
+ {
+ if (trace) logger.trace(this + " get cached or create " + classname + " from BaseClassPool - checking parent (parentLast)");
+ clazz = getCachedOrCreateFromPoolParent(pool, classname, create, trace);
+ }
+ return clazz;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 55872 $
+ *
+ **/
+public class AbstractClassPoolFactory implements ScopedClassPoolFactory
+{
+ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return new AbstractClassPool(cl, src, repository);
+ }
+
+ public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return new AbstractClassPool(src, repository);
+ }
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractIsLocalResourcePlugin.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractIsLocalResourcePlugin.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractIsLocalResourcePlugin.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,78 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.net.URL;
+
+import javassist.ClassPool;
+
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractIsLocalResourcePlugin implements IsLocalResourcePlugin
+{
+ private final BaseClassPool pool;
+
+ public AbstractIsLocalResourcePlugin(BaseClassPool pool)
+ {
+ this.pool = pool;
+ initialise();
+ }
+
+ protected void initialise()
+ {
+
+ }
+
+ protected AbstractClassPool getPool()
+ {
+ return pool;
+ }
+
+ /**
+ * Checks if the resource can be found in the parent classpool's loader
+ * and returns true if it either does not exist in the parent or if
+ * the parent has a different URL for the resource
+ */
+ protected boolean isSameInParent(String classResourceName, URL foundURL)
+ {
+ ClassPool parent = pool.getParent();
+ if (parent != null)
+ {
+ ClassLoader parentLoader = parent.getClassLoader();
+ URL parentURL = parentLoader.getResource(classResourceName);
+ if (parentURL == null)
+ {
+ return false;
+ }
+ if (parentURL.equals(foundURL))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import org.jboss.logging.Logger;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractJBossClassPoolFactory implements ScopedClassPoolFactory
+{
+ protected final Logger log = Logger.getLogger(this.getClass().getName());
+
+ protected ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ //Make sure that we get classpools for all the parent classloaders
+ if (cl == null)
+ {
+ return ClassPool.getDefault();
+ }
+ ClassLoader parent = SecurityActions.getParent(cl);
+
+ if (parent != null)
+ {
+ return repository.registerClassLoader(parent);
+ }
+ return src;
+ }
+
+ public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return new TempJBossClassPool(src, repository);
+ }
+
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractJBossDelegatingClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractJBossDelegatingClassPoolFactory extends AbstractJBossClassPoolFactory
+{
+ public ScopedClassPool create(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ return new TempJBossDelegatingClassPool(src, repository);
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractParentDelegationStrategy.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractParentDelegationStrategy.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/AbstractParentDelegationStrategy.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.CtClass;
+
+import org.jboss.logging.Logger;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractParentDelegationStrategy implements ParentDelegationStrategy
+{
+ protected final Logger logger = Logger.getLogger(this.getClass().getName());
+ private AbstractClassPoolDomain domain;
+ private AbstractClassPoolDomain parent;
+
+ protected AbstractParentDelegationStrategy(ClassPoolDomain parent, ClassPoolToClassPoolDomainAdaptorFactory adaptorFactory)
+ {
+ if (parent == null)
+ {
+ if (adaptorFactory == null)
+ {
+ throw new IllegalStateException("Null parent and null adaptorFactory");
+ }
+ this.parent = adaptorFactory.createAdaptor();
+ }
+ else
+ {
+ if (parent instanceof AbstractClassPoolDomain == false)
+ {
+ throw new IllegalArgumentException("Parent must implement AbstractClassPoolDomain");
+ }
+ this.parent = (AbstractClassPoolDomain)parent;
+ }
+
+ if (this.parent == null)
+ {
+ throw new IllegalStateException("Parent was not set");
+ }
+ }
+
+ protected boolean hasParent()
+ {
+ if (logger.isTraceEnabled()) logger.trace(this + " " + getDomain() + " hasParent " + parent != null);
+ return parent != null;
+ }
+
+ protected AbstractClassPoolDomain getDomain()
+ {
+ return domain;
+ }
+
+ public CtClass getCachedOrCreateFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace)
+ {
+ return parent.getCachedOrCreate(initiatingPool, classname, resourceName, create, trace);
+ }
+
+ public void setDomain(AbstractClassPoolDomain domain)
+ {
+ if (domain == null)
+ {
+ throw new IllegalArgumentException("Null domain");
+ }
+ if (this.domain != null)
+ {
+ throw new IllegalArgumentException("Cannot change domain");
+ }
+ this.domain = domain;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,158 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+
+/**
+ * Intermediate class containing commonly needed functionality for the new classpools. I don't want to
+ * modify AbstractClassPool too much
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BaseClassPool extends AbstractClassPool
+{
+ private IsLocalResourcePlugin isLocalResourcePlugin;
+
+ public BaseClassPool(ClassLoader cl, ClassPool parent, ScopedClassPoolRepository repository)
+ {
+ super(cl, parent, repository);
+ isLocalResourcePlugin = IsLocalResourcePluginFactoryRegistry.getPluginFactory(cl).create(this);
+ if (logger.isTraceEnabled()) logger.trace(this + " isLocalResourcePlugin:" + isLocalResourcePlugin);
+ }
+
+ public BaseClassPool(ClassLoader cl, ClassPool parent, ScopedClassPoolRepository repository, Class<? extends ClassPoolSearchStrategy> searchStrategy)
+ {
+ super(cl, parent, repository, searchStrategy);
+ isLocalResourcePlugin = IsLocalResourcePluginFactoryRegistry.getPluginFactory(cl).create(this);
+ if (logger.isTraceEnabled()) logger.trace(this + " isLocalResourcePlugin:" + isLocalResourcePlugin);
+ }
+
+
+ /**
+ * Stores the classes created in the ScopedClassPool cache.
+ */
+ @Override
+ public CtClass createCtClass(String classname, boolean useCache)
+ {
+ CtClass clazz = super.createCtClass(classname, useCache);
+ if (clazz != null)
+ {
+ lockInCache(clazz);
+ }
+ return clazz;
+ }
+
+ /**
+ * Uses the parent ClassPool, if available, to create the CtClass representing
+ * {@code classname}.
+ *
+ * @param classname the name of the queried CtClass
+ * @param useCache whether the ScopedClassPool cache should be used to search for the CtClass
+ * @param trace enables tracing
+ * @return a {@code CtClass} representing {@code classname}
+ */
+ protected CtClass createParentCtClass(String classname, boolean useCache, boolean trace)
+ {
+ if (parent == null)
+ {
+ return null;
+ }
+
+ //Make parent create class
+ if (parent instanceof BaseClassPool)
+ {
+ return ((BaseClassPool)parent).createCtClass(classname, useCache);
+ }
+ else
+ {
+ return plainParentGet(classname);
+ }
+ }
+
+ private CtClass plainParentGet(String classname)
+ {
+ try
+ {
+ return parent.get(classname);
+ }
+ catch (NotFoundException e)
+ {
+ }
+ return null;
+ }
+
+ public ClassPool getParent()
+ {
+ return parent;
+ }
+
+ @Override
+ protected boolean isLocalClassLoaderResource(String classResourceName)
+ {
+ return isLocalResourcePlugin.isMyResource(classResourceName);
+ }
+
+ @Override
+ public final CtClass get(String classname) throws NotFoundException
+ {
+ boolean trace = logger.isTraceEnabled();
+ if (trace) logger.trace(this + " initiating get of " + classname);
+
+ try
+ {
+ CtClass clazz = super.get(classname);
+ if (trace)
+ {
+ logger.trace(this + " completed get of " + classname + " " + getClassPoolLogStringForClass(clazz));
+ }
+ return clazz;
+ }
+ catch (NotFoundException e)
+ {
+ // AutoGenerated
+ NotFoundException wrapped = new NotFoundException(e.getMessage() + " could not be found from " + this);
+ wrapped.setStackTrace(e.getStackTrace());
+ throw wrapped;
+ }
+ }
+
+ @Override
+ public CtClass get0(String classname, boolean useCache) throws NotFoundException
+ {
+ return super.get0(classname, useCache);
+ }
+
+ @Override
+ public void close()
+ {
+ super.close();
+
+ if (logger.isTraceEnabled()) logger.trace(this + " closing");
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPoolDomain.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPoolDomain.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/BaseClassPoolDomain.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,152 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.CtClass;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BaseClassPoolDomain extends AbstractClassPoolDomain
+{
+ private String domainName;
+
+ private List<DelegatingClassPool> delegatingPools = new ArrayList<DelegatingClassPool>();
+
+ private ParentDelegationStrategy parentDelegationStrategy;
+
+ public BaseClassPoolDomain(String domainName, ClassPoolDomain parent, boolean parentFirst)
+ {
+ this(domainName,
+ new DefaultParentDelegationStrategy(
+ parent,
+ parentFirst,
+ DefaultClassPoolToClassPoolDomainAdaptorFactory.getInstance())
+ );
+ }
+
+ protected BaseClassPoolDomain(String domainName, ParentDelegationStrategy parentDelegationStrategy)
+ {
+ this.domainName = domainName;
+ this.parentDelegationStrategy = parentDelegationStrategy;
+ parentDelegationStrategy.setDomain(this);
+ if (logger.isTraceEnabled()) logger.trace("Created " + this + " parentDelegationStrategy:" + parentDelegationStrategy);
+ }
+
+ @Override
+ synchronized void addClassPool(DelegatingClassPool pool)
+ {
+ if (!delegatingPools.contains(pool))
+ {
+ if (logger.isTraceEnabled()) logger.trace(this + " adding pool " + pool);
+ delegatingPools.add(pool);
+ }
+ }
+
+ @Override
+ protected synchronized void removeClassPool(DelegatingClassPool pool)
+ {
+ if (logger.isTraceEnabled()) logger.trace(this + " removing pool " + pool);
+ delegatingPools.remove(pool);
+ }
+
+ @Override
+ synchronized CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, boolean create)
+ {
+ boolean trace = logger.isTraceEnabled();
+ String resourceName = ClassLoaderUtils.getResourceName(classname);
+
+ CtClass clazz = getCachedOrCreate(initiatingPool, classname, resourceName, create, trace);
+
+ if (clazz == null)
+ {
+ clazz = getCachedOrCreateFromPoolParent(initiatingPool, classname, create, trace);
+ }
+ return clazz;
+ }
+
+ @Override
+ protected CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace)
+ {
+ if (trace) logger.trace(this + " looking for " + classname);
+
+ CtClass clazz = null;
+ if (isParentBefore(classname))
+ {
+ if (trace) logger.trace(this + " checking parent first for " + classname);
+ clazz = getCachedOrCreateFromParent(initiatingPool, classname, resourceName, create, trace);
+ }
+ if (clazz == null)
+ {
+ List<DelegatingClassPool> pools = getPoolsForClassName(classname);
+ if (pools.size() > 0)
+ {
+ for (DelegatingClassPool pool : pools)
+ {
+ clazz = pool.loadLocally(classname, resourceName, create);
+ if (clazz != null)
+ {
+ break;
+ }
+ }
+ }
+ }
+ if (clazz == null && isParentAfter(classname))
+ {
+ if (trace) logger.trace(this + " checking parent last for " + classname);
+ clazz = getCachedOrCreateFromParent(initiatingPool, classname, resourceName, create, trace);
+ }
+ if (trace) logger.trace(this + " found " + classname + " in " + (clazz == null ? "null" : clazz.getClassPool()));
+ return clazz;
+ }
+
+ @Override
+ protected CtClass getCachedOrCreateFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace)
+ {
+ return parentDelegationStrategy.getCachedOrCreateFromParent(initiatingPool, classname, resourceName, create, trace);
+ }
+
+ public String toString()
+ {
+ return "[" + super.toString() + " name:" + domainName + "]";
+ }
+
+ protected boolean isParentBefore(String classname)
+ {
+ return parentDelegationStrategy.isParentBefore(classname);
+ }
+
+ protected boolean isParentAfter(String classname)
+ {
+ return parentDelegationStrategy.isParentAfter(classname);
+ }
+
+ protected List<DelegatingClassPool> getPoolsForClassName(String classname)
+ {
+ return delegatingPools;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassLoaderUtils.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassLoaderUtils.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassLoaderUtils.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javassist.CtClass;
+import javassist.bytecode.Descriptor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderUtils
+{
+ private static final Set<String> primitiveNames;
+ static
+ {
+ Set<String> temp = new HashSet<String>();
+ temp.add(CtClass.booleanType.getName());
+ temp.add(CtClass.byteType.getName());
+ temp.add(CtClass.charType.getName());
+ temp.add(CtClass.doubleType.getName());
+ temp.add(CtClass.floatType.getName());
+ temp.add(CtClass.intType.getName());
+ temp.add(CtClass.longType.getName());
+ temp.add(CtClass.shortType.getName());
+ temp.add(CtClass.voidType.getName());
+ primitiveNames = Collections.unmodifiableSet(temp);
+ }
+
+ public static String getResourceName(String classname)
+ {
+ final String name = stripArrayFromClassName(classname);
+ final int lastIndex = name.lastIndexOf('$');
+ if (lastIndex < 0)
+ {
+ return name.replaceAll("[\\.]", "/") + ".class";
+ }
+ else
+ {
+ return name.substring(0, lastIndex).replaceAll("[\\.]", "/") + name.substring(lastIndex) + ".class";
+ }
+ }
+
+ public static String getPackageName(String classname)
+ {
+ final int last = classname.lastIndexOf('.');
+ if (last < 0)
+ {
+ return "";
+ }
+ else
+ {
+ return classname.substring(0, last);
+ }
+ }
+
+ public static String stripArrayFromClassName(String classname)
+ {
+ if (classname.charAt(0) == '[')
+ {
+ return Descriptor.toClassName(classname);
+ }
+ if (classname.endsWith("[]"))
+ {
+ return classname.substring(0, classname.indexOf("[]"));
+ }
+ return classname;
+ }
+
+ public static boolean isPrimitiveType(String classname)
+ {
+ final String name = stripArrayFromClassName(classname);
+ return primitiveNames.contains(name);
+ }
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomain.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomain.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomain.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,31 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ClassPoolDomain
+{
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomainRegistry.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomainRegistry.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolDomainRegistry.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolDomainRegistry
+{
+ final static ClassPoolDomainRegistry INSTANCE = new ClassPoolDomainRegistry();
+
+ final Map<Object, WeakReference<ClassPoolDomain>> domains = new WeakHashMap<Object, WeakReference<ClassPoolDomain>>();
+
+ public static ClassPoolDomainRegistry getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public synchronized ClassPoolDomain getDomain(Object key)
+ {
+ WeakReference<ClassPoolDomain> ref = domains.get(key);
+ if (ref == null)
+ {
+ return null;
+ }
+ return ref.get();
+ }
+
+ public synchronized void addClassPoolDomain(Object key, ClassPoolDomain domain)
+ {
+ domains.put(key, new WeakReference<ClassPoolDomain>(domain));
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolRepository.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,168 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+import javassist.scopedpool.ScopedClassPoolRepositoryImpl;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Singleton classpool repository
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 87799 $
+ */
+public class ClassPoolRepository implements ScopedClassPoolRepository
+{
+ private static final Logger logger = Logger.getLogger(ClassPoolRepository.class);
+
+ private final static ClassPoolRepository instance = new ClassPoolRepository();
+
+ /** The classes per classppol */
+ protected final HashMap<ClassLoader, HashSet<Class<?>>> ucl2classes = new HashMap<ClassLoader, HashSet<Class<?>>>();
+
+ ScopedClassPoolRepository delegate;
+
+ public static ClassPoolRepository getInstance()
+ {
+ return instance;
+ }
+
+ private ClassPoolRepository()
+ {
+ this.delegate = ScopedClassPoolRepositoryImpl.getInstance();
+ //This was needed when jboss-aop.jar was deployed in the jboss/lib directory since the AspectManager bean had no chance to initialise it
+ delegate.setClassPoolFactory(new AbstractClassPoolFactory());
+// if (!setJBossSpecificStartupVariables())
+// {
+// delegate.setClassPoolFactory(new AbstractClassPoolFactory());
+// }
+ }
+
+// private boolean setJBossSpecificStartupVariables()
+// {
+// //We are running within JBoss 5, let's default to the JBossClassPoolFactory and set the ScopedClassPoolHelper
+// //so that we get correct behaviour before the AspectManager service has been deployed
+// try
+// {
+// Class jbcpf = Class.forName("org.jboss.aop.deployment.JBossClassPoolFactory");
+// ScopedClassPoolFactory factory = (ScopedClassPoolFactory)jbcpf.newInstance();
+//
+// Class hlpr = Class.forName("org.jboss.aop.deployment.JBossScopedClassLoaderHelper");
+// AOPScopedClassLoaderHelper helper = (AOPScopedClassLoaderHelper)hlpr.newInstance();
+// delegate.setClassPoolFactory(factory);
+// AspectManager.scopedCLHelper = helper;
+// return true;
+// }
+// catch (Exception e)
+// {
+// }
+// return false;//Not running in JBoss probably
+// }
+
+ public void setClassPoolFactory(ScopedClassPoolFactory factory)
+ {
+ delegate.setClassPoolFactory(factory);
+ }
+
+ public ScopedClassPoolFactory getClassPoolFactory()
+ {
+ return delegate.getClassPoolFactory();
+ }
+
+ public boolean isPrune()
+ {
+ return delegate.isPrune();
+ }
+
+ public void setPrune(boolean prune)
+ {
+ delegate.setPrune(prune);
+ }
+
+ public ScopedClassPool createScopedClassPool(ClassLoader cl, ClassPool src)
+ {
+ return delegate.createScopedClassPool(cl, src);
+ }
+
+ public ClassPool findClassPool(ClassLoader cl)
+ {
+ return delegate.findClassPool(cl);
+ }
+
+ /**
+ * Get the registered classloaders
+ *
+ * @return the registered classloaders
+ */
+ public Map<ClassLoader, ClassPool> getRegisteredCLs()
+ {
+ return delegate.getRegisteredCLs();
+ }
+
+ /**
+ * This method will check to see if a register classloader has been undeployed (as in JBoss)
+ */
+ public void clearUnregisteredClassLoaders()
+ {
+ delegate.clearUnregisteredClassLoaders();
+ }
+
+ public ClassPool registerClassLoader(ClassLoader ucl)
+ {
+ if (ucl == null)
+ {
+ return delegate.registerClassLoader(SecurityActions.getContextClassLoader());
+ }
+ return delegate.registerClassLoader(ucl);
+ }
+
+ public void unregisterClassLoader(ClassLoader cl)
+ {
+ delegate.unregisterClassLoader(cl);
+ }
+
+ public void registerClass(Class<?> clazz)
+ {
+ ClassLoader classLoader = SecurityActions.getClassLoader(clazz);
+ HashSet<Class<?>> classes = ucl2classes.get(classLoader);
+ if (classes == null)
+ {
+ classes = new HashSet<Class<?>>();
+ ucl2classes.put(classLoader, classes);
+ }
+ classes.add(clazz);
+ }
+
+ public void perfomUnregisterClassLoader(ClassLoader cl)
+ {
+ ucl2classes.remove(cl);
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolSearchStrategy.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolSearchStrategy.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolSearchStrategy.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.CtClass;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ClassPoolSearchStrategy
+{
+ CtClass getCached(String classname);
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdapter.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdapter.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdapter.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,98 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+
+/**
+ * Adapts a ClassPool to a ClassPoolDomain, i.e., this class represents an
+ * unitary ClassPoolDomain.
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolToClassPoolDomainAdapter extends AbstractClassPoolDomain
+{
+ protected ClassPool pool;
+
+ public ClassPoolToClassPoolDomainAdapter()
+ {
+ this.pool = initialiseParentClassLoader();
+ if (logger.isTraceEnabled()) logger.trace("Created " + this);
+ validate();
+ }
+
+ public ClassPoolToClassPoolDomainAdapter(ClassPool pool)
+ {
+ this.pool = pool;
+ if (logger.isTraceEnabled()) logger.trace("Created " + this);
+ validate();
+ }
+
+ private void validate()
+ {
+ if (pool == null)
+ {
+ throw new IllegalStateException("Null parent classpool");
+ }
+ }
+
+ public ClassPool initialiseParentClassLoader()
+ {
+ return ClassPool.getDefault();
+ }
+
+ public void addClassPool(DelegatingClassPool pool)
+ {
+ throw new IllegalStateException("Cannot add pools to the domain adaptor");
+ }
+
+
+ synchronized CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace)
+ {
+ return getCachedOrCreateFromPool(pool, classname, create, trace);
+ }
+
+ @Override
+ CtClass getCachedOrCreateFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace)
+ {
+ return null;
+ }
+
+ void removeClassPool(DelegatingClassPool pool)
+ {
+ throw new IllegalStateException("Cannot remove pools from the domain adaptor");
+ }
+
+ public String toString()
+ {
+ return "ClassPoolToDomainAdapter[" + System.identityHashCode(this) + " " + pool.toString() + "]";
+ }
+
+ @Override
+ CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, boolean create)
+ {
+ throw new IllegalStateException("Should never be called");
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdaptorFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdaptorFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ClassPoolToClassPoolDomainAdaptorFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ClassPoolToClassPoolDomainAdaptorFactory
+{
+ ClassPoolToClassPoolDomainAdapter createAdaptor();
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePlugin.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePlugin.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePlugin.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultClassLoaderIsLocalResourcePlugin extends AbstractIsLocalResourcePlugin implements IsLocalResourcePlugin
+{
+ public DefaultClassLoaderIsLocalResourcePlugin(BaseClassPool pool)
+ {
+ super(pool);
+ }
+
+ public boolean isMyResource(String resourceName)
+ {
+ return getPool().getClassLoader().getResource(resourceName) != null;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultClassLoaderIsLocalResourcePluginFactory implements IsLocalResourcePluginFactory
+{
+
+ public IsLocalResourcePlugin create(BaseClassPool pool)
+ {
+ return new DefaultClassLoaderIsLocalResourcePlugin(pool);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassPoolToClassPoolDomainAdaptorFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassPoolToClassPoolDomainAdaptorFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultClassPoolToClassPoolDomainAdaptorFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultClassPoolToClassPoolDomainAdaptorFactory implements ClassPoolToClassPoolDomainAdaptorFactory
+{
+ private static final DefaultClassPoolToClassPoolDomainAdaptorFactory INSTANCE = new DefaultClassPoolToClassPoolDomainAdaptorFactory();
+
+ private DefaultClassPoolToClassPoolDomainAdaptorFactory()
+ {
+
+ }
+
+ public static ClassPoolToClassPoolDomainAdaptorFactory getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public ClassPoolToClassPoolDomainAdapter createAdaptor()
+ {
+ return new ClassPoolToClassPoolDomainAdapter();
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultParentDelegationStrategy.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultParentDelegationStrategy.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DefaultParentDelegationStrategy.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class DefaultParentDelegationStrategy extends AbstractParentDelegationStrategy
+{
+ boolean parentFirst;
+ DefaultParentDelegationStrategy(ClassPoolDomain parent, boolean parentFirst, ClassPoolToClassPoolDomainAdaptorFactory adaptorFactory)
+ {
+ super(parent, adaptorFactory);
+ this.parentFirst = parentFirst;
+ }
+
+ public boolean isParentBefore(String classname)
+ {
+ boolean isParentBefore = hasParent() && parentFirst == true;
+ if (logger.isTraceEnabled()) logger.trace(this + " " + getDomain() + " isParentBefore " + isParentBefore);
+ return isParentBefore;
+ }
+
+ public boolean isParentAfter(String classname)
+ {
+ boolean isParentAfter = hasParent() && parentFirst == false;
+ if (logger.isTraceEnabled()) logger.trace(this + " " + getDomain() + " isParentAfter " + isParentAfter);
+ return isParentAfter;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DelegatingClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DelegatingClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/DelegatingClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,129 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+/**
+ * Base class for classpools backed by a domain
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegatingClassPool extends BaseClassPool
+{
+ private final AbstractClassPoolDomain domain;
+
+ private boolean closed;
+
+ public DelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent, ScopedClassPoolRepository repository)
+ {
+ super(cl, parent, repository);
+ if (domain == null)
+ {
+ throw new IllegalArgumentException("Domain was null");
+ }
+ if (domain instanceof AbstractClassPoolDomain == false)
+ {
+ throw new IllegalArgumentException("Domain must implement AbstractClassPoolDomain");
+ }
+ this.domain = (AbstractClassPoolDomain)domain;
+ if (logger.isTraceEnabled()) logger.trace(this + " domain:" + this);
+ this.domain.addClassPool(this);
+ }
+
+ public CtClass loadLocally(String classname, String resourceName, boolean create)
+ {
+ boolean trace = logger.isTraceEnabled();
+ if (trace) logger.trace(this + " attempt to load locally " + classname);
+
+ CtClass clazz = null;
+ if (isLocalResource(resourceName, trace))
+ {
+ clazz = getCachedLocally(classname);
+ if (clazz == null && create)
+ {
+ clazz = createCtClass(classname, true);
+ }
+ }
+ if (trace) logger.trace(this + " loaded locally " + classname + " " + getClassPoolLogStringForClass(clazz));
+ return clazz;
+ }
+
+ /**
+ * Overrides ClassPool.get0() so that we can look up classes without caching them in the initiating pool.
+ * The DelgatingClassPool + DomainClassPool handle the caching in the correct pool + handles the
+ * parentFirst functionality
+ */
+ @Override
+ public synchronized CtClass get0(String classname, boolean useCache) throws NotFoundException
+ {
+ if (isGeneratedClass(classname))
+ {
+ return null;
+ }
+ CtClass clazz = domain.getCachedOrCreate(this, classname, true);
+ if (clazz == null)
+ {
+ //It is probably a generated proxy. The package name can be different (for example if it is
+ //a proxy for a java system class) than the package names exported by the loaders.
+ //TODO It should be possible to remove this once these have been done:
+ //https://jira.jboss.org/jira/browse/JBCL-25
+ //https://jira.jboss.org/jira/browse/JBCL-92
+ clazz = loadLocally(classname, ClassLoaderUtils.getResourceName(classname), true);
+ }
+ return clazz;
+ }
+
+ @Override
+ public boolean isUnloadedClassLoader()
+ {
+ return closed;
+ }
+
+ @Override
+ public void close()
+ {
+ closed = true;
+ super.close();
+ domain.removeClassPool(this);
+ }
+
+ @Override
+ public CtClass getCached(String classname)
+ {
+ if (isGeneratedClass(classname))
+ {
+ return null;
+ }
+ return domain.getCachedOrCreate(this, classname, false);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "[" + super.toString() + " domain: " + domain + "]";
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePlugin.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePlugin.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePlugin.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IsLocalResourcePlugin
+{
+ boolean isMyResource(String resourceName);
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ * Creates IsLocalResourcePlugins for a specific instance of {@link BaseClassPool}
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IsLocalResourcePluginFactory
+{
+ IsLocalResourcePlugin create(BaseClassPool pool);
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactoryRegistry.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactoryRegistry.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/IsLocalResourcePluginFactoryRegistry.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,117 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.net.URLClassLoader;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.util.loading.Translatable;
+
+/**
+ * A global registry for IsLocalResourcePluginFactories.
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IsLocalResourcePluginFactoryRegistry
+{
+ private static Map<Class<?>, IsLocalResourcePluginFactory> plugins = new WeakHashMap<Class<?>, IsLocalResourcePluginFactory>();
+
+ static
+ {
+ addPluginFactory(ClassLoader.class, new DefaultClassLoaderIsLocalResourcePluginFactory());
+ addPluginFactory(URLClassLoader.class, new URLClassLoaderIsLocalResourcePluginFactory());
+ addPluginFactory(Translatable.class, new TranslatableClassLoaderIsLocalResourcePluginFactory());
+ }
+
+ /**
+ * Registers {@code plugin} as the factory associated with the {@code classLoaderClass}.
+ *
+ * @param classLoaderClass the class of a specific ClassLoader
+ * @param plugin a plugin factory that will be used for classes loaded by
+ * a class loader of type {@code classLoaderClass}
+ */
+ public static synchronized void addPluginFactory(Class<?> classLoaderClass, IsLocalResourcePluginFactory plugin)
+ {
+ plugins.put(classLoaderClass, plugin);
+ }
+
+ /**
+ * Unregisters {@code plugin} as the factory associated with the {@code classLoaderClass}.
+ *
+ * @param classLoaderClass the class of a specific ClassLoader
+ * @param plugin a plugin factory that should no longer be used for classes loaded by
+ * a class loader of type {@code classLoaderClass}
+ */
+ public static synchronized void removePluginFactory(Class<?> classLoaderClass, IsLocalResourcePluginFactory plugin)
+ {
+ plugins.remove(classLoaderClass);
+ }
+
+ /**
+ * Returns the plugin factory associated with the {@code classLoader}.
+ *
+ * @return a plugin factory that should be used for classes loaded by
+ * {@code classLoader}
+ */
+ public static synchronized IsLocalResourcePluginFactory getPluginFactory(ClassLoader classLoader)
+ {
+ if (classLoader != null)
+ {
+ return getPluginFactory(classLoader.getClass());
+ }
+ return getPluginFactory(ClassLoader.class);
+ }
+
+ /**
+ * Returns the plugin factory associated with the {@code classLoaderClass}.
+ *
+ * @return a plugin factory that should be used for classes loaded by
+ * a class loader of type {@code classLoaderClass}
+ */
+ public static synchronized IsLocalResourcePluginFactory getPluginFactory(Class<?> classLoaderClass)
+ {
+ IsLocalResourcePluginFactory plugin = plugins.get(classLoaderClass);
+ if (plugin == null)
+ {
+ Class<?>[] interfaces = classLoaderClass.getInterfaces();
+ if (interfaces.length > 0)
+ {
+ for (Class<?> iface : interfaces)
+ {
+ plugin = getPluginFactory(iface);
+ if (plugin != null)
+ {
+ return plugin;
+ }
+ }
+ }
+ Class<?> superClass = classLoaderClass.getSuperclass();
+ if (superClass != null && superClass != Object.class)
+ {
+ return getPluginFactory(superClass);
+ }
+ }
+ return plugin;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/NonDelegatingClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/NonDelegatingClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/NonDelegatingClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+
+/**
+ * ClassPool for class loaders not backed by a repository/classloading domain
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class NonDelegatingClassPool extends BaseClassPool
+{
+ public NonDelegatingClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, boolean parentFirst)
+ {
+ super(cl, src, repository, AbstractClassPool.SEARCH_LOCAL_ONLY_STRATEGY);
+ super.childFirstLookup = !parentFirst;
+ }
+
+ @Override
+ public CtClass createCtClass(String classname, boolean useCache)
+ {
+ boolean trace = logger.isTraceEnabled();
+ CtClass clazz = null;
+ if (!childFirstLookup)
+ {
+ if (trace)logger.trace(this + " attempting to create " + classname + " in parent pool (parentFirst)");
+ clazz = createParentCtClass(classname, useCache, trace);
+ }
+ if (clazz == null && isLocalResource(getResourceName(classname), trace))
+ {
+ clazz = super.createCtClass(classname, useCache);
+ }
+ if (childFirstLookup && clazz == null)
+ {
+ if (trace)logger.trace(this + " attempting to create " + classname + " in parent pool (parentLast)");
+ clazz = createParentCtClass(classname, useCache, trace);
+ }
+
+ if (trace)logger.trace(this + " created " + classname + " " + getClassPoolLogStringForClass(clazz));
+ return clazz;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ParentDelegationStrategy.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ParentDelegationStrategy.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ParentDelegationStrategy.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.CtClass;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ParentDelegationStrategy
+{
+ void setDomain(AbstractClassPoolDomain domain);
+
+ CtClass getCachedOrCreateFromParent(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace);
+
+ boolean isParentBefore(String classname);
+
+ boolean isParentAfter(String classname);
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/SecurityActions.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/SecurityActions.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/SecurityActions.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,217 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.beans
+.PropertyEditorManager;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import org.jboss.util.propertyeditor.ClassArrayEditor;
+import org.jboss.util.propertyeditor.IntArrayEditor;
+import org.jboss.util.propertyeditor.StringArrayEditor;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+ interface GetParentAction
+ {
+ ClassLoader getParent(ClassLoader loader);
+
+ GetParentAction NON_PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(ClassLoader loader)
+ {
+ return loader.getParent();
+ }
+ };
+
+ GetParentAction PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(final ClassLoader loader)
+ {
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run() throws Exception
+ {
+ return loader.getParent();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException(e.getException());
+ }
+ }
+ };
+ }
+
+ public static ClassLoader getParent(ClassLoader loader)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetParentAction.NON_PRIVILEGED.getParent(loader);
+ }
+ else
+ {
+ return GetParentAction.PRIVILEGED.getParent(loader);
+ }
+ }
+
+
+ private interface InitPropertyEditorsAction
+ {
+ void initEditors();
+
+ InitPropertyEditorsAction PRIVILEGED = new InitPropertyEditorsAction()
+ {
+ public void initEditors()
+ {
+ try
+ {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ doInitEditors();
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException(e.getException());
+ }
+ }
+ };
+
+ InitPropertyEditorsAction NON_PRIVILEGED = new InitPropertyEditorsAction()
+ {
+ public void initEditors()
+ {
+ doInitEditors();
+ }
+ };
+ }
+
+ private static void doInitEditors()
+ {
+ String[] currentPath = PropertyEditorManager.getEditorSearchPath();
+ int length = currentPath != null ? currentPath.length : 0;
+ String[] newPath = new String[length+2];
+ System.arraycopy(currentPath, 0, newPath, 2, length);
+ // Put the JBoss editor path first
+ // The default editors are not very flexible
+ newPath[0] = "org.jboss.util.propertyeditor";
+ newPath[1] = "org.jboss.mx.util.propertyeditor";
+ PropertyEditorManager.setEditorSearchPath(newPath);
+
+ /* Register the editor types that will not be found using the standard
+ class name to editor name algorithm. For example, the type String[] has
+ a name '[Ljava.lang.String;' which does not map to a XXXEditor name.
+ */
+ Class<String[]> strArrayType = String[].class;
+ PropertyEditorManager.registerEditor(strArrayType, StringArrayEditor.class);
+
+ @SuppressWarnings("unchecked")
+ Class<Class[]> clsArrayType = Class[].class;
+ PropertyEditorManager.registerEditor(clsArrayType, ClassArrayEditor.class);
+
+ Class<int[]> intArrayType = int[].class;
+ PropertyEditorManager.registerEditor(intArrayType, IntArrayEditor.class);
+ }
+
+
+ static void initEditors()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ InitPropertyEditorsAction.NON_PRIVILEGED.initEditors();
+ }
+ else
+ {
+ InitPropertyEditorsAction.PRIVILEGED.initEditors();
+ }
+ }
+
+ public static class GetContextClassLoaderAction implements PrivilegedAction<ClassLoader>
+ {
+ public static GetContextClassLoaderAction INSTANCE = new GetContextClassLoaderAction();
+
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+
+ static ClassLoader getContextClassLoader()
+ {
+ if (System.getSecurityManager() == null)
+ return Thread.currentThread().getContextClassLoader();
+ else
+ return AccessController.doPrivileged(GetContextClassLoaderAction.INSTANCE);
+ }
+
+ interface GetClassLoaderAction
+ {
+ ClassLoader getClassLoader(Class<?> clazz);
+
+ GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+ public ClassLoader getClassLoader(Class<?> clazz)
+ {
+ return clazz.getClassLoader();
+ }};
+
+ GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+ public ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }});
+ }};
+ }
+
+ public static ClassLoader getClassLoader(Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+ }
+ else
+ {
+ return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+
+/**
+ * The temporary classpool used by the instrumentor. It's main job is to delegate to the parent classpool
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TempJBossClassPool extends AbstractClassPool
+{
+ boolean isParentAbstractPool;
+ public TempJBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(cl, src, repository);
+ if (src instanceof AbstractClassPool)
+ {
+ isParentAbstractPool = true;
+ }
+ }
+
+ public TempJBossClassPool(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(src, repository);
+ if (src instanceof AbstractClassPool)
+ {
+ isParentAbstractPool = true;
+ }
+ }
+
+ public CtClass getCached(String classname)
+ {
+ CtClass clazz = null;
+ if (isParentAbstractPool)
+ {
+ clazz = ((AbstractClassPool)parent).getCached(classname);
+ }
+ if (clazz == null)
+ {
+ clazz = super.getCached(classname);
+ }
+ return clazz;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossDelegatingClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossDelegatingClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TempJBossDelegatingClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TempJBossDelegatingClassPool extends AbstractClassPool
+{
+ boolean isParentPoolDelegating;
+ public TempJBossDelegatingClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(cl, src, repository);
+ if (src instanceof BaseClassPool)
+ {
+ isParentPoolDelegating = true;
+ }
+ }
+
+ public TempJBossDelegatingClassPool(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(src, repository);
+ if (src instanceof BaseClassPool)
+ {
+ isParentPoolDelegating = true;
+ }
+ }
+ @Override
+ public CtClass get0(String classname, boolean useCache) throws NotFoundException
+ {
+ CtClass clazz = null;
+ if (isParentPoolDelegating)
+ {
+ clazz = ((BaseClassPool)parent).get0(classname, useCache);
+ }
+ if (clazz == null)
+ {
+ clazz = super.get0(classname, useCache);
+ }
+ return clazz;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.net.URL;
+
+import org.jboss.util.loading.Translatable;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TranslatableClassLoaderIsLocalResourcePlugin extends AbstractIsLocalResourcePlugin
+{
+ public TranslatableClassLoaderIsLocalResourcePlugin(BaseClassPool pool)
+ {
+ super(pool);
+ }
+
+ public boolean isMyResource(String resourceName)
+ {
+ ClassLoader loader = getPool().getClassLoader();
+ if (loader instanceof Translatable == false)
+ {
+ throw new IllegalStateException("ClassLoader is not instance of Translatable " + loader);
+ }
+ URL url = ((Translatable)getPool().getClassLoader()).getResourceLocally(resourceName);
+ if (url == null)
+ {
+ return false;
+ }
+ if (isSameInParent(resourceName, url))
+ {
+ return false;
+ }
+ return true;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TranslatableClassLoaderIsLocalResourcePluginFactory implements IsLocalResourcePluginFactory
+{
+ public IsLocalResourcePlugin create(BaseClassPool pool)
+ {
+ return new TranslatableClassLoaderIsLocalResourcePlugin(pool);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePlugin.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePlugin.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePlugin.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+import java.net.URL;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class URLClassLoaderIsLocalResourcePlugin extends AbstractIsLocalResourcePlugin
+{
+ public URLClassLoaderIsLocalResourcePlugin(BaseClassPool pool)
+ {
+ super(pool);
+ }
+
+ public boolean isMyResource(String classResourceName)
+ {
+ //TODO This should be moved into URLClassLoaderIsLocalResourcePlugin, and the -core tests should be updated to
+ //not use the same urls
+ ClassLoader myLoader = getPool().getClassLoader();
+ URL myURL = myLoader.getResource(classResourceName);
+ if (myURL == null)
+ {
+ return false;
+ }
+ if (isSameInParent(classResourceName, myURL))
+ {
+ return false;
+ }
+ return true;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePluginFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePluginFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/URLClassLoaderIsLocalResourcePluginFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class URLClassLoaderIsLocalResourcePluginFactory implements IsLocalResourcePluginFactory
+{
+
+ public IsLocalResourcePlugin create(BaseClassPool pool)
+ {
+ return new URLClassLoaderIsLocalResourcePlugin(pool);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,84 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.jboss4;
+
+import java.io.File;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.AbstractClassPool;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 82781 $
+ */
+public class JBossClassPool extends AbstractClassPool implements ToClassInvokerPoolReference
+{
+ ToClassInvoker toClassInvoker = null;
+
+ protected JBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+ {
+ super(cl, src, repository);
+ toClassInvoker = new ToClassInvoker(tmp);
+ }
+
+ protected JBossClassPool(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(src, repository);
+ }
+
+ public boolean isUnloadedClassLoader()
+ {
+ if (getClassLoader() instanceof RepositoryClassLoader)
+ {
+ RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
+ return rcl.getLoaderRepository() == null;
+ }
+ return false;
+ }
+
+ public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+ }
+
+ public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return super.toClass(cc, loader, domain);
+ }
+
+ @Override
+ public void lockInCache(CtClass clazz)
+ {
+ super.lockInCache(clazz);
+ localResources.put(getResourceName(clazz.getName()), Boolean.TRUE);
+ }
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/JBossClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,130 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.jboss4;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.AbstractClassPool;
+import org.jboss.classpool.AbstractJBossClassPoolFactory;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 70841 $
+ **/
+public class JBossClassPoolFactory extends AbstractJBossClassPoolFactory implements ScopedClassPoolFactory
+{
+ protected File tmpClassesDir;
+
+ public JBossClassPoolFactory(File tmpClassesDir) throws IOException
+ {
+ this.tmpClassesDir = tmpClassesDir;
+
+ }
+ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ ClassPool parent = getCreateParentClassPools(cl, src, repository);
+ if (cl instanceof RepositoryClassLoader)
+ {
+ File tempdir = getTempDirectory(cl);
+ URL tmpCP;
+ try
+ {
+ tmpCP = createURLAndAddToLoader(cl, tempdir);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ if (ScopedRepositoryClassLoaderHelper.isScopedClassLoader(cl))
+ {
+ //It is scoped
+ return new ScopedJBossClassPool(cl, parent, repository, tempdir, tmpCP);
+ }
+ return new JBossClassPool(cl, parent, repository, tempdir, tmpCP);
+ }
+ return new AbstractClassPool(cl, parent, repository);
+ }
+
+ protected File getTempDirectory(ClassLoader cl)
+ {
+ File tempdir = null;
+ int attempts = 0;
+ IOException ex = null;
+ while (tempdir == null && attempts < 5)
+ {
+ //Workaround for JBAOP-254, retry a few times
+ try
+ {
+ tempdir = createTempDir(cl);
+ }
+ catch (IOException e)
+ {
+ ex = e;
+ }
+ }
+
+ if (tempdir == null)
+ {
+ throw new RuntimeException("", ex);
+ }
+
+ return tempdir;
+ }
+
+ public File createTempDir(ClassLoader cl) throws IOException
+ {
+ File tempdir = File.createTempFile("ucl", "", tmpClassesDir);
+ tempdir.delete();
+ tempdir.mkdir();
+ tempdir.deleteOnExit();
+
+ return tempdir;
+ }
+
+ private URL createURLAndAddToLoader(ClassLoader cl, File tempdir) throws IOException
+ {
+ URL tmpURL = tempdir.toURL();
+ URL tmpCP = new URL(tmpURL, "?dynamic=true");
+
+ RepositoryClassLoader ucl = (RepositoryClassLoader) cl;
+
+ // We may be undeploying.
+ if (ucl.getLoaderRepository() != null)
+ {
+ ucl.addURL(tmpCP);
+ }
+
+ return tmpCP;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/LoaderRepositoryUrlUtil.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/LoaderRepositoryUrlUtil.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/LoaderRepositoryUrlUtil.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,173 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.jboss4;
+
+import java.net.URL;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.util.MBeanServerLocator;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class LoaderRepositoryUrlUtil implements NotificationListener
+{
+ final static MBeanServer SERVER;
+ final static ObjectName MAIN_LOADER_REPOSITORY_OBJECT_NAME;
+ final static LoaderRepository MAIN_LOADER_REPOSITORY;
+ static
+ {
+ SERVER = MBeanServerLocator.locateJBoss();
+ try
+ {
+ MAIN_LOADER_REPOSITORY_OBJECT_NAME = new ObjectName("JMImplementation:name=Default,service=LoaderRepository");
+ MAIN_LOADER_REPOSITORY = (LoaderRepository)SERVER.invoke(MAIN_LOADER_REPOSITORY_OBJECT_NAME, "getInstance", new Object[0], new String[0]);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ long currentSequenceNumber;
+ long lastSequenceNumber = -1;
+ URL[] urls;
+
+ public LoaderRepositoryUrlUtil()
+ {
+ try
+ {
+ SERVER.addNotificationListener(MAIN_LOADER_REPOSITORY_OBJECT_NAME, this, null, null);
+ }
+ catch (InstanceNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public synchronized void handleNotification(Notification notification, Object handback)
+ {
+ if (notification.getType().equals(LoaderRepository.CLASSLOADER_ADDED))
+ {
+ currentSequenceNumber = notification.getSequenceNumber();
+ }
+ else if (notification.getType().equals(LoaderRepository.CLASSLOADER_REMOVED))
+ {
+ currentSequenceNumber = notification.getSequenceNumber();
+ }
+ }
+
+ public synchronized UrlInfo getURLInfo(HeirarchicalLoaderRepository3 scopedLoader, UrlInfo urlInfo)
+ {
+ boolean changed = false;
+ if (lastSequenceNumber != currentSequenceNumber)
+ {
+ urls = MAIN_LOADER_REPOSITORY.getURLs();
+ lastSequenceNumber = currentSequenceNumber;
+ changed = true;
+ }
+ if (!changed)
+ {
+ changed = urlInfo != null && (urlInfo.getSequenceNumber() != lastSequenceNumber);
+ }
+ if (urlInfo == null || changed)
+ {
+ URL[] localUrls = getLocalUrls(scopedLoader, urls);
+ urlInfo = new UrlInfo(urls, localUrls, lastSequenceNumber);
+ }
+ return urlInfo;
+ }
+
+ public long getCurrentSequenceNumber()
+ {
+ return currentSequenceNumber;
+ }
+
+ private URL[] getLocalUrls(HeirarchicalLoaderRepository3 scopedRepository, URL[] globalUrls)
+ {
+ URL[] scopedRepositoryUrls = scopedRepository.getURLs();
+
+ //This is a bit of a hack, since this relies on the order of the urls returned by HeirarchicalLoaderRepository3
+ //My urls, followed by parent urls.
+ int scopedLength = 0;
+ for (int i = 0 ; i < scopedRepositoryUrls.length ; i++)
+ {
+ for (int j = 0 ; j < globalUrls.length ; j ++)
+ {
+ if (scopedRepositoryUrls[i].equals(globalUrls[j]))
+ {
+ scopedLength = i;
+ break;
+ }
+ }
+ if (scopedLength > 0)
+ {
+ break;
+ }
+ }
+
+ URL[] localUrls = new URL[scopedLength];
+ System.arraycopy(scopedRepositoryUrls, 0, localUrls, 0, scopedLength);
+ return localUrls;
+ }
+
+ public class UrlInfo
+ {
+
+ URL[] globalUrls;
+ URL[] localUrls;
+ long sequenceNumber;
+
+ public UrlInfo(URL[] globalUrls, URL[] localUrls, long sequenceNumber)
+ {
+ super();
+ this.globalUrls = globalUrls;
+ this.localUrls = localUrls;
+ this.sequenceNumber = sequenceNumber;
+ }
+
+ public URL[] getGlobalUrls()
+ {
+ return globalUrls;
+ }
+
+ public URL[] getLocalUrls()
+ {
+ return localUrls;
+ }
+
+ public long getSequenceNumber()
+ {
+ return sequenceNumber;
+ }
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedJBossClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedJBossClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedJBossClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,273 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.jboss4;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.AbstractClassPool;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.jboss4.LoaderRepositoryUrlUtil.UrlInfo;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * A classpool in JBoss backed by a scoped (HierarchicalLoaderRepository) loader repository
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScopedJBossClassPool extends JBossClassPool
+{
+ final static LoaderRepositoryUrlUtil LOADER_REPOSITORY_UTIL = new LoaderRepositoryUrlUtil();
+
+ private UrlInfo urlInfo;
+ private ThreadLocal<ClassPool> lastPool = new ThreadLocal<ClassPool>();
+
+ public ScopedJBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+ {
+ super(cl, src, repository, tmp, tmpURL);
+
+ boolean parentFirst = false;
+ LoaderRepository loaderRepository = null;
+ ClassLoader prnt = cl;
+ while (prnt != null)
+ {
+ if (prnt instanceof RepositoryClassLoader)
+ {
+ loaderRepository = ((RepositoryClassLoader)prnt).getLoaderRepository();
+ if (loaderRepository instanceof HeirarchicalLoaderRepository3)
+ {
+ parentFirst = ((HeirarchicalLoaderRepository3)loaderRepository).getUseParentFirst();
+ }
+ break;
+ }
+ prnt = SecurityActions.getParent(cl);
+ }
+
+ super.childFirstLookup = !parentFirst;
+ }
+
+
+ private HeirarchicalLoaderRepository3 getRepository()
+ {
+ ClassLoader cl = getClassLoader0();
+ if (cl != null)
+ {
+ return (HeirarchicalLoaderRepository3)((RepositoryClassLoader)cl).getLoaderRepository();
+ }
+ return null;
+ }
+
+ private URL getResourceUrlForClass(String resourcename)
+ {
+ HeirarchicalLoaderRepository3 repo = getRepository();
+ return repo.getResource(resourcename, super.getClassLoader());
+ }
+
+ private boolean isMine(URL url)
+ {
+ HeirarchicalLoaderRepository3 repo = getRepository();
+ if (repo != null)
+ {
+ //The URL of the class loaded with my scoped classloader
+ if (url != null)
+ {
+ urlInfo = LOADER_REPOSITORY_UTIL.getURLInfo(getRepository(), urlInfo);
+
+ URL[] myUrls = urlInfo.getLocalUrls();
+ String resource = url.toString();
+ for (int i = 0 ; i < myUrls.length ; i++)
+ {
+ if (resource.indexOf(myUrls[i].toString()) >= 0)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public CtClass getCached(String classname)
+ {
+ if (classname == null)
+ {
+ return null;
+ }
+ if (isUnloadedClassLoader())
+ {
+ return null;
+ }
+
+ if (generatedClasses.get(classname) != null)
+ {
+ //It is a new class, and this callback is probably coming from the frozen check when creating a new nested class
+ return super.getCached(classname);
+ }
+
+ //Is this from the scoped classloader itself of from the parent?
+ String resourcename = getResourceName(classname);
+ URL url = getResourceUrlForClass(resourcename);
+ boolean isMine = isMine(url);
+
+ if (isMine)
+ {
+ if (super.childFirstLookup)
+ {
+ //Parent delegation is false, attempt to get this class out of ourselves
+ CtClass clazz = super.getCachedLocally(classname);
+ if (clazz == null)
+ {
+ clazz = createCtClass(classname, false);
+ if (clazz != null)
+ {
+ lockInCache(clazz);
+ }
+ }
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ return super.getCached(classname);
+ }
+
+
+ try
+ {
+ ClassPool pool = getCorrectPoolForResource(classname, url);
+ if (pool != lastPool.get())
+ {
+ lastPool.set(pool);
+ return pool.get(classname);
+ }
+ }
+ catch (NotFoundException e)
+ {
+ }
+ catch(StackOverflowError e)
+ {
+ throw e;
+ }
+ finally
+ {
+ lastPool.set(null);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected boolean includeInGlobalSearch()
+ {
+ return false;
+ }
+
+ private ClassPool getCorrectPoolForResource(String classname, URL url)
+ {
+ ClassPoolRepository classPoolRepository = ClassPoolRepository.getInstance();
+ synchronized(classPoolRepository.getRegisteredCLs())
+ {
+ //JBoss 5 has an extra NoAnnotationURLCLassLoader that is not on the default path, make sure that that is checked at the end
+ //FIXME This needs revisiting/removing once the
+ ArrayList<AbstractClassPool> noAnnotationURLClassLoaderPools = null;
+ String resource = url.toString();
+ for(ClassPool pool : classPoolRepository.getRegisteredCLs().values())
+ {
+ AbstractClassPool candidate = (AbstractClassPool)pool;
+ if (candidate.isUnloadedClassLoader())
+ {
+ classPoolRepository.unregisterClassLoader(candidate.getClassLoader());
+ continue;
+ }
+
+ if (candidate.getClassLoader() instanceof RepositoryClassLoader)
+ {
+ //Sometimes the ClassLoader is a proxy for MBeanProxyExt?!
+ RepositoryClassLoader rcl = (RepositoryClassLoader)candidate.getClassLoader();
+ URL[] urls = rcl.getClasspath();
+
+ for (int i = 0 ; i < urls.length ; i++)
+ {
+ if (resource.indexOf(urls[i].getFile()) >= 0)
+ {
+ return candidate;
+ }
+ }
+ }
+ //FIXME Remove once we have the JBoss 5 version of pool
+ else if (isInstanceOfNoAnnotationURLClassLoader(candidate.getClassLoader()))
+ {
+ if (noAnnotationURLClassLoaderPools == null)
+ {
+ noAnnotationURLClassLoaderPools = new ArrayList<AbstractClassPool>();
+ }
+ noAnnotationURLClassLoaderPools.add(candidate);
+ }
+ }
+
+ //FIXME Remove once we have the JBoss 5 version of pool
+ if (noAnnotationURLClassLoaderPools != null)
+ {
+ for (AbstractClassPool pool : noAnnotationURLClassLoaderPools)
+ {
+ try
+ {
+ pool.get(classname);
+ return pool;
+ }
+ catch(NotFoundException ignoreTryNext)
+ {
+ }
+ }
+ }
+ }
+ return ClassPoolRepository.getInstance().getClassPoolFactory().
+ create(ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ }
+
+ /**
+ * NoAnnotationURLCLassLoader lives in different packages in JBoss 4 and 5
+ */
+ private boolean isInstanceOfNoAnnotationURLClassLoader(ClassLoader loader)
+ {
+ Class<?> parent = loader.getClass();
+ while (parent != null)
+ {
+ if ("NoAnnotationURLClassLoader".equals(parent.getSimpleName()))
+ {
+ return true;
+ }
+ parent = parent.getSuperclass();
+ }
+ return false;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedRepositoryClassLoaderHelper.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedRepositoryClassLoaderHelper.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ScopedRepositoryClassLoaderHelper.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.jboss4;
+
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @autor adrian at jboss.org
+ * @version $Revision$
+ */
+public class ScopedRepositoryClassLoaderHelper
+{
+ public static boolean isScopedClassLoader(ClassLoader loader)
+ {
+ boolean scoped = false;
+ if (loader instanceof RepositoryClassLoader)
+ {
+ LoaderRepository repository = ((RepositoryClassLoader)loader).getLoaderRepository();
+ if (repository instanceof HeirarchicalLoaderRepository3)
+ {
+ scoped = true;
+ //HeirarchicalLoaderRepository3 hlr = (HeirarchicalLoaderRepository3)repository;
+ //boolean parentFirst = hlr.getUseParentFirst();
+ }
+ }
+ return scoped;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/SecurityActions.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/SecurityActions.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/SecurityActions.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,84 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss4;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+ interface GetParentAction
+ {
+ ClassLoader getParent(ClassLoader loader);
+
+ GetParentAction NON_PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(ClassLoader loader)
+ {
+ return loader.getParent();
+ }
+ };
+
+ GetParentAction PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(final ClassLoader loader)
+ {
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run() throws Exception
+ {
+ return loader.getParent();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException(e.getException());
+ }
+ }
+ };
+ }
+
+ public static ClassLoader getParent(ClassLoader loader)
+ {
+ if (loader == null)
+ {
+ return null;
+ }
+ if (System.getSecurityManager() == null)
+ {
+ return GetParentAction.NON_PRIVILEGED.getParent(loader);
+ }
+ else
+ {
+ return GetParentAction.PRIVILEGED.getParent(loader);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvoker.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvoker.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvoker.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,103 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss4;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ToClassInvoker
+{
+ Logger logger = Logger.getLogger(this.getClass());
+
+ public File tmpDir;
+
+ public Object tmplock = new Object();
+
+ public ToClassInvoker(File tmpDir)
+ {
+ this.tmpDir = tmpDir;
+ }
+
+ public Class<?> toClass(ToClassInvokerPoolReference pool, CtClass cc, String classFileName, ClassLoader loader, ProtectionDomain domain)
+ throws CannotCompileException
+ {
+ boolean trace = logger.isTraceEnabled();
+ pool.lockInCache(cc);
+ final ClassLoader myloader = pool.getClassLoader();
+ if (myloader == null || tmpDir == null)
+ {
+ if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " tmpDir:" + tmpDir + " default to superPool.toClass for " + cc.getName());
+ Class<?> clazz = pool.superPoolToClass(cc, loader, domain);
+ if (trace) logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + clazz);
+ return clazz;
+ }
+ Class<?> dynClass = null;
+ try
+ {
+ File classFile = null;
+ // Write the clas file to the tmpdir
+ synchronized (tmplock)
+ {
+ classFile = new File(tmpDir, classFileName);
+ if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " writing bytes to " + classFile);
+ File pkgDirs = classFile.getParentFile();
+ pkgDirs.mkdirs();
+ FileOutputStream stream = new FileOutputStream(classFile);
+ stream.write(cc.toBytecode());
+ stream.flush();
+ stream.close();
+ classFile.deleteOnExit();
+ }
+ // We have to clear Blacklist caches or the class will never
+ // be found
+ //((UnifiedClassLoader)dcl).clearBlacklists();
+ // To be backward compatible
+ RepositoryClassLoader rcl = (RepositoryClassLoader)myloader;
+ rcl.clearClassBlackList();
+ rcl.clearResourceBlackList();
+
+ // Now load the class through the cl
+ dynClass = myloader.loadClass(cc.getName());
+ if (trace) logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + dynClass);
+ return dynClass;
+ }
+ catch (Exception ex)
+ {
+ ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
+ cfe.initCause(ex);
+ throw cfe;
+ }
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvokerPoolReference.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvokerPoolReference.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss4/ToClassInvokerPoolReference.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss4;
+
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ToClassInvokerPoolReference
+{
+ Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException;
+ ClassLoader getClassLoader();
+ void lockInCache(CtClass clazz);
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/DomainRegistry.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/DomainRegistry.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/DomainRegistry.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,55 @@
+package org.jboss.classpool.jboss5;
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.
+*/
+
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.dependency.Module;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface DomainRegistry
+{
+ ClassLoaderSystem getSystem();
+
+ ClassLoaderDomain getDefaultDomain();
+
+ boolean initMapsForLoader(ClassLoader loader, Module module, ClassLoader parentUnitLoader);
+
+ void cleanupLoader(ClassLoader loader);
+
+ ClassLoaderDomain getClassLoaderDomainForLoader(ClassLoader cl);
+
+ ClassLoader getParentUnitLoader(ClassLoader loader);
+
+ Module getModule(ClassLoader loader);
+
+ ClassLoader getClassLoader(Module module);
+
+ //List<ScopedVFSClassLoaderDomain> getAOPDomainsForClassLoaderDomain(ClassLoaderDomain domain);
+
+ //ReadWriteLock getAOPDomainsLockForClassLoaderDomain(ClassLoaderDomain domain);
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,76 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss5;
+
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.AbstractClassPool;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBoss5ClassPool extends AbstractClassPool implements ToClassInvokerPoolReference
+{
+ protected ToClassInvoker toClassInvoker = null;
+
+ boolean closed;
+
+ protected JBoss5ClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, URL tmpURL)
+ {
+ super(cl, src, repository);
+ toClassInvoker = new ToClassInvoker(tmpURL);
+ }
+
+ protected JBoss5ClassPool(ClassPool src, ScopedClassPoolRepository repository)
+ {
+ super(src, repository);
+ }
+
+ public boolean isUnloadedClassLoader()
+ {
+ return closed;
+ }
+
+ public void close()
+ {
+ closed = true;
+ super.close();
+ }
+
+ public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+ }
+
+ public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return super.toClass(cc, loader, domain);
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/JBoss5ClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,102 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.jboss5;
+
+import java.net.URL;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classpool.AbstractClassPool;
+import org.jboss.classpool.AbstractJBossClassPoolFactory;
+import org.jboss.classpool.ClassPoolRepository;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 64815 $
+ **/
+public class JBoss5ClassPoolFactory extends AbstractJBossClassPoolFactory implements ScopedClassPoolFactory
+{
+ private DomainRegistry registry;
+
+ public JBoss5ClassPoolFactory(DomainRegistry registry)
+ {
+ this.registry = registry;
+ }
+
+ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ ClassPool parent = getCreateParentClassPools(cl, src, repository);
+
+ ScopedClassPool pool = null;
+
+ if (cl instanceof RealClassLoader)
+ {
+ Module module = registry.getModule(cl);
+ if (module != null && module.getDeterminedParentDomainName() != null)
+ {
+ //It is scoped
+ ClassLoaderSystem sys = registry.getSystem();
+ ClassLoaderDomain domain = sys.getDomain(module.getDeterminedDomainName());
+ boolean parentFirst = module.isJ2seClassLoadingCompliance();
+ ClassPool parentDomainPool = getParentUnitClassPool(cl);
+ pool = new ScopedJBoss5ClassPool(cl, parent, parentDomainPool, repository, getTempURL(module), parentFirst, domain);
+ }
+ else
+ {
+ pool = new JBoss5ClassPool(cl, parent, repository, getTempURL(module));
+ }
+ }
+
+ if (pool == null)
+ {
+ pool = new AbstractClassPool(cl, parent, repository);
+ }
+ log.debug("Created pool " + pool + " for loader " + cl);
+
+ return pool;
+ }
+
+ private ClassPool getParentUnitClassPool(ClassLoader cl)
+ {
+ ClassLoader parent = registry.getParentUnitLoader(cl);
+ return ClassPoolRepository.getInstance().registerClassLoader(parent);
+ }
+
+
+ private URL getTempURL(Module module)
+ {
+ if (module == null)
+ return null;
+
+ return module.getDynamicClassRoot();
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/RegisterModuleCallback.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/RegisterModuleCallback.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/RegisterModuleCallback.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,68 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss5;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.logging.Logger;
+
+/**
+ * Use with org.jboss.classpool.jbosscl.JBossClDelegatingClassPoolFactory
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class RegisterModuleCallback
+{
+ Logger logger = Logger.getLogger(this.getClass());
+
+ private Set<Module> registeredModules = new HashSet<Module>();
+ private Set<Module> unregisteredModules = new HashSet<Module>();
+
+ public synchronized void addModule(Module module)
+ {
+ logger.debug("Adding module " + module);
+ unregisteredModules.add(module);
+ }
+
+ public synchronized void removeModule(Module module)
+ {
+ logger.debug("Removing module " + module);
+ registeredModules.remove(module);
+ unregisteredModules.remove(module);
+ }
+
+ public synchronized Set<Module> getUnregisteredModules()
+ {
+ return Collections.unmodifiableSet(new HashSet<Module>(unregisteredModules));
+ }
+
+ public synchronized void registerModule(Module module)
+ {
+ logger.debug("Registering module " + module);
+ registeredModules.add(module);
+ unregisteredModules.remove(module);
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ScopedJBoss5ClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ScopedJBoss5ClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ScopedJBoss5ClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,400 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss5;
+
+import java.lang.ref.WeakReference;
+import java.net.URL;
+import java.util.ArrayList;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.Loader;
+import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.classpool.AbstractClassPool;
+import org.jboss.classpool.ClassPoolRepository;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScopedJBoss5ClassPool extends JBoss5ClassPool
+{
+ ThreadLocal<ClassPool> lastPool = new ThreadLocal<ClassPool>();
+ WeakReference<ClassLoaderDomain> domainRef;
+ /** The classpool representing the parent domain of this one */
+ ClassPool parentDomainPool;
+
+ public ScopedJBoss5ClassPool(ClassLoader cl, ClassPool src, ClassPool parentDomainPool, ScopedClassPoolRepository repository,
+ URL tmpURL, boolean parentFirst, ClassLoaderDomain domain)
+ {
+ super(cl, src, repository, tmpURL);
+ super.childFirstLookup = !parentFirst;
+ this.parentDomainPool = parentDomainPool;
+ this.domainRef = new WeakReference<ClassLoaderDomain>(domain);
+
+ logger.debug("Created new ScopedJBoss5ClasPool for " + cl + ", with parent: " + src + ", parentDomain: " + parentDomainPool + ", parentFirst: " + parentFirst);
+ }
+
+ private URL getResourceUrlForClass(String resourcename)
+ {
+ ClassLoaderDomain domain = domainRef.get();
+ return domain.getResource(resourcename);
+ }
+
+ private boolean isMine(URL myURL, String resourceName)
+ {
+ if (myURL == null)
+ {
+ return false;
+ }
+
+ ClassLoaderDomain domain = domainRef.get();
+ Loader parent = domain.getParent();
+ URL parentURL = parent.getResource(resourceName);
+
+ if (parentURL == null)
+ {
+ return true;
+ }
+
+ if (!myURL.equals(parentURL))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ @Override
+ protected synchronized CtClass get0(String classname, boolean useCache) throws NotFoundException
+ {
+ CtClass clazz = null;
+ if (useCache)
+ {
+ clazz = getCached(classname);
+ if (clazz != null)
+ return clazz;
+ }
+
+ if (!childFirstLookup)
+ {
+ if (parentDomainPool != null)
+ {
+ clazz = performGet(parentDomainPool, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ if (parent != null)
+ {
+ clazz = performGet(parent, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ }
+
+ clazz = createCtClass(classname, useCache);
+ if (clazz != null)
+ {
+ // clazz.getName() != classname if classname is "[L<name>;".
+ if (useCache)
+ cacheCtClass(clazz.getName(), clazz, false);
+
+ return clazz;
+ }
+
+ if (childFirstLookup)
+ {
+ if (parent != null)
+ {
+ clazz = performGet(parent, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ if (parentDomainPool != null)
+ {
+ clazz = performGet(parentDomainPool, classname);
+ if (clazz != null)
+ {
+ return clazz;
+ }
+ }
+ }
+
+ return clazz;
+ }
+
+ private CtClass performGet(ClassPool pool, String classname)
+ {
+ try
+ {
+ // TODO check whether we should enable this optimization
+ //Want to avoid calling get() if possible since that creates NotFoundExceptions
+ //on misses which is expensive
+ /*if (pool instanceof AbstractClassPool)
+ {
+ return ((AbstractClassPool)pool).internalGet0(classname, true);
+ }
+ else
+ {*/
+ return pool.getCtClass(classname);
+ }
+ catch (NotFoundException e)
+ {
+ return null;
+ }
+ }
+
+
+ public CtClass getCached(String classname)
+ {
+ boolean trace = logger.isTraceEnabled();
+
+ if (trace)
+ {
+ logger.trace("getCached() " + classname);
+ }
+
+ if (classname == null)
+ {
+ if (trace)
+ {
+ logger.trace("getCached() returning null (classname == null)");
+ }
+ return null;
+ }
+ if (isUnloadedClassLoader())
+ {
+ if (trace)
+ {
+ logger.trace("getCached() returning null (unloaded)");
+ }
+ return null;
+ }
+
+ if (generatedClasses.get(classname) != null)
+ {
+ //It is a new class, and this callback is probably coming from the frozen check when creating a new nested class
+ if (trace)
+ {
+ logger.trace("getCached() In generated classes - check super");
+ }
+ return super.getCached(classname);
+ }
+
+ //Is this from the scoped classloader itself of from the parent?
+ String resourcename = getResourceName(classname);
+ URL url = getResourceUrlForClass(resourcename);
+
+ if (isMine(url, resourcename))
+ {
+ if (super.childFirstLookup)
+ {
+ //Parent delegation is false, attempt to get this class out of ourselves
+ CtClass clazz = super.getCachedLocally(classname);
+ if (clazz == null)
+ {
+ if (trace)
+ {
+ logger.trace("getCached() Creating my class " + classname);
+ }
+ clazz = createCtClass(classname, false);
+ if (clazz != null)
+ {
+ lockInCache(clazz);
+ }
+ }
+ if (clazz != null)
+ {
+ if (trace)
+ {
+ logger.trace("getCached() Returning my class " + classname);
+ }
+ return clazz;
+ }
+ }
+ if (trace)
+ {
+ logger.trace("getCached() Checking super for my class " + classname);
+ }
+ return super.getCached(classname);
+ }
+ else if (url == null)
+ {
+ if (trace)
+ {
+ logger.trace("getCached() Checking super for my class " + classname + " (no url)");
+ }
+ return super.getCached(classname);
+ }
+
+
+ try
+ {
+ ClassPool pool = getCorrectPoolForResource(classname, resourcename, url, trace);
+ if (trace)
+ {
+ logger.trace("getCached() Found pool for class " + classname + " " + pool);
+ }
+ if (pool != lastPool.get())
+ {
+ lastPool.set(pool);
+ CtClass found = pool.get(classname);
+ if (trace)
+ {
+ logger.trace("getCached() Found clazz " + classname + " in " + pool + " : " + found);
+ }
+ return found;
+ }
+ }
+ catch (NotFoundException e)
+ {
+ }
+ catch(StackOverflowError e)
+ {
+ throw e;
+ }
+ finally
+ {
+ lastPool.set(null);
+ }
+
+ return null;
+ }
+
+ @Override
+ protected boolean includeInGlobalSearch()
+ {
+ return false;
+ }
+
+ private ClassPool getCorrectPoolForResource(String classname, String resourceName, URL url, boolean trace)
+ {
+ synchronized(ClassPoolRepository.getInstance().getRegisteredCLs())
+ {
+ //JBoss 5 has an extra NoAnnotationURLCLassLoader that is not on the default path, make sure that that is checked at the end
+ //FIXME This needs revisiting/removing once the
+ ArrayList<ClassPool> noAnnotationURLClassLoaderPools = null;
+
+ ClassPoolRepository classPoolRepository = ClassPoolRepository.getInstance();
+ for(ClassPool classPool: classPoolRepository.getRegisteredCLs().values())
+ {
+ AbstractClassPool candidate = (AbstractClassPool)classPool;
+ if (candidate.isUnloadedClassLoader())
+ {
+ classPoolRepository.unregisterClassLoader(candidate.getClassLoader());
+ continue;
+ }
+
+ if (candidate.getClassLoader() instanceof RealClassLoader)
+ {
+ //Sometimes the ClassLoader is a proxy for MBeanProxyExt?!
+ RealClassLoader bcl = (RealClassLoader)candidate.getClassLoader();
+ URL foundUrl = bcl.getResourceLocally(resourceName);
+ if (foundUrl != null)
+ {
+ if (url.equals(foundUrl))
+ {
+ if (trace)
+ {
+ logger.trace("getCorrectPoolForResource() Candidate classloader " + bcl + " has local resource " + foundUrl);
+ }
+ return candidate;
+ }
+ }
+ }
+ //FIXME Remove once we have the JBoss 5 version of pool
+ else if (isInstanceOfNoAnnotationURLClassLoader(candidate.getClassLoader()))
+ {
+ if (noAnnotationURLClassLoaderPools == null)
+ {
+ noAnnotationURLClassLoaderPools = new ArrayList<ClassPool>();
+ }
+ noAnnotationURLClassLoaderPools.add(candidate);
+ }
+ }
+
+ //FIXME Remove once we have the JBoss 5 version of pool
+ if (noAnnotationURLClassLoaderPools != null)
+ {
+ for (ClassPool pool : noAnnotationURLClassLoaderPools)
+ {
+ try
+ {
+ pool.get(classname);
+ if (trace)
+ {
+ logger.trace("getCorrectPoolForResource(() Found " + classname + " (no url)");
+ }
+ return pool;
+ }
+ catch(NotFoundException ignoreTryNext)
+ {
+ }
+ }
+ }
+ }
+ return createTempPool();
+ }
+
+ private ClassPool createTempPool()
+ {
+ //Rememeber that the stuff in jboss5/lib goes in a child classloader of the default classloader. We need
+ //to make this the parent of the temp classloader
+ ClassLoader loader = this.getClass().getClassLoader();// AspectManager.class.getClassLoader(); TODO validate this
+ ClassPool pool = ClassPoolRepository.getInstance().registerClassLoader(loader);
+ return ClassPoolRepository.getInstance().getClassPoolFactory().create(pool, ClassPoolRepository.getInstance());
+ }
+
+ /**
+ * NoAnnotationURLCLassLoader lives in different packages in JBoss 4 and 5
+ */
+ private boolean isInstanceOfNoAnnotationURLClassLoader(ClassLoader loader)
+ {
+ if (loader == null)
+ {
+ return false;
+ }
+ Class<?> parent = loader.getClass();
+ while (parent != null)
+ {
+ if ("NoAnnotationURLClassLoader".equals(parent.getSimpleName()))
+ {
+ return true;
+ }
+ parent = parent.getSuperclass();
+ }
+ return false;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/SecurityActions.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/SecurityActions.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/SecurityActions.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss5;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+ interface GetParentAction
+ {
+ ClassLoader getParent(ClassLoader loader);
+
+ GetParentAction NON_PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(ClassLoader loader)
+ {
+ return loader.getParent();
+ }
+ };
+
+ GetParentAction PRIVILEGED = new GetParentAction()
+ {
+ public ClassLoader getParent(final ClassLoader loader)
+ {
+ try
+ {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+ {
+ public ClassLoader run() throws Exception
+ {
+ return loader.getParent();
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException(e.getException());
+ }
+ }
+ };
+ }
+
+ public static ClassLoader getParent(ClassLoader loader)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetParentAction.NON_PRIVILEGED.getParent(loader);
+ }
+ else
+ {
+ return GetParentAction.PRIVILEGED.getParent(loader);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvoker.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvoker.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvoker.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,102 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss5;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
+
+/**
+ *
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ToClassInvoker
+{
+ Logger logger = Logger.getLogger(this.getClass());
+
+ public URL tempURL;
+
+ public Object tmplock = new Object();
+
+ public ToClassInvoker(URL tempURL)
+ {
+ this.tempURL = tempURL;
+ }
+
+ public Class<?> toClass(ToClassInvokerPoolReference pool, CtClass cc, String classFileName, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ boolean trace = logger.isTraceEnabled();
+ pool.lockInCache(cc);
+ final ClassLoader myloader = pool.getClassLoader();
+ if (myloader == null || tempURL == null)
+ {
+ if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " tempURL:" + tempURL + " default to superPool.toClass for " + cc.getName());
+ Class<?> clazz = pool.superPoolToClass(cc, loader, domain);
+ if (trace) logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + clazz);
+ return clazz;
+ }
+
+ try
+ {
+ URL outputURL = new URL(tempURL.toString() + "/" + classFileName);
+ //Write the classfile to the temporary url
+ synchronized (tmplock)
+ {
+ if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " writing bytes to " + tempURL);
+ ByteArrayOutputStream byteout = new ByteArrayOutputStream();
+ BufferedOutputStream out = new BufferedOutputStream(byteout);
+ out.write(cc.toBytecode());
+ out.flush();
+ out.close();
+
+ byte[] classBytes = byteout.toByteArray();
+ MemoryContextFactory factory = MemoryContextFactory.getInstance();
+ factory.putFile(outputURL, classBytes);
+
+ if (myloader instanceof RealClassLoader)
+ {
+ ((RealClassLoader)myloader).clearBlackList(classFileName);
+ }
+
+ Class<?> clazz = myloader.loadClass(cc.getName());
+ if (trace) logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + clazz);
+ return clazz;
+ }
+ }
+ catch(Exception e)
+ {
+ ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName() + " on " + this + " loader:" + myloader);
+ cfe.initCause(e);
+ throw cfe;
+ }
+ }
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvokerPoolReference.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvokerPoolReference.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/ToClassInvokerPoolReference.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jboss5;
+
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+/**
+ * Exposes methods on ClassPool needed by JBoss5ClassPool
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ToClassInvokerPoolReference
+{
+ Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException;
+ ClassLoader getClassLoader();
+ void lockInCache(CtClass clazz);
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/VFSClassLoaderDomainRegistry.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/VFSClassLoaderDomainRegistry.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jboss5/VFSClassLoaderDomainRegistry.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,285 @@
+package org.jboss.classpool.jboss5;
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.
+*/
+
+
+import java.lang.ref.WeakReference;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.dependency.Module;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSClassLoaderDomainRegistry implements DomainRegistry
+{
+ final static ClassLoaderDomain domain = new ClassLoaderDomain("NOT_USED_PLACEHOLDER");
+
+ private ClassLoaderSystem system;
+
+ private ClassLoaderDomain defaultDomain;
+
+ /** classloader domains by their classloaders */
+ private Map<ClassLoader, WeakReference<ClassLoaderDomain>> classLoaderDomainsByLoader = new WeakHashMap<ClassLoader, WeakReference<ClassLoaderDomain>>();
+
+ /** aopDomains by classloader */
+ //private Map<ClassLoader, ScopedVFSClassLoaderDomain> aopDomainsByClassLoader = new WeakHashMap<ClassLoader, ScopedVFSClassLoaderDomain>();
+
+ /** aopDomains by classloader domain */
+ //private Map<ClassLoaderDomain, List<ScopedVFSClassLoaderDomain>> aopDomainsByClassLoaderDomain = new WeakHashMap<ClassLoaderDomain, List<ScopedVFSClassLoaderDomain>>();
+
+ //private Map<ClassLoaderDomain, ReadWriteLock> aopDomainsLocksByClassLoaderDomain = new WeakHashMap<ClassLoaderDomain, ReadWriteLock>();
+
+
+ /** parent deployment unit classloaders indexed by children */
+ private Map<ClassLoader, WeakReference<ClassLoader>> classLoaderUnitParents = new WeakHashMap<ClassLoader, WeakReference<ClassLoader>>();
+
+ /** Modules by classloader */
+ private Map<ClassLoader, WeakReference<Module>> classLoaderModules = new WeakHashMap<ClassLoader, WeakReference<Module>>();
+
+ /** classloaders by module */
+ private Map<Module, WeakReference<ClassLoader>> moduleClassLoaders = new WeakHashMap<Module, WeakReference<ClassLoader>>();
+
+ private Map<ClassLoaderDomain, Integer> classLoaderDomainReferenceCounts = new WeakHashMap<ClassLoaderDomain, Integer>();
+
+ /**
+ * Needed for the tests, not expected to be needed in production
+ */
+ public void setSystem(ClassLoaderSystem system)
+ {
+ this.system = system;
+ }
+
+ /**
+ * Needed for the tests, not expected to be needed in production
+ */
+ public void setDefaultDomain(ClassLoaderDomain domain)
+ {
+ this.defaultDomain = domain;
+ }
+
+ public synchronized ClassLoaderSystem getSystem()
+ {
+ if (system == null)
+ {
+ system = ClassLoaderSystem.getInstance();
+ }
+ return system;
+ }
+
+ public synchronized ClassLoaderDomain getDefaultDomain()
+ {
+ if (defaultDomain == null)
+ {
+ defaultDomain = getSystem().getDefaultDomain();
+ }
+ return defaultDomain;
+ }
+
+ public synchronized boolean initMapsForLoader(ClassLoader loader, Module module, ClassLoader parentUnitLoader)
+ {
+ if (loader == parentUnitLoader)
+ {
+ throw new IllegalArgumentException("initMapsForLoader() should only be called if parentUnitLoader is different from loader");
+ }
+ ClassLoaderSystem system = getSystem();
+
+ String domainName = module.getDeterminedDomainName();
+ ClassLoaderDomain clDomain = system.getDomain(domainName);
+ if (clDomain == null && domain != null)
+ {
+ throw new IllegalStateException("Have " + domain + " but no classloader domain");
+ }
+
+ boolean ret = false;
+ if (!classLoaderDomainsByLoader.containsKey(loader))
+ {
+ Integer count = classLoaderDomainReferenceCounts.get(clDomain);
+ int cnt = count == null ? 0 : count.intValue();
+ classLoaderDomainReferenceCounts.put(clDomain, cnt);
+
+ classLoaderDomainsByLoader.put(loader, new WeakReference<ClassLoaderDomain>(clDomain));
+ classLoaderUnitParents.put(loader, new WeakReference<ClassLoader>(parentUnitLoader));
+ classLoaderModules.put(loader, new WeakReference<Module>(module));
+ moduleClassLoaders.put(module, new WeakReference<ClassLoader>(loader));
+ ret = true;
+ if (domain != null)
+ {
+
+
+ /*ReadWriteLock lock = aopDomainsLocksByClassLoaderDomain.get(clDomain);
+ if (lock == null)
+ {
+ lock = new ReentrantReadWriteLock();
+ aopDomainsLocksByClassLoaderDomain.put(clDomain, lock);
+ }
+
+ lock.writeLock().lock();
+ try
+ {
+ List<ScopedVFSClassLoaderDomain> aopDomains = aopDomainsByClassLoaderDomain.get(clDomain);
+ if (aopDomains == null)
+ {
+ synchronized (aopDomainsByClassLoaderDomain)
+ {
+ aopDomains = new CopyOnWriteArrayList<ScopedVFSClassLoaderDomain>();
+ if (!aopDomains.contains(clDomain))
+ {
+ aopDomainsByClassLoaderDomain.put(clDomain, aopDomains);
+ }
+ }
+ }
+ aopDomains.add(domain);
+ }
+ finally
+ {
+ lock.writeLock().unlock();
+ }*/
+ }
+ }
+
+
+ return ret;
+ }
+
+ public synchronized void cleanupLoader(ClassLoader loader)
+ {
+ WeakReference<ClassLoaderDomain> clDomainRef = classLoaderDomainsByLoader.remove(loader);
+ ClassLoaderDomain clDomain = clDomainRef == null ? null : clDomainRef.get();
+ if (clDomain != null)
+ {
+ Integer count = classLoaderDomainReferenceCounts.get(clDomain);
+ int cnt = count == null ? 0 : count.intValue();
+ if (cnt > 0)
+ {
+ cnt--;
+ }
+ if (cnt == 0)
+ {
+ //aopDomainsByClassLoaderDomain.remove(clDomain);
+ classLoaderDomainReferenceCounts.remove(clDomain);
+ }
+ else
+ {
+ classLoaderDomainReferenceCounts.put(clDomain, ++cnt);
+ }
+ //ScopedVFSClassLoaderDomain aopDomain = aopDomainsByClassLoader.remove(loader);
+ classLoaderUnitParents.remove(loader);
+ WeakReference<Module> moduleRef = classLoaderModules.remove(loader);
+ if (moduleRef != null)
+ {
+ Module module = moduleRef.get();
+ if (module != null)
+ {
+ moduleClassLoaders.remove(module);
+ }
+ }
+
+ /*List<ScopedVFSClassLoaderDomain> aopDomains = aopDomainsByClassLoaderDomain.get(clDomain);
+ if (aopDomains != null)
+ {
+ aopDomains.remove(aopDomain);
+ }
+ if (aopDomain != null)
+ {
+ aopDomain.getParent().unsubscribeSubDomain(aopDomain);
+ }*/
+ }
+ //aopDomainsByClassLoader.remove(loader);
+ }
+
+ /*public synchronized Domain getRegisteredDomain(ClassLoader cl)
+ {
+ return aopDomainsByClassLoader.get(cl);
+ }*/
+
+ public synchronized ClassLoaderDomain getClassLoaderDomainForLoader(ClassLoader cl)
+ {
+ WeakReference<ClassLoaderDomain> clDomainRef = classLoaderDomainsByLoader.get(cl);
+ if (clDomainRef != null)
+ {
+ return clDomainRef.get();
+ }
+
+ ClassLoader parent = SecurityActions.getParent(cl);
+ if (parent != null)
+ {
+ ClassLoaderDomain domain = getClassLoaderDomainForLoader(parent);
+ if (domain != null)
+ {
+ classLoaderDomainsByLoader.put(parent, new WeakReference<ClassLoaderDomain>(domain));
+ return domain;
+ }
+ }
+ return null;
+ }
+
+ public synchronized ClassLoader getParentUnitLoader(ClassLoader loader)
+ {
+ WeakReference<ClassLoader> parentRef = classLoaderUnitParents.get(loader);
+ if (parentRef != null)
+ {
+ return parentRef.get();
+ }
+ return null;
+ }
+
+ public synchronized Module getModule(ClassLoader loader)
+ {
+ WeakReference<Module> moduleRef = classLoaderModules.get(loader);
+ if (moduleRef != null)
+ {
+ return moduleRef.get();
+ }
+ return null;
+ }
+
+ public synchronized ClassLoader getClassLoader(Module module)
+ {
+ WeakReference<ClassLoader> loaderRef = moduleClassLoaders.get(module);
+ if (loaderRef != null)
+ {
+ return loaderRef.get();
+ }
+ return null;
+ }
+
+ /*public List<ScopedVFSClassLoaderDomain> getAOPDomainsForClassLoaderDomain(ClassLoaderDomain domain)
+ {
+ List<ScopedVFSClassLoaderDomain> domains = aopDomainsByClassLoaderDomain.get(domain);
+ if (domains != null)
+ {
+ return domains;
+ }
+ return Collections.emptyList();
+ }
+
+ public ReadWriteLock getAOPDomainsLockForClassLoaderDomain(ClassLoaderDomain domain)
+ {
+ return aopDomainsLocksByClassLoaderDomain.get(domain);
+ }*/
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolDomain.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolDomain.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolDomain.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,251 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classpool.BaseClassPool;
+import org.jboss.classpool.BaseClassPoolDomain;
+import org.jboss.classpool.ClassLoaderUtils;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.DelegatingClassPool;
+import org.jboss.classpool.jboss5.DomainRegistry;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolDomain extends BaseClassPoolDomain
+{
+ Map<String, Set<DelegatingClassPool>> poolsByPackage = new HashMap<String, Set<DelegatingClassPool>>();
+ final static List<DelegatingClassPool> EMPTY_LIST = Collections.unmodifiableList(Collections.EMPTY_LIST);
+
+ DomainRegistry registry;
+
+ public JBossClClassPoolDomain(String domainName, ClassPoolDomain parent, ParentPolicy parentPolicy, DomainRegistry registry)
+ {
+ super(domainName,
+ new JBossClParentDelegationStrategy(
+ parent,
+ parentPolicy,
+ JBossClClassPoolToClassPoolDomainAdaptorFactory.getInstance())
+ );
+ this.registry = registry;
+ }
+
+ synchronized void setupPoolsByPackage(DelegatingClassPool pool)
+ {
+ if (pool instanceof JBossClDelegatingClassPool == false)
+ {
+ throw new IllegalStateException("Not an instance of JBossClDelegatingClassPool: " + pool.getClass().getName());
+ }
+
+ Module module = getModuleForPool(pool);
+ boolean trace = logger.isTraceEnabled();
+
+ for (String pkg : module.getPackageNames())
+ {
+ Set<DelegatingClassPool> pools = poolsByPackage.get(pkg);
+ if (pools == null)
+ {
+ pools = new LinkedHashSet<DelegatingClassPool>();
+ poolsByPackage.put(pkg, pools);
+ }
+ pools.add(pool);
+ if (trace) logger.trace(this + " adding package " + pkg + " for pool " + pool);
+ }
+ }
+
+ @Override
+ protected synchronized void removeClassPool(DelegatingClassPool pool)
+ {
+ super.removeClassPool(pool);
+
+ Module module = getModuleForPool(pool);
+ boolean trace = logger.isTraceEnabled();
+
+ for (String pkg : module.getPackageNames())
+ {
+ Set<DelegatingClassPool> pools = poolsByPackage.get(pkg);
+ if (pools != null)
+ {
+ pools.remove(pool);
+ if (pools.size() == 0)
+ {
+ poolsByPackage.remove(pkg);
+ if (trace) logger.trace(this + " removing package " + pkg + " for pool " + pool);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected CtClass getCachedOrCreate(DelegatingClassPool initiatingPool, String classname, String resourceName, boolean create, boolean trace)
+ {
+ if (trace) logger.trace(this + " looking for " + classname);
+
+ CtClass clazz = getCheckPrimitive(classname);
+ if (clazz != null)
+ {
+ if (trace) logger.trace(this + " isPrimitive " + classname);
+ }
+ else
+ {
+ Module module = getModuleForPool(initiatingPool);
+ if (module != null && module.isImportAll())
+ {
+ //Use the old "big ball of mud" model
+ if (trace) logger.trace(this + " isImportAll");
+ return super.getCachedOrCreate(initiatingPool, classname, resourceName, create, trace);
+ }
+
+ //Attempt OSGi style loading
+ if (isParentBefore(classname))
+ {
+ if (trace) logger.trace(this + " checking parent first for " + classname);
+ clazz = getCachedOrCreateFromParent(null, classname, resourceName, create, trace);
+ }
+
+ //Check imports first
+ if (clazz == null && module != null)
+ {
+ if (trace) logger.trace(this + " checking imports for " + classname);
+ clazz = getCtClassFromModule(module, classname, trace);
+ }
+
+ //Try to check the initiating pool itself
+ if (clazz == null && initiatingPool != null)
+ {
+ if (trace) logger.trace(this + " checking pool " + initiatingPool + " locally for " + classname);
+ clazz = initiatingPool.loadLocally(classname, resourceName, create);
+ }
+
+ if (clazz == null && isParentAfter(classname))
+ {
+ if (trace) logger.trace(this + " checking parent last for " + classname);
+ clazz = getCachedOrCreateFromParent(null, classname, resourceName, create, trace);
+ }
+ }
+ if (trace) logger.trace(this + " found " + classname + " in " + (clazz == null ? "null" : clazz.getClassPool()));
+ return clazz;
+ }
+
+ private CtClass getCheckPrimitive(String classname)
+ {
+ if (ClassLoaderUtils.isPrimitiveType(classname))
+ {
+ try
+ {
+ return ClassPool.getDefault().get(classname);
+ }
+ catch(NotFoundException e)
+ {
+ throw new RuntimeException(classname + " should have been a primitive", e);
+ }
+ }
+ return null;
+ }
+
+ private Module getModuleForPool(DelegatingClassPool pool)
+ {
+ if (pool == null)
+ {
+ return null;
+ }
+ Module module = ((JBossClDelegatingClassPool)pool).getModule();
+ if (logger.isTraceEnabled()) logger.trace(this + " got module " + module + " for " + pool);
+ return module;
+ }
+
+ @Override
+ protected List<DelegatingClassPool> getPoolsForClassName(String classname)
+ {
+ String packageName = ClassLoaderUtils.getPackageName(classname);
+ Set<DelegatingClassPool> poolSet = poolsByPackage.get(packageName);
+ if (poolSet == null)
+ {
+ return EMPTY_LIST;
+ }
+ return new ArrayList<DelegatingClassPool>(poolSet);
+ }
+
+ private CtClass getCtClassFromModule(final Module module, final String classname, boolean trace)
+ {
+ Module found = null;
+ try
+ {
+ found = AccessController.doPrivileged(new PrivilegedExceptionAction<Module>()
+ {
+
+ public Module run() throws Exception
+ {
+ return module.getModuleForClass(ClassLoaderUtils.stripArrayFromClassName(classname));
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ if (e.getCause() instanceof ClassNotFoundException == false)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ if (trace) logger.trace(this + " module for " + classname + " " + found);
+
+ if (found == null || found == module)
+ {
+ return null;
+ }
+ ClassLoader foundLoader = registry.getClassLoader(found);
+ ClassPool pool = ClassPoolRepository.getInstance().registerClassLoader(foundLoader);
+ try
+ {
+ if (pool instanceof BaseClassPool)
+ {
+ return getCachedOrCreateFromPool((BaseClassPool)pool, classname, true, trace);
+ }
+ return pool.get(classname);
+ }
+ catch(NotFoundException e)
+ {
+ }
+ return null;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdapter.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdapter.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdapter.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import javassist.ClassPool;
+
+import org.jboss.classloader.spi.base.BaseClassLoaderDomain;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.ClassPoolToClassPoolDomainAdapter;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolToClassPoolDomainAdapter extends ClassPoolToClassPoolDomainAdapter
+{
+ @Override
+ public ClassPool initialiseParentClassLoader()
+ {
+ return ClassPoolRepository.getInstance().registerClassLoader(BaseClassLoaderDomain.class.getClassLoader());
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdaptorFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdaptorFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClClassPoolToClassPoolDomainAdaptorFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import org.jboss.classpool.ClassPoolToClassPoolDomainAdapter;
+import org.jboss.classpool.ClassPoolToClassPoolDomainAdaptorFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolToClassPoolDomainAdaptorFactory implements ClassPoolToClassPoolDomainAdaptorFactory
+{
+ private static final JBossClClassPoolToClassPoolDomainAdaptorFactory INSTANCE = new JBossClClassPoolToClassPoolDomainAdaptorFactory();
+
+ private JBossClClassPoolToClassPoolDomainAdaptorFactory()
+ {
+
+ }
+
+ public static ClassPoolToClassPoolDomainAdaptorFactory getInstance()
+ {
+ return INSTANCE;
+ }
+
+ public ClassPoolToClassPoolDomainAdapter createAdaptor()
+ {
+ return new JBossClClassPoolToClassPoolDomainAdapter();
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,95 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import java.lang.ref.WeakReference;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.DelegatingClassPool;
+import org.jboss.classpool.jboss5.RegisterModuleCallback;
+import org.jboss.classpool.jboss5.ToClassInvoker;
+import org.jboss.classpool.jboss5.ToClassInvokerPoolReference;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClDelegatingClassPool extends DelegatingClassPool implements ToClassInvokerPoolReference
+{
+ private WeakReference<Module> module;
+ private RegisterModuleCallback callback;
+
+ ToClassInvoker toClassInvoker;
+
+ protected JBossClDelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent,
+ ScopedClassPoolRepository repository, Module module, RegisterModuleCallback callback)
+ {
+ super(domain, cl, parent, repository);
+ if (module == null)
+ {
+ throw new IllegalStateException("Null Module for loader " + cl);
+ }
+ if (domain instanceof JBossClClassPoolDomain == false)
+ {
+ throw new IllegalArgumentException("Domain was not instance of JBossClClassPoolDomain: " + domain.getClass().getName());
+ }
+ this.module = new WeakReference<Module>(module);
+ this.callback = callback;
+ toClassInvoker = new ToClassInvoker(module == null ? null : module.getDynamicClassRoot());
+ if (logger.isTraceEnabled()) logger.trace(this + " module");
+ ((JBossClClassPoolDomain)domain).setupPoolsByPackage(this);
+ }
+
+ Module getModule()
+ {
+ if (module != null)
+ {
+ return module.get();
+ }
+ return null;
+ }
+
+ public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+ }
+
+ public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return super.toClass(cc, loader, domain);
+ }
+
+ @Override
+ public void close()
+ {
+ super.close();
+ callback.removeModule(getModule());
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClDelegatingClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,177 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Set;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classpool.AbstractJBossDelegatingClassPoolFactory;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.ClassPoolDomainRegistry;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.ClassPoolToClassPoolDomainAdapter;
+import org.jboss.classpool.NonDelegatingClassPool;
+import org.jboss.classpool.jboss5.DomainRegistry;
+import org.jboss.classpool.jboss5.RegisterModuleCallback;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClDelegatingClassPoolFactory extends AbstractJBossDelegatingClassPoolFactory implements ScopedClassPoolFactory
+{
+ private final DomainRegistry registry;
+
+ private final RegisterModuleCallback registerModuleCallback;
+
+ public JBossClDelegatingClassPoolFactory(DomainRegistry registry, RegisterModuleCallback registerModuleCallback)
+ {
+ this.registry = registry;
+ this.registerModuleCallback = registerModuleCallback;
+ }
+
+ public ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ ClassPool parent = getCreateParentClassPools(cl, src, repository);
+
+ if (cl instanceof RealClassLoader)
+ {
+ Module module = registry.getModule(cl);
+ if (module == null)
+ {
+ module = getModuleForClassLoader(cl);
+ }
+ registerModuleCallback.registerModule(module);
+ registerBootstrapLoaders();
+ ClassPoolDomain domain = getDomain(module, cl);
+ return new JBossClDelegatingClassPool(domain, cl, parent, repository, module, registerModuleCallback);
+ }
+
+ return new NonDelegatingClassPool(cl, parent, repository, true);
+ }
+
+ private synchronized ClassPoolDomain getDomain(Module module, ClassLoader cl)
+ {
+ ClassLoaderDomain domain = null;
+ ClassLoaderSystem sys = registry.getSystem();
+ if (module != null && module.getDeterminedParentDomainName() != null)
+ {
+ //It is scoped
+ domain = sys.getDomain(module.getDeterminedDomainName());
+ }
+
+ if (domain == null)
+ {
+ domain = registry.getDefaultDomain();
+ }
+
+ ClassPoolDomain poolDomain = ClassPoolDomainRegistry.getInstance().getDomain(domain);
+ if (poolDomain == null)
+ {
+ String parentDomainName = domain.getParentDomainName();
+ ClassPoolDomain parentPoolDomain = null;
+ if (parentDomainName != null)
+ {
+ ClassLoaderDomain parentDomain = sys.getDomain(parentDomainName);
+ if (parentDomain == null)
+ {
+ throw new RuntimeException("No domain found called: " + parentDomainName);
+ }
+ parentPoolDomain = ClassPoolDomainRegistry.getInstance().getDomain(parentDomain);
+ }
+ if (parentDomainName == null)
+ {
+ ClassLoader parentUnitLoader = registry.getParentUnitLoader(cl);
+ if (parentUnitLoader != null)
+ {
+ ClassPool parentUnitPool = ClassPoolRepository.getInstance().registerClassLoader(parentUnitLoader);
+ parentPoolDomain = new ClassPoolToClassPoolDomainAdapter(parentUnitPool);
+ }
+ }
+ poolDomain = new JBossClClassPoolDomain(domain.getName(), parentPoolDomain, domain.getParentPolicy(), registry);
+
+ ClassPoolDomainRegistry.getInstance().addClassPoolDomain(domain, poolDomain);
+ }
+ return poolDomain;
+ }
+
+ @Override
+ protected ClassPool getCreateParentClassPools(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ ClassPool parent = super.getCreateParentClassPools(cl, src, repository);
+ if (parent == ClassPool.getDefault())
+ {
+ //In AS BaseClassLoader seems to normally have a null parent
+ return null;
+ }
+ return parent;
+ }
+
+ private void registerBootstrapLoaders()
+ {
+ Set<Module> unregistered = registerModuleCallback.getUnregisteredModules();
+ if (unregistered.size() > 0)
+ {
+ for (Module module : unregistered)
+ {
+ ClassLoader loader = getClassLoaderForModule(module);
+ log.debug("Registering loader for module " + module + ": " + loader);
+ ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+ }
+ }
+
+ private ClassLoader getClassLoaderForModule(final Module module)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+
+ public ClassLoader run()
+ {
+ return ClassLoading.getClassLoaderForModule(module);
+ }
+ });
+ }
+
+ private Module getModuleForClassLoader(final ClassLoader classLoader)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<Module>()
+ {
+ public Module run()
+ {
+ return ClassLoading.getModuleForClassLoader(classLoader);
+ }
+ });
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClParentDelegationStrategy.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClParentDelegationStrategy.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/JBossClParentDelegationStrategy.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classpool.AbstractParentDelegationStrategy;
+import org.jboss.classpool.ClassLoaderUtils;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.ClassPoolToClassPoolDomainAdaptorFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class JBossClParentDelegationStrategy extends AbstractParentDelegationStrategy
+{
+ ParentPolicy parentPolicy;
+
+ JBossClParentDelegationStrategy(ClassPoolDomain parent, ParentPolicy parentPolicy, ClassPoolToClassPoolDomainAdaptorFactory adaptorFactory)
+ {
+ super(parent, adaptorFactory);
+ if (parentPolicy == null)
+ {
+ throw new IllegalStateException("Null parent policy");
+ }
+ this.parentPolicy = parentPolicy;
+ }
+
+ public boolean isParentAfter(String classname)
+ {
+ ClassFilter filter = parentPolicy.getAfterFilter();
+ boolean isParentAfter = filter.matchesClassName(ClassLoaderUtils.stripArrayFromClassName(classname));
+ if (logger.isTraceEnabled()) logger.trace(this + " " + getDomain() + " isParentAfter " + isParentAfter);
+ return isParentAfter;
+ }
+
+ public boolean isParentBefore(String classname)
+ {
+ ClassFilter filter = parentPolicy.getBeforeFilter();
+ boolean isParentBefore = filter.matchesClassName(ClassLoaderUtils.stripArrayFromClassName(classname));
+ if (logger.isTraceEnabled()) logger.trace(this + " " + getDomain() + " isParentBefore " + isParentBefore);
+ return isParentBefore;
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/SecurityActions.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/SecurityActions.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/jbosscl/SecurityActions.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,90 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+
+ interface GetClassLoaderAction
+ {
+ ClassLoader getClassLoader(Class<?> clazz);
+
+ GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+ public ClassLoader getClassLoader(Class<?> clazz)
+ {
+ return clazz.getClassLoader();
+ }};
+
+ GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+ public ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }});
+ }};
+ }
+
+ static ClassLoader getClassLoader(Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+ }
+ else
+ {
+ return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+ }
+ }
+
+ public static class GetContextClassLoaderAction implements PrivilegedAction<ClassLoader>
+ {
+ public static GetContextClassLoaderAction INSTANCE = new GetContextClassLoaderAction();
+
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+
+ static ClassLoader getContextClassLoader()
+ {
+ if (System.getSecurityManager() == null)
+ return Thread.currentThread().getContextClassLoader();
+ else
+ return AccessController.doPrivileged(GetContextClassLoaderAction.INSTANCE);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPool.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPool.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,70 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl;
+
+import java.io.File;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.DelegatingClassPool;
+import org.jboss.classpool.jboss4.ToClassInvoker;
+import org.jboss.classpool.jboss4.ToClassInvokerPoolReference;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossUclDelegatingClassPool extends DelegatingClassPool implements ToClassInvokerPoolReference
+{
+ ToClassInvoker toClassInvoker = null;
+
+ public JBossUclDelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent,
+ ScopedClassPoolRepository repository, File tmpDir, URL tmpURL)
+ {
+ super(domain, cl, parent, repository);
+ toClassInvoker = new ToClassInvoker(tmpDir);
+ }
+
+ public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+ }
+
+ public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+ {
+ return super.toClass(cc, loader, domain);
+ }
+
+ @Override
+ public void lockInCache(CtClass clazz)
+ {
+ super.lockInCache(clazz);
+ localResources.put(getResourceName(clazz.getName()), Boolean.TRUE);
+ }
+}
Added: projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPoolFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/main/java/org/jboss/classpool/ucl/JBossUclDelegatingClassPoolFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,166 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPool;
+import javassist.scopedpool.ScopedClassPoolFactory;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.AbstractJBossDelegatingClassPoolFactory;
+import org.jboss.classpool.BaseClassPoolDomain;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.ClassPoolDomainRegistry;
+import org.jboss.classpool.NonDelegatingClassPool;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.mx.server.ServerConstants;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossUclDelegatingClassPoolFactory extends AbstractJBossDelegatingClassPoolFactory implements ScopedClassPoolFactory
+{
+ private ClassPoolDomain mainDomain;
+ protected File tmpClassesDir;
+
+ public JBossUclDelegatingClassPoolFactory(File tmpClassesDir) throws IOException
+ {
+ System.out.println("TMP CLASSES DIR: " + tmpClassesDir);
+ this.tmpClassesDir = tmpClassesDir;
+ }
+
+ public synchronized ScopedClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+ {
+ ClassPool parent = getCreateParentClassPools(cl, src, repository);
+
+ if (cl instanceof RepositoryClassLoader)
+ {
+ ClassPoolDomain domain = getDomain((RepositoryClassLoader)cl);
+
+ File tempdir = getTempDirectory(cl);
+ URL tmpCP = createURLAndAddToLoader(cl, tempdir);
+
+ return new JBossUclDelegatingClassPool(domain, cl, parent, repository, tempdir, tmpCP);
+ }
+
+ return new NonDelegatingClassPool(cl, parent, repository, true);
+ }
+
+ private ClassPoolDomain getDomain(RepositoryClassLoader cl)
+ {
+ LoaderRepository loaderRepository = cl.getLoaderRepository();
+ ClassPoolDomainRegistry registry = ClassPoolDomainRegistry.getInstance();
+ ClassPoolDomain domain = registry.getDomain(loaderRepository);
+ if (domain == null)
+ {
+ if (loaderRepository instanceof HeirarchicalLoaderRepository3)
+ {
+
+ boolean parentFirst = ((HeirarchicalLoaderRepository3)loaderRepository).getUseParentFirst();
+ domain = new BaseClassPoolDomain("Scoped" + System.identityHashCode(loaderRepository), mainDomain, parentFirst);
+ }
+ else
+ {
+ if (mainDomain == null)
+ {
+ domain = new BaseClassPoolDomain(ServerConstants.DEFAULT_LOADER_NAME, null, false);
+ mainDomain = domain;
+ }
+ else
+ {
+ domain = mainDomain;
+ }
+ registry.addClassPoolDomain(loaderRepository, domain);
+ }
+ }
+ return domain;
+ }
+
+ protected File getTempDirectory(ClassLoader cl)
+ {
+ File tempdir = null;
+ int attempts = 0;
+ IOException ex = null;
+ while (tempdir == null && attempts < 5)
+ {
+ //Workaround for JBAOP-254, retry a few times
+ try
+ {
+ tempdir = createTempDir(cl);
+ }
+ catch (IOException e)
+ {
+ ex = e;
+ }
+ }
+
+ if (tempdir == null)
+ {
+ throw new RuntimeException("", ex);
+ }
+
+ return tempdir;
+ }
+
+ public File createTempDir(ClassLoader cl) throws IOException
+ {
+ File tempdir = File.createTempFile("ucl", "", tmpClassesDir);
+ tempdir.delete();
+ tempdir.mkdir();
+ tempdir.deleteOnExit();
+
+ return tempdir;
+ }
+
+ private URL createURLAndAddToLoader(ClassLoader cl, File tempdir)
+ {
+ try
+ {
+ URL tmpURL = tempdir.toURL();
+ URL tmpCP = new URL(tmpURL, "?dynamic=true");
+
+ RepositoryClassLoader ucl = (RepositoryClassLoader) cl;
+
+ // We may be undeploying.
+ if (ucl.getLoaderRepository() != null)
+ {
+ ucl.addURL(tmpCP);
+ }
+
+ return tmpCP;
+ }
+ catch(Exception e)
+ {
+ // AutoGenerated
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/main/resources/jbossorg-eula.txt
===================================================================
--- projects/jboss-classpool/trunk/src/main/resources/jbossorg-eula.txt (rev 0)
+++ projects/jboss-classpool/trunk/src/main/resources/jbossorg-eula.txt 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,107 @@
+LICENSE AGREEMENT
+JBOSS(r)
+
+This License Agreement governs the use of the Software Packages and any updates to the Software
+Packages, regardless of the delivery mechanism. Each Software Package is a collective work
+under U.S. Copyright Law. Subject to the following terms, Red Hat, Inc. ("Red Hat") grants to
+the user ("Client") a license to the applicable collective work(s) pursuant to the
+GNU Lesser General Public License v. 2.1 except for the following Software Packages:
+(a) JBoss Portal Forums and JBoss Transactions JTS, each of which is licensed pursuant to the
+GNU General Public License v.2;
+
+(b) JBoss Rules, which is licensed pursuant to the Apache License v.2.0;
+
+(c) an optional download for JBoss Cache for the Berkeley DB for Java database, which is licensed under the
+(open source) Sleepycat License (if Client does not wish to use the open source version of this database,
+it may purchase a license from Sleepycat Software);
+
+and (d) the BPEL extension for JBoss jBPM, which is licensed under the Common Public License v.1,
+and, pursuant to the OASIS BPEL4WS standard, requires parties wishing to redistribute to enter various
+royalty-free patent licenses.
+
+Each of the foregoing licenses is available at http://www.opensource.org/licenses/index.php.
+
+1. The Software. "Software Packages" refer to the various software modules that are created and made available
+for distribution by the JBoss.org open source community at http://www.jboss.org. Each of the Software Packages
+may be comprised of hundreds of software components. The end user license agreement for each component is located in
+the component's source code. With the exception of certain image files identified in Section 2 below,
+the license terms for the components permit Client to copy, modify, and redistribute the component,
+in both source code and binary code forms. This agreement does not limit Client's rights under,
+or grant Client rights that supersede, the license terms of any particular component.
+
+2. Intellectual Property Rights. The Software Packages are owned by Red Hat and others and are protected under copyright
+and other laws. Title to the Software Packages and any component, or to any copy, modification, or merged portion shall
+remain with the aforementioned, subject to the applicable license. The "JBoss" trademark, "Red Hat" trademark, the
+individual Software Package trademarks, and the "Shadowman" logo are registered trademarks of Red Hat and its affiliates
+in the U.S. and other countries. This agreement permits Client to distribute unmodified copies of the Software Packages
+using the Red Hat trademarks that Red Hat has inserted in the Software Packages on the condition that Client follows Red Hat's
+trademark guidelines for those trademarks located at http://www.redhat.com/about/corporate/trademark/. Client must abide by
+these trademark guidelines when distributing the Software Packages, regardless of whether the Software Packages have been modified.
+If Client modifies the Software Packages, then Client must replace all Red Hat trademarks and logos identified at
+http://www.jboss.com/company/logos, unless a separate agreement with Red Hat is executed or other permission granted.
+Merely deleting the files containing the Red Hat trademarks may corrupt the Software Packages.
+
+3. Limited Warranty. Except as specifically stated in this Paragraph 3 or a license for a particular
+component, to the maximum extent permitted under applicable law, the Software Packages and the
+components are provided and licensed "as is" without warranty of any kind, expressed or implied,
+including the implied warranties of merchantability, non-infringement or fitness for a particular purpose.
+Red Hat warrants that the media on which Software Packages may be furnished will be free from defects in
+materials and manufacture under normal use for a period of 30 days from the date of delivery to Client.
+Red Hat does not warrant that the functions contained in the Software Packages will meet Client's requirements
+or that the operation of the Software Packages will be entirely error free or appear precisely as described
+in the accompanying documentation. This warranty extends only to the party that purchases the Services
+pertaining to the Software Packages from Red Hat or a Red Hat authorized distributor.
+
+4. Limitation of Remedies and Liability. To the maximum extent permitted by applicable law, the remedies
+described below are accepted by Client as its only remedies. Red Hat's entire liability, and Client's
+exclusive remedies, shall be: If the Software media is defective, Client may return it within 30 days of
+delivery along with a copy of Client's payment receipt and Red Hat, at its option, will replace it or
+refund the money paid by Client for the Software. To the maximum extent permitted by applicable law,
+Red Hat or any Red Hat authorized dealer will not be liable to Client for any incidental or consequential
+damages, including lost profits or lost savings arising out of the use or inability to use the Software,
+even if Red Hat or such dealer has been advised of the possibility of such damages. In no event shall
+Red Hat's liability under this agreement exceed the amount that Client paid to Red Hat under this
+Agreement during the twelve months preceding the action.
+
+5. Export Control. As required by U.S. law, Client represents and warrants that it:
+(a) understands that the Software Packages are subject to export controls under the
+U.S. Commerce Department's Export Administration Regulations ("EAR");
+
+(b) is not located in a prohibited destination country under the EAR or U.S. sanctions regulations
+(currently Cuba, Iran, Iraq, Libya, North Korea, Sudan and Syria);
+
+(c) will not export, re-export, or transfer the Software Packages to any prohibited destination, entity,
+or individual without the necessary export license(s) or authorizations(s) from the U.S. Government;
+
+(d) will not use or transfer the Software Packages for use in any sensitive nuclear, chemical or
+biological weapons, or missile technology end-uses unless authorized by the U.S. Government by
+regulation or specific license;
+
+(e) understands and agrees that if it is in the United States and exports or transfers the Software
+Packages to eligible end users, it will, as required by EAR Section 740.17(e), submit semi-annual
+reports to the Commerce Department's Bureau of Industry & Security (BIS), which include the name and
+address (including country) of each transferee;
+
+and (f) understands that countries other than the United States may restrict the import, use, or
+export of encryption products and that it shall be solely responsible for compliance with any such
+import, use, or export restrictions.
+
+6. Third Party Programs. Red Hat may distribute third party software programs with the Software Packages
+that are not part of the Software Packages and which Client must install separately. These third party
+programs are subject to their own license terms. The license terms either accompany the programs or
+can be viewed at http://www.redhat.com/licenses/. If Client does not agree to abide by the applicable
+license terms for such programs, then Client may not install them. If Client wishes to install the programs
+on more than one system or transfer the programs to another party, then Client must contact the licensor
+of the programs.
+
+7. General. If any provision of this agreement is held to be unenforceable, that shall not affect the
+enforceability of the remaining provisions. This License Agreement shall be governed by the laws of the
+State of North Carolina and of the United States, without regard to any conflict of laws provisions,
+except that the United Nations Convention on the International Sale of Goods shall not apply.
+
+Copyright 2006 Red Hat, Inc. All rights reserved.
+"JBoss" and the JBoss logo are registered trademarks of Red Hat, Inc.
+All other trademarks are the property of their respective owners.
+
+ Page 1 of 1 18 October 2006
+
Property changes on: projects/jboss-classpool/trunk/src/main/resources/jbossorg-eula.txt
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/common/ClassFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/common/ClassFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/common/ClassFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.common;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Assert;
+
+import org.jboss.classpool.AbstractClassPool;
+import org.jboss.classpool.ClassPoolRepository;
+
+/**
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassFactory
+{
+ public static final String PACKAGE = "org.test.classpool.proxy";
+ private static final String CLASS = "Proxy";
+ private static int counter = 0;
+
+ public static Object create(Class<?> parent, ClassLoader loader) throws Exception
+ {
+ String packageName = parent.getPackage().getName();
+ if (!packageName.startsWith("java.") && !packageName.startsWith("sun."))
+ {
+ packageName += ".";
+ }
+ else
+ {
+ packageName = PACKAGE + ".";
+ }
+ String className = packageName + CLASS + counter++;
+ ClassPool pool = ClassPoolRepository.getInstance().getRegisteredCLs().get(loader);
+ try
+ {
+ registerGeneratedClass(pool, className);
+ CtClass ctClazz = pool.makeClass(packageName + CLASS + counter++);
+ ctClazz.setSuperclass(pool.get(parent.getName()));
+ Class<?> clazz = pool.toClass(ctClazz);
+ Assert.assertSame(loader, clazz.getClassLoader());
+ return clazz.newInstance();
+ }
+ catch(RuntimeException re)
+ {
+ unregisterGeneratedClass(pool, className);
+ throw re;
+ }
+ }
+
+ /**
+ * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it.
+ */
+ public static CtClass create(ClassPool pool, String name)
+ {
+ registerGeneratedClass(pool, name);
+ return pool.makeClass(name);
+ }
+
+ /**
+ * Utility method to make a new class in a pool. It makes sure that the class is registered with the pool, so others can find it.
+ */
+ public static CtClass createNested(CtClass outer, String name, boolean isStatic) throws CannotCompileException
+ {
+ final String classname = outer.getName() + "$" + name;
+ try
+ {
+ registerGeneratedClass(outer.getClassPool(), classname);
+ CtClass inner = outer.makeNestedClass(name, true);
+ return inner;
+ }
+ catch (RuntimeException e)
+ {
+ unregisterGeneratedClass(outer.getClassPool(), classname);
+ throw e;
+ }
+ }
+
+ private static void registerGeneratedClass(ClassPool pool, String name)
+ {
+ if (pool != null && pool instanceof AbstractClassPool)
+ {
+ ((AbstractClassPool) pool).registerGeneratedClass(name);
+ }
+ }
+
+ private static void unregisterGeneratedClass(ClassPool pool, String name)
+ {
+ if (pool != null && pool instanceof AbstractClassPool)
+ {
+ ((AbstractClassPool) pool).doneGeneratingClass(name);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import org.jboss.test.classpool.support.AlwaysWritablePermissionCollectionTestPolicyPlugin;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate extends JBossClClassPoolTestDelegate
+{
+ public AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate(Class<?> clazz) throws Exception
+ {
+ super(clazz);
+ }
+
+ @Override
+ protected void setUpSecurity() throws Exception
+ {
+ AlwaysWritablePermissionCollectionTestPolicyPlugin.initialisePlugin();
+ super.setUpSecurity();
+ }
+
+ @Override
+ public void tearDownSecurity() throws Exception
+ {
+ super.tearDownSecurity();
+ AlwaysWritablePermissionCollectionTestPolicyPlugin.cleanupPlugin();
+ }
+
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalDomainSanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalDomainSanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalDomainSanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,499 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.dependency.test.HierarchicalDomainUnitTestCase using our test framework,
+ * ClassPoolWithHierarchicalDomainSanityTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithHierarchicalDomainSanityTestCase extends JBossClClassPoolTest
+{
+ public ClassLoaderWithHierarchicalDomainSanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithHierarchicalDomainSanityTestCase.class);
+ }
+
+ public void testParentFirst() throws Exception
+ {
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ ClassLoader clChildA = null;
+ Result resultChildA = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ clChildA = createChildDomainParentFirstClassLoader(resultChildA, "aChild", childDomainName, true, JAR_A_2);
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_A, clChildA, clParentA);
+ assertCannotLoadClass(CLASS_B, clChildA);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ clB = createChildDomainParentFirstClassLoader(resultB, "b", childDomainName, builderB, JAR_B_1);
+
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassLoader(clChildA);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultChildA);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+
+ public void testParentLast() throws Exception
+ {
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ ClassLoader clChildA = null;
+ Result resultChildA = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ clChildA = createChildDomainParentLastClassLoader(resultChildA, "aChild", childDomainName, true, JAR_A_2);
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_A, clChildA);
+ assertCannotLoadClass(CLASS_B, clChildA);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ clB = createChildDomainParentLastClassLoader(resultB, "b", childDomainName, builderB, JAR_B_1);
+
+ assertLoadClass(CLASS_A, clChildA);
+ assertLoadClass(CLASS_B, clB);
+ assertLoadClass(CLASS_A, clB, clChildA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassLoader(clChildA);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultChildA);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+
+ public void testParentLastNotInChild() throws Exception
+ {
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ clB = createChildDomainParentLastClassLoader(resultB, "b", childDomainName, builderB, JAR_B_1);
+
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+
+ public void testParentFirstWrongWayAround() throws Exception
+ {
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ clB = createChildDomainParentFirstClassLoader(resultB, "b", childDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassLoader(resultB);
+
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultB);
+ }
+
+ public void testParentLastWrongWayAround() throws Exception
+ {
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ clB = createChildDomainParentLastClassLoader(resultB, "b", childDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassLoader(resultB);
+
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ }
+
+ public void testParentRedeploy() throws Exception
+ {
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ clB = createChildDomainParentFirstClassLoader(resultB, "b", childDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassLoader(resultB);
+
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+
+ assertNoClassLoader(resultParentA);
+ assertNoClassLoader(resultB);
+
+ try
+ {
+ clParentA = createClassLoader(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultB);
+ }
+
+ public void testParentOtherDomain() throws Exception
+ {
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ final String parentDomainName = "ParentDomain";
+ try
+ {
+ clParentA = createChildDomainParentFirstClassLoader(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ clB = createChildDomainParentFirstClassLoader(resultB, "b", childDomainName, parentDomainName, builderB, JAR_B_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertLoadClass(CLASS_B, clB);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ }
+
+ public void testParentOtherDomainLazy() throws Exception
+ {
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String parentDomainName = "ParentDomain";
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ clB = createChildDomainParentFirstClassLoader(resultB, "b", childDomainName, parentDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassLoader(resultB);
+
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createChildDomainParentFirstClassLoader(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ assertNoClassLoader(resultParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultB);
+ }
+
+ // TODO: FLAVIA eu não entendo este teste
+ public void testParentRedeployOtherDomain() throws Exception
+ {
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ final String parentDomainName = "ParentDomain";
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ clB = createChildDomainParentFirstClassLoader(resultB, "b", childDomainName, parentDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassLoader(resultB);
+
+ ClassLoader clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createChildDomainParentFirstClassLoader(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ assertNoClassLoader(resultParentA);
+ assertNoClassLoader(resultB);
+
+ try
+ {
+ clParentA = createChildDomainParentFirstClassLoader(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+
+ clB = assertClassLoader(resultB.getFactory());
+ assertLoadClass(CLASS_A, clParentA);
+ assertCannotLoadClass(CLASS_B, clParentA);
+ assertLoadClass(CLASS_A, clB, clParentA);
+ }
+ finally
+ {
+ unregisterClassLoader(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassLoader(resultB);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalParentLoaderSanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalParentLoaderSanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithHierarchicalParentLoaderSanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,129 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.test.classpool.support.NoMatchClassFilter;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloader.domain.test.HierarchicalParentLoaderUnitTestCase using our test framework,
+ * ClassPoolWithHierarchicalParentLoaderUnitTestCaseSanityTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithHierarchicalParentLoaderSanityTestCase extends JBossClClassPoolTest
+{
+ public ClassLoaderWithHierarchicalParentLoaderSanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithHierarchicalParentLoaderSanityTestCase.class);
+ }
+
+ public void testHierarchyBefore() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.BEFORE, true);
+ }
+
+
+ public void testHierarchyBeforeNotFound() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.BEFORE, false, false);
+ }
+
+ public void testHierarchyAfterNotReached() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.AFTER_BUT_JAVA_BEFORE, false);
+ }
+
+ public void testHierarchyAfterReached() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.AFTER_BUT_JAVA_BEFORE, null, true);
+ }
+
+ public void testHierarchyFiltered() throws Exception
+ {
+ NoMatchClassFilter filter = new NoMatchClassFilter(CLASS_A);
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, new ParentPolicy(filter, ClassFilter.NOTHING), false);
+
+ assertTrue("Should have been filtered", filter.filtered);
+ }
+
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, boolean expectedParent) throws Exception
+ {
+ runTest(parentParentPolicy, childParentPolicy, true, JAR_A_2, expectedParent);
+ }
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, boolean createParent, boolean expectedParent) throws Exception
+ {
+ runTest(parentParentPolicy, childParentPolicy, createParent, JAR_A_2, expectedParent);
+ }
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, URL url, boolean expectedParent) throws Exception
+ {
+ runTest(parentParentPolicy, childParentPolicy, true, url, expectedParent);
+ }
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, boolean createParent, URL childURL, boolean expectedParent) throws Exception
+ {
+ final String parentName = "parent";
+ final String childName = "child";
+ ClassLoaderDomain parent = getSystem().createAndRegisterDomain(parentName, parentParentPolicy);
+ ClassLoaderDomain child = getSystem().createAndRegisterDomain(childName, childParentPolicy, parent);
+
+ ClassLoader parentLoader = null;
+ ClassLoader childLoader = null;
+ try
+ {
+ //Since the domain is created first, the first/last flag from these two methods is ignored, instead the
+ //policy used when creating the domain is used
+ if (createParent)
+ {
+ parentLoader = createChildDomainParentLastClassLoader("ParentLoader", parentName, true, JAR_A_1);
+ }
+ childLoader = createChildDomainParentLastClassLoader("ChildLoader", childName, parentName, true, childURL);
+ assertLoadClass(CLASS_A, childLoader, expectedParent ? parentLoader : childLoader);
+ }
+ finally
+ {
+ unregisterClassLoader(parentLoader);
+ unregisterClassLoader(childLoader);
+ unregisterDomain(child);
+ unregisterDomain(parent);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithModuleDependencySanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,357 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.ModuleDependencyUnitTestCase using our test framework,
+ * the original tests are testImportNoVersionCheck, testImportVersionCheck and testImportVersionCheckFailed.
+ * ClassPoolWithModuleDependencyTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithModuleDependencySanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithModuleDependencySanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithModuleDependencySanityTestCase.class);
+ }
+
+ public void testImportNoVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ Result resultA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(resultA, "A", builderA, JAR_A_1);
+
+ Class<?> aFromA = assertLoadClass(CLASS_A, clA, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("ModuleB").
+ createRequireModule("ModuleA");
+ clB = createClassLoader(resultB, "B", builderB, JAR_B_1);
+
+ Class<?> aFromA1 = assertLoadClass(CLASS_A, clA, clA);
+ assertSame(aFromA, aFromA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(aFromA, aFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> aFromA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(aFromA, aFromA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(resultA);
+ }
+
+ public void testImportVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ Result resultA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "1.0.0").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(resultA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")).
+ createPackage(PACKAGE_B);
+ clB = createClassLoader(resultB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(resultB);
+
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(resultA);
+ }
+
+ public void testImportVersionCheckFailed() throws Exception
+ {
+ ClassLoader clA = null;
+ Result resultA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "3.0.0").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(resultA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")).
+ createPackage(PACKAGE_B);
+ try
+ {
+ createClassLoader(resultB, "B", builderB, JAR_B_1);
+ fail("Should not have been able to create loader");
+ }
+ catch(NoSuchClassLoaderException expected)
+ {
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassLoader("B");
+ }
+ assertNoClassLoader(resultB);
+
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(resultA);
+ }
+
+ //These are my extra tests
+ public void testSeveralModulesWithSamePackages() throws Exception
+ {
+ ClassLoader clAModuleX = null;
+ ClassLoader clAModuleA = null;
+ ClassLoader clAModuleY = null;
+ Result rAX = new Result();
+ Result rAA = new Result();
+ Result rAY = new Result();
+ try
+ {
+ BundleInfoBuilder builderAX = BundleInfoBuilder.getBuilder().
+ createModule("ModuleX").
+ createPackage(PACKAGE_A);
+ clAModuleX = createClassLoader(rAX, "X", builderAX, JAR_A_1);
+
+ BundleInfoBuilder builderAA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clAModuleA = createClassLoader(rAA, "A", builderAA, JAR_A_1);
+
+ BundleInfoBuilder builderAY = BundleInfoBuilder.getBuilder().
+ createModule("ModuleY").
+ createPackage(PACKAGE_A);
+ clAModuleY = createClassLoader(rAY, "Y", builderAY, JAR_A_1);
+
+ Class<?> classAX = assertLoadClass(CLASS_A, clAModuleX);
+ Class<?> classAA = assertLoadClass(CLASS_A, clAModuleA);
+ Class<?> classAY = assertLoadClass(CLASS_A, clAModuleY);
+ assertCannotLoadClass(clAModuleX, CLASS_B);
+ assertCannotLoadClass(clAModuleA, CLASS_B);
+ assertCannotLoadClass(clAModuleY, CLASS_B);
+
+ ClassLoader clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA").
+ createPackage(PACKAGE_B);
+ clB = createClassLoader(resultB, "B", builderB, JAR_B_1);
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleX);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleY);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleX, CLASS_B);
+ assertCannotLoadClass(clAModuleA, CLASS_B);
+ assertCannotLoadClass(clAModuleY, CLASS_B);
+
+ assertLoadClass(CLASS_B, clB, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clAModuleA);
+ assertSame(aFromB, classAA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(resultB);
+
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleX);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleY);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleX, CLASS_B);
+ assertCannotLoadClass(clAModuleA, CLASS_B);
+ assertCannotLoadClass(clAModuleY, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clAModuleY);
+ unregisterClassLoader(clAModuleA);
+ unregisterClassLoader(clAModuleX);
+ }
+ assertNoClassLoader(rAY);
+ assertNoClassLoader(rAA);
+ assertNoClassLoader(rAX);
+ }
+
+ public void testSeveralModulesWithSameNamesDifferentVersions() throws Exception
+ {
+ ClassLoader clAModuleA1 = null;
+ ClassLoader clAModuleA2 = null;
+ ClassLoader clAModuleA3 = null;
+ Result rA1 = new Result();
+ Result rA2 = new Result();
+ Result rA3 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "1.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA1 = createClassLoader(rA1, "X", builderA1, JAR_A_1);
+
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "2.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA2 = createClassLoader(rA2, "A", builderA2, JAR_A_1);
+
+ BundleInfoBuilder builderA3 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "3.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA3 = createClassLoader(rA3, "Y", builderA3, JAR_A_1);
+
+ Class<?> classAX = assertLoadClass(CLASS_A, clAModuleA1);
+ Class<?> classAA = assertLoadClass(CLASS_A, clAModuleA2);
+ Class<?> classAY = assertLoadClass(CLASS_A, clAModuleA3);
+ assertCannotLoadClass(clAModuleA1, CLASS_B);
+ assertCannotLoadClass(clAModuleA2, CLASS_B);
+ assertCannotLoadClass(clAModuleA3, CLASS_B);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("2.0.0", true, "3.0.0", false)).
+ createPackage(PACKAGE_B);
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleA1);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA2);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleA3);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleA1, CLASS_B);
+ assertCannotLoadClass(clAModuleA2, CLASS_B);
+ assertCannotLoadClass(clAModuleA3, CLASS_B);
+
+ assertLoadClass(CLASS_B, clB, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clAModuleA2);
+ assertSame(aFromB, classAA);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+
+ Class<?> classAX1 = assertLoadClass(CLASS_A, clAModuleA1);
+ assertSame(classAX, classAX1);
+ Class<?> classAA1 = assertLoadClass(CLASS_A, clAModuleA2);
+ assertSame(classAA, classAA1);
+ Class<?> classAY1 = assertLoadClass(CLASS_A, clAModuleA3);
+ assertSame(classAY, classAY1);
+ assertCannotLoadClass(clAModuleA1, CLASS_B);
+ assertCannotLoadClass(clAModuleA2, CLASS_B);
+ assertCannotLoadClass(clAModuleA3, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clAModuleA3);
+ unregisterClassLoader(clAModuleA2);
+ unregisterClassLoader(clAModuleA1);
+ }
+ assertNoClassLoader(rA1);
+ assertNoClassLoader(rA2);
+ assertNoClassLoader(rA3);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithPackageDependencySanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,272 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.PackageDependencyUnitTestCase using our test framework,
+ * the original tests are testImportNoVersionCheck, testImportVersionCheck and testImportVersionCheckFailed.
+ * ClassPoolWithPackageDependencyTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithPackageDependencySanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithPackageDependencySanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithPackageDependencySanityTestCase.class);
+ }
+
+ public void testImportNoVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A);
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, aFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testImportVersionCheck() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A, "1.0.0");
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", "2.0.0"));
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertLoadClass(CLASS_B, clB);
+ Class<?> aFromB = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, aFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+
+ assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testImportVersionCheckFailed() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A, "3.0.0");
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", "2.0.0"));
+ try
+ {
+ createClassLoader(rB, "B", builderB, JAR_B_1);
+ fail("Should not have been able to create loader");
+ }
+ catch(NoSuchClassLoaderException expected)
+ {
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader("B");
+ }
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+ //These are mine
+
+ public void testSeveralModulesWithSamePackagesDifferentVersions() throws Exception
+ {
+ ClassLoader clA1 = null;
+ ClassLoader clA2 = null;
+ ClassLoader clA3 = null;
+ Result rA1 = new Result();
+ Result rA2 = new Result();
+ Result rA3 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "1.0.0");
+ clA1 = createClassLoader(rA1, "A1", builderA1, JAR_A_1);
+
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "2.0.0");
+ clA2 = createClassLoader(rA2, "A2", builderA2, JAR_A_1);
+
+ BundleInfoBuilder builderA3 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "3.0.0");
+ clA3 = createClassLoader(rA3, "A3", builderA3, JAR_A_1);
+
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA1);
+ Class<?> classA2 = assertLoadClass(CLASS_A, clA2);
+ Class<?> classA3 = assertLoadClass(CLASS_A, clA3);
+ assertCannotLoadClass(clA1, CLASS_B);
+ assertCannotLoadClass(clA2, CLASS_B);
+ assertCannotLoadClass(clA3, CLASS_B);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", false, "2.0.0", true));
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA11 = assertLoadClass(CLASS_A, clA1);
+ assertSame(classA1, classA11);
+ Class<?> classA21 = assertLoadClass(CLASS_A, clA2);
+ assertSame(classA2, classA21);
+ Class<?> classA31 = assertLoadClass(CLASS_A, clA3);
+ assertSame(classA3, classA31);
+ assertCannotLoadClass(clA1, CLASS_B);
+ assertCannotLoadClass(clA2, CLASS_B);
+ assertCannotLoadClass(clA3, CLASS_B);
+
+ assertLoadClass(CLASS_B, clB);
+ Class<?> classAFromB = assertLoadClass(CLASS_A, clB, clA2);
+ assertSame(classA2, classAFromB);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+ Class<?> classA11 = assertLoadClass(CLASS_A, clA1);
+ assertSame(classA1, classA11);
+ Class<?> classA21 = assertLoadClass(CLASS_A, clA2);
+ assertSame(classA2, classA21);
+ Class<?> classA31 = assertLoadClass(CLASS_A, clA3);
+ assertSame(classA3, classA31);
+ assertCannotLoadClass(clA1, CLASS_B);
+ assertCannotLoadClass(clA2, CLASS_B);
+ assertCannotLoadClass(clA3, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA3);
+ unregisterClassLoader(clA2);
+ unregisterClassLoader(clA1);
+ }
+ assertNoClassLoader(rA1);
+ assertNoClassLoader(rA2);
+ assertNoClassLoader(rA3);
+
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportModuleSanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportModuleSanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportModuleSanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,226 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.ReExportPackageUnitTestCase using our test framework,
+ * ClassPoolWithReExportPackageTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithReExportModuleSanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithReExportModuleSanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithReExportModuleSanityTestCase.class);
+ }
+
+ public void testReExport() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportModule("a");
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ assertLoadClass(CLASS_A, clB, clA);
+ Class<?> classB = assertLoadClass(CLASS_B, clB);
+ assertCannotLoadClass(clB, CLASS_C);
+
+ ClassLoader clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequireModule("b");
+ clC = createClassLoader(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clC, clA);
+ assertSame(classA, classA1);
+ classB1 = assertLoadClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassLoader(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testNoReExport() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportModule("a");
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB = assertLoadClass(CLASS_B, clB);
+ assertCannotLoadClass(clB, CLASS_C);
+
+ ClassLoader clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_B);
+ clC = createClassLoader(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ assertCannotLoadClass(clC, CLASS_A);
+ classB1 = assertLoadClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassLoader(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportPackageSanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportPackageSanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithReExportPackageSanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,229 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.ReExportModuleUnitTestCase using our test framework,
+ * ClassPoolWithReExportModuleTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithReExportPackageSanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithReExportPackageSanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithReExportPackageSanityTestCase.class);
+ }
+
+ public void testReExport() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportPackage(PACKAGE_A);
+
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB = assertLoadClass(CLASS_B, clB);
+ assertCannotLoadClass(clB, CLASS_C);
+
+ ClassLoader clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequireModule("b");
+ clC = createClassLoader(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clC, clA);
+ assertSame(classA, classA1);
+ classB1 = assertLoadClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassLoader(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ classA1 = assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testNoReExport() throws Exception
+ {
+ ClassLoader clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassLoader(rA, "A", builderA, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+
+ ClassLoader clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportModule("a");
+ clB = createClassLoader(rB, "B", builderB, JAR_B_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB = assertLoadClass(CLASS_B, clB);
+ assertCannotLoadClass(clB, CLASS_C);
+
+ ClassLoader clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_B);
+ clC = createClassLoader(rC, "C", builderC, JAR_C_1);
+
+ assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ assertCannotLoadClass(clC, CLASS_A);
+ classB1 = assertLoadClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassLoader(clC);
+ }
+ assertNoClassLoader(rC);
+ assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ assertLoadClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ Class<?> classB1 = assertLoadClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertNoClassLoader(rB);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertNoClassLoader(rA);
+
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithRepositorySanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithRepositorySanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithRepositorySanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,553 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+
+/**
+ * Tests the behaviour of the new classloaders
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithRepositorySanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithRepositorySanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithRepositorySanityTestCase.class);
+ }
+
+ public void testGlobalScope() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ try
+ {
+ clA = createClassLoader("A", true, JAR_A_1);
+ assertModule(clA);
+ clB = createClassLoader("B", true, JAR_B_1);
+ assertModule(clB);
+ try
+ {
+ Class<?> aFromA = clA.loadClass(CLASS_A);
+ assertNotNull(aFromA);
+ Class<?> bFromA = clA.loadClass(CLASS_B);
+ assertNotNull(bFromA);
+ Class<?> aFromB = clB.loadClass(CLASS_A);
+ Class<?> bFromB = clB.loadClass(CLASS_B);
+ assertSame(aFromA, aFromB);
+ assertSame(bFromA, bFromB);
+ assertSame(clA, aFromA.getClassLoader());
+ assertSame(clB, bFromB.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ Class<?> aFromA = clA.loadClass(CLASS_A);
+ assertNotNull(aFromA);
+
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ assertCannotLoadClass(getDefaultDomain(), CLASS_A);
+ }
+
+ public void testChildDomain() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ ClassLoaderDomain childDomain = null;
+ ClassLoader clC = null;
+ try
+ {
+ clA = createClassLoader("A", true, JAR_A_1);
+ assertModule(clA);
+ clB = createClassLoader("B", true, JAR_B_2);
+ assertModule(clB);
+ clC = createChildDomainParentFirstClassLoader("C", "CHILD", true, JAR_C_1);
+ assertModule(clC);
+
+ childDomain = getChildDomainForLoader(clC);
+ assertNotNull(childDomain);
+ assertSame(getSystem().getDefaultDomain(), childDomain.getParent());
+
+ Class<?> aFromA = clA.loadClass(CLASS_A);
+ assertNotNull(aFromA);
+ Class<?> bFromB = clB.loadClass(CLASS_B);
+ assertNotNull(bFromB);
+ Class<?> cFromC = clC.loadClass(CLASS_C);
+ assertNotNull(cFromC);
+ Class<?> aFromC = clC.loadClass(CLASS_A);
+ assertNotNull(aFromC);
+ Class<?> bFromC = clC.loadClass(CLASS_B);
+ assertNotNull(bFromC);
+
+ assertSame(aFromA, aFromC);
+ assertSame(bFromB, bFromC);
+ assertSame(clA, aFromA.getClassLoader());
+ assertSame(clB, bFromB.getClassLoader());
+ assertSame(clC, cFromC.getClassLoader());
+
+ assertCannotLoadClass(clA, CLASS_C);
+ assertCannotLoadClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ unregisterClassLoader(clB);
+ unregisterClassLoader(clC);
+ unregisterDomain(childDomain);
+ }
+ }
+
+ public void testSiblingDomains() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ ClassLoaderDomain domainA = null;
+ ClassLoaderDomain domainB = null;
+ try
+ {
+ clA = createChildDomainParentFirstClassLoader("A", "ChildA", true, JAR_A_1);
+ assertModule(clA);
+ clB = createChildDomainParentLastClassLoader("B", "ChildB", true, JAR_B_1);
+ assertModule(clB);
+
+ domainA = getChildDomainForLoader(clA);
+ assertNotNull(domainA);
+ assertSame(getSystem().getDefaultDomain(), domainA.getParent());
+ domainB = getChildDomainForLoader(clB);
+ assertNotNull(domainB);
+ assertSame(getSystem().getDefaultDomain(), domainB.getParent());
+ assertNotSame(domainA, domainB);
+
+ Class<?> clazzA = clA.loadClass(CLASS_A);
+ assertSame(clA, clazzA.getClassLoader());
+ Class<?> clazzB = clB.loadClass(CLASS_B);
+ assertSame(clB, clazzB.getClassLoader());
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clB, CLASS_A);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ unregisterClassLoader(clB);
+ unregisterDomain(clA);
+ unregisterDomain(clB);
+ }
+ }
+
+ public void testChildWithNewClassesInParent() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ ClassLoader clScoped = null;
+ try
+ {
+ clScoped = createChildDomainParentFirstClassLoader("SCOPED", "SCOPED", true, JAR_B_1);
+ assertModule(clScoped);
+ assertCannotLoadClass(clScoped, CLASS_A);
+
+ clGlobal = createClassLoader("GLOBAL", true, JAR_A_1);
+ assertModule(clScoped);
+ assertModule(clGlobal);
+
+ Class<?> aFromChild = clScoped.loadClass(CLASS_A);
+ assertNotNull(aFromChild);
+ Class<?> aFromParent = clGlobal.loadClass(CLASS_A);
+ assertNotNull(aFromParent);
+ assertSame(aFromChild, aFromParent);
+ assertSame(clGlobal, aFromParent.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(clGlobal);
+ unregisterClassLoader(clScoped);
+ unregisterDomain(clScoped);
+ }
+ }
+
+ public void testChildOverrideWithParentDelegation() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ ClassLoader clScoped = null;
+ try
+ {
+ clGlobal = createClassLoader("GLOBAL", true, JAR_A_1);
+ clScoped = createChildDomainParentFirstClassLoader("SCOPED", "SCOPED", true, JAR_B_1);
+ Class<?> aFromParent = clGlobal.loadClass(CLASS_A);
+ assertNotNull(aFromParent);
+ Class<?> aFromChild = clScoped.loadClass(CLASS_A);
+ assertNotNull(aFromChild);
+ assertSame(aFromParent, aFromChild);
+ assertSame(clGlobal, aFromParent.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(clGlobal);
+ unregisterClassLoader(clScoped);
+ unregisterDomain(clScoped);
+ }
+ }
+
+ public void testChildOverrideWithNoParentDelegation() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ ClassLoader clScoped = null;
+ try
+ {
+ clGlobal = createClassLoader("GLOBAL", true, JAR_A_1);
+ clScoped = createChildDomainParentLastClassLoader("CHILD", "CHILD", true, JAR_A_1);
+ Class<?> aFromParent = clGlobal.loadClass(CLASS_A);
+ assertNotNull(aFromParent);
+ Class<?> aFromChild = clScoped.loadClass(CLASS_A);
+ assertNotNull(aFromChild);
+ assertNotSame(aFromParent, aFromChild);
+ assertSame(clGlobal, aFromParent.getClassLoader());
+ assertSame(clScoped, aFromChild.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(clGlobal);
+ unregisterClassLoader(clScoped);
+ unregisterDomain(clScoped);
+ }
+ }
+
+ public void testURLChildOfGlobalUcl() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ ClassLoader clChildA = null;
+ ClassLoader clChildB = null;
+ try
+ {
+ clGlobal = createClassLoader("GLOBAL", true, JAR_A_1);
+ clChildA = createChildURLClassLoader(clGlobal, JAR_B_1);
+
+ Class<?> aFromA = clChildA.loadClass(CLASS_A);
+ assertSame(clGlobal, aFromA.getClassLoader());
+ Class<?> bFromA = clChildA.loadClass(CLASS_B);
+ assertSame(clChildA, bFromA.getClassLoader());
+
+ clChildB = createChildURLClassLoader(clGlobal, JAR_A_2);
+ Class<?> aFromB = clChildB.loadClass(CLASS_A);
+ assertSame(clGlobal, aFromB.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(clGlobal);
+ unregisterClassLoader(clChildA);
+ unregisterClassLoader(clChildB);
+ }
+ }
+
+ public void testUndeploySibling() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ try
+ {
+ try
+ {
+ clA = createClassLoader("A", true, JAR_A_1);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ clB = createClassLoader("B", true, JAR_B_1);
+ Class<?> bFromA = clA.loadClass(CLASS_B);
+ assertSame(clB, bFromA.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(clB);
+ }
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(clA);
+ }
+ }
+
+
+ public void testUndeployParentDomainClassLoader() throws Exception
+ {
+ ClassLoader globalA = null;
+ ClassLoader globalB = null;
+ ClassLoader child = null;
+ try
+ {
+ try
+ {
+ globalA = createClassLoader("A", true, JAR_A_1);
+ assertCannotLoadClass(globalA, CLASS_B);
+
+ child = createChildDomainParentLastClassLoader("C", "C", true, JAR_C_1);
+ assertCannotLoadClass(child, CLASS_B);
+
+ globalB = createClassLoader("B", true, JAR_B_1);
+ Class<?> bFromChild = child.loadClass(CLASS_B);
+ Class<?> bFromA = globalA.loadClass(CLASS_B);
+ assertSame(globalB, bFromA.getClassLoader());
+ assertSame(bFromA, bFromChild);
+ }
+ finally
+ {
+ unregisterClassLoader(globalB);
+ }
+ assertCannotLoadClass(child, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader(globalA);
+ unregisterClassLoader(child);
+ unregisterDomain(getChildDomainForLoader(child));
+ }
+ }
+
+ public void testClassLoaderWithParentClassLoader() throws Exception
+ {
+ ClassLoader parent = createChildURLClassLoader(null, JAR_B_1);
+ ClassLoader global = null;
+ try
+ {
+ global = createChildDomainParentFirstClassLoader("A", "A", true, parent, JAR_A_1);
+ Class<?> aFromGlobal = global.loadClass(CLASS_A);
+ assertSame(global, aFromGlobal.getClassLoader());
+ Class<?> bFromGlobal = global.loadClass(CLASS_B);
+ assertSame(parent, bFromGlobal.getClassLoader());
+ Class<?> bFromParent = parent.loadClass(CLASS_B);
+ assertSame(bFromGlobal, bFromParent);
+ }
+ finally
+ {
+ unregisterClassLoader(global);
+ unregisterClassLoader(parent);
+ unregisterDomain(global);
+ }
+ }
+
+
+ public void testClassLoaderWithParentClassLoaderAndSameClassInDomain() throws Exception
+ {
+ ClassLoader parent = createChildURLClassLoader(null, JAR_B_1);
+ ClassLoader globalA = null;
+ ClassLoader globalB = null;
+ ClassLoader globalC = null;
+ try
+ {
+ final String domain = "CHILD";
+ globalA = createChildDomainParentFirstClassLoader("A", domain, true, parent, JAR_A_1);
+ Class<?> aFromGlobal = globalA.loadClass(CLASS_A);
+ assertSame(globalA, aFromGlobal.getClassLoader());
+ Class<?> bFromGlobalA = globalA.loadClass(CLASS_B);
+ assertSame(parent, bFromGlobalA.getClassLoader());
+
+ globalB = createChildDomainParentFirstClassLoader("B", domain, true, parent, JAR_B_2);
+ Class<?> bFromParent = parent.loadClass(CLASS_B);
+ assertSame(parent, bFromParent.getClassLoader());
+ assertSame(bFromGlobalA, bFromParent);
+
+ Class<?> bFromGlobalB = globalB.loadClass(CLASS_B);
+ assertSame(bFromGlobalB, bFromParent);
+
+ globalC = createChildDomainParentLastClassLoader("C", domain + "2", true, parent, JAR_B_2);
+ assertLoadClass(CLASS_B, globalC);
+ }
+ finally
+ {
+ unregisterClassLoader(globalA);
+ unregisterClassLoader(globalB);
+ unregisterClassLoader(globalC);
+ unregisterClassLoader(parent);
+ unregisterDomain(globalA);
+ unregisterDomain(globalC);
+ }
+ }
+
+ public void testSeveralLevelsOfDomain() throws Exception
+ {
+ ClassLoader parent = null;
+ ClassLoader cl1B = null;
+ ClassLoader cl1C = null;
+ ClassLoader cl2B = null;
+ ClassLoader cl2C = null;
+ ClassLoader cl11A = null;
+ ClassLoader cl11B = null;
+ ClassLoader cl11C = null;
+ ClassLoader cl12A = null;
+ ClassLoader cl12B = null;
+ ClassLoader cl12C = null;
+
+ try
+ {
+ parent = createClassLoader("A", true, JAR_A_1);
+ Class<?> aFromParent = parent.loadClass(CLASS_A);
+ assertSame(parent, aFromParent.getClassLoader());
+
+ final String domain1 = "1";
+ cl1B = createChildDomainParentFirstClassLoader("1B", domain1, true, JAR_B_1);
+ cl1C = createChildDomainParentFirstClassLoader("1C", domain1, true, JAR_C_1);
+ Class<?> aFrom1B = cl1B.loadClass(CLASS_A);
+ Class<?> bFrom1B = cl1B.loadClass(CLASS_B);
+ Class<?> cFrom1B = cl1B.loadClass(CLASS_C);
+ Class<?> aFrom1C = cl1C.loadClass(CLASS_A);
+ Class<?> bFrom1C = cl1C.loadClass(CLASS_B);
+ Class<?> cFrom1C = cl1C.loadClass(CLASS_C);
+ assertSame(aFromParent, aFrom1B);
+ assertSame(aFromParent, aFrom1C);
+ assertSame(bFrom1B, bFrom1C);
+ assertSame(cFrom1B, cFrom1C);
+ assertSame(cl1B, bFrom1B.getClassLoader());
+ assertSame(cl1C, cFrom1B.getClassLoader());
+
+
+ final String domain2 = "2";
+ cl2B = createChildDomainParentFirstClassLoader("2B", domain2, true, JAR_B_1);
+ cl2C = createChildDomainParentFirstClassLoader("2C", domain2, true, JAR_C_1);
+ Class<?> aFrom2B = cl2B.loadClass(CLASS_A);
+ Class<?> bFrom2B = cl2B.loadClass(CLASS_B);
+ Class<?> cFrom2B = cl2B.loadClass(CLASS_C);
+ Class<?> aFrom2C = cl2C.loadClass(CLASS_A);
+ Class<?> bFrom2C = cl2C.loadClass(CLASS_B);
+ Class<?> cFrom2C = cl2C.loadClass(CLASS_C);
+ assertSame(aFromParent, aFrom2B);
+ assertSame(aFromParent, aFrom2C);
+ assertSame(bFrom2B, bFrom2C);
+ assertSame(cFrom2B, cFrom2C);
+ assertSame(cl2B, bFrom2B.getClassLoader());
+ assertSame(cl2C, cFrom2B.getClassLoader());
+ assertNotSame(bFrom1B, bFrom2B);
+ assertNotSame(bFrom2C, bFrom1C);
+ assertNotSame(cFrom2C, cFrom1C);
+
+ final String domain11 = "11";
+ cl11A = createChildDomainParentFirstClassLoader("11A", domain11, domain1, true, JAR_A_2);
+ cl11B = createChildDomainParentFirstClassLoader("11B", domain11, domain1, true, JAR_B_2);
+ cl11C = createChildDomainParentFirstClassLoader("11C", domain11, domain1, true, JAR_C_2);
+ final String domain12 = "12";
+ cl12A = createChildDomainParentLastClassLoader("12A", domain12, domain1, true, JAR_A_2);
+ cl12B = createChildDomainParentLastClassLoader("12B", domain12, domain1, true, JAR_B_2);
+ cl12C = createChildDomainParentLastClassLoader("12C", domain12, domain1, true, JAR_C_2);
+ Class<?> aFrom11A = cl11A.loadClass(CLASS_A);
+ Class<?> aFrom11B = cl11B.loadClass(CLASS_A);
+ Class<?> aFrom11C = cl11C.loadClass(CLASS_A);
+ assertSame(aFromParent, aFrom11A);
+ assertSame(aFromParent, aFrom11B);
+ assertSame(aFromParent, aFrom11C);
+ Class<?> aFrom12A = cl12A.loadClass(CLASS_A);
+ Class<?> aFrom12B = cl12B.loadClass(CLASS_A);
+ Class<?> aFrom12C = cl12C.loadClass(CLASS_A);
+ assertNotSame(aFromParent, aFrom12A);
+ assertSame(aFrom12A, aFrom12B);
+ assertSame(aFrom12A, aFrom12C);
+ assertSame(cl12A, aFrom12A.getClassLoader());
+
+ Class<?> bFrom11A = cl11A.loadClass(CLASS_B);
+ Class<?> bFrom11B = cl11B.loadClass(CLASS_B);
+ Class<?> bFrom11C = cl11C.loadClass(CLASS_B);
+ Class<?> cFrom11A = cl11A.loadClass(CLASS_C);
+ Class<?> cFrom11B = cl11B.loadClass(CLASS_C);
+ Class<?> cFrom11C = cl11C.loadClass(CLASS_C);
+ assertSame(bFrom11A, bFrom11B);
+ assertSame(bFrom11A, bFrom11C);
+ assertSame(cl1B, bFrom11B.getClassLoader());
+ assertSame(cFrom11A, cFrom11B);
+ assertSame(cFrom11A, cFrom11C);
+ assertSame(cl1C, cFrom11C.getClassLoader());
+
+ Class<?> bFrom12A = cl12A.loadClass(CLASS_B);
+ Class<?> bFrom12B = cl12B.loadClass(CLASS_B);
+ Class<?> bFrom12C = cl12C.loadClass(CLASS_B);
+ Class<?> cFrom12A = cl12A.loadClass(CLASS_C);
+ Class<?> cFrom12B = cl12B.loadClass(CLASS_C);
+ Class<?> cFrom12C = cl12C.loadClass(CLASS_C);
+ assertSame(bFrom12A, bFrom12B);
+ assertSame(bFrom12A, bFrom12C);
+ assertSame(cl12B, bFrom12B.getClassLoader());
+ assertSame(cFrom12A, cFrom12B);
+ assertSame(cFrom12A, cFrom12C);
+ assertSame(cl12C, cFrom12C.getClassLoader());
+ assertNotSame(bFrom11B, bFrom12B);
+ assertNotSame(cFrom11C, cFrom12C);
+ }
+ finally
+ {
+ unregisterClassLoader(parent);
+ unregisterClassLoader(cl1B);
+ unregisterClassLoader(cl1C);
+ unregisterClassLoader(cl2B);
+ unregisterClassLoader(cl2C);
+ unregisterClassLoader(cl11A);
+ unregisterClassLoader(cl11B);
+ unregisterClassLoader(cl11C);
+ unregisterClassLoader(cl12A);
+ unregisterClassLoader(cl12B);
+ unregisterClassLoader(cl12C);
+
+ unregisterDomain(cl12A);
+ unregisterDomain(cl11A);
+ unregisterDomain(cl2B);
+ unregisterDomain(cl1B);
+ }
+ }
+
+ public void testUclLoaderOrdering() throws Exception
+ {
+ ClassLoader globalA = null;
+ ClassLoader globalB = null;
+ ClassLoader globalC = null;
+ try
+ {
+ globalA = createClassLoader("A1", true, JAR_A_1);
+ globalB = createClassLoader("A2", true, JAR_A_1);
+ globalC = createClassLoader("A3", true, JAR_A_1);
+
+ Class<?> aFromA = globalA.loadClass(CLASS_A);
+ Class<?> aFromB = globalB.loadClass(CLASS_A);
+ Class<?> aFromC = globalC.loadClass(CLASS_A);
+ assertSame(aFromA, aFromB);
+ assertSame(aFromA, aFromC);
+ assertSame(globalA, aFromA.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassLoader(globalA);
+ unregisterClassLoader(globalB);
+ unregisterClassLoader(globalC);
+ }
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithUsesPackageSanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithUsesPackageSanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassLoaderWithUsesPackageSanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,111 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.vfs.metadata.test.UsesPackageUnitTestCase using our test framework,
+ * ClassPoolWithUsesPackageTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderWithUsesPackageSanityTestCase extends JBossClClassPoolTest
+{
+
+ public ClassLoaderWithUsesPackageSanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassLoaderWithUsesPackageSanityTestCase.class);
+ }
+
+ public void testUsesImport() throws Exception
+ {
+ ClassLoader clA1 = null;
+ Result rA1 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("a1").
+ createPackage(PACKAGE_A);
+ clA1 = createClassLoader(rA1, "A1", builderA1, JAR_A_1);
+ Class<?> classA = assertLoadClass(CLASS_A, clA1);
+
+ ClassLoader clA2 = null;
+ Result rA2 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("a2").
+ createUsesPackage(PACKAGE_A);
+
+ clA2 = createClassLoader(rA2, "A2", builderA2, JAR_A_1);
+ Class<?> classA1 = assertLoadClass(CLASS_A, clA1);
+ assertSame(classA, classA1);
+ classA1 = assertLoadClass(CLASS_A, clA2, clA1);
+ assertSame(classA, classA1);
+ }
+ finally
+ {
+ unregisterClassLoader(clA2);
+ }
+ assertNoClassLoader(rA2);
+ assertLoadClass(CLASS_A, clA1);
+ }
+ finally
+ {
+ unregisterClassLoader(clA1);
+ }
+ assertNoClassLoader(rA1);
+ }
+
+ public void testUsesNoImport() throws Exception
+ {
+ ClassLoader clA1 = null;
+ Result rA1 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("a1").
+ createUsesPackage(PACKAGE_A);
+ clA1 = createClassLoader(rA1, "A1", builderA1, JAR_A_1);
+ assertLoadClass(CLASS_A, clA1);
+ }
+ finally
+ {
+ unregisterClassLoader(clA1);
+ }
+ assertNoClassLoader(rA1);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalDomainTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalDomainTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalDomainTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,499 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import javassist.ClassPool;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloading.dependency.test.HierarchicalDomainUnitTestCase using our test framework,
+ * ClassPoolWithHierarchicalDomainSanityTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithHierarchicalDomainTestCase extends JBossClClassPoolTest
+{
+ public ClassPoolWithHierarchicalDomainTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithHierarchicalDomainTestCase.class);
+ }
+
+ public void testParentFirst() throws Exception
+ {
+ ClassPool poolParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ poolParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, poolParentA);
+ assertCannotLoadCtClass(CLASS_B, poolParentA);
+
+ ClassPool poolChildA = null;
+ Result resultChildA = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ poolChildA = createChildDomainParentFirstClassPool(resultChildA, "aChild", childDomainName, true, JAR_A_2);
+ assertLoadCtClass(CLASS_A, poolParentA);
+ assertLoadCtClass(CLASS_A, poolChildA, poolParentA);
+ assertCannotLoadCtClass(CLASS_B, poolChildA);
+
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ poolB = createChildDomainParentFirstClassPool(resultB, "b", childDomainName, builderB, JAR_B_1);
+
+ assertLoadCtClass(CLASS_A, poolParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ assertLoadCtClass(CLASS_A, poolB, poolParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ }
+ assertNoClassPool(resultB);
+ }
+ finally
+ {
+ unregisterClassPool(poolChildA);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultChildA);
+ }
+ finally
+ {
+ unregisterClassPool(poolParentA);
+ }
+ assertNoClassPool(resultParentA);
+ }
+
+ public void testParentLast() throws Exception
+ {
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ ClassPool poolChildA = null;
+ Result resultChildA = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ poolChildA = createChildDomainParentLastClassPool(resultChildA, "aChild", childDomainName, true, JAR_A_2);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_A, poolChildA);
+ assertCannotLoadCtClass(CLASS_B, poolChildA);
+
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ poolB = createChildDomainParentLastClassPool(resultB, "b", childDomainName, builderB, JAR_B_1);
+
+ assertLoadCtClass(CLASS_A, poolChildA);
+ assertLoadCtClass(CLASS_B, poolB);
+ assertLoadCtClass(CLASS_A, poolB, poolChildA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ }
+ assertNoClassPool(resultB);
+ }
+ finally
+ {
+ unregisterClassPool(poolChildA);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultChildA);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ }
+ assertNoClassPool(resultParentA);
+ }
+
+ public void testParentLastNotInChild() throws Exception
+ {
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ poolB = createChildDomainParentLastClassPool(resultB, "b", childDomainName, builderB, JAR_B_1);
+
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultB);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ }
+ assertNoClassPool(resultParentA);
+ }
+
+ public void testParentFirstWrongWayAround() throws Exception
+ {
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ poolB = createChildDomainParentFirstClassPool(resultB, "b", childDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassPool(resultB);
+
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ }
+ assertNoClassPool(resultParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultB);
+ }
+
+ public void testParentLastWrongWayAround() throws Exception
+ {
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ poolB = createChildDomainParentLastClassPool(resultB, "b", childDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassPool(resultB);
+
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ }
+ assertNoClassPool(resultParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ }
+
+ public void testParentRedeploy() throws Exception
+ {
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ poolB = createChildDomainParentFirstClassPool(resultB, "b", childDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassPool(resultB);
+
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ }
+
+ assertNoClassPool(resultParentA);
+ assertNoClassPool(resultB);
+
+ try
+ {
+ clParentA = createClassPool(resultParentA, "aParent", true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ }
+ assertNoClassPool(resultParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultB);
+ }
+
+ public void testParentOtherDomain() throws Exception
+ {
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ final String parentDomainName = "ParentDomain";
+ try
+ {
+ clParentA = createChildDomainParentFirstClassPool(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ poolB = createChildDomainParentFirstClassPool(resultB, "b", childDomainName, parentDomainName, builderB, JAR_B_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertLoadCtClass(CLASS_B, poolB);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ }
+
+ public void testParentOtherDomainLazy() throws Exception
+ {
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String parentDomainName = "ParentDomain";
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ poolB = createChildDomainParentFirstClassPool(resultB, "b", childDomainName, parentDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassPool(resultB);
+
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createChildDomainParentFirstClassPool(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ assertNoClassPool(resultParentA);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultB);
+ }
+
+ public void testParentRedeployOtherDomain() throws Exception
+ {
+ ClassPool poolB = null;
+ Result resultB = new Result();
+ final String parentDomainName = "ParentDomain";
+ final String childDomainName = "ChildDomain";
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_A);
+ try
+ {
+ poolB = createChildDomainParentFirstClassPool(resultB, "b", childDomainName, parentDomainName, builderB, JAR_B_1);
+ fail("Should be no loader");
+ }
+ catch(NoSuchClassLoaderException e)
+ {
+ }
+ assertNoClassPool(resultB);
+
+ ClassPool clParentA = null;
+ Result resultParentA = new Result();
+ try
+ {
+ clParentA = createChildDomainParentFirstClassPool(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ assertNoClassPool(resultParentA);
+ assertNoClassPool(resultB);
+
+ try
+ {
+ clParentA = createChildDomainParentFirstClassPool(resultParentA, "aParent", parentDomainName, true, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+
+ poolB = assertClassPool(resultB.getFactory());
+ assertLoadCtClass(CLASS_A, clParentA);
+ assertCannotLoadCtClass(CLASS_B, clParentA);
+ assertLoadCtClass(CLASS_A, poolB, clParentA);
+ }
+ finally
+ {
+ unregisterClassPool(clParentA);
+ unregisterDomain(parentDomainName);
+ }
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ unregisterDomain(childDomainName);
+ }
+ assertNoClassPool(resultB);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalParentLoaderTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalParentLoaderTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithHierarchicalParentLoaderTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,129 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+
+import java.net.URL;
+
+import javassist.ClassPool;
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.test.classpool.support.NoMatchClassFilter;
+
+/**
+ * Tests the behaviour of the new classloaders so that we can get the same in the new classpools
+ * Reproduces org.jboss.test.classloader.domain.test.HierarchicalParentLoaderUnitTestCase using our test framework,
+ * ClassPoolWithHierarchicalParentLoaderUnitTestCaseSanityTestCase replicates this with the javassist classpools
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithHierarchicalParentLoaderTestCase extends JBossClClassPoolTest
+{
+ public ClassPoolWithHierarchicalParentLoaderTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithHierarchicalParentLoaderTestCase.class);
+ }
+
+ public void testHierarchyBefore() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.BEFORE, true);
+ }
+
+
+ public void testHierarchyBeforeNotFound() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.BEFORE, false, false);
+ }
+
+ public void testHierarchyAfterNotReached() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.AFTER_BUT_JAVA_BEFORE, false);
+ }
+
+ public void testHierarchyAfterReached() throws Exception
+ {
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, ParentPolicy.AFTER_BUT_JAVA_BEFORE, null, true);
+ }
+
+ public void testHierarchyFiltered() throws Exception
+ {
+ NoMatchClassFilter filter = new NoMatchClassFilter(CLASS_A);
+ runTest(ParentPolicy.BEFORE_BUT_JAVA_ONLY, new ParentPolicy(filter, ClassFilter.NOTHING), false);
+
+ assertTrue("Should have been filtered", filter.filtered);
+ }
+
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, boolean expectedParent) throws Exception
+ {
+ runTest(parentParentPolicy, childParentPolicy, true, JAR_A_2, expectedParent);
+ }
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, boolean createParent, boolean expectedParent) throws Exception
+ {
+ runTest(parentParentPolicy, childParentPolicy, createParent, JAR_A_2, expectedParent);
+ }
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, URL url, boolean expectedParent) throws Exception
+ {
+ runTest(parentParentPolicy, childParentPolicy, true, null, expectedParent);
+ }
+
+ private void runTest(ParentPolicy parentParentPolicy, ParentPolicy childParentPolicy, boolean createParent, URL childURL, boolean expectedParent) throws Exception
+ {
+ final String parentName = "parent";
+ final String childName = "child";
+ ClassLoaderDomain parent = getSystem().createAndRegisterDomain(parentName, parentParentPolicy);
+ ClassLoaderDomain child = getSystem().createAndRegisterDomain(childName, childParentPolicy, parent);
+
+ ClassPool parentPool = null;
+ ClassPool childPool = null;
+ try
+ {
+ //Since the domain is created first, the first/last flag from these two methods is ignored, instead the
+ //policy used when creating the domain is used
+ if (createParent)
+ {
+ parentPool = createChildDomainParentLastClassPool("ParentLoader", parentName, true, JAR_A_1);
+ }
+ childPool = createChildDomainParentLastClassPool("ChildLoader", childName, parentName, true, childURL);
+ assertLoadCtClass(CLASS_A, childPool, expectedParent ? parentPool : childPool);
+ }
+ finally
+ {
+ unregisterClassPool(parentPool);
+ unregisterClassPool(childPool);
+ unregisterDomain(child);
+ unregisterDomain(parent);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithModuleDependencyTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithModuleDependencyTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithModuleDependencyTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,361 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Reproduces the behavior found in ClassLoaderWithModuleDependencySanityTestCase
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithModuleDependencyTestCase extends JBossClClassPoolTest
+{
+ final static String STRING = String.class.getName();
+
+ public ClassPoolWithModuleDependencyTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithModuleDependencyTestCase.class);
+ }
+
+ public void testImportNoVersionCheck() throws Exception
+ {
+ ClassPool clA = null;
+ Result resultA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(resultA, "A", builderA, JAR_A_1);
+
+ CtClass aFromA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+
+ ClassPool clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("ModuleB").
+ createRequireModule("ModuleA");
+ clB = createClassPool(resultB, "B", builderB, JAR_B_1);
+
+ CtClass aFromA1 = assertLoadCtClass(CLASS_A, clA, clA);
+ assertSame(aFromA, aFromA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertLoadCtClass(CLASS_B, clB, clB);
+ CtClass aFromB = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(aFromA, aFromB);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ CtClass aFromA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(aFromA, aFromA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(resultA);
+ }
+
+ public void testImportVersionCheck() throws Exception
+ {
+ ClassPool clA = null;
+ Result resultA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "1.0.0").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(resultA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+
+ ClassPool clB = null;
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")).
+ createPackage(PACKAGE_B);
+ clB = createClassPool(resultB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertLoadCtClass(CLASS_B, clB);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(resultB);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(resultA);
+ }
+
+ public void testImportVersionCheckFailed() throws Exception
+ {
+ ClassPool clA = null;
+ Result resultA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "3.0.0").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(resultA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ Result resultB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("1.0.0", "2.0.0")).
+ createPackage(PACKAGE_B);
+ try
+ {
+ createClassPool(resultB, "B", builderB, JAR_B_1);
+ fail("Should not have been able to create loader");
+ }
+ catch(NoSuchClassLoaderException expected)
+ {
+ }
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertNoClassLoader(resultB);
+ }
+ finally
+ {
+ unregisterClassLoader("B");
+ }
+ assertNoClassLoader(resultB);
+
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(resultA);
+ }
+
+ //These are my extra tests
+ public void testSeveralModulesWithSamePackages() throws Exception
+ {
+ ClassPool clAModuleX = null;
+ ClassPool clAModuleA = null;
+ ClassPool clAModuleY = null;
+ Result rAX = new Result();
+ Result rAA = new Result();
+ Result rAY = new Result();
+
+ try
+ {
+ BundleInfoBuilder builderAX = BundleInfoBuilder.getBuilder().
+ createModule("ModuleX").
+ createPackage(PACKAGE_A);
+ clAModuleX = createClassPool(rAX, "X", builderAX, JAR_A_1);
+
+ BundleInfoBuilder builderAA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clAModuleA = createClassPool(rAA, "A", builderAA, JAR_A_1);
+
+ BundleInfoBuilder builderAY = BundleInfoBuilder.getBuilder().
+ createModule("ModuleY").
+ createPackage(PACKAGE_A);
+ clAModuleY = createClassPool(rAY, "Y", builderAY, JAR_A_1);
+
+ CtClass classAX = assertLoadCtClass(CLASS_A, clAModuleX);
+ CtClass classAA = assertLoadCtClass(CLASS_A, clAModuleA);
+ CtClass classAY = assertLoadCtClass(CLASS_A, clAModuleY);
+ assertCannotLoadCtClass(clAModuleX, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA, CLASS_B);
+ assertCannotLoadCtClass(clAModuleY, CLASS_B);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA").
+ createPackage(PACKAGE_B);
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classAX1 = assertLoadCtClass(CLASS_A, clAModuleX);
+ assertSame(classAX, classAX1);
+ CtClass classAA1 = assertLoadCtClass(CLASS_A, clAModuleA);
+ assertSame(classAA, classAA1);
+ CtClass classAY1 = assertLoadCtClass(CLASS_A, clAModuleY);
+ assertSame(classAY, classAY1);
+ assertCannotLoadCtClass(clAModuleX, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA, CLASS_B);
+ assertCannotLoadCtClass(clAModuleY, CLASS_B);
+
+ assertLoadCtClass(CLASS_B, clB, clB);
+ CtClass aFromB = assertLoadCtClass(CLASS_A, clB, clAModuleA);
+ assertSame(aFromB, classAA);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+
+ CtClass classAX1 = assertLoadCtClass(CLASS_A, clAModuleX);
+ assertSame(classAX, classAX1);
+ CtClass classAA1 = assertLoadCtClass(CLASS_A, clAModuleA);
+ assertSame(classAA, classAA1);
+ CtClass classAY1 = assertLoadCtClass(CLASS_A, clAModuleY);
+ assertSame(classAY, classAY1);
+ assertCannotLoadCtClass(clAModuleX, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA, CLASS_B);
+ assertCannotLoadCtClass(clAModuleY, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clAModuleY);
+ unregisterClassPool(clAModuleA);
+ unregisterClassPool(clAModuleX);
+ }
+ assertNoClassLoader(rAY);
+ assertNoClassLoader(rAA);
+ assertNoClassLoader(rAX);
+ }
+
+ public void testSeveralModulesWithSameNamesDifferentVersions() throws Exception
+ {
+ ClassPool clAModuleA1 = null;
+ ClassPool clAModuleA2 = null;
+ ClassPool clAModuleA3 = null;
+ Result rA1 = new Result();
+ Result rA2 = new Result();
+ Result rA3 = new Result();
+
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "1.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA1 = createClassPool(rA1, "X", builderA1, JAR_A_1);
+
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "2.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA2 = createClassPool(rA2, "A", builderA2, JAR_A_1);
+
+ BundleInfoBuilder builderA3 = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA", "3.0.0").
+ createPackage(PACKAGE_A);
+ clAModuleA3 = createClassPool(rA3, "Y", builderA3, JAR_A_1);
+
+ CtClass classAX = assertLoadCtClass(CLASS_A, clAModuleA1);
+ CtClass classAA = assertLoadCtClass(CLASS_A, clAModuleA2);
+ CtClass classAY = assertLoadCtClass(CLASS_A, clAModuleA3);
+ assertCannotLoadCtClass(clAModuleA1, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA2, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA3, CLASS_B);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createRequireModule("ModuleA", new VersionRange("2.0.0", true, "3.0.0", false)).
+ createPackage(PACKAGE_B);
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classAX1 = assertLoadCtClass(CLASS_A, clAModuleA1);
+ assertSame(classAX, classAX1);
+ CtClass classAA1 = assertLoadCtClass(CLASS_A, clAModuleA2);
+ assertSame(classAA, classAA1);
+ CtClass classAY1 = assertLoadCtClass(CLASS_A, clAModuleA3);
+ assertSame(classAY, classAY1);
+ assertCannotLoadCtClass(clAModuleA1, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA2, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA3, CLASS_B);
+
+ assertLoadCtClass(CLASS_B, clB, clB);
+ CtClass aFromB = assertLoadCtClass(CLASS_A, clB, clAModuleA2);
+ assertSame(aFromB, classAA);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+
+ CtClass classAX1 = assertLoadCtClass(CLASS_A, clAModuleA1);
+ assertSame(classAX, classAX1);
+ CtClass classAA1 = assertLoadCtClass(CLASS_A, clAModuleA2);
+ assertSame(classAA, classAA1);
+ CtClass classAY1 = assertLoadCtClass(CLASS_A, clAModuleA3);
+ assertSame(classAY, classAY1);
+ assertCannotLoadCtClass(clAModuleA1, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA2, CLASS_B);
+ assertCannotLoadCtClass(clAModuleA3, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clAModuleA3);
+ unregisterClassPool(clAModuleA2);
+ unregisterClassPool(clAModuleA1);
+ }
+ assertNoClassLoader(rA1);
+ assertNoClassLoader(rA2);
+ assertNoClassLoader(rA3);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithPackageDependencyTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithPackageDependencyTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithPackageDependencyTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,270 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Reproduces the behaviour found in ClassLoaderWithPackageDependencySanityTestCase
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithPackageDependencyTestCase extends JBossClClassPoolTest
+{
+
+ public ClassPoolWithPackageDependencyTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithPackageDependencyTestCase.class);
+ }
+
+ public void testImportNoVersionCheck() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A);
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertLoadCtClass(CLASS_B, clB);
+ CtClass aFromB = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, aFromB);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testImportVersionCheck() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A, "1.0.0");
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", "2.0.0"));
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertLoadCtClass(CLASS_B, clB);
+ CtClass aFromB = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, aFromB);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+
+ assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testImportVersionCheckFailed() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A, "3.0.0");
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", "2.0.0"));
+ try
+ {
+ createClassPool(rB, "B", builderB, JAR_B_1);
+ fail("Should not have been able to create loader");
+ }
+ catch(NoSuchClassLoaderException expected)
+ {
+ }
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassLoader("B");
+ }
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ }
+
+ //These are mine
+
+ public void testSeveralModulesWithSamePackagesDifferentVersions() throws Exception
+ {
+ ClassPool clA1 = null;
+ ClassPool clA2 = null;
+ ClassPool clA3 = null;
+ Result rA1 = new Result();
+ Result rA2 = new Result();
+ Result rA3 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "1.0.0");
+ clA1 = createClassPool(rA1, "A1", builderA1, JAR_A_1);
+
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "2.0.0");
+ clA2 = createClassPool(rA2, "A2", builderA2, JAR_A_1);
+
+ BundleInfoBuilder builderA3 = BundleInfoBuilder.getBuilder().
+ createModule("PackageA").
+ createPackage(PACKAGE_A, "3.0.0");
+ clA3 = createClassPool(rA3, "A3", builderA3, JAR_A_1);
+
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA1);
+ CtClass classA2 = assertLoadCtClass(CLASS_A, clA2);
+ CtClass classA3 = assertLoadCtClass(CLASS_A, clA3);
+ assertCannotLoadCtClass(clA1, CLASS_B);
+ assertCannotLoadCtClass(clA2, CLASS_B);
+ assertCannotLoadCtClass(clA3, CLASS_B);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createPackage(PACKAGE_B).
+ createRequirePackage(PACKAGE_A, new VersionRange("1.0.0", false, "2.0.0", true));
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA11 = assertLoadCtClass(CLASS_A, clA1);
+ assertSame(classA1, classA11);
+ CtClass classA21 = assertLoadCtClass(CLASS_A, clA2);
+ assertSame(classA2, classA21);
+ CtClass classA31 = assertLoadCtClass(CLASS_A, clA3);
+ assertSame(classA3, classA31);
+ assertCannotLoadCtClass(clA1, CLASS_B);
+ assertCannotLoadCtClass(clA2, CLASS_B);
+ assertCannotLoadCtClass(clA3, CLASS_B);
+
+ assertLoadCtClass(CLASS_B, clB);
+ CtClass classAFromB = assertLoadCtClass(CLASS_A, clB, clA2);
+ assertSame(classA2, classAFromB);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+ CtClass classA11 = assertLoadCtClass(CLASS_A, clA1);
+ assertSame(classA1, classA11);
+ CtClass classA21 = assertLoadCtClass(CLASS_A, clA2);
+ assertSame(classA2, classA21);
+ CtClass classA31 = assertLoadCtClass(CLASS_A, clA3);
+ assertSame(classA3, classA31);
+ assertCannotLoadCtClass(clA1, CLASS_B);
+ assertCannotLoadCtClass(clA2, CLASS_B);
+ assertCannotLoadCtClass(clA3, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(clA3);
+ unregisterClassPool(clA2);
+ unregisterClassPool(clA1);
+ }
+ assertNoClassLoader(rA1);
+ assertNoClassLoader(rA2);
+ assertNoClassLoader(rA3);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportModuleTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportModuleTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportModuleTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,227 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Reproduces the behaviour of ClassLoaderWithReExportModuleSanityTestCase
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithReExportModuleTestCase extends JBossClClassPoolTest
+{
+
+ public ClassPoolWithReExportModuleTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithReExportModuleTestCase.class);
+ }
+
+ public void testReExport() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportModule("a");
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB = assertLoadCtClass(CLASS_B, clB);
+ assertCannotLoadCtClass(clB, CLASS_C);
+
+ ClassPool clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequireModule("b");
+ clC = createClassPool(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clC, clA);
+ assertSame(classA, classA1);
+ classB1 = assertLoadCtClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadCtClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassPool(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testNoReExport() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportModule("a");
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB = assertLoadCtClass(CLASS_B, clB);
+ assertCannotLoadCtClass(clB, CLASS_C);
+
+ ClassPool clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_B);
+ clC = createClassPool(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ assertCannotLoadCtClass(clC, CLASS_A);
+ classB1 = assertLoadCtClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadCtClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassPool(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportPackageTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportPackageTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReExportPackageTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,228 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Reproduces ClassLoaderWithReExportPackageSanityTestCase
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithReExportPackageTestCase extends JBossClClassPoolTest
+{
+
+ public ClassPoolWithReExportPackageTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithReExportPackageTestCase.class);
+ }
+
+ public void testReExport() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportPackage(PACKAGE_A);
+
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB = assertLoadCtClass(CLASS_B, clB);
+ assertCannotLoadCtClass(clB, CLASS_C);
+
+ ClassPool clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequireModule("b");
+ clC = createClassPool(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clC, clA);
+ assertSame(classA, classA1);
+ classB1 = assertLoadCtClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadCtClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassPool(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+
+ public void testNoReExport() throws Exception
+ {
+ ClassPool clA = null;
+ Result rA = new Result();
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("a").
+ createPackage(PACKAGE_A);
+ clA = createClassPool(rA, "A", builderA, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+
+ ClassPool clB = null;
+ Result rB = new Result();
+ try
+ {
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("b").
+ createPackage(PACKAGE_B).
+ createReExportModule("a");
+ clB = createClassPool(rB, "B", builderB, JAR_B_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB = assertLoadCtClass(CLASS_B, clB);
+ assertCannotLoadCtClass(clB, CLASS_C);
+
+ ClassPool clC = null;
+ Result rC = new Result();
+ try
+ {
+ BundleInfoBuilder builderC = BundleInfoBuilder.getBuilder().
+ createRequirePackage(PACKAGE_B);
+ clC = createClassPool(rC, "C", builderC, JAR_C_1);
+
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ assertCannotLoadCtClass(clC, CLASS_A);
+ classB1 = assertLoadCtClass(CLASS_B, clC, clB);
+ assertSame(classB, classB1);
+ assertLoadCtClass(CLASS_C, clC);
+ }
+ finally
+ {
+ unregisterClassPool(clC);
+ }
+ assertNoClassLoader(rC);
+ classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ classA1 = assertLoadCtClass(CLASS_A, clB, clA);
+ assertSame(classA, classA1);
+ CtClass classB1 = assertLoadCtClass(CLASS_B, clB);
+ assertSame(classB, classB1);
+ assertCannotLoadCtClass(clB, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clB);
+ }
+ assertNoClassLoader(rB);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA);
+ assertSame(classA, classA1);
+ assertCannotLoadCtClass(clA, CLASS_B);
+ assertCannotLoadCtClass(clA, CLASS_C);
+ }
+ finally
+ {
+ unregisterClassPool(clA);
+ }
+ assertNoClassLoader(rA);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReplaceReferencesTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReplaceReferencesTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithReplaceReferencesTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,356 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_ROOT;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.ProtectionDomain;
+import java.util.Collection;
+
+import javassist.ClassPool;
+import javassist.CodeConverter;
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.CtNewMethod;
+import javassist.Modifier;
+import javassist.scopedpool.ScopedClassPool;
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.DomainClassLoader;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.util.loading.Translator;
+
+/**
+ * Test that field/constructor wrapper replacement works since there were some problems in AS5
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithReplaceReferencesTestCase extends JBossClClassPoolTest
+{
+ final static String STRING = String.class.getName();
+
+ public final static URL JAR_PARENT = getURLRelativeToProjectRoot("/replacereferences-parent.jar");
+
+ public final static URL JAR_CHILD = getURLRelativeToProjectRoot("/replacereferences-child.jar");
+
+ public final static String PACKAGE_REPLACEMENT = PACKAGE_ROOT + ".replacereferences";
+
+ public final static String PACKAGE_REPLACEMENT_CHILD = PACKAGE_REPLACEMENT + ".child";
+
+ public final static String PACKAGE_REPLACEMENT_PARENT = PACKAGE_REPLACEMENT + ".parent";
+
+ public final static String CLASS_INVOKED = PACKAGE_REPLACEMENT + ".Invoked";
+
+ public final static String CLASS_PARENT_CALLER = PACKAGE_REPLACEMENT_PARENT + ".ParentCaller";
+
+ public final static String CLASS_CHILD_CALLER = PACKAGE_REPLACEMENT_CHILD + ".ChildCaller";
+
+ public final String x = "org.jboss.test.classpool.support.excluded";
+
+ private final static Translator TRANSLATOR = new MyTranslator();
+
+ public ClassPoolWithReplaceReferencesTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithReplaceReferencesTestCase.class);
+ }
+
+ public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ return new AlwaysWritablePermissionCollectionTestPolicyPluginTestDelegate(clazz);
+ }
+
+ public void testParentLoadedParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ getSystem().setTranslator(TRANSLATOR);
+ globalPool = createClassPool("GLOBAL", true, JAR_PARENT);
+ scopedPool = createChildDomainParentFirstClassPool("SCOPED", "SCOPED", true, JAR_CHILD);
+
+ loadClassAndRunTest(CLASS_PARENT_CALLER, globalPool.getClassLoader());
+ loadClassAndRunTest(CLASS_CHILD_CALLER, scopedPool.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ getSystem().setTranslator(null);
+ }
+ }
+
+ public void testParentLoadedNoParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ getSystem().setTranslator(TRANSLATOR);
+ globalPool = createClassPool("GLOBAL", true, JAR_PARENT);
+ scopedPool = createChildDomainParentLastClassPool("SCOPED", "SCOPED", true, JAR_CHILD);
+
+ loadClassAndRunTest(CLASS_PARENT_CALLER, globalPool.getClassLoader());
+ loadClassAndRunTest(CLASS_CHILD_CALLER, scopedPool.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ getSystem().setTranslator(null);
+ }
+ }
+
+ public void testParentNotLoadedParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ getSystem().setTranslator(TRANSLATOR);
+ globalPool = createClassPool("GLOBAL", true, JAR_PARENT);
+ scopedPool = createChildDomainParentFirstClassPool("SCOPED", "SCOPED", true, JAR_CHILD);
+
+ loadClassAndRunTest(CLASS_CHILD_CALLER, scopedPool.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ getSystem().setTranslator(null);
+ }
+ }
+
+ public void testParentNotLoadedNoParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ getSystem().setTranslator(TRANSLATOR);
+ globalPool = createClassPool("GLOBAL", true, JAR_PARENT);
+ scopedPool = createChildDomainParentLastClassPool("SCOPED", "SCOPED", true, JAR_CHILD);
+
+ loadClassAndRunTest(CLASS_CHILD_CALLER, scopedPool.getClassLoader());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ getSystem().setTranslator(null);
+ }
+ }
+
+ private void loadClassAndRunTest(String classname, ClassLoader loader) throws Exception
+ {
+ Class<?> caller = loader.loadClass(classname);
+ Method m = caller.getMethod("test");
+ m.invoke(null, new Object[]
+ {});
+ }
+
+ final static class MyTranslator implements Translator
+ {
+ public void unregisterClassLoader(DomainClassLoader loader)
+ {
+ }
+
+ public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
+ ProtectionDomain protectionDomain, byte[] classfileBuffer) throws Exception
+ {
+ if (!className.startsWith(PACKAGE_REPLACEMENT))
+ {
+ return null;
+ }
+ if (className.endsWith("Invoked"))
+ {
+ return null;
+ }
+
+ ClassPool pool = ClassPoolRepository.getInstance().registerClassLoader(loader);
+ CtClass clazz = pool.get(className);
+ if (className.endsWith("Caller"))
+ {
+ instrumentReplaceReferences(clazz);
+ }
+ else
+ {
+ instrumentCreateWrappers(clazz);
+ }
+
+ if (clazz.isModified())
+ {
+ return clazz.toBytecode();
+ }
+ return null;
+ }
+
+ private CtClass instrumentCreateWrappers(CtClass clazz)
+ {
+ try
+ {
+ if (!clazz.getName().startsWith(PACKAGE_REPLACEMENT))
+ {
+ return clazz;
+ }
+ addWrappersToClass(clazz);
+ }
+ catch (Exception e)
+ {
+ System.err.println("Exception creating wrappers for " + clazz);
+ e.printStackTrace();
+ }
+ return clazz;
+ }
+
+ private CtClass instrumentReplaceReferences(CtClass clazz) throws Exception
+ {
+ if (!clazz.getName().startsWith(PACKAGE_REPLACEMENT))
+ {
+ return clazz;
+ }
+ replaceReferences(clazz);
+ return clazz;
+ }
+
+ public void unregisterClassLoader(ClassLoader loader)
+ {
+ }
+
+ private void addWrappersToClass(CtClass clazz) throws Exception
+ {
+ addFieldWrappers(clazz);
+ addConstructorWrappers(clazz);
+ }
+
+ private void addFieldWrappers(CtClass clazz) throws Exception
+ {
+ CtClass objectCt = clazz.getClassPool().getCtClass(Object.class.getName());
+
+ for (CtField field : clazz.getFields())
+ {
+ if (field.getDeclaringClass() == objectCt)
+ {
+ continue;
+ }
+ CtMethod rmethod =
+ CtNewMethod.make(
+ Modifier.PUBLIC | Modifier.STATIC,
+ CtClass.intType,
+ getFieldReadWrapperName(field.getName()),
+ new CtClass[]{objectCt},
+ null,
+ "{" + CLASS_INVOKED + ".invoked = true; return ((" + clazz.getName() + ")$1)." + field.getName() + ";}",
+ clazz);
+ clazz.addMethod(rmethod);
+
+
+ CtMethod wmethod =
+ CtNewMethod.make(
+ Modifier.PUBLIC | Modifier.STATIC,
+ CtClass.voidType,
+ getFieldWriteWrapperName(field.getName()),
+ new CtClass[]{objectCt, field.getType()},
+ null,
+ "{" + CLASS_INVOKED + ".invoked = true; ((" + clazz.getName() + ")$1)." + field.getName() + "=(int)$2;}",
+ clazz);
+ clazz.addMethod(wmethod);
+ }
+ }
+
+ private void addConstructorWrappers(CtClass clazz) throws Exception
+ {
+ for (CtConstructor ctor : clazz.getConstructors())
+ {
+ CtMethod wrapper = CtNewMethod.make(clazz, getConstructorName(clazz), ctor.getParameterTypes(), null,
+ "{" + CLASS_INVOKED + ".invoked = true; return new " + clazz.getName() + "($$);}", clazz);
+ wrapper.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
+ clazz.addMethod(wrapper);
+ }
+ }
+
+ private void replaceReferences(final CtClass clazz) throws Exception
+ {
+ CodeConverter conv = new CodeConverter();
+ ScopedClassPool pool = ClassPoolRepository.getInstance().getClassPoolFactory().
+ create(clazz.getClassPool(), ClassPoolRepository.getInstance());
+ Collection<String> refs = AccessController.doPrivileged(new PrivilegedAction<Collection<String>>() {
+
+ public Collection<String> run()
+ {
+ return clazz.getRefClasses();
+ }});
+
+ for (String ref : refs)
+ {
+ if (ref.startsWith(PACKAGE_REPLACEMENT_CHILD) || ref.startsWith(PACKAGE_REPLACEMENT_PARENT))
+ {
+ if (ref.endsWith("Caller"))
+ {
+ continue;
+ }
+ CtClass ctRef = pool.get(ref);
+ CtField[] fields = ctRef.getDeclaredFields();
+ for (CtField fld : fields)
+ {
+ conv.replaceFieldRead(fld, ctRef, getFieldReadWrapperName(fld.getName()));
+ conv.replaceFieldWrite(fld, ctRef, getFieldWriteWrapperName(fld.getName()));
+ }
+ conv.replaceNew(ctRef, ctRef, getConstructorName(ctRef));
+ }
+ }
+ clazz.instrument(conv);
+ }
+
+ private String getFieldReadWrapperName(String fieldName)
+ {
+ return fieldName + "_read";
+ }
+
+ private String getFieldWriteWrapperName(String fieldName)
+ {
+ return fieldName + "_write";
+ }
+
+ private String getConstructorName(CtClass clazz)
+ {
+ return clazz.getSimpleName() + "_new";
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithRepositoryTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,1039 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_C;
+
+import java.util.ArrayList;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import junit.framework.Test;
+
+import org.jboss.classloader.spi.ClassLoaderDomain;
+import org.jboss.test.classpool.common.ClassFactory;
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithRepositoryTestCase extends JBossClClassPoolTest
+{
+ final static String STRING = String.class.getName();
+
+ public ClassPoolWithRepositoryTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithRepositoryTestCase.class);
+ }
+
+ public void testGlobalScope() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ try
+ {
+ poolA = createClassPool("A", true, JAR_A_1);
+ poolB = createClassPool("B", true, JAR_B_1);
+ try
+ {
+ CtClass aFromA = poolA.get(CLASS_A);
+ assertNotNull(aFromA);
+ CtClass bFromA = poolA.get(CLASS_B);
+ assertNotNull(bFromA);
+ CtClass aFromB = poolB.get(CLASS_A);
+ CtClass bFromB = poolB.get(CLASS_B);
+ assertSame(aFromA, aFromB);
+ assertSame(poolA, aFromA.getClassPool());
+ assertSame(poolB, bFromB.getClassPool());
+
+ checkCanLoadString(poolA, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ }
+ CtClass aFromA = poolA.get(CLASS_A);
+ assertNotNull(aFromA);
+
+ assertCannotLoadCtClass(poolA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(poolA);
+ }
+ }
+
+ public void testChildDomain() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ ClassLoaderDomain childDomain = null;
+ ClassPool poolC = null;
+ try
+ {
+ poolA = createClassPool("A", true, JAR_A_1);
+ poolB = createClassPool("B", true, JAR_B_1);
+ poolC = createChildDomainParentFirstClassPool("C", "CHILD", true, JAR_C_1);
+
+ childDomain = getChildDomainForPool(poolC);
+ assertNotNull(childDomain);
+ assertSame(getSystem().getDefaultDomain(), childDomain.getParent());
+
+ CtClass aFromA = poolA.get(CLASS_A);
+ assertNotNull(aFromA);
+ CtClass bFromB = poolB.get(CLASS_B);
+ assertNotNull(bFromB);
+ CtClass cFromC = poolC.get(CLASS_C);
+ assertNotNull(cFromC);
+ CtClass aFromC = poolC.get(CLASS_A);
+ assertNotNull(aFromC);
+ CtClass bFromC = poolC.get(CLASS_B);
+ assertNotNull(bFromC);
+
+ assertSame(aFromA, aFromC);
+ assertSame(bFromB, bFromC);
+ assertSame(poolA, aFromA.getClassPool());
+ assertSame(poolB, bFromB.getClassPool());
+ assertSame(poolC, cFromC.getClassPool());
+
+ assertCannotLoadCtClass(poolA, CLASS_C);
+ assertCannotLoadCtClass(poolB, CLASS_C);
+
+ checkCanLoadString(poolA, poolB);
+ checkCanLoadString(poolB, poolC);
+ }
+ finally
+ {
+ unregisterClassPool(poolA);
+ unregisterClassPool(poolB);
+ unregisterClassPool(poolC);
+ unregisterDomain(childDomain.getName());
+ }
+ }
+
+ public void testSiblingDomains() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ ClassLoaderDomain domainA = null;
+ ClassLoaderDomain domainB = null;
+ try
+ {
+ poolA = createChildDomainParentFirstClassPool("A", "ChildA", true, JAR_A_1);
+ poolB = createChildDomainParentLastClassPool("B", "ChildB", true, JAR_B_1);
+
+ domainA = getChildDomainForPool(poolA);
+ assertNotNull(domainA);
+ assertSame(getSystem().getDefaultDomain(), domainA.getParent());
+ domainB = getChildDomainForPool(poolB);
+ assertNotNull(domainB);
+ assertSame(getSystem().getDefaultDomain(), domainB.getParent());
+ assertNotSame(domainA, domainB);
+
+ CtClass clazzA = poolA.get(CLASS_A);
+ assertSame(poolA, clazzA.getClassPool());
+ CtClass clazzB = poolB.get(CLASS_B);
+ assertSame(poolB, clazzB.getClassPool());
+ assertCannotLoadCtClass(poolA, CLASS_B);
+ assertCannotLoadCtClass(poolB, CLASS_A);
+
+ checkCanLoadString(poolA, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(poolA);
+ unregisterClassPool(poolB);
+ unregisterDomain(poolA);
+ unregisterDomain(poolB);
+ }
+ }
+
+ public void testChildWithNewClassesInParent() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ scopedPool = createChildDomainParentFirstClassPool("SCOPED", "SCOPED", true, JAR_B_1);
+ assertCannotLoadCtClass(scopedPool, CLASS_A);
+
+ globalPool = createClassPool("GLOBAL", true, JAR_A_1);
+
+ CtClass aFromChild = scopedPool.get(CLASS_A);
+ assertNotNull(aFromChild);
+ CtClass aFromParent = globalPool.get(CLASS_A);
+ assertNotNull(aFromParent);
+ assertSame(aFromChild, aFromParent);
+ assertSame(globalPool, aFromParent.getClassPool());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ }
+ }
+
+ public void testChildOverrideWithParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ globalPool = createClassPool("GLOBAL", true, JAR_A_1);
+ scopedPool = createChildDomainParentFirstClassPool("SCOPED", "SCOPED", true, JAR_B_1);
+ CtClass aFromParent = globalPool.get(CLASS_A);
+ assertNotNull(aFromParent);
+ CtClass aFromChild = scopedPool.get(CLASS_A);
+ assertNotNull(aFromChild);
+ assertSame(aFromParent, aFromChild);
+ assertSame(globalPool, aFromParent.getClassPool());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ }
+ }
+
+ public void testURLChildOfGlobalUcl() throws Exception
+ {
+ ClassPool global = null;
+ ClassPool childA = null;
+ ClassPool childB = null;
+ try
+ {
+ global = createClassPool("GLOBAL", true, JAR_A_1);
+ childA = createChildURLClassPool(global, JAR_B_1);
+
+ CtClass aFromA = childA.get(CLASS_A);
+ assertSame(global, aFromA.getClassPool());
+ CtClass bFromA = childA.get(CLASS_B);
+ assertSame(childA, bFromA.getClassPool());
+
+ childB = createChildURLClassPool(global, JAR_A_2);
+ CtClass aFromB = childB.get(CLASS_A);
+ assertSame(global, aFromB.getClassPool());
+ }
+ finally
+ {
+ unregisterClassPool(global);
+ unregisterClassPool(childA);
+ unregisterClassPool(childB);
+ }
+ }
+
+ public void testChildOverrideWithNoParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ globalPool = createClassPool("GLOBAL", true, JAR_A_1);
+ scopedPool = createChildDomainParentLastClassPool("CHILD", "CHILD", true, JAR_A_1);
+ CtClass aFromParent = globalPool.get(CLASS_A);
+ assertNotNull(aFromParent);
+ CtClass aFromChild = scopedPool.get(CLASS_A);
+ assertNotNull(aFromChild);
+ assertNotSame(aFromParent, aFromChild);
+ assertSame(globalPool, aFromParent.getClassPool());
+ assertSame(scopedPool, aFromChild.getClassPool());
+ }
+ finally
+ {
+ unregisterClassPool(globalPool);
+ unregisterClassPool(scopedPool);
+ unregisterDomain(scopedPool);
+ }
+ }
+
+
+ public void testUndeploySibling() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ try
+ {
+ try
+ {
+ poolA = createClassPool("A", true, JAR_A_1);
+ assertCannotLoadCtClass(poolA, CLASS_B);
+
+ poolB = createClassPool("B", true, JAR_B_1);
+ CtClass bFromA = poolA.get(CLASS_B);
+ assertSame(poolB, bFromA.getClassPool());
+ }
+ finally
+ {
+ unregisterClassPool(poolB);
+ }
+ assertCannotLoadCtClass(poolA, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(poolA);
+ }
+ }
+
+
+ public void testUndeployParentDomainClassLoader() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool child = null;
+ try
+ {
+ try
+ {
+ globalA = createClassPool("A", true, JAR_A_1);
+ assertCannotLoadCtClass(globalA, CLASS_B);
+
+ child = createChildDomainParentLastClassPool("C", "C", true, JAR_C_1);
+ assertCannotLoadCtClass(child, CLASS_B);
+
+ globalB = createClassPool("B", true, JAR_B_1);
+ CtClass bFromChild = child.get(CLASS_B);
+ CtClass bFromA = globalA.get(CLASS_B);
+ assertSame(globalB, bFromA.getClassPool());
+ assertSame(bFromA, bFromChild);
+ }
+ finally
+ {
+ unregisterClassPool(globalB);
+ }
+ assertCannotLoadCtClass(child, CLASS_B);
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(child);
+ unregisterDomain(child);
+ }
+ }
+
+
+ public void testSeveralLevelsOfDomain() throws Exception
+ {
+ ClassPool parent = null;
+ ClassPool cl1B = null;
+ ClassPool cl1C = null;
+ ClassPool cl2B = null;
+ ClassPool cl2C = null;
+ ClassPool cl11A = null;
+ ClassPool cl11B = null;
+ ClassPool cl11C = null;
+ ClassPool cl12A = null;
+ ClassPool cl12B = null;
+ ClassPool cl12C = null;
+
+ try
+ {
+ parent = createClassPool("A", true, JAR_A_1);
+ CtClass aFromParent = parent.get(CLASS_A);
+ assertSame(parent, aFromParent.getClassPool());
+
+ final String domain1 = "1";
+ cl1B = createChildDomainParentFirstClassPool("1B", domain1, true, JAR_B_1);
+ cl1C = createChildDomainParentFirstClassPool("1C", domain1, true, JAR_C_1);
+ CtClass aFrom1B = cl1B.get(CLASS_A);
+ CtClass bFrom1B = cl1B.get(CLASS_B);
+ CtClass cFrom1B = cl1B.get(CLASS_C);
+ CtClass aFrom1C = cl1C.get(CLASS_A);
+ CtClass bFrom1C = cl1C.get(CLASS_B);
+ CtClass cFrom1C = cl1C.get(CLASS_C);
+ assertSame(aFromParent, aFrom1B);
+ assertSame(aFromParent, aFrom1C);
+ assertSame(bFrom1B, bFrom1C);
+ assertSame(cFrom1B, cFrom1C);
+ assertSame(cl1B, bFrom1B.getClassPool());
+ assertSame(cl1C, cFrom1B.getClassPool());
+
+
+ final String domain2 = "2";
+ cl2B = createChildDomainParentFirstClassPool("2B", domain2, true, JAR_B_1);
+ cl2C = createChildDomainParentFirstClassPool("2C", domain2, true, JAR_C_1);
+ CtClass aFrom2B = cl2B.get(CLASS_A);
+ CtClass bFrom2B = cl2B.get(CLASS_B);
+ CtClass cFrom2B = cl2B.get(CLASS_C);
+ CtClass aFrom2C = cl2C.get(CLASS_A);
+ CtClass bFrom2C = cl2C.get(CLASS_B);
+ CtClass cFrom2C = cl2C.get(CLASS_C);
+ assertSame(aFromParent, aFrom2B);
+ assertSame(aFromParent, aFrom2C);
+ assertSame(bFrom2B, bFrom2C);
+ assertSame(cFrom2B, cFrom2C);
+ assertSame(cl2B, bFrom2B.getClassPool());
+ assertSame(cl2C, cFrom2B.getClassPool());
+ assertNotSame(bFrom1B, bFrom2B);
+ assertNotSame(bFrom2C, bFrom1C);
+ assertNotSame(cFrom2C, cFrom1C);
+
+ final String domain11 = "11";
+ cl11A = createChildDomainParentFirstClassPool("11A", domain11, domain1, true, JAR_A_2);
+ cl11B = createChildDomainParentFirstClassPool("11B", domain11, domain1, true, JAR_B_2);
+ cl11C = createChildDomainParentFirstClassPool("11C", domain11, domain1, true, JAR_C_2);
+ final String domain12 = "12";
+ cl12A = createChildDomainParentLastClassPool("12A", domain12, domain1, true, JAR_A_2);
+ cl12B = createChildDomainParentLastClassPool("12B", domain12, domain1, true, JAR_B_2);
+ cl12C = createChildDomainParentLastClassPool("12C", domain12, domain1, true, JAR_C_2);
+ CtClass aFrom11A = cl11A.get(CLASS_A);
+ CtClass aFrom11B = cl11B.get(CLASS_A);
+ CtClass aFrom11C = cl11C.get(CLASS_A);
+ assertSame(aFromParent, aFrom11A);
+ assertSame(aFromParent, aFrom11B);
+ assertSame(aFromParent, aFrom11C);
+ CtClass aFrom12A = cl12A.get(CLASS_A);
+ CtClass aFrom12B = cl12B.get(CLASS_A);
+ CtClass aFrom12C = cl12C.get(CLASS_A);
+ assertNotSame(aFromParent, aFrom12A);
+ assertSame(aFrom12A, aFrom12B);
+ assertSame(aFrom12A, aFrom12C);
+ assertSame(cl12A, aFrom12A.getClassPool());
+
+ CtClass bFrom11A = cl11A.get(CLASS_B);
+ CtClass bFrom11B = cl11B.get(CLASS_B);
+ CtClass bFrom11C = cl11C.get(CLASS_B);
+ CtClass cFrom11A = cl11A.get(CLASS_C);
+ CtClass cFrom11B = cl11B.get(CLASS_C);
+ CtClass cFrom11C = cl11C.get(CLASS_C);
+ assertSame(bFrom11A, bFrom11B);
+ assertSame(bFrom11A, bFrom11C);
+ assertSame(cl1B, bFrom11B.getClassPool());
+ assertSame(cFrom11A, cFrom11B);
+ assertSame(cFrom11A, cFrom11C);
+ assertSame(cl1C, cFrom11C.getClassPool());
+
+ CtClass bFrom12A = cl12A.get(CLASS_B);
+ CtClass bFrom12B = cl12B.get(CLASS_B);
+ CtClass bFrom12C = cl12C.get(CLASS_B);
+ CtClass cFrom12A = cl12A.get(CLASS_C);
+ CtClass cFrom12B = cl12B.get(CLASS_C);
+ CtClass cFrom12C = cl12C.get(CLASS_C);
+ assertSame(bFrom12A, bFrom12B);
+ assertSame(bFrom12A, bFrom12C);
+ assertSame(cl12B, bFrom12B.getClassPool());
+ assertSame(cFrom12A, cFrom12B);
+ assertSame(cFrom12A, cFrom12C);
+ assertSame(cl12C, cFrom12C.getClassPool());
+ assertNotSame(bFrom11B, bFrom12B);
+ assertNotSame(cFrom11C, cFrom12C);
+ }
+ finally
+ {
+ unregisterClassPool(parent);
+ unregisterClassPool(cl1B);
+ unregisterClassPool(cl1C);
+ unregisterClassPool(cl2B);
+ unregisterClassPool(cl2C);
+ unregisterClassPool(cl11A);
+ unregisterClassPool(cl11B);
+ unregisterClassPool(cl11C);
+ unregisterClassPool(cl12A);
+ unregisterClassPool(cl12B);
+ unregisterClassPool(cl12C);
+
+ unregisterDomain(cl12A);
+ unregisterDomain(cl11A);
+ unregisterDomain(cl2B);
+ unregisterDomain(cl1B);
+ }
+ }
+
+
+ public void testUclLoaderOrdering() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool globalC = null;
+ try
+ {
+ globalA = createClassPool("A", true, JAR_A_1);
+ globalB = createClassPool("B", true, JAR_A_1);
+ globalC = createClassPool("C", true, JAR_A_1);
+
+ CtClass aFromA = globalA.get(CLASS_A);
+ CtClass aFromB = globalB.get(CLASS_A);
+ CtClass aFromC = globalC.get(CLASS_A);
+ assertSame(aFromA, aFromB);
+ assertSame(aFromA, aFromC);
+ assertSame(globalA, aFromA.getClassPool());
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ unregisterClassPool(globalC);
+ }
+ }
+
+ public void testSimpleGeneratingClass() throws Exception
+ {
+
+ ClassPool global = null;
+ try
+ {
+ final String classname = CLASS_A + "XYZ";
+ global = createClassPool("A", true, JAR_A_1);
+ CtClass newCtClass = global.makeClass(classname);
+ Class<?> newClass = newCtClass.toClass();
+ Class<?> foundClass = global.getClassLoader().loadClass(classname);
+ assertSame(newClass, foundClass);
+ }
+ finally
+ {
+ unregisterClassPool(global);
+ }
+ }
+
+ public void testGeneratingClassAndFindInSameDomain() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ try
+ {
+ final String classnameA = PACKAGE_A + ".NewClassA";
+ final String classnameB = PACKAGE_B + ".NewClassB";
+ globalA = createClassPool("A", true, JAR_A_1);
+ globalB = createClassPool("B", true, JAR_B_1);
+
+ CtClass newCtClassA = globalA.makeClass(classnameA);
+ Class<?> newClassA = newCtClassA.toClass();
+ assertSame(globalA.getClassLoader(), newClassA.getClassLoader());
+ assertSame(newClassA, globalA.getClassLoader().loadClass(classnameA));
+ assertSame(newClassA, globalB.getClassLoader().loadClass(classnameA));
+
+ CtClass newCtClassB = globalB.makeClass(classnameB);
+ Class<?> newClassB = newCtClassB.toClass();
+ assertSame(globalB.getClassLoader(), newClassB.getClassLoader());
+ assertSame(newClassB, globalA.getClassLoader().loadClass(classnameB));
+ assertSame(newClassB, globalB.getClassLoader().loadClass(classnameB));
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ }
+ }
+
+ public void testGeneratingClassAndFindPreviouslyBlacklistedInSameDomain() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ try
+ {
+ final String classnameA = PACKAGE_A + ".NewClassA";
+ final String classnameB = PACKAGE_B + ".NewClassB";
+ globalA = createClassPool("A", true, JAR_A_1);
+ globalB = createClassPool("B", true, JAR_B_1);
+
+ assertCannotLoadClass(globalA.getClassLoader(), classnameA);
+ assertCannotLoadClass(globalA.getClassLoader(), classnameB);
+ assertCannotLoadClass(globalB.getClassLoader(), classnameA);
+ assertCannotLoadClass(globalB.getClassLoader(), classnameB);
+
+ CtClass newCtClassA = globalA.makeClass(classnameA);
+ Class<?> newClassA = newCtClassA.toClass();
+ assertSame(globalA.getClassLoader(), newClassA.getClassLoader());
+ assertSame(newClassA, globalA.getClassLoader().loadClass(classnameA));
+ assertSame(newClassA, globalB.getClassLoader().loadClass(classnameA));
+
+ CtClass newCtClassB = globalB.makeClass(classnameB);
+ Class<?> newClassB = newCtClassB.toClass();
+ assertSame(globalB.getClassLoader(), newClassB.getClassLoader());
+ assertSame(newClassB, globalA.getClassLoader().loadClass(classnameB));
+ assertSame(newClassB, globalB.getClassLoader().loadClass(classnameB));
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ }
+ }
+
+ public void testGeneratingCrossDomainClassHierarchy() throws Exception
+ {
+ ClassPool global = null;
+ ClassPool child1 = null;
+ ClassPool child2 = null;
+ try
+ {
+ final String parentName = PACKAGE_A + ".Parent";
+ final String childName = PACKAGE_C + ".Child";
+ global = createClassPool("A", true, JAR_A_1);
+ child1 = createChildDomainParentLastClassPool("C1", "C1", true, JAR_B_1);
+ child2 = createChildDomainParentLastClassPool("C2", "C2", "C1", true, JAR_C_1);
+
+ assertCannotLoadCtClass(global, parentName);
+ assertCannotLoadCtClass(child1, parentName);
+ assertCannotLoadCtClass(child2, parentName);
+ assertCannotLoadCtClass(child2, childName);
+
+ CtClass parentClass = global.makeClass(parentName);
+
+ CtClass childClass = child2.makeClass(childName);
+ childClass.setSuperclass(parentClass);
+
+ CtClass parentFromGlobal = global.get(parentName);
+ assertSame(global, parentFromGlobal.getClassPool());
+ assertSame(parentClass, parentFromGlobal);
+
+ CtClass childFromChild2 = child2.get(childName);
+ assertSame(child2, childFromChild2.getClassPool());
+ assertSame(childClass, childFromChild2);
+
+ assertCannotLoadCtClass(global, childName);
+ assertCannotLoadCtClass(child1, childName);
+
+ CtClass parentFromChildA = childClass.getSuperclass();
+ assertSame(parentClass, parentFromChildA);
+
+ CtClass parentFromChildB = child2.get(parentName);
+ assertSame(parentClass, parentFromChildB);
+
+ Class<?> parentClazz = parentClass.toClass();
+ assertSame(global.getClassLoader(), parentClazz.getClassLoader());
+
+ Class<?> childClazz = childClass.toClass();
+ assertSame(child2.getClassLoader(), childClazz.getClassLoader());
+
+ Class<?> parentClazzFromParent = global.getClassLoader().loadClass(parentName);
+ assertSame(parentClazz, parentClazzFromParent);
+
+ Class<?> parentClazzFromChild = child2.getClassLoader().loadClass(parentName);
+ assertSame(parentClazz, parentClazzFromChild);
+
+ Class<?> childClazzFromChild = child2.getClassLoader().loadClass(childName);
+ assertSame(childClazz, childClazzFromChild);
+ }
+ finally
+ {
+ unregisterClassPool(global);
+ unregisterClassPool(child1);
+ unregisterClassPool(child2);
+ unregisterDomain(child1);
+ unregisterDomain(child2);
+ }
+ }
+
+ public void testGeneratingClassInMyPackagesInDelegatingPool() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool child = null;
+ try
+ {
+ final String aClassName = PACKAGE_A + ".Parent";
+ final String bClassName = PACKAGE_B + ".BClazz";
+ globalA = createClassPool("A", true, JAR_A_1);
+ globalB = createClassPool("B", true, JAR_B_1);
+ child = createChildURLClassPool(globalA, JAR_C_1);
+
+
+ assertCannotLoadCtClass(globalA, aClassName);
+ assertCannotLoadCtClass(globalB, aClassName);
+ assertCannotLoadCtClass(child, aClassName);
+ assertCannotLoadCtClass(globalA, bClassName);
+ assertCannotLoadCtClass(globalB, bClassName);
+ assertCannotLoadCtClass(child, bClassName);
+
+ CtClass a = globalA.makeClass(aClassName);
+ CtClass b = globalB.makeClass(bClassName);
+
+ CtClass aFromA = globalA.get(aClassName);
+ assertSame(a, aFromA);
+ assertSame(globalA, aFromA.getClassPool());
+ CtClass aFromB = globalB.get(aClassName);
+ assertSame(a, aFromB);
+ CtClass bFromA = globalA.get(bClassName);
+ assertSame(b, bFromA);
+ assertSame(globalB, bFromA.getClassPool());
+ CtClass bFromB = globalB.get(bClassName);
+ assertSame(b, bFromB);
+ CtClass aFromChild = child.get(aClassName);
+ assertSame(a, aFromChild);
+ CtClass bFromChild = child.get(bClassName);
+ assertSame(b, bFromChild);
+
+ Class<?> clazzA = a.toClass();
+ assertSame(globalA.getClassLoader(), clazzA.getClassLoader());
+
+ Class<?> clazzB = b.toClass();
+ assertSame(globalB.getClassLoader(), clazzB.getClassLoader());
+
+ Class<?> clazzAFromA = globalA.getClassLoader().loadClass(aClassName);
+ assertSame(clazzA, clazzAFromA);
+ Class<?> clazzAFromB = globalB.getClassLoader().loadClass(aClassName);
+ assertSame(clazzA, clazzAFromB);
+ Class<?> clazzAFromChild = child.getClassLoader().loadClass(aClassName);
+ assertSame(clazzA, clazzAFromChild);
+
+ Class<?> clazzBFromA = globalA.getClassLoader().loadClass(bClassName);
+ assertSame(clazzB, clazzBFromA);
+ Class<?> clazzBFromB = globalB.getClassLoader().loadClass(bClassName);
+ assertSame(clazzB, clazzBFromB);
+ Class<?> clazzBFromChild = child.getClassLoader().loadClass(bClassName);
+ assertSame(clazzB, clazzBFromChild);
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ unregisterClassPool(child);
+ }
+ }
+
+ public void testCanLoadArrrayCtClass() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ try
+ {
+ poolA = createClassPool("A", true, JAR_A_1);
+ poolB = createClassPool("B", true, JAR_B_1);
+ accessCanLoadCtArray(poolA, poolB);
+ accessCanLoadCtArray(poolA, poolB);
+ }
+ finally
+ {
+ unregisterClassPool(poolA);
+ unregisterClassPool(poolB);
+ }
+ }
+
+ private void accessCanLoadCtArray(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ poolA.get(String.class.getName() + "[][]");
+ CtClass a = poolA.get(CLASS_A);
+ CtClass aArray = poolA.get(CLASS_A + "[]");
+ CtClass bArray = poolA.get(CLASS_B + "[][]");
+ CtClass b = poolA.get(CLASS_B);
+
+ CtClass byteClassA = poolA.get("byte");
+ CtClass byteClassB = poolB.get("byte");
+ assertSame(byteClassA, byteClassB);
+ assertNotSame(poolA, byteClassA.getClassPool());
+ assertNotSame(poolB, byteClassA.getClassPool());
+ CtClass intArrayClass = poolA.get("int[]");
+ CtClass intClass = poolB.get("int");
+ assertSame(intClass, intArrayClass.getComponentType());
+ assertSame(byteClassA.getClassPool(), intClass.getClassPool());
+
+
+
+ assertTrue(aArray.isArray());
+ assertSame(a, aArray.getComponentType());
+ assertTrue(bArray.isArray());
+ assertTrue(bArray.getComponentType().isArray());
+ assertSame(b, bArray.getComponentType().getComponentType());
+ assertNotSame(aArray.getClassPool(), bArray.getClassPool());
+ assertSame(poolA, aArray.getClassPool());
+ assertSame(poolB, bArray.getClassPool());
+ assertSame(a.getClassPool(), aArray.getClassPool());
+ assertSame(b.getClassPool(), bArray.getClassPool());
+ }
+
+ public void testClassLoaderWithParentClassLoader() throws Exception
+ {
+ ClassPool parent = createChildURLClassPool(null, JAR_B_1);
+ ClassPool global = null;
+ try
+ {
+ global = createChildDomainParentFirstClassPool("A", "A", true, parent, JAR_A_1);
+ CtClass aFromGlobal = global.get(CLASS_A);
+ assertSame(global, aFromGlobal.getClassPool());
+ CtClass bFromGlobal = global.get(CLASS_B);
+ assertSame(parent, bFromGlobal.getClassPool());
+ CtClass bFromParent = parent.get(CLASS_B);
+ assertSame(bFromGlobal, bFromParent);
+ }
+ finally
+ {
+ unregisterClassPool(global);
+ unregisterClassPool(parent);
+ unregisterDomain(global);
+ }
+ }
+
+ public void testClassLoaderWithParentClassLoaderAndSameClassInDomain() throws Exception
+ {
+ ClassPool parent = createChildURLClassPool(null, JAR_B_1);
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool globalC = null;
+ try
+ {
+ final String domain = "CHILD";
+ globalA = createChildDomainParentFirstClassPool("A", domain, true, parent, JAR_A_1);
+ CtClass aFromGlobal = globalA.get(CLASS_A);
+ assertSame(globalA, aFromGlobal.getClassPool());
+ CtClass bFromGlobalA = globalA.get(CLASS_B);
+ assertSame(parent, bFromGlobalA.getClassPool());
+
+ globalB = createChildDomainParentFirstClassPool("B", domain, true, parent, JAR_B_2);
+ CtClass bFromParent = parent.get(CLASS_B);
+ assertSame(parent, bFromParent.getClassPool());
+ assertSame(bFromGlobalA, bFromParent);
+
+ CtClass bFromGlobalB = globalB.get(CLASS_B);
+ assertSame(bFromGlobalB, bFromParent);
+
+ globalC = createChildDomainParentLastClassPool("C", domain + "2", true, parent, JAR_B_2);
+ assertLoadCtClass(CLASS_B, globalC);
+ }
+ finally
+ {
+ unregisterClassPool(globalA);
+ unregisterClassPool(globalB);
+ unregisterClassPool(globalC);
+ unregisterClassPool(parent);
+ unregisterDomain(globalA);
+ unregisterDomain(globalC);
+ }
+ }
+
+ public void testCreatedClassInSamePackage() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ globalPoolA = createClassPool("A", true, JAR_A_1);
+ globalPoolB = createClassPool("B", true, JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ Class<?> classA = loaderA.loadClass(CLASS_A);
+ Class<?> classB = loaderB.loadClass(CLASS_B);
+
+ Object createdA = ClassFactory.create(classA, loaderA);
+ Object createdB = ClassFactory.create(classB, loaderB);
+
+ Class<?> createdClassA = createdA.getClass();
+ Class<?> createdClassB = createdB.getClass();
+
+ assertTrue(classA.isAssignableFrom(createdClassA));
+ assertTrue(classB.isAssignableFrom(createdClassB));
+ assertTrue(createdClassA.getName().startsWith(PACKAGE_A));
+ assertTrue(createdClassB.getName().startsWith(PACKAGE_B));
+
+ assertSame(createdClassA, loaderA.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderA.loadClass(createdClassB.getName()));
+ assertSame(createdClassA, loaderB.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderB.loadClass(createdClassB.getName()));
+ }
+ finally
+ {
+ unregisterClassPool(globalPoolA);
+ unregisterClassPool(globalPoolB);
+ }
+ }
+
+ /*public void testMakeContainerProxyInSamePackage() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ globalPoolA = createClassPool("A", true, JAR_A_1);
+ globalPoolB = createClassPool("B", true, JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ loaderA.loadClass(ProxyTemplate.class.getName());
+
+ Object proxyA = assertMakeContainerProxy(loaderA.loadClass(CLASS_A), loaderA);
+ Object proxyB = assertMakeContainerProxy(loaderB.loadClass(CLASS_B), loaderB);
+
+ Class<?> clazzA = proxyA.getClass();
+ Class<?> clazzB = proxyB.getClass();
+
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzA));
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzB));
+ assertTrue(clazzA.getName().startsWith(PACKAGE_A));
+ assertTrue(clazzB.getName().startsWith(PACKAGE_B));
+
+ assertSame(clazzA, loaderA.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderA.loadClass(clazzB.getName()));
+ assertSame(clazzA, loaderB.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderB.loadClass(clazzB.getName()));
+ }
+ finally
+ {
+ unregisterClassPool(globalPoolA);
+ unregisterClassPool(globalPoolB);
+ }
+ }*/
+
+ /*public void testMakeContainerProxyForSystemClass() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A).
+ createPackage(ContainerProxyFactory.PROXY_CLASSES_DEFAULT_PACKAGE);
+ globalPoolA = createClassPool("A", true, builderA, JAR_A_1);
+
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("ModuleB").
+ createPackage(PACKAGE_B).
+ createPackage(ContainerProxyFactory.PROXY_CLASSES_DEFAULT_PACKAGE);
+ globalPoolB = createClassPool("B", true, builderB, JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ loaderA.loadClass(ProxyTemplate.class.getName());
+
+ Object proxyA = assertMakeContainerProxy(ArrayList.class, loaderA);
+ Object proxyB = assertMakeContainerProxy(ArrayList.class, loaderB);
+
+ Class<?> clazzA = proxyA.getClass();
+ Class<?> clazzB = proxyB.getClass();
+
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzA));
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzB));
+ assertTrue(clazzA.getName().startsWith(ContainerProxyFactory.PROXY_CLASSES_DEFAULT_PACKAGE));
+ assertTrue(clazzB.getName().startsWith(ContainerProxyFactory.PROXY_CLASSES_DEFAULT_PACKAGE));
+
+ assertSame(clazzA, loaderA.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderA.loadClass(clazzB.getName()));
+ assertSame(clazzA, loaderB.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderB.loadClass(clazzB.getName()));
+ }
+ finally
+ {
+ unregisterClassPool(globalPoolA);
+ unregisterClassPool(globalPoolB);
+ }
+ }*/
+
+ public void testCreateClassForSystemClass() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ BundleInfoBuilder builderA = BundleInfoBuilder.getBuilder().
+ createModule("ModuleA").
+ createPackage(PACKAGE_A).
+ createPackage(ClassFactory.PACKAGE);
+ globalPoolA = createClassPool("A", true, builderA, JAR_A_1);
+
+ BundleInfoBuilder builderB = BundleInfoBuilder.getBuilder().
+ createModule("ModuleB").
+ createPackage(PACKAGE_B).
+ createPackage(ClassFactory.PACKAGE);
+ globalPoolB = createClassPool("B", true, builderB, JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ Object createdA = ClassFactory.create(ArrayList.class, loaderA);
+ Object createdB = ClassFactory.create(ArrayList.class, loaderB);
+
+ Class<?> createdClassA = createdA.getClass();
+ Class<?> createdClassB = createdB.getClass();
+
+ assertTrue(ArrayList.class.isAssignableFrom(createdClassA));
+ assertTrue(ArrayList.class.isAssignableFrom(createdClassB));
+ assertTrue(createdClassA.getName().startsWith(ClassFactory.PACKAGE));
+ assertTrue(createdClassB.getName().startsWith(ClassFactory.PACKAGE));
+
+ assertSame(createdClassA, loaderA.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderA.loadClass(createdClassB.getName()));
+ assertSame(createdClassA, loaderB.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderB.loadClass(createdClassB.getName()));
+ }
+ finally
+ {
+ unregisterClassPool(globalPoolA);
+ unregisterClassPool(globalPoolB);
+ }
+ }
+
+ /*private Object assertMakeContainerProxy(Class<?> parent, ClassLoader loader) throws Exception
+ {
+ AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+ params.setProxiedClass(parent);
+ params.setTarget(parent.newInstance());
+ params.setClassLoader(loader);
+ params.setInterfaces(new Class<?>[] {java.io.Serializable.class});
+ GeneratedAOPProxyFactory factory = new GeneratedAOPProxyFactory();
+ Object proxy = factory.createAdvisedProxy(params);
+ assertFalse(parent.getName() == proxy.getClass().getName());
+ assertSame(loader, proxy.getClass().getClassLoader());
+ return proxy;
+ }*/
+
+ /*private static final String PROXY_PACKAGE = "org.test.classpool.proxy";
+ private static final String PROXY_CLASS = PROXY_PACKAGE + ".Proxy";
+ private static int counter = 0;
+
+ private Object assertMakeSimpleProxy(Class<?> parent, ClassLoader loader) throws Exception
+ {
+ //AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+ //params.setProxiedClass(parent);
+ //params.setTarget(parent.newInstance());
+ //params.setClassLoader(loader);
+ ClassPool pool = ClassPoolRepository.getInstance().getRegisteredCLs().get(loader);
+ CtClass ctClazz = pool.makeClass(PROXY_CLASS + counter++);
+ ctClazz.setSuperclass(pool.get(parent.getName()));
+ Class<?> clazz = pool.toClass(ctClazz);
+ //params.setInterfaces(new Class<?>[] {java.io.Serializable.class});
+ //GeneratedAOPProxyFactory factory = new GeneratedAOPProxyFactory();
+ //Object proxy = factory.createAdvisedProxy(params);
+ //assertFalse(parent.getName() == proxy.getClass().getName());
+ assertSame(loader, clazz.getClassLoader());
+ //return proxy;
+ return clazz.newInstance();
+ }*/
+
+ private void checkCanLoadString(ClassPool poolA, ClassPool poolB) throws NotFoundException
+ {
+ CtClass strA = poolA.getCtClass(STRING);
+ CtClass strB = poolB.getCtClass(STRING);
+ assertSame(strA, strB);
+ assertSame(strB.getClassPool(), strA.getClassPool());
+ assertNotSame(poolA, strA.getClassPool());
+ assertNotSame(poolB, strB.getClassPool());
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithUsesPackageTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithUsesPackageTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/ClassPoolWithUsesPackageTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+
+/**
+ * Reproduces ClassLoaderWithUsesPackageSanityTestCase
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolWithUsesPackageTestCase extends JBossClClassPoolTest
+{
+
+ public ClassPoolWithUsesPackageTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ClassPoolWithUsesPackageTestCase.class);
+ }
+
+ public void testUsesImport() throws Exception
+ {
+ ClassPool clA1 = null;
+ Result rA1 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("a1").
+ createPackage(PACKAGE_A);
+ clA1 = createClassPool(rA1, "A1", builderA1, JAR_A_1);
+ CtClass classA = assertLoadCtClass(CLASS_A, clA1);
+
+ ClassPool clA2 = null;
+ Result rA2 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA2 = BundleInfoBuilder.getBuilder().
+ createModule("a2").
+ createUsesPackage(PACKAGE_A);
+
+ clA2 = createClassPool(rA2, "A2", builderA2, JAR_A_1);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA1);
+ assertSame(classA, classA1);
+ classA1 = assertLoadCtClass(CLASS_A, clA2, clA1);
+ assertSame(classA, classA1);
+ }
+ finally
+ {
+ unregisterClassPool(clA2);
+ }
+ assertNoClassLoader(rA2);
+ CtClass classA1 = assertLoadCtClass(CLASS_A, clA1);
+ assertSame(classA, classA1);
+ }
+ finally
+ {
+ unregisterClassPool(clA1);
+ }
+ assertNoClassLoader(rA1);
+ }
+
+ public void testUsesNoImport() throws Exception
+ {
+ ClassPool clA1 = null;
+ Result rA1 = new Result();
+ try
+ {
+ BundleInfoBuilder builderA1 = BundleInfoBuilder.getBuilder().
+ createModule("a1").
+ createUsesPackage(PACKAGE_A);
+ clA1 = createClassPool(rA1, "A1", builderA1, JAR_A_1);
+ assertLoadCtClass(CLASS_A, clA1);
+ }
+ finally
+ {
+ unregisterClassPool(clA1);
+ }
+ assertNoClassLoader(rA1);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolDelegatingTestSuite.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolDelegatingTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JBoss-cl Pool Tests");
+
+ suite.addTest(ClassPoolWithRepositoryTestCase.suite());
+ suite.addTest(ClassPoolWithModuleDependencyTestCase.suite());
+ suite.addTest(ClassPoolWithPackageDependencyTestCase.suite());
+ suite.addTest(ClassPoolWithReExportModuleTestCase.suite());
+ suite.addTest(ClassPoolWithReExportPackageTestCase.suite());
+ suite.addTest(ClassPoolWithUsesPackageTestCase.suite());
+ suite.addTest(ClassPoolWithHierarchicalDomainTestCase.suite());
+ suite.addTest(ClassPoolWithHierarchicalParentLoaderTestCase.suite());
+ suite.addTest(ClassPoolWithReplaceReferencesTestCase.suite());
+ return suite;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolSanityTestSuite.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolSanityTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JBoss-cl Sanity Tests");
+
+ suite.addTest(ClassLoaderWithRepositorySanityTestCase.suite());
+ suite.addTest(ClassLoaderWithModuleDependencySanityTestCase.suite());
+ suite.addTest(ClassLoaderWithPackageDependencySanityTestCase.suite());
+ suite.addTest(ClassLoaderWithReExportModuleSanityTestCase.suite());
+ suite.addTest(ClassLoaderWithReExportPackageSanityTestCase.suite());
+ suite.addTest(ClassLoaderWithUsesPackageSanityTestCase.suite());
+ suite.addTest(ClassLoaderWithHierarchicalDomainSanityTestCase.suite());
+ suite.addTest(ClassLoaderWithHierarchicalParentLoaderSanityTestCase.suite());
+
+ return suite;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTest.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTest.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTest.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,1010 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.classloader.plugins.filter.CombiningClassFilter;
+import org.jboss.classloader.plugins.filter.PatternClassFilter;
+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.spi.filter.PackageClassFilter;
+import org.jboss.classloader.test.support.IsolatedClassLoaderTestHelper;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.jboss5.RegisterModuleCallback;
+import org.jboss.classpool.jboss5.VFSClassLoaderDomainRegistry;
+import org.jboss.classpool.jbosscl.JBossClDelegatingClassPoolFactory;
+import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.classpool.support.BundleInfoBuilder;
+import org.jboss.test.classpool.support.Result;
+import org.jboss.test.classpool.support.SupportClasses;
+import org.jboss.test.classpool.support.TestVFSClassLoaderFactory;
+import org.jboss.test.classpool.support.TestVFSClassLoaderFactoryFactory;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.virtual.VFS;
+
+/**
+ * Base class for testing the new JBoss classloaders
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolTest extends MicrocontainerTest
+{
+ public final static URL JAR_A_1 = getURLRelativeToProjectRoot(SupportClasses.JAR_A_1);
+ public final static URL JAR_A_2 = getURLRelativeToProjectRoot(SupportClasses.JAR_A_2);
+ public final static URL JAR_B_1 = getURLRelativeToProjectRoot(SupportClasses.JAR_B_1);
+ public final static URL JAR_B_2 = getURLRelativeToProjectRoot(SupportClasses.JAR_B_2);
+ public final static URL JAR_C_1 = getURLRelativeToProjectRoot(SupportClasses.JAR_C_1);
+ public final static URL JAR_C_2 = getURLRelativeToProjectRoot(SupportClasses.JAR_C_2);
+
+ //Keep a strong reference to the URL classloaders so that they are not garbage collected
+ final static Set<URLClassLoader> registeredURLClassLoaders = new HashSet<URLClassLoader>();
+
+ private Map<ClassLoader, ClassLoaderDomain> scopedChildDomainsByLoader = new WeakHashMap<ClassLoader, ClassLoaderDomain>();
+
+ private LoaderNameDeploymentRegistry loaderNameDeploymentRegistry = new LoaderNameDeploymentRegistry();
+
+ /** The classloader helper */
+ protected static final ClassLoaderSystem system = ClassLoaderSystem.getInstance();
+ private static boolean initialisedDefaultDomain;
+ private static final ClassFilter aopFilter;
+ static
+ {
+ String[] classPatterns = new String[] {
+ "org\\.jboss\\.aop\\..+",
+ "org\\.jboss\\.classloading\\..+",
+ "org\\.jboss\\.classloader\\..+",
+ "org\\.jboss\\.virtual\\..+",
+ "org\\.jboss\\.test\\.classpool\\.jbosscl\\..+\\..+",
+ "org\\.jboss\\.metadata\\..+",
+ "org\\.test\\.classpool\\.proxy\\..+"};
+ String[] resourcePatterns = new String[] {
+ "org/jboss/aop/.+",
+ "org/jboss/classloading/.+",
+ "org/jboss/classloader/.+",
+ "org/jboss/virtual/.+",
+ "org/jboss/test/classpool/jbosscl/.+\\..+",
+ "org/jboss/metadata/.+",
+ "org/test/classpool/proxy/.+"};
+ aopFilter = new PatternClassFilter(classPatterns, resourcePatterns, null);
+ }
+
+ protected static VFSClassLoaderDomainRegistry domainRegistry;
+
+ ClassLoading classLoading = new ClassLoading();
+
+ static
+ {
+
+ domainRegistry = new VFSClassLoaderDomainRegistry();
+
+ // TODO remove this later; currently, AspectManager sets the classpoolfactory
+ // at ScopedClassPoolRepositoryImpl, overwriting the setClassPoolFactory command below
+ // Notice that AspectManager.instance() is invoked by AOPDependencyBuilder, so
+ // we have no way of avoiding AspectManager creation
+ AspectManager.instance();
+ ClassPoolRepository.getInstance().setClassPoolFactory(new JBossClDelegatingClassPoolFactory(domainRegistry, new RegisterModuleCallback()));
+ VFS.init();
+ }
+
+
+ public static ClassLoaderSystem getSystem()
+ {
+ if (!initialisedDefaultDomain)
+ {
+ ClassLoaderDomain defaultDomain = system.getDefaultDomain();
+
+ Set<String> parentPackages = IsolatedClassLoaderTestHelper.getParentPackages();
+ String[] parentPkgs = parentPackages.toArray(new String[parentPackages.size()]);
+ PackageClassFilter filter = new PackageClassFilter(parentPkgs);
+ filter.setIncludeJava(true);
+ CombiningClassFilter beforeFilter = CombiningClassFilter.create(filter, aopFilter);
+ ParentPolicy parentPolicy = new ParentPolicy(beforeFilter, ClassFilter.NOTHING);
+
+ defaultDomain.setParentPolicy(parentPolicy);
+ }
+ return system;
+ }
+
+ public static Test suite(Class<?> clazz)
+ {
+ return AbstractTestCaseWithSetup.suite(clazz);
+ }
+
+ public JBossClClassPoolTest(String name)
+ {
+ super(name);
+ }
+
+
+ public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ return new JBossClClassPoolTestDelegate(clazz);
+ }
+
+
+ protected static URL getURLRelativeToProjectRoot(String relativePath)
+ {
+ try
+ {
+ URL url = JBossClClassPoolTest.class.getProtectionDomain().getCodeSource().getLocation();
+ String location = url.toString();
+ int index = location.lastIndexOf("/target/") + "/target/".length();
+ location = location.substring(0, index);
+
+ location = location + relativePath;
+ return new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ // AutoGenerated
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected ClassLoaderDomain getDefaultDomain()
+ {
+ return getSystem().getDefaultDomain();
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ //enableTrace("org.jboss.aop.classpool");
+ //enableTrace("org.jboss.classpool.jbosscl");
+ deploy("/org/jboss/test/classpool/jbosscl/Common.xml");
+ }
+
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ undeploy("/org/jboss/test/classpool/jbosscl/Common.xml");
+ super.tearDown();
+ }
+
+ protected String array(String name)
+ {
+ return name + "[]";
+ }
+
+ protected ClassLoader createClassLoader(String name, boolean importAll, URL... urls) throws Exception
+ {
+ return createClassLoader(null, name, importAll, urls);
+ }
+
+ protected ClassLoader createClassLoader(Result result, String name, boolean importAll, URL... urls) throws Exception
+ {
+ TestVFSClassLoaderFactory factory = TestVFSClassLoaderFactoryFactory.createClassLoaderFactory(name, importAll, urls);
+ return createClassLoader(result, factory);
+ }
+
+ protected ClassLoader createClassLoader(String name, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassLoader(null, name, builder, urls);
+ }
+
+ protected ClassLoader createClassLoader(Result result, String name, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassLoader(result, name, false, builder, urls);
+ }
+
+ protected ClassLoader createClassLoader(String name, boolean importAll, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassLoader(null, name, importAll, builder, urls);
+ }
+
+ protected ClassLoader createClassLoader(Result result, String name, boolean importAll, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ TestVFSClassLoaderFactory factory = TestVFSClassLoaderFactoryFactory.createClassLoaderFactory(name, importAll, builder, urls);
+ return createClassLoader(result, factory);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader((Result)null, name, domainName, importAll, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(Result result, String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader(result, name, domainName, importAll, null, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(String name, String domainName, boolean importAll, ClassLoader parent, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader(null, name, domainName, importAll, parent, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(Result result, String name, String domainName, boolean importAll, ClassLoader parent, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(result, name, domainName, null, true, importAll, parent, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader(null, name, domainName, parentDomainName, importAll, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(Result result, String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(result, name, domainName, parentDomainName, true, importAll, null, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader((Result)null, name, domainName, importAll, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(Result result, String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader(result, name, domainName, importAll, null, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(String name, String domainName, boolean importAll, ClassLoader parent, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader(null, name, domainName, importAll, parent, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(Result result, String name, String domainName, boolean importAll, ClassLoader parent, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(result, name, domainName, null, false, importAll, parent, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader(null, name, domainName, parentDomainName, importAll, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(Result result, String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(result, name, domainName, parentDomainName, false, importAll, null, urls);
+ }
+
+ protected ClassLoader createChildDomainClassLoader(String name, String domainName, String parentDomainName, boolean parentFirst, boolean importAll, ClassLoader parent, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(null, name, domainName, parentDomainName, parentFirst, importAll, parent, urls);
+ }
+
+ protected ClassLoader createChildDomainClassLoader(Result result, String name, String domainName, String parentDomainName, boolean parentFirst, boolean importAll, ClassLoader parent, URL... urls) throws Exception
+ {
+ TestVFSClassLoaderFactory factory = TestVFSClassLoaderFactoryFactory.createClassLoaderFactory(name, importAll, domainName, parentDomainName, parentFirst, urls);
+
+ ClassLoader classLoader = createClassLoader(result, factory, parent);
+
+ registerDomainAndLoader(classLoader, domainName);
+ return classLoader;
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader((Result)null, name, domainName, builder, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(Result result, String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader(result, name, domainName, null, builder, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(String name, String domainName, String parentDomainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassLoader(null, name, domainName, parentDomainName, builder, urls);
+ }
+
+ protected ClassLoader createChildDomainParentFirstClassLoader(Result result, String name, String domainName, String parentDomainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(result, name, domainName, parentDomainName, builder, true, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader((Result)null, name, domainName, builder, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(Result result, String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader(result, name, domainName, null, builder, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(String name, String domainName, String parentDomainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassLoader(null, name, domainName, parentDomainName, builder, urls);
+ }
+
+ protected ClassLoader createChildDomainParentLastClassLoader(Result result, String name, String domainName, String parentDomainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(result, name, domainName, parentDomainName, builder, false, urls);
+ }
+
+ protected ClassLoader createChildDomainClassLoader(String name, String domainName, String parentDomainName, BundleInfoBuilder builder, boolean parentFirst, URL... urls) throws Exception
+ {
+ return createChildDomainClassLoader(null, name, domainName, parentDomainName, builder, parentFirst, urls);
+ }
+
+ protected ClassLoader createChildDomainClassLoader(Result result, String name, String domainName, String parentDomainName, BundleInfoBuilder builder, boolean parentFirst, URL... urls) throws Exception
+ {
+ TestVFSClassLoaderFactory factory = TestVFSClassLoaderFactoryFactory.createClassLoaderFactory(name, domainName, parentDomainName, builder, parentFirst, urls);
+
+ ClassLoader classLoader = createClassLoader(result, factory);
+
+ registerDomainAndLoader(classLoader, domainName);
+ return classLoader;
+ }
+
+ private void registerDomainAndLoader(ClassLoader classLoader, String domainName)
+ {
+ ClassLoaderDomain domain = getSystem().getDomain(domainName);
+ scopedChildDomainsByLoader.put(classLoader, domain);
+ }
+
+ protected ClassLoader createChildURLClassLoader(ClassLoader parent, URL url)
+ {
+ URLClassLoader cl = new URLClassLoader(new URL[] {url}, parent);
+ registeredURLClassLoaders.add(cl);
+ return cl;
+ }
+
+ private ClassLoader createClassLoader(Result result, TestVFSClassLoaderFactory factory) throws Exception
+ {
+ return createClassLoader(result, factory, null);
+ }
+
+ private ClassLoader createClassLoader(Result result, TestVFSClassLoaderFactory factory, ClassLoader parent) throws Exception
+ {
+ if (parent != null)
+ {
+ factory.setParent(parent);
+ }
+
+ KernelDeployment deployment = install(factory);
+ loaderNameDeploymentRegistry.registerDeployment(factory.getName(), deployment);
+ if (result != null)
+ {
+ result.setFactory(factory);
+ }
+ ClassLoader loader = assertClassLoader(factory, parent);
+
+ return loader;
+ }
+
+ /**
+ * Here since we cannot access this via the classloading api
+ */
+ protected ClassLoaderDomain getChildDomainForLoader(ClassLoader loader)
+ {
+ return scopedChildDomainsByLoader.get(loader);
+ }
+
+ protected ClassLoaderDomain getChildDomainForPool(ClassPool pool)
+ {
+ return getChildDomainForLoader(pool.getClassLoader());
+ }
+
+ protected void unregisterDomain(ClassLoaderDomain domain)
+ {
+ if (domain != null)
+ {
+ ClassLoaderDomain registeredDomain = getSystem().getDomain(domain.getName());
+ if (registeredDomain == null)
+ throw new IllegalStateException("Domain is not registered: " + domain.getName());
+ if (registeredDomain != domain)
+ throw new IllegalStateException(domain + " is not the same as " + registeredDomain);
+ getSystem().unregisterDomain(domain);
+ }
+ }
+
+ protected void unregisterDomain(ClassLoader loader)
+ {
+ if (loader != null)
+ {
+ ClassLoaderDomain domain = getChildDomainForLoader(loader);
+ unregisterDomain(domain);
+ }
+ }
+
+ protected void unregisterDomain(ClassPool pool)
+ {
+ if (pool != null)
+ {
+ ClassLoaderDomain domain = getChildDomainForPool(pool);
+ unregisterDomain(domain);
+ }
+ }
+
+ protected void assertCannotLoadClass(ClassLoader cl, String className)
+ {
+ try
+ {
+ cl.loadClass(className);
+ fail("Should not have been able to load " + className);
+ }
+ catch(Exception expected)
+ {
+ }
+ }
+
+ protected void assertCannotLoadClass(String className, ClassLoader cl)
+ {
+ assertCannotLoadClass(cl, className);
+ }
+
+ protected void assertCannotLoadCtClass(ClassPool pool, String className)
+ {
+ try
+ {
+ pool.get(className);
+ }
+ catch(Exception e)
+ {
+ }
+ }
+
+ protected void assertCannotLoadCtClass(String className, ClassPool pool)
+ {
+ assertCannotLoadCtClass(pool, className);
+ }
+
+ protected void assertCannotLoadClass(ClassLoaderDomain domain, String className)
+ {
+ try
+ {
+ Class<?> clazz = domain.loadClass(className);
+ if (clazz == null)
+ {
+ return;
+ }
+ fail("Should not have been able to load " + className);
+ }
+ catch(Exception expected)
+ {
+ }
+ }
+
+ protected ClassPool createClassPool(String name, boolean importAll, URL... urls) throws Exception
+ {
+ return createClassPool(null, name, importAll, urls);
+ }
+
+ protected ClassPool createClassPool(Result result, String name, boolean importAll, URL... urls) throws Exception
+ {
+ ClassLoader loader = createClassLoader(result, name, importAll, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createClassPool(String name, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassPool(null, name, builder, urls);
+ }
+
+ protected ClassPool createClassPool(Result result, String name, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassPool(result, name, false, builder, urls);
+ }
+
+ protected ClassPool createClassPool(String name, boolean importAll, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassPool(null, name, importAll, builder, urls);
+ }
+
+ protected ClassPool createClassPool(Result result, String name, boolean importAll, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ TestVFSClassLoaderFactory factory = TestVFSClassLoaderFactoryFactory.createClassLoaderFactory(name, importAll, builder, urls);
+ ClassLoader loader = createClassLoader(result, factory);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassPool((Result)null, name, domainName, importAll, urls);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(Result result, String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentFirstClassLoader(result, name, domainName, importAll, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(String name, String domainName, boolean importAll, ClassPool parent, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassPool(null, name, domainName, importAll, parent, urls);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(Result result, String name, String domainName, boolean importAll, ClassPool parent, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentFirstClassLoader(result, name, domainName, importAll, parent.getClassLoader(), urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassPool(null, name, domainName, parentDomainName, importAll, urls);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(Result result, String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentFirstClassLoader(result, name, domainName, parentDomainName, importAll, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassPool((Result)null, name, domainName, importAll, urls);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(Result result, String name, String domainName, boolean importAll, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentLastClassLoader(result, name, domainName, importAll, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(String name, String domainName, boolean importAll, ClassPool parent, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassPool(null, name, domainName, importAll, parent, urls);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(Result result, String name, String domainName, boolean importAll, ClassPool parent, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentLastClassLoader(result, name, domainName, importAll, parent.getClassLoader(), urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassPool(null, name, domainName, parentDomainName, importAll, urls);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(Result result, String name, String domainName, String parentDomainName, boolean importAll, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentLastClassLoader(result, name, domainName, parentDomainName, importAll, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(String name, String domainName, String parentDomainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassPool(null, name, domainName, parentDomainName, builder, urls);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(Result result, String name, String domainName, String parentDomainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentFirstClassLoader(result, name, domainName, parentDomainName, builder, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentFirstClassPool((Result)null, name, domainName, builder, urls);
+ }
+
+ protected ClassPool createChildDomainParentFirstClassPool(Result result, String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentFirstClassLoader(result, name, domainName, builder, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createChildDomainParentLastClassPool(null, name, domainName, builder, urls);
+ }
+
+ protected ClassPool createChildDomainParentLastClassPool(Result result, String name, String domainName, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ ClassLoader loader = createChildDomainParentLastClassLoader(result, name, domainName, builder, urls);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassPool createChildURLClassPool(ClassPool parent, URL url)
+ {
+ ClassLoader parentLoader = null;
+ if (parent != null)
+ {
+ parentLoader = parent.getClassLoader();
+ }
+ ClassLoader loader = createChildURLClassLoader(parentLoader, url);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected void registerModule(ClassLoader loader, Module module)
+ {
+ registerModule(loader, module, null);
+ }
+
+ protected void registerModule(ClassLoader loader, Module module, ClassLoader parent)
+ {
+ if (getSystem() != domainRegistry.getSystem())
+ {
+ domainRegistry.setSystem(getSystem());
+ }
+
+ //TODO I have just hacked the domain here so this might cause problems
+ //with the tests if we try to do weaving. However, it should be fine while just testing pools
+ //and loaders
+ /*ScopedVFSClassLoaderDomainSetup setup = peekClassLoaderDomainSetup();
+ ScopedVFSClassLoaderDomain domain = null;
+ if (setup != null)
+ {
+ ClassLoaderDomain clDomain = getSystem().getDomain(module.getDomainName());
+ setup.setClassLoaderAndDomain(loader, clDomain);
+ domain = setup.getDomain();
+ }*/
+ domainRegistry.initMapsForLoader(loader, module, parent);
+ }
+
+ protected void unregisterModule(ClassLoader loader)
+ {
+ domainRegistry.cleanupLoader(loader);
+ }
+
+ protected void assertModule(ClassLoader loader)
+ {
+ ClassLoaderDomain domainForLoader = scopedChildDomainsByLoader.get(loader);
+ if (domainForLoader == null)
+ {
+ //domainForLoader = helper.getDomain();
+ domainForLoader = getSystem().getDefaultDomain();
+ }
+ assertNotNull(domainForLoader);
+
+ ClassLoaderDomain domainForModule = domainRegistry.getClassLoaderDomainForLoader(loader);
+ assertNotNull(domainForModule);
+ assertSame(domainForLoader, domainForModule);
+
+ Module module = domainRegistry.getModule(loader);
+ assertNotNull(module);
+ assertEquals(domainForModule.getName(), module.getDomainName());
+ assertEquals(domainForModule.getParentDomainName(), module.getParentDomainName());
+ }
+
+
+ protected void assertNoClassLoader(Result result) throws Exception
+ {
+ if (result == null)
+ {
+ throw new IllegalStateException("Null result");
+ }
+ assertNoClassLoader(getContextName(result.getFactory()));
+ }
+
+ protected void assertNoClassPool(Result result) throws Exception
+ {
+ if (result == null)
+ {
+ throw new IllegalStateException("Null result");
+ }
+ assertNoClassLoader(getContextName(result.getFactory()));
+ }
+
+ protected void assertNoClassLoader(String name) throws Exception
+ {
+ try
+ {
+ Object bean = getBean(name, null);
+ if (bean != null)
+ fail("Should not be here: " + bean);
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+
+ protected void unregisterClassPool(ClassPool pool) throws Exception
+ {
+ if (pool != null)
+ {
+ ClassLoader loader = pool.getClassLoader();
+ ClassPoolRepository.getInstance().unregisterClassLoader(loader);
+ if (loader != null)
+ {
+ unregisterClassLoader(loader);
+ }
+ }
+ }
+
+ protected void unregisterClassLoader(ClassLoader classLoader) throws Exception
+ {
+ if (classLoader != null)
+ {
+ if (registeredURLClassLoaders.remove(classLoader) == false)
+ {
+ domainRegistry.cleanupLoader(classLoader);
+ KernelDeployment deployment = loaderNameDeploymentRegistry.unregisterDeployment(classLoader);
+ unregisterDeployment(deployment);
+ }
+ }
+ }
+
+ protected void unregisterClassLoader(String name) throws Exception
+ {
+ KernelDeployment deployment = loaderNameDeploymentRegistry.unregisterDeployment(name);
+ unregisterDeployment(deployment);
+ }
+
+ private void unregisterDeployment(KernelDeployment deployment)
+ {
+ if (deployment != null)
+ {
+ undeploy(deployment);
+ }
+ }
+
+ /**
+ * Unregister a domain
+ *
+ * @param name the domain name
+ */
+ protected void unregisterDomain(String name)
+ {
+ if (name != null)
+ {
+ ClassLoaderDomain registeredDomain = getSystem().getDomain(name);
+ unregisterDomain(registeredDomain);
+ }
+ }
+
+ protected KernelDeployment install(TestVFSClassLoaderFactory metaData) throws Exception
+ {
+ AbstractKernelDeployment deployment = new AbstractKernelDeployment();
+ deployment.setName(metaData.getName() + ":" + metaData.getVersion());
+ deployment.setBeanFactories(Collections.singletonList((BeanMetaDataFactory) metaData));
+ deploy(deployment);
+ return deployment;
+ }
+
+ protected String getContextName(TestVFSClassLoaderFactory factory)
+ {
+ String contextName = factory.getContextName();
+ if (contextName == null)
+ contextName = factory.getName() + ":" + factory.getVersion();
+ return contextName;
+ }
+
+ protected ClassLoader assertClassLoader(TestVFSClassLoaderFactory factory) throws Exception
+ {
+ return assertClassLoader(factory, null);
+ }
+
+ protected ClassLoader assertClassLoader(TestVFSClassLoaderFactory factory, ClassLoader parent) throws Exception
+ {
+ try
+ {
+ Object obj = getBean(getContextName(factory));
+ ClassLoader loader = assertInstanceOf(obj, ClassLoader.class);
+
+ Module module = assertModule(getContextName(factory));
+ registerModule(loader, module, parent);
+ loaderNameDeploymentRegistry.registerLoaderName(factory.getName(), loader);
+
+ return loader;
+ }
+ catch (IllegalStateException e)
+ {
+ throw new NoSuchClassLoaderException(e);
+ }
+ }
+
+ protected ClassPool assertClassPool(TestVFSClassLoaderFactory factory) throws Exception
+ {
+ ClassLoader loader = assertClassLoader(factory);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected Class<?> assertLoadClass(String name, ClassLoader initiating) throws Exception
+ {
+ return assertLoadClass(name, initiating, initiating);
+ }
+
+ protected Class<?> assertLoadClass(String name, ClassLoader initiating, ClassLoader expected) throws Exception
+ {
+ Class<?> clazz = initiating.loadClass(name);
+ if (expected != null)
+ {
+ assertSame(expected, clazz.getClassLoader());
+ }
+ return clazz;
+ }
+
+ protected CtClass assertLoadCtClass(String name, ClassPool initiating) throws Exception
+ {
+ return assertLoadCtClass(name, initiating, initiating);
+ }
+
+ protected CtClass assertLoadCtClass(String name, ClassPool initiating, ClassPool expected) throws Exception
+ {
+ CtClass clazz = initiating.get(name);
+ if (expected != null)
+ {
+ assertSame(expected, clazz.getClassPool());
+ }
+
+ //Load twice to test both create and cache
+ clazz = initiating.get(name);
+ if (expected != null)
+ {
+ assertSame(expected, clazz.getClassPool());
+ }
+
+ assertLoadCtClassArray(name, clazz, initiating, expected);
+
+ return clazz;
+ }
+
+ private void assertLoadCtClassArray(String name, CtClass clazz, ClassPool initiating, ClassPool expected) throws Exception
+ {
+ assertLoadCtClassArray(name, clazz, 1, initiating, expected);
+ assertLoadCtClassArray(name, clazz, 2, initiating, expected);
+ }
+
+ private void assertLoadCtClassArray(String name, CtClass clazz, int dimensions, ClassPool initiating, ClassPool expected) throws Exception
+ {
+ String arrayName = name;
+ for (int i = 0 ; i < dimensions ; i++)
+ {
+ arrayName = array(arrayName);
+ }
+ CtClass array = initiating.get(arrayName);
+
+ if (expected != null)
+ {
+ assertSame(expected, array.getClassPool());
+ }
+
+ assertSame(clazz.getClassPool(), array.getClassPool());
+
+ CtClass type = array;
+ for (int i = 0 ; i < dimensions ; i++)
+ {
+ type = type.getComponentType();
+ }
+ assertSame(type, clazz);
+ }
+
+ protected Module assertModule(String contextName)
+ {
+ return assertBean(contextName + "$MODULE", Module.class);
+ }
+
+ /**
+ * The test classes should not be on the launcher classpath
+ */
+ public void testClassesNotOnClasspath()
+ {
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_A);
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_B);
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_C);
+ }
+
+ static class NoSuchClassLoaderException extends Exception
+ {
+ private static final long serialVersionUID = 1L;
+
+ public NoSuchClassLoaderException(Exception e)
+ {
+ super(e);
+ }
+ }
+
+ private static class LoaderNameDeploymentRegistry
+ {
+ private Map<String, KernelDeployment> deploymentsByName = new HashMap<String, KernelDeployment>();
+
+ private Map<ClassLoader, String> namesByLoader = new HashMap<ClassLoader, String>();
+
+ private void registerDeployment(String name, KernelDeployment deployment)
+ {
+ if (!deploymentsByName.containsKey(name))
+ {
+ deploymentsByName.put(name, deployment);
+ }
+ }
+
+ private void registerLoaderName(String name, ClassLoader loader)
+ {
+ if (loader != null)
+ {
+ namesByLoader.put(loader, name);
+ }
+ }
+
+ private KernelDeployment unregisterDeployment(String name)
+ {
+ return deploymentsByName.remove(name);
+ }
+
+ private KernelDeployment unregisterDeployment(ClassLoader loader)
+ {
+ String name = namesByLoader.remove(loader);
+ return unregisterDeployment(name);
+ }
+ }
+
+ /*private static ScopedVFSClassLoaderDomainSetup classLoaderDomainSetup;
+
+ protected static void pushClassLoaderDomainSetup(ScopedVFSClassLoaderDomainSetup setup)
+ {
+ classLoaderDomainSetup = setup;
+ }
+
+ protected static ScopedVFSClassLoaderDomainSetup popClassLoaderDomainSetup()
+ {
+ ScopedVFSClassLoaderDomainSetup setup = classLoaderDomainSetup;
+ classLoaderDomainSetup = null;
+ return setup;
+ }
+
+ protected static ScopedVFSClassLoaderDomainSetup peekClassLoaderDomainSetup()
+ {
+ return classLoaderDomainSetup;
+ }*/
+
+ /*public class ScopedVFSClassLoaderDomainSetup
+ {
+ ScopedVFSClassLoaderDomain domain;
+
+ String name;
+ boolean parentDelegation;
+ boolean parentFirst;
+ DomainRegistry registry;
+
+ public ScopedVFSClassLoaderDomainSetup(String name, boolean parentDelegation, boolean parentFirst, DomainRegistry registry)
+ {
+ this.name = name;
+ this.parentDelegation = parentDelegation;
+ this.parentFirst = parentFirst;
+ this.registry = registry;
+ }
+
+ public ScopedVFSClassLoaderDomain getDomain()
+ {
+ return domain;
+ }
+
+ public void setClassLoaderAndDomain(ClassLoader loader, ClassLoaderDomain clDomain)
+ {
+ if (domain == null)
+ {
+ domain = new ScopedVFSClassLoaderDomain(loader, name, parentDelegation, parentFirst, clDomain, registry);
+ }
+ }
+ }*/
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestDelegate.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestDelegate.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestDelegate.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolTestDelegate extends MicrocontainerTestDelegate
+{
+
+ public JBossClClassPoolTestDelegate(Class<?> clazz) throws Exception
+ {
+ super(clazz);
+// String property = System.getProperty("jboss.aop.secure", "true");
+// boolean enableSecurity = Boolean.valueOf(property).booleanValue();
+// this.enableSecurity = enableSecurity;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestSuite.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestSuite.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/jbosscl/test/JBossClClassPoolTestSuite.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.jbosscl.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossClClassPoolTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JBoss-cl All Tests");
+
+ suite.addTest(JBossClClassPoolSanityTestSuite.suite());
+ suite.addTest(JBossClClassPoolDelegatingTestSuite.suite());
+ return suite;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/AlwaysWritablePermissionCollectionTestPolicyPlugin.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/AlwaysWritablePermissionCollectionTestPolicyPlugin.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/AlwaysWritablePermissionCollectionTestPolicyPlugin.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+import java.security.CodeSource;
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.security.SecurityPermission;
+import java.util.Enumeration;
+import java.util.PropertyPermission;
+
+import org.jboss.test.security.TestsPolicyPlugin;
+
+/**
+ * The original TestPolicyPlugin reuses the underlying PermissionCollection. This causes problems
+ * for tests creating several ProtectionDomains, since the ProtectionDomain's constructor
+ * marks the PolicyCollection as read-only so we get errors
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class AlwaysWritablePermissionCollectionTestPolicyPlugin extends TestsPolicyPlugin
+{
+ public AlwaysWritablePermissionCollectionTestPolicyPlugin(Class<?> clazz)
+ {
+ super(clazz);
+ }
+
+ public synchronized PermissionCollection getPermissions(CodeSource codesource)
+ {
+ return new AlwaysWritablePermissionCollection(super.getPermissions(codesource));
+ }
+
+ public static void initialisePlugin()
+ {
+ System.setProperty("org.jboss.test.security.PolicyPlugin", AlwaysWritablePermissionCollectionTestPolicyPlugin.class.getName());
+ }
+
+ public static void cleanupPlugin()
+ {
+ System.clearProperty("org.jboss.test.security.PolicyPlugin");
+ }
+
+ private static class AlwaysWritablePermissionCollection extends PermissionCollection
+ {
+ private static final long serialVersionUID = 1L;
+
+ volatile PermissionCollection lastDelegate;
+ volatile PermissionCollection delegate;
+
+ final static Permission GET_POLICY = new SecurityPermission("getPolicy");
+ final static Permission PARENT_PKGS = new PropertyPermission("jboss.test.parent.pkgs", "read");
+
+ private AlwaysWritablePermissionCollection(PermissionCollection delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public void add(Permission permission)
+ {
+ delegate.add(permission);
+ }
+
+ public Enumeration<Permission> elements()
+ {
+ return delegate.elements();
+ }
+
+ public boolean equals(Object obj)
+ {
+ return delegate.equals(obj);
+ }
+
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ public boolean implies(Permission permission)
+ {
+ return delegate.implies(permission);
+ }
+
+ public boolean isReadOnly()
+ {
+ return delegate.isReadOnly();
+ }
+
+ public void setReadOnly()
+ {
+ //ignore
+ }
+
+ public String toString()
+ {
+ return delegate.toString();
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/BundleInfoBuilder.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/BundleInfoBuilder.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/BundleInfoBuilder.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,179 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BundleInfoBuilder
+{
+ static ClassLoadingMetaDataFactory clmdf = ClassLoadingMetaDataFactory.getInstance();
+
+ List<Capability> capabilities = new ArrayList<Capability>();
+ List<Requirement> requirements = new ArrayList<Requirement>();
+
+ private BundleInfoBuilder()
+ {
+
+ }
+
+ public static BundleInfoBuilder getBuilder()
+ {
+ return new BundleInfoBuilder();
+ }
+
+ public BundleInfoBuilder createModule(String name)
+ {
+ capabilities.add(clmdf.createModule(name));
+ return this;
+ }
+
+ public BundleInfoBuilder createModule(String name, Object version)
+ {
+ capabilities.add(clmdf.createModule(name, version));
+ return this;
+ }
+
+ public BundleInfoBuilder createRequireModule(String name)
+ {
+ requirements.add(clmdf.createRequireModule(name, null));
+ return this;
+ }
+
+ public BundleInfoBuilder createRequireModule(String name, VersionRange versionRange)
+ {
+ requirements.add(clmdf.createRequireModule(name, versionRange));
+ return this;
+ }
+
+ public BundleInfoBuilder createRequireModule(String name, VersionRange versionRange, boolean optional, boolean reExport, boolean dynamic)
+ {
+ requirements.add(clmdf.createRequireModule(name, versionRange, optional, reExport, dynamic));
+ return this;
+ }
+
+ public BundleInfoBuilder createPackage(String name)
+ {
+ capabilities.add(clmdf.createPackage(name));
+ return this;
+ }
+
+ public BundleInfoBuilder createPackage(String name, Object version)
+ {
+ capabilities.add(clmdf.createPackage(name, version));
+ return this;
+ }
+
+ public BundleInfoBuilder createRequirePackage(String name)
+ {
+ requirements.add(clmdf.createRequirePackage(name));
+ return this;
+ }
+
+ public BundleInfoBuilder createRequirePackage(String name, VersionRange versionRange)
+ {
+ requirements.add(clmdf.createRequirePackage(name, versionRange));
+ return this;
+ }
+
+ public BundleInfoBuilder createRequirePackage(String name, VersionRange versionRange, boolean optional, boolean reExport, boolean dynamic)
+ {
+ requirements.add(clmdf.createRequirePackage(name, versionRange, optional, reExport, dynamic));
+ return this;
+ }
+
+ public BundleInfoBuilder createReExportModule(String name)
+ {
+ requirements.add(clmdf.createReExportModule(name));
+ return this;
+ }
+
+ public BundleInfoBuilder createReExportModule(String name, VersionRange versionRange)
+ {
+ requirements.add(clmdf.createReExportModule(name, versionRange));
+ return this;
+ }
+
+ public BundleInfoBuilder createReExportModule(String name, VersionRange versionRange, boolean optional)
+ {
+ requirements.add(clmdf.createReExportModule(name, versionRange, optional));
+ return this;
+ }
+
+ public BundleInfoBuilder createReExportPackage(String name)
+ {
+ requirements.add(clmdf.createReExportPackage(name));
+ return this;
+ }
+
+ public BundleInfoBuilder createReExportPackage(String name, VersionRange versionRange)
+ {
+ requirements.add(clmdf.createReExportPackage(name, versionRange));
+ return this;
+ }
+
+ public BundleInfoBuilder createReExportPackage(String name, VersionRange versionRange, boolean optional)
+ {
+ requirements.add(clmdf.createReExportPackage(name, versionRange, optional));
+ return this;
+ }
+
+ public BundleInfoBuilder createUsesPackage(String name)
+ {
+ requirements.add(clmdf.createUsesPackage(name));
+ return this;
+ }
+
+ public BundleInfoBuilder createUsesPackage(String name, VersionRange versionRange)
+ {
+ requirements.add(clmdf.createUsesPackage(name, versionRange));
+ return this;
+ }
+
+ public BundleInfoBuilder createUsesPackage(String name, VersionRange versionRange, boolean reExport)
+ {
+ requirements.add(clmdf.createUsesPackage(name, versionRange, reExport));
+ return this;
+ }
+
+
+
+ public List<Capability> getCapabilities()
+ {
+ return capabilities;
+ }
+
+ public List<Requirement> getRequirements()
+ {
+ return requirements;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/CapabilityInfo.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/CapabilityInfo.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/CapabilityInfo.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CapabilityInfo extends ModuleOrPackageInfo
+{
+ public CapabilityInfo(String name, Object version)
+ {
+ // FIXME ModuleCapabilityInfo constructor
+ super(name, version);
+ }
+
+ public CapabilityInfo(String name)
+ {
+ // FIXME ModuleCapabilityInfo constructor
+ super(name);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ModuleOrPackageInfo.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ModuleOrPackageInfo.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/ModuleOrPackageInfo.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ModuleOrPackageInfo
+{
+ private String name;
+
+ private Object version;
+
+ public ModuleOrPackageInfo(String name, Object version)
+ {
+ this.name = name;
+ this.version = version;
+ }
+
+ public ModuleOrPackageInfo(String name)
+ {
+ this(name, null);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Object getVersion()
+ {
+ return version;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/NoMatchClassFilter.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/NoMatchClassFilter.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/NoMatchClassFilter.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,70 @@
+/*
+ * 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.classpool.support;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloader.spi.filter.ClassFilter;
+
+/**
+ * NoMatchClassFilter.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class NoMatchClassFilter implements ClassFilter
+{
+ String className;
+
+ public boolean filtered = false;
+
+ public NoMatchClassFilter(String classname)
+ {
+ this.className = classname;
+ }
+
+ public boolean matchesClassName(String className)
+ {
+ if (this.className.equals(className))
+ {
+ filtered = true;
+ return false;
+ }
+ return true;
+ }
+
+ public boolean matchesResourcePath(String resourcePath)
+ {
+ if (ClassLoaderUtils.classNameToPath(this.className).equals(resourcePath))
+ {
+ filtered = true;
+ return false;
+ }
+ return true;
+ }
+
+ public boolean matchesPackageName(String packageName)
+ {
+ if (ClassLoaderUtils.getClassPackageName(this.className).equals(packageName))
+ return false;
+ return true;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/RequirementInfo.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/RequirementInfo.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/RequirementInfo.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,75 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequirementInfo extends ModuleOrPackageInfo
+{
+ boolean optional;
+ boolean reExport;
+ boolean dynamic;
+
+ public RequirementInfo(String name, VersionRange range)
+ {
+ super(name, range);
+ }
+
+ public RequirementInfo(String name)
+ {
+ super(name);
+ }
+
+ public RequirementInfo(String name, VersionRange range, boolean optional, boolean reExport, boolean dynamic)
+ {
+ super(name, range);
+ this.optional = optional;
+ this.reExport = reExport;
+ this.dynamic = dynamic;
+ }
+
+ @Override
+ public VersionRange getVersion()
+ {
+ return (VersionRange)super.getVersion();
+ }
+
+ public boolean isOptional()
+ {
+ return optional;
+ }
+
+ public boolean isReExport()
+ {
+ return reExport;
+ }
+
+ public boolean isDynamic()
+ {
+ return dynamic;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/Result.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/Result.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/Result.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,42 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Result
+{
+ private TestVFSClassLoaderFactory factory;
+
+ public TestVFSClassLoaderFactory getFactory()
+ {
+ return factory;
+ }
+
+ public void setFactory(TestVFSClassLoaderFactory factory)
+ {
+ this.factory = factory;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/SupportClasses.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.support;
+
+import java.net.URL;
+
+/**
+ *
+ *
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision: 1.1 $
+ */
+public class SupportClasses
+{
+ public final static String JAR_A_1 = "a1.jar";
+ public final static String JAR_A_2 = "a2.jar";
+ public final static String JAR_B_1 = "b1.jar";
+ public final static String JAR_B_2 = "b2.jar";
+ public final static String JAR_C_1 = "c1.jar";
+ public final static String JAR_C_2 = "c2.jar";
+
+ public static final String PACKAGE_ROOT = SupportClasses.class.getPackage().getName() + ".excluded";
+ public final static String PACKAGE_A = PACKAGE_ROOT + ".a";
+ public final static String PACKAGE_B = PACKAGE_ROOT + ".b";
+ public final static String PACKAGE_C = PACKAGE_ROOT + ".c";
+
+ public final static String CLASS_A = PACKAGE_A + ".A";
+ public final static String CLASS_B = PACKAGE_B + ".B";
+ public final static String CLASS_C = PACKAGE_C + ".C";
+}
\ No newline at end of file
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,104 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.vfs.dependency.VFSClassLoaderPolicyModule;
+import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestVFSClassLoaderFactory extends VFSClassLoaderFactory
+{
+ private static final long serialVersionUID = 1L;
+
+ private ClassLoader parent;
+
+ @Override
+ protected Class<? extends VFSClassLoaderPolicyModule> getModuleClass()
+ {
+ return TestVFSClassLoaderPolicyModule.class;
+ }
+
+ public void setParent(ClassLoader parent)
+ {
+ this.parent = parent;
+ }
+
+ @Override
+ public List<BeanMetaData> getBeans()
+ {
+
+ List<BeanMetaData> result = super.getBeans();
+ if (parent != null)
+ {
+ //We need to modify the Module factory method used to create the classloader to pass in the parent
+ if (result.size() != 2)
+ {
+ throw new IllegalStateException("Expected size=2, was " + result.size());
+ }
+
+ BeanMetaData classLoader = null;
+ BeanMetaData module = null;
+ for (BeanMetaData bean : result)
+ {
+ if (bean.getBean().equals(ClassLoader.class.getName()))
+ {
+ classLoader = bean;
+ }
+ else
+ {
+ module = bean;
+ }
+ }
+
+ if (module == null)
+ {
+ throw new IllegalStateException("Could not find module");
+ }
+ if (classLoader == null)
+ {
+ throw new IllegalStateException("Could not find module");
+ }
+
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(classLoader.getName(), ClassLoader.class.getName());
+ builder.setNoClassLoader();
+ builder.setFactory(module.getName());
+ builder.setFactoryMethod("registerClassLoaderPolicy");
+ builder.addConstructorParameter(ClassLoaderSystem.class.getName(), builder.createInject(getClassLoaderSystemName()));
+ builder.addConstructorParameter(ClassLoader.class.getName(), parent);
+ classLoader = builder.getBeanMetaData();
+
+ result = Arrays.asList(classLoader, module);
+ }
+
+ return result;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactoryFactory.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactoryFactory.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderFactoryFactory.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,135 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ExportAll;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestVFSClassLoaderFactoryFactory
+{
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, boolean importAll, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, importAll, null, false, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, boolean importAll, BundleInfoBuilder builder, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, importAll, null, null, builder, false, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, String domainName, BundleInfoBuilder builder, boolean parentFirst, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, domainName, null, builder, parentFirst, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, String domainName, String parentDomainName, BundleInfoBuilder builder, boolean parentFirst, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, false, domainName, parentDomainName, builder, false, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, boolean importAll, String moduleName, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, importAll, null, false, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, boolean importAll, String domainName, boolean parentFirst, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, importAll, domainName, null, parentFirst, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, boolean importAll, String domainName, String parentDomainName, boolean parentFirst, URL... urls) throws Exception
+ {
+ return createClassLoaderFactory(name, importAll, domainName, parentDomainName, null, parentFirst, urls);
+ }
+
+ public static TestVFSClassLoaderFactory createClassLoaderFactory(String name, boolean importAll, String domainName, String parentDomainName, BundleInfoBuilder builder, boolean parentFirst, URL... urls) throws Exception
+ {
+ TestVFSClassLoaderFactory factory = new TestVFSClassLoaderFactory();
+ factory.setName(name);
+ factory.setImportAll(importAll);
+ if (importAll)
+ {
+ factory.setExportAll(ExportAll.NON_EMPTY);
+ }
+ factory.setRoots(urlsToStringList(urls));
+ addCapabilitiesAndRequirements(factory, builder);
+ setupDomain(factory, domainName, parentDomainName, parentFirst);
+ return factory;
+ }
+
+ private static void addCapabilitiesAndRequirements(ClassLoadingMetaData md, BundleInfoBuilder builder)
+ {
+ if (builder != null)
+ {
+ md.getCapabilities().setCapabilities(builder.getCapabilities());
+ md.getRequirements().setRequirements(builder.getRequirements());
+ }
+ }
+
+ private static void setupDomain(ClassLoadingMetaData md, String domainName, String parentDomainName, boolean parentFirst)
+ {
+ if (domainName != null)
+ {
+ md.setDomain(domainName);
+ md.setJ2seClassLoadingCompliance(parentFirst);
+ if (parentDomainName != null)
+ {
+ md.setParentDomain(parentDomainName);
+ }
+ else
+ {
+ md.setParentDomain(ClassLoaderSystem.DEFAULT_DOMAIN_NAME);
+ }
+ }
+ else
+ {
+ md.setDomain(ClassLoaderSystem.DEFAULT_DOMAIN_NAME);
+ }
+ }
+
+ private static List<String> urlsToStringList(URL... urls)
+ {
+ List<String> urlList = new ArrayList<String>(urls.length);
+ if (urls.length > 0)
+ {
+ for (URL url : urls)
+ {
+ if (url != null)
+ {
+ urlList.add(url.toString());
+ }
+ }
+ }
+ return urlList;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderPolicyModule.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/TestVFSClassLoaderPolicyModule.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support;
+
+import java.net.URL;
+
+import org.jboss.classloading.spi.vfs.dependency.VFSClassLoaderPolicyModule;
+import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.MemoryFileFactory;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestVFSClassLoaderPolicyModule extends VFSClassLoaderPolicyModule
+{
+ private static final long serialVersionUID = 1;
+
+ /** In AS we need a URL to create the temporary files */
+ URL dynamicClassRoot;
+ VirtualFile classes;
+
+ public TestVFSClassLoaderPolicyModule(VFSClassLoaderFactory classLoadingMetaData, String contextName)
+ {
+ // FIXME TesetMockClassLoaderPolicyModule constructor
+ super(classLoadingMetaData, contextName);
+ }
+
+ /**
+ * Get/Create the vfs memory file where we will create dynamic classes
+ */
+ @Override
+ public URL getDynamicClassRoot()
+ {
+ initDynamicClassRoot();
+ return dynamicClassRoot;
+ }
+
+ /**
+ * Prepend the dynamic URL location to the classpath
+ */
+ @Override
+ protected VirtualFile[] determineVFSRoots()
+ {
+ initDynamicClassRoot();
+ VirtualFile[] roots = super.determineVFSRoots();
+ VirtualFile[] newRoots = new VirtualFile[roots.length + 1];
+ newRoots[0] = classes;
+ System.arraycopy(roots, 0, newRoots, 1, roots.length);
+
+ return newRoots;
+ }
+
+ private synchronized void initDynamicClassRoot()
+ {
+ if (dynamicClassRoot == null)
+ {
+ try
+ {
+ dynamicClassRoot = new URL("vfsmemory", GUID.asString(), "");
+ classes = MemoryFileFactory.createRoot(dynamicClassRoot).getRoot();
+ }
+ catch (Exception e)
+ {
+ // AutoGenerated
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/a/A.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/a/A.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/a/A.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.a;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/b/B.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/b/B.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/b/B.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.b;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/a/A.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/a/A.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/a/A.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.a;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/b/B.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/b/B.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/b/B.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.b;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/c/C.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/c/C.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/c/C.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.c;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class C
+{
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/Invoked.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/Invoked.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/Invoked.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.replacereferences;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Invoked
+{
+ public static boolean invoked;
+
+ public static boolean getAndReset()
+ {
+ boolean inv = invoked;
+ invoked = false;
+ return inv;
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/Child.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/Child.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/Child.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.replacereferences.child;
+
+import org.jboss.test.classpool.support.excluded.replacereferences.parent.Parent;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Child extends Parent
+{
+ int child;
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/ChildCaller.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/ChildCaller.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/child/ChildCaller.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,73 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.replacereferences.child;
+
+import junit.framework.Assert;
+
+import org.jboss.test.classpool.support.excluded.replacereferences.Invoked;
+import org.jboss.test.classpool.support.excluded.replacereferences.parent.Parent;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision: 1.1 $
+ */
+public class ChildCaller
+{
+ public static void test()
+ {
+ Invoked.invoked = false;
+ Child child = new Child();
+ Assert.assertTrue("Invoked not called for Child constructor", Invoked.invoked);
+
+ Invoked.invoked = false;
+ child.child = 7;
+ Assert.assertTrue("Invoked not called for Child.child write", Invoked.invoked);
+
+ int i = child.child;
+ Assert.assertTrue("Invoked not called for Child.child read", Invoked.invoked);
+ Assert.assertEquals("Expected 7 for Child.child, was " + i, 7, i);
+
+ Invoked.invoked = false;
+ child.parent = 8;
+ Assert.assertTrue("Invoked not called for Child.parent write", Invoked.invoked);
+
+ Invoked.invoked = false;
+ i = child.parent;
+ Assert.assertTrue("Invoked not called for Child.parent read", Invoked.invoked);
+ Assert.assertEquals("Expected 8 for Child.parent, was " + i, 8, i);
+
+ Invoked.invoked = false;
+ Parent parent = new Parent();
+ Assert.assertTrue("Invoked not called for Parent constructor", Invoked.invoked);
+
+ Invoked.invoked = false;
+ parent.parent = 5;
+ Assert.assertTrue("Invoked not called for Parent.parent write", Invoked.invoked);
+
+ Invoked.invoked = false;
+ i = parent.parent;
+ Assert.assertTrue("Invoked not called for Parent.parent read", Invoked.invoked);
+ Assert.assertEquals("Expected 5 for Parent.parent, was " + i, 5, i);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/Parent.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/Parent.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/Parent.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.replacereferences.parent;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Parent
+{
+ public int parent;
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/ParentCaller.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/ParentCaller.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/support/excluded/replacereferences/parent/ParentCaller.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.support.excluded.replacereferences.parent;
+
+import junit.framework.Assert;
+
+import org.jboss.test.classpool.support.excluded.replacereferences.Invoked;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParentCaller
+{
+ public static void test()
+ {
+ Invoked.invoked = false;
+ Parent parent = new Parent();
+ Assert.assertTrue("Invoked not called for Parent constructor", Invoked.invoked);
+
+ Invoked.invoked = false;
+ parent.parent = 5;
+ Assert.assertTrue("Invoked not called for Parent.parent write", Invoked.invoked);
+
+ Invoked.invoked = false;
+ int i = parent.parent;
+ Assert.assertTrue("Invoked not called for Parent.parent read", Invoked.invoked);
+ Assert.assertEquals("Expected 5 for Parent.parent, was " + i, 5 ,i);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTest.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTest.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTest.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,142 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.ClassPool;
+
+import org.jboss.classpool.AbstractClassPoolDomain;
+import org.jboss.classpool.BaseClassPoolDomain;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.DelegatingClassPool;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.classpool.support.SupportClasses;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolTest extends AbstractTestCaseWithSetup
+{
+ public final static URL JAR_A = getURLRelativeToProjectRoot(SupportClasses.JAR_A_1);
+ public final static URL JAR_B = getURLRelativeToProjectRoot(SupportClasses.JAR_B_1);
+
+ //Hard references to classloaders used for pools to avoid them being garbage collected before the test finished
+ private final static List<ClassLoader> loaders = new ArrayList<ClassLoader>();
+
+ public ClassPoolTest(String name)
+ {
+ super(name);
+ }
+
+ protected static URL getURLRelativeToProjectRoot(String relativePath)
+ {
+ try
+ {
+ URL url = ClassPoolTest.class.getProtectionDomain().getCodeSource().getLocation();
+ String location = url.toString();
+ int index = location.lastIndexOf("/target/") + "/target/".length();
+ location = location.substring(0, index);
+
+ location = location + relativePath;
+ return new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ // AutoGenerated
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ AbstractTestDelegate delegate = new ClassPoolTestDelegate(clazz);
+ String property = "false"; // System.getProperty("jboss.aop.secure", "false"); // TODO fix this
+ boolean enableSecurity = Boolean.valueOf(property).booleanValue();
+ delegate.enableSecurity = enableSecurity;
+ return delegate;
+ }
+
+ protected static AbstractClassPoolDomain createClassPoolDomain(String name, ClassPoolDomain parent, boolean parentFirst)
+ {
+ AbstractClassPoolDomain domain = new BaseClassPoolDomain(name, parent, parentFirst);
+ return domain;
+ }
+
+ protected static DelegatingClassPool createDelegatingClassPool(ClassPoolDomain domain, URL...urls) throws ClassNotFoundException
+ {
+ ClassLoader loader = new URLClassLoader(urls);
+ for (URL url : urls)
+ {
+ if (url == JAR_A)
+ {
+ loader.loadClass(SupportClasses.CLASS_A);
+ }
+ else if (url == JAR_B)
+ {
+ loader.loadClass(SupportClasses.CLASS_B);
+ }
+
+ }
+ //Once all the classes in the loader have been loaded, it seems to clear the URLs. Work around this
+ //by recreating the loader since we need the urls in the URLClassLoaderIsLocalResourcePlugin
+ loader = new URLClassLoader(urls);
+ //Add hard reference to loader
+ loaders.add(loader);
+ return new DelegatingClassPool(domain, loader, ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+// enableTrace("org.jboss.aop.classpool");
+ }
+
+ protected void assertCannotLoadClass(ClassLoader loader, String classname)
+ {
+ try
+ {
+ loader.loadClass(classname);
+ fail("Should not have been able to load " + classname);
+ }
+ catch(ClassNotFoundException expected)
+ {
+ }
+ }
+
+ /**
+ * The test classes should not be on the launcher classpath
+ */
+ public void testClassesNotOnClasspath()
+ {
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_A);
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_B);
+ }}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTestDelegate.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTestDelegate.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ClassPoolTestDelegate.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.test;
+
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolTestDelegate extends AbstractTestDelegate
+{
+ public ClassPoolTestDelegate(Class<?> clazz)
+ {
+ super(clazz);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/DelegatingClassPoolTestSuite.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/DelegatingClassPoolTestSuite.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/DelegatingClassPoolTestSuite.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegatingClassPoolTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("DelegatingClassPool All Tests");
+
+ suite.addTest(IsLocalResourcePluginFactoryTestCase.suite());
+ suite.addTest(SimpleDelegatingClassPoolTestCase.suite());
+ suite.addTest(ScopedSiblingDelegatingClassPoolTestCase.suite());
+ suite.addTest(ParentFirstDelegatingClassPoolTestCase.suite());
+ suite.addTest(ParentLastDelegatingClassPoolTestCase.suite());
+
+
+ return suite;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/IsLocalResourcePluginFactoryTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/IsLocalResourcePluginFactoryTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/IsLocalResourcePluginFactoryTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,182 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import javassist.ClassPool;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.classpool.BaseClassPoolDomain;
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.DefaultClassLoaderIsLocalResourcePlugin;
+import org.jboss.classpool.DefaultClassLoaderIsLocalResourcePluginFactory;
+import org.jboss.classpool.DelegatingClassPool;
+import org.jboss.classpool.IsLocalResourcePlugin;
+import org.jboss.classpool.IsLocalResourcePluginFactory;
+import org.jboss.classpool.IsLocalResourcePluginFactoryRegistry;
+import org.jboss.classpool.TranslatableClassLoaderIsLocalResourcePlugin;
+import org.jboss.classpool.TranslatableClassLoaderIsLocalResourcePluginFactory;
+import org.jboss.classpool.URLClassLoaderIsLocalResourcePlugin;
+import org.jboss.classpool.URLClassLoaderIsLocalResourcePluginFactory;
+import org.jboss.util.loading.Translatable;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IsLocalResourcePluginFactoryTestCase extends TestCase
+{
+ final static ClassPoolDomain DOMAIN = new BaseClassPoolDomain("Test", null, true);
+ final static URL[] URLS;
+ static
+ {
+ try
+ {
+ URLS = new URL[] {new URL("http://www.blah.com")};
+ }
+ catch (MalformedURLException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(IsLocalResourcePluginFactoryTestCase.class);
+ }
+
+ public IsLocalResourcePluginFactoryTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testDefaultClassLoader()
+ {
+ DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new DefaultClassLoader(), ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ assertFactoryAndPlugin(pool, DefaultClassLoaderIsLocalResourcePluginFactory.class, DefaultClassLoaderIsLocalResourcePlugin.class);
+ }
+
+ public void testURLClassLoaderDirect()
+ {
+ DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new URLClassLoader(URLS), ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ assertFactoryAndPlugin(pool, URLClassLoaderIsLocalResourcePluginFactory.class, URLClassLoaderIsLocalResourcePlugin.class);
+ }
+
+ public void testURLClassLoaderSubClass()
+ {
+ DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new URLCLassLoaderSubClass(URLS), ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ assertFactoryAndPlugin(pool, URLClassLoaderIsLocalResourcePluginFactory.class, URLClassLoaderIsLocalResourcePlugin.class);
+ }
+
+ public void testTranslatableClassLoaderImplementation()
+ {
+ DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new TranslatableImplementation(), ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ assertFactoryAndPlugin(pool, TranslatableClassLoaderIsLocalResourcePluginFactory.class, TranslatableClassLoaderIsLocalResourcePlugin.class);
+ }
+
+ public void testTranslatableClassLoaderImplementationAndURLClassLoaderSubClass()
+ {
+ DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new TranslatableImplementationAndURLClassLoaderSubClass(URLS), ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ assertFactoryAndPlugin(pool, TranslatableClassLoaderIsLocalResourcePluginFactory.class, TranslatableClassLoaderIsLocalResourcePlugin.class);
+ }
+
+ public void testTranslatable2ClassLoaderImplementationAndURLClassLoaderSubClass()
+ {
+ DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new Translatable2ImplementationAndURLClassLoaderSubClass(URLS), ClassPool.getDefault(), ClassPoolRepository.getInstance());
+ assertFactoryAndPlugin(pool, TranslatableClassLoaderIsLocalResourcePluginFactory.class, TranslatableClassLoaderIsLocalResourcePlugin.class);
+ }
+
+
+ private void assertFactoryAndPlugin(DelegatingClassPool pool, Class<?> factoryClass, Class<?> pluginClass)
+ {
+ IsLocalResourcePluginFactory factory = IsLocalResourcePluginFactoryRegistry.getPluginFactory(pool.getClassLoader());
+ assertNotNull(factory);
+ assertEquals(factoryClass, factory.getClass());
+ IsLocalResourcePlugin plugin = factory.create(pool);
+ assertEquals(pluginClass, plugin.getClass());
+ }
+
+ static class DefaultClassLoader extends ClassLoader
+ {
+ }
+
+ static class URLCLassLoaderSubClass extends URLClassLoader
+ {
+ public URLCLassLoaderSubClass(URL[] urls)
+ {
+ super(urls);
+ }
+
+ }
+
+ static class TranslatableImplementation extends ClassLoader implements Translatable
+ {
+ public URL getResourceLocally(String name)
+ {
+ return null;
+ }
+
+ }
+
+ static class TranslatableImplementationAndURLClassLoaderSubClass extends URLClassLoader implements Translatable
+ {
+
+ public TranslatableImplementationAndURLClassLoaderSubClass(URL[] urls)
+ {
+ super(urls);
+ }
+
+ public URL getResourceLocally(String name)
+ {
+ return null;
+ }
+
+ }
+
+ interface Translatable2 extends Translatable
+ {
+
+ }
+
+ static class Translatable2ImplementationAndURLClassLoaderSubClass extends URLClassLoader implements Translatable2
+ {
+
+ public Translatable2ImplementationAndURLClassLoaderSubClass(URL[] urls)
+ {
+ super(urls);
+ }
+
+ public URL getResourceLocally(String name)
+ {
+ return null;
+ }
+ }
+
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentFirstDelegatingClassPoolTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentFirstDelegatingClassPoolTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentFirstDelegatingClassPoolTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,296 @@
+package org.jboss.test.classpool.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classpool.ClassPoolDomain;
+import org.jboss.test.classpool.common.ClassFactory;
+
+
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.
+*/
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParentFirstDelegatingClassPoolTestCase extends ClassPoolTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(ParentFirstDelegatingClassPoolTestCase.class);
+ }
+
+ public ParentFirstDelegatingClassPoolTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testClassInParentOnly() throws Exception
+ {
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", null, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessClassInParentOnly(parentPool, childPool);
+ accessClassInParentOnly(parentPool, childPool);
+ }
+
+ private void accessClassInParentOnly(ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(parentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(parentPool, a2.getClassPool());
+ assertEquals(a1, a2);
+
+ CtClass b = childPool.get(CLASS_B);
+ assertEquals(childPool, b.getClassPool());
+ try
+ {
+ parentPool.get(CLASS_B);
+ fail("Should not have been found");
+ }
+ catch(NotFoundException e)
+ {
+ }
+
+ CtClass string = childPool.get(String.class.getName());
+ assertNotSame("java.lang.String should be loaded by the parent pool", childPool, string.getClassPool());
+ assertEquals(ClassPool.getDefault(), string.getClassPool());
+ }
+
+ public void testClassInGrandParentOnly() throws Exception
+ {
+ ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessClassInGrandParentOnly(grandParentPool, parentPool, childPool);
+ accessClassInGrandParentOnly(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessClassInGrandParentOnly(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+ assertEquals(a1, a2);
+
+ CtClass a3 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+
+ assertEquals(a2, a3);
+
+
+ CtClass b1 = childPool.get(CLASS_B);
+ assertEquals(parentPool, b1.getClassPool());
+ CtClass b2 = childPool.get(CLASS_B);
+ assertEquals(parentPool, b2.getClassPool());
+ assertEquals(b1, b2);
+
+ try
+ {
+ grandParentPool.get(CLASS_B);
+ fail("Should not have been found");
+ }
+ catch(NotFoundException e)
+ {
+ }
+ }
+
+ public void testChildNotInParent() throws Exception
+ {
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", null, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildNotInParent(parentPool, childPool);
+ accessChildNotInParent(parentPool, childPool);
+ }
+
+ private void accessChildNotInParent(ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ try
+ {
+ parentPool.get(CLASS_A);
+ fail("Should not have been found");
+ }
+ catch(NotFoundException e)
+ {
+ }
+ CtClass a = childPool.get(CLASS_A);
+ assertEquals(childPool, a.getClassPool());
+
+ }
+
+ public void testChildInParent() throws Exception
+ {
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", null, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInParent(parentPool, childPool);
+ accessChildInParent(parentPool, childPool);
+ }
+
+ private void accessChildInParent(ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(parentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(parentPool, a2.getClassPool());
+
+ assertSame(a1, a2);
+ }
+
+ public void testChildInParentAndGrandParent() throws Exception
+ {
+ ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInParentAndGrandParent(grandParentPool, parentPool, childPool);
+ accessChildInParentAndGrandParent(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInParentAndGrandParent(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+ assertSame(a1, a2);
+
+ CtClass a3 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+ assertSame(a2, a3);
+ }
+
+ public void testChildInParentAndGrandParentFromTop() throws Exception
+ {
+ ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInParentAndGrandParentFromTop(grandParentPool, parentPool, childPool);
+ accessChildInParentAndGrandParentFromTop(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInParentAndGrandParentFromTop(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+ assertSame(a1, a2);
+
+ CtClass a3 = childPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+ assertSame(a2, a3);
+ }
+
+ public void testChildInGrandParent() throws Exception
+ {
+ ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInGrandParent(grandParentPool, parentPool, childPool);
+ accessChildInGrandParent(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInGrandParent(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+ assertSame(a1, a2);
+
+ CtClass a3 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+ assertSame(a2, a3);
+ }
+
+ public void testGenerateSameNestedClassInChildAndParent() throws Exception
+ {
+ ClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+ CtClass parentA = parentPool.get(CLASS_A);
+ CtClass parentClazz = ClassFactory.createNested(parentA, "Test", true);
+ assertSame(parentPool, parentClazz.getClassPool());
+ Class<?> parentClass = parentClazz.toClass();
+ assertSame(parentPool.getClassLoader(), parentClass.getClassLoader());
+ Class<?> parentAClass = parentA.toClass();
+ assertSame(parentPool.getClassLoader(), parentAClass.getClassLoader());
+
+ CtClass childA = childPool.get(CLASS_A);
+ try
+ {
+ ClassFactory.createNested(childA, "Test", true);
+ }
+ catch(Exception e)
+ {
+
+ }
+ assertSame(parentA, childA);
+ assertSame(parentClazz, childPool.get(CLASS_A + "$Test"));
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentLastDelegatingClassPoolTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentLastDelegatingClassPoolTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ParentLastDelegatingClassPoolTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,266 @@
+package org.jboss.test.classpool.test;
+
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classpool.AbstractClassPoolDomain;
+import org.jboss.test.classpool.common.ClassFactory;
+
+
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.
+*/
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParentLastDelegatingClassPoolTestCase extends ClassPoolTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(ParentLastDelegatingClassPoolTestCase.class);
+ }
+
+ public ParentLastDelegatingClassPoolTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testChildInParent() throws Exception
+ {
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInParent(parentPool, childPool);
+ accessChildInParent(parentPool, childPool);
+ }
+
+ private void accessChildInParent(ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(childPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(parentPool, a2.getClassPool());
+ }
+
+ public void testChildInGrandParent() throws Exception
+ {
+ AbstractClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInGrandParent(grandParentPool, parentPool, childPool);
+ accessChildInGrandParent(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInGrandParent(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(childPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+
+ CtClass a3 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+ }
+
+ public void testChildInGrandParentFromTop() throws Exception
+ {
+ AbstractClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInGrandParentFromTop(grandParentPool, parentPool, childPool);
+ accessChildInGrandParentFromTop(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInGrandParentFromTop(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+
+ CtClass a3 = childPool.get(CLASS_A);
+ assertEquals(childPool, a3.getClassPool());
+ }
+
+ public void testChildInSibling() throws Exception
+ {
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ AbstractClassPoolDomain childA = createClassPoolDomain("CHILDA", parent, false);
+ ClassPool childPoolA = createDelegatingClassPool(childA, JAR_A);
+ AbstractClassPoolDomain childB = createClassPoolDomain("CHILDB", parent, false);
+ ClassPool childPoolB = createDelegatingClassPool(childB, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInSibling(parentPool, childPoolA, childPoolB);
+ accessChildInSibling(parentPool, childPoolA, childPoolB);
+ }
+
+ private void accessChildInSibling(ClassPool parentPool, ClassPool childPoolA, ClassPool childPoolB) throws Exception
+ {
+ CtClass a1 = childPoolA.get(CLASS_A);
+ assertEquals(childPoolA, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(parentPool, a2.getClassPool());
+
+ CtClass a3 = childPoolB.get(CLASS_A);
+ assertEquals(childPoolB, a3.getClassPool());
+ }
+
+ public void testClassInParentOnly() throws Exception
+ {
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessClassInParentOnly(parentPool, childPool);
+ accessClassInParentOnly(parentPool, childPool);
+ }
+
+ private void accessClassInParentOnly(ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(parentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(parentPool, a2.getClassPool());
+ }
+
+ public void testClassInGrandParentOnly() throws Exception
+ {
+ AbstractClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInGrandParentOnly(grandParentPool, parentPool, childPool);
+ accessChildInGrandParentOnly(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInGrandParentOnly(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = childPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+
+ CtClass a3 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+ }
+
+ public void testClassInGrandParentOnlyFromTop() throws Exception
+ {
+ AbstractClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+ ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessChildInGrandParentOnlyFromTop(grandParentPool, parentPool, childPool);
+ accessChildInGrandParentOnlyFromTop(grandParentPool, parentPool, childPool);
+ }
+
+ private void accessChildInGrandParentOnlyFromTop(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+ {
+ CtClass a1 = grandParentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a1.getClassPool());
+
+ CtClass a2 = parentPool.get(CLASS_A);
+ assertEquals(grandParentPool, a2.getClassPool());
+
+ CtClass a3 = childPool.get(CLASS_A);
+ assertEquals(grandParentPool, a3.getClassPool());
+ }
+
+ public void testGenerateSameClassInChildAndParent() throws Exception
+ {
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+ CtClass parentClazz = ClassFactory.create(parentPool, "test.Test");
+ assertSame(parentClazz, parentPool.get("test.Test"));
+ assertSame(parentPool, parentClazz.getClassPool());
+ Class<?> parentClass = parentClazz.toClass();
+ assertSame(parentPool.getClassLoader(), parentClass.getClassLoader());
+
+ CtClass childClazz = ClassFactory.create(childPool, "test.Test");
+ assertSame(childClazz, childPool.get("test.Test"));
+ assertSame(childPool, childClazz.getClassPool());
+ Class<?> childClass = childClazz.toClass();
+ assertSame(childPool.getClassLoader(), childClass.getClassLoader());
+ }
+
+ public void testGenerateSameNestedClassInChildAndParent() throws Exception
+ {
+ AbstractClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+ ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+ AbstractClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+ ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+ CtClass parentA = parentPool.get(CLASS_A);
+ CtClass parentClazz = ClassFactory.createNested(parentA, "Test", true);
+ assertSame(parentPool, parentClazz.getClassPool());
+ Class<?> parentClass = parentClazz.toClass();
+ assertSame(parentPool.getClassLoader(), parentClass.getClassLoader());
+ Class<?> parentAClass = parentA.toClass();
+ assertSame(parentPool.getClassLoader(), parentAClass.getClassLoader());
+
+ CtClass childA = childPool.get(CLASS_A);
+ CtClass childClazz = ClassFactory.createNested(childA, "Test", true);
+ assertSame(childPool, childClazz.getClassPool());
+ Class<?> childClass = childClazz.toClass();
+ assertSame(childPool.getClassLoader(), childClass.getClassLoader());
+ Class<?> childAClass = childA.toClass();
+ assertSame(childPool.getClassLoader(), childAClass.getClassLoader());
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,115 @@
+package org.jboss.test.classpool.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classpool.ClassPoolDomain;
+
+
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.
+*/
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScopedSiblingDelegatingClassPoolTestCase extends ClassPoolTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(ScopedSiblingDelegatingClassPoolTestCase.class);
+ }
+
+ public ScopedSiblingDelegatingClassPoolTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testNoVisibilityBetweenSiblings() throws Exception
+ {
+ ClassPoolDomain root = createClassPoolDomain("ROOT", null, false);
+ ClassPoolDomain domainA = createClassPoolDomain("A", root, false);
+ ClassPool poolA = createDelegatingClassPool(domainA, JAR_A);
+ ClassPoolDomain domainB = createClassPoolDomain("B", root, false);
+ ClassPool poolB = createDelegatingClassPool(domainB, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessNoVisibilityBetweenSiblings(poolA, poolB);
+ accessNoVisibilityBetweenSiblings(poolA, poolB);
+ }
+
+ public void accessNoVisibilityBetweenSiblings(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ CtClass a = poolA.get(CLASS_A);
+ assertEquals(poolA, a.getClassPool());
+ CtClass b = poolB.get(CLASS_B);
+ assertEquals(poolB, b.getClassPool());
+
+ try
+ {
+ poolA.get(CLASS_B);
+ fail("Should not have found B in poolA");
+ }
+ catch (Exception e)
+ {
+ }
+ try
+ {
+ poolB.get(CLASS_A);
+ fail("Should not have found A in poolB");
+ }
+ catch (Exception e)
+ {
+ }
+ }
+
+ public void testUsesOwnCopy() throws Exception
+ {
+ ClassPoolDomain root = createClassPoolDomain("ROOT", null, false);
+ ClassPoolDomain domainA = createClassPoolDomain("A", root, false);
+ ClassPool poolA = createDelegatingClassPool(domainA, JAR_A, JAR_B);
+ ClassPoolDomain domainB = createClassPoolDomain("B", root, false);
+ ClassPool poolB = createDelegatingClassPool(domainB, JAR_B, JAR_A);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessUsesOwnCopy(poolA, poolB);
+ accessUsesOwnCopy(poolA, poolB);
+ }
+
+ public void accessUsesOwnCopy(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ CtClass aa = poolA.get(CLASS_A);
+ assertEquals(poolA, aa.getClassPool());
+ CtClass ab = poolA.get(CLASS_A);
+ assertEquals(poolA, ab.getClassPool());
+
+ CtClass ba = poolB.get(CLASS_A);
+ assertEquals(poolB, ba.getClassPool());
+ CtClass bb = poolB.get(CLASS_B);
+ assertEquals(poolB, bb.getClassPool());
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/SimpleDelegatingClassPoolTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/SimpleDelegatingClassPoolTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/test/SimpleDelegatingClassPoolTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,155 @@
+package org.jboss.test.classpool.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classpool.ClassPoolDomain;
+
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.
+*/
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleDelegatingClassPoolTestCase extends ClassPoolTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(SimpleDelegatingClassPoolTestCase.class);
+ }
+
+ public SimpleDelegatingClassPoolTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testAllClassesOnePool() throws Exception
+ {
+ ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+ ClassPool pool = createDelegatingClassPool(domain, JAR_A, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessAllClassesOnePool(pool);
+ accessAllClassesOnePool(pool);
+ }
+
+ private void accessAllClassesOnePool(ClassPool pool) throws Exception
+ {
+ CtClass a = pool.get(CLASS_A);
+ CtClass b = pool.get(CLASS_B);
+ assertEquals(pool, a.getClassPool());
+ assertEquals(pool, b.getClassPool());
+
+ CtClass string = pool.get(String.class.getName());
+ assertNotSame("java.lang.String should be loaded by the parent pool", pool, string.getClassPool());
+ assertEquals(ClassPool.getDefault(), string.getClassPool());
+ }
+
+ public void testOnePoolPerClassLoadedByA() throws Exception
+ {
+ ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+ ClassPool poolA = createDelegatingClassPool(domain, JAR_A);
+ ClassPool poolB = createDelegatingClassPool(domain, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessOnePoolPerClassLoadedByA(poolA, poolB);
+ accessOnePoolPerClassLoadedByA(poolA, poolB);
+ }
+
+ private void accessOnePoolPerClassLoadedByA(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ CtClass a = poolA.get(CLASS_A);
+ CtClass b = poolA.get(CLASS_B);
+
+ assertNotSame(a.getClassPool(), b.getClassPool());
+ assertEquals(poolA, a.getClassPool());
+ assertEquals(poolB, b.getClassPool());
+ }
+
+ public void testOnePoolPerClassLoadedByB() throws Exception
+ {
+ ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+ ClassPool poolA = createDelegatingClassPool(domain, JAR_A);
+ ClassPool poolB = createDelegatingClassPool(domain, JAR_B);
+
+ //The first time we access the pool it will create the classes, second time will use the cache
+ accessOnePoolPerClassLoadedByB(poolA, poolB);
+ accessOnePoolPerClassLoadedByB(poolA, poolB);
+}
+
+ public void accessOnePoolPerClassLoadedByB(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ CtClass a = poolB.get(CLASS_A);
+ CtClass b = poolB.get(CLASS_B);
+
+ assertNotSame(a.getClassPool(), b.getClassPool());
+ assertEquals(poolA, a.getClassPool());
+ assertEquals(poolB, b.getClassPool());
+ }
+
+ public void testCanLoadArrrayCtClass() throws Exception
+ {
+ ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+ ClassPool poolA = createDelegatingClassPool(domain, JAR_A);
+ ClassPool poolB = createDelegatingClassPool(domain, JAR_B);
+ accessCanLoadCtArray(poolA, poolB);
+ accessCanLoadCtArray(poolA, poolB);
+ }
+
+ private void accessCanLoadCtArray(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ poolA.get(String.class.getName() + "[][]");
+ CtClass a = poolA.get(CLASS_A);
+ CtClass aArray = poolA.get(CLASS_A + "[]");
+ CtClass bArray = poolA.get(CLASS_B + "[][]");
+ CtClass b = poolA.get(CLASS_B);
+
+ CtClass byteClassA = poolA.get("byte");
+ CtClass byteClassB = poolB.get("byte");
+ assertSame(byteClassA, byteClassB);
+ assertNotSame(poolA, byteClassA.getClassPool());
+ assertNotSame(poolB, byteClassA.getClassPool());
+ CtClass intArrayClass = poolA.get("int[]");
+ CtClass intClass = poolB.get("int");
+ assertSame(intClass, intArrayClass.getComponentType());
+ assertSame(byteClassA.getClassPool(), intClass.getClassPool());
+
+
+
+ assertTrue(aArray.isArray());
+ assertSame(a, aArray.getComponentType());
+ assertTrue(bArray.isArray());
+ assertTrue(bArray.getComponentType().isArray());
+ assertSame(b, bArray.getComponentType().getComponentType());
+ assertNotSame(aArray.getClassPool(), bArray.getClassPool());
+ assertSame(poolA, aArray.getClassPool());
+ assertSame(poolB, bArray.getClassPool());
+ assertSame(a.getClassPool(), aArray.getClassPool());
+ assertSame(b.getClassPool(), bArray.getClassPool());
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,82 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl.support;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * An attempt to emulate the web classloader with parent last search order in AS
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParentLastURLClassLoader extends URLClassLoader
+{
+ ClassLoader parent;
+ URLClassLoader delegate;
+
+ public ParentLastURLClassLoader(URL[] urls, ClassLoader parent)
+ {
+ super(urls, parent);
+ delegate = new URLClassLoader(urls);
+ this.parent = parent;
+ }
+
+ @Override
+ public URL findResource(String name)
+ {
+ URL url = delegate.findResource(name);
+ if (url == null && parent instanceof URLClassLoader)
+ {
+ url = ((URLClassLoader)parent).findResource(name);
+ }
+ return url;
+ }
+
+ @Override
+ public URL getResource(String name)
+ {
+ URL url = delegate.getResource(name);
+ if (url == null)
+ {
+ url = parent.getResource(name);
+ }
+ return url;
+ }
+
+ @Override
+ public Class<?> loadClass(String name) throws ClassNotFoundException
+ {
+ try
+ {
+ return delegate.loadClass(name);
+ }
+ catch(ClassNotFoundException e)
+ {
+ }
+ return parent.loadClass(name);
+ }
+
+
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassLoaderSanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassLoaderSanityTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassLoaderSanityTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,357 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * This is here to figure out how the UCLs work, and we will duplicate this
+ * in the classpool test
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UclClassLoaderSanityTestCase extends UclClassPoolTest
+{
+ public UclClassLoaderSanityTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(UclClassLoaderSanityTestCase.class);
+ }
+
+
+ public void testGlobalScope() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ try
+ {
+ clA = createGlobalClassLoader(JAR_A_1);
+ clB = createGlobalClassLoader(JAR_B_1);
+ try
+ {
+ Class<?> aFromA = clA.loadClass(CLASS_A);
+ assertNotNull(aFromA);
+ Class<?> bFromA = clA.loadClass(CLASS_B);
+ assertNotNull(bFromA);
+ Class<?> aFromB = clB.loadClass(CLASS_A);
+ Class<?> bFromB = clB.loadClass(CLASS_B);
+ assertSame(aFromA, aFromB);
+ assertSame(bFromA, bFromB);
+ assertSame(clA, aFromA.getClassLoader());
+ assertSame(clB, bFromB.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clB);
+ }
+ Class<?> aFromA = clA.loadClass(CLASS_A);
+ assertNotNull(aFromA);
+
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clA);
+ }
+ assertCannotLoadClass(getGlobalRepository(), CLASS_A);
+ }
+
+ public void testChildDomain() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ ClassLoader clC = null;
+ try
+ {
+ clA = createGlobalClassLoader(JAR_A_1);
+ clB = createGlobalClassLoader(JAR_B_1);
+ clC = createChildClassLoader(JAR_C_1, false);
+
+ Class<?> aFromA = clA.loadClass(CLASS_A);
+ assertNotNull(aFromA);
+ Class<?> bFromB = clB.loadClass(CLASS_B);
+ assertNotNull(bFromB);
+ Class<?> cFromC = clC.loadClass(CLASS_C);
+ assertNotNull(cFromC);
+ Class<?> aFromC = clC.loadClass(CLASS_A);
+ assertNotNull(aFromC);
+ Class<?> bFromC = clC.loadClass(CLASS_B);
+ assertNotNull(bFromC);
+
+ assertSame(aFromA, aFromC);
+ assertSame(bFromB, bFromC);
+ assertSame(clA, aFromA.getClassLoader());
+ assertSame(clB, bFromB.getClassLoader());
+ assertSame(clC, cFromC.getClassLoader());
+
+ assertCannotLoadClass(clA, CLASS_C);
+ assertCannotLoadClass(clB, CLASS_C);
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clA);
+ removeClassLoaderFromRepository(clB);
+ }
+ }
+
+ public void testSiblingDomains() throws Exception
+ {
+ ClassLoader clA = createChildClassLoader(JAR_A_1, true);
+ ClassLoader clB = createChildClassLoader(JAR_B_1, false);
+
+ Class<?> clazzA = clA.loadClass(CLASS_A);
+ assertSame(clA, clazzA.getClassLoader());
+ Class<?> clazzB = clB.loadClass(CLASS_B);
+ assertSame(clB, clazzB.getClassLoader());
+ assertCannotLoadClass(clA, CLASS_B);
+ assertCannotLoadClass(clB, CLASS_A);
+ }
+
+ public void testChildWithNewClassesInParent() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ ClassLoader clScoped = null;
+ try
+ {
+ clScoped = createChildClassLoader(JAR_B_1, true);
+ assertCannotLoadClass(clScoped, CLASS_A);
+
+ clGlobal = createGlobalClassLoader(JAR_A_1);
+ Class<?> aFromChild = clScoped.loadClass(CLASS_A);
+ assertNotNull(aFromChild);
+ Class<?> aFromParent = clGlobal.loadClass(CLASS_A);
+ assertNotNull(aFromParent);
+ assertSame(aFromChild, aFromParent);
+ assertSame(clGlobal, aFromParent.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clGlobal);
+ }
+ }
+
+ public void testChildOverrideWithParentDelegation() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ try
+ {
+ clGlobal = createGlobalClassLoader(JAR_A_1);
+ ClassLoader clScoped = createChildClassLoader(JAR_A_2, true);
+ Class<?> aFromParent = clGlobal.loadClass(CLASS_A);
+ assertNotNull(aFromParent);
+ Class<?> aFromChild = clScoped.loadClass(CLASS_A);
+ assertNotNull(aFromChild);
+ assertSame(aFromParent, aFromChild);
+ assertSame(clGlobal, aFromParent.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clGlobal);
+ }
+ }
+
+ public void testChildOverrideWithNoParentDelegation() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ try
+ {
+ clGlobal = createGlobalClassLoader(JAR_A_1);
+ ClassLoader clScoped = createChildClassLoader(JAR_A_2, false);
+ Class<?> aFromParent = clGlobal.loadClass(CLASS_A);
+ assertNotNull(aFromParent);
+ Class<?> aFromChild = clScoped.loadClass(CLASS_A);
+ assertNotNull(aFromChild);
+ assertNotSame(aFromParent, aFromChild);
+ assertSame(clGlobal, aFromParent.getClassLoader());
+ assertSame(clScoped, aFromChild.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clGlobal);
+ }
+ }
+
+ public void testURLChildOfGlobalUcl() throws Exception
+ {
+ ClassLoader clGlobal = null;
+ try
+ {
+ clGlobal = createGlobalClassLoader(JAR_A_1);
+ ClassLoader clChildA = createChildURLClassLoader(clGlobal, JAR_B_1);
+
+ Class<?> aFromA = clChildA.loadClass(CLASS_A);
+ assertSame(clGlobal, aFromA.getClassLoader());
+ Class<?> bFromA = clChildA.loadClass(CLASS_B);
+ assertSame(clChildA, bFromA.getClassLoader());
+
+ ClassLoader clChildB = createChildURLClassLoader(clGlobal, JAR_A_2);
+ Class<?> aFromB = clChildB.loadClass(CLASS_A);
+ assertSame(clGlobal, aFromB.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clGlobal);
+ }
+ }
+
+ public void testUndeploySibling() throws Exception
+ {
+ ClassLoader clA = null;
+ ClassLoader clB = null;
+ try
+ {
+ try
+ {
+ clA = createGlobalClassLoader(JAR_A_1);
+ assertCannotLoadClass(clA, CLASS_B);
+
+ clB = createGlobalClassLoader(JAR_B_1);
+ Class<?> bFromA = clA.loadClass(CLASS_B);
+ assertSame(clB, bFromA.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clB);
+ }
+ assertCannotLoadClass(clA, CLASS_B);
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(clA);
+ }
+ }
+
+
+// public void testUndeployParentDomainClassLoader() throws Exception
+// {
+// ClassLoader globalA = null;
+// ClassLoader globalB = null;
+// ClassLoader child = null;
+// try
+// {
+// try
+// {
+// globalA = createGlobalClassLoader(JAR_A_1);
+// assertCannotLoadClass(globalA, CLASS_B);
+//
+// child = createChildClassLoader(JAR_C_1, true);
+// assertCannotLoadClass(child, CLASS_B);
+//
+// globalB = createGlobalClassLoader(JAR_B_1);
+// Class<?> bFromChild = child.loadClass(CLASS_B);
+// Class<?> bFromA = globalA.loadClass(CLASS_B);
+// assertSame(globalB, bFromA.getClassLoader());
+// assertSame(bFromA, bFromChild);
+// }
+// finally
+// {
+// removeClassLoaderFromRepository(globalB);
+// }
+// assertCannotLoadClass(child, CLASS_B);
+// }
+// finally
+// {
+// removeClassLoaderFromRepository(globalA);
+// }
+// }
+
+ public void testUclWithParentClassLoader() throws Exception
+ {
+ ClassLoader parent = createChildURLClassLoader(null, JAR_B_1);
+ ClassLoader global = null;
+ try
+ {
+ global = createGlobalClassLoaderWithParent(JAR_A_1, parent);
+ Class<?> aFromGlobal = global.loadClass(CLASS_A);
+ assertSame(global, aFromGlobal.getClassLoader());
+ Class<?> bFromGlobal = global.loadClass(CLASS_B);
+ assertSame(parent, bFromGlobal.getClassLoader());
+ Class<?> bFromParent = parent.loadClass(CLASS_B);
+ assertSame(bFromGlobal, bFromParent);
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(global);
+ }
+ }
+
+
+ public void testUclWithParentClassLoaderAndSameClassInDomain() throws Exception
+ {
+ ClassLoader parent = createChildURLClassLoader(null, JAR_B_1);
+ ClassLoader globalA = null;
+ ClassLoader globalB = null;
+ try
+ {
+ globalA = createGlobalClassLoaderWithParent(JAR_A_1, parent);
+ Class<?> aFromGlobal = globalA.loadClass(CLASS_A);
+ assertSame(globalA, aFromGlobal.getClassLoader());
+
+ globalB = createGlobalClassLoader(JAR_B_2);
+ Class<?> bFromGlobalA = globalA.loadClass(CLASS_B);
+ assertSame(globalB, bFromGlobalA.getClassLoader());
+ Class<?> bFromParent = parent.loadClass(CLASS_B);
+ assertSame(parent, bFromParent.getClassLoader());
+ assertNotSame(bFromGlobalA, bFromParent);
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(globalA);
+ removeClassLoaderFromRepository(globalB);
+ }
+ }
+
+ public void testUclLoaderOrdering() throws Exception
+ {
+ ClassLoader globalA = null;
+ ClassLoader globalB = null;
+ ClassLoader globalC = null;
+ try
+ {
+ globalA = createGlobalClassLoader(JAR_A_1);
+ globalB = createGlobalClassLoader(JAR_A_1);
+ globalC = createGlobalClassLoader(JAR_A_1);
+
+ Class<?> aFromA = globalA.loadClass(CLASS_A);
+ Class<?> aFromB = globalB.loadClass(CLASS_A);
+ Class<?> aFromC = globalC.loadClass(CLASS_A);
+ assertSame(aFromA, aFromB);
+ assertSame(aFromA, aFromC);
+ assertSame(globalA, aFromA.getClassLoader());
+ }
+ finally
+ {
+ removeClassLoaderFromRepository(globalA);
+ removeClassLoaderFromRepository(globalB);
+ removeClassLoaderFromRepository(globalC);
+ }
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,327 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl.test;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Set;
+
+import javassist.ClassPool;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+
+import org.jboss.classpool.ClassPoolRepository;
+import org.jboss.classpool.ucl.JBossUclDelegatingClassPoolFactory;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.mx.loading.UnifiedClassLoader3;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.classpool.support.SupportClasses;
+import org.jboss.test.classpool.ucl.support.ParentLastURLClassLoader;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UclClassPoolTest extends AbstractTestCaseWithSetup
+{
+ public final static URL JAR_A_1 = getURLRelativeToProjectRoot(SupportClasses.JAR_A_1);
+ public final static URL JAR_A_2 = getURLRelativeToProjectRoot(SupportClasses.JAR_A_2);
+ public final static URL JAR_B_1 = getURLRelativeToProjectRoot(SupportClasses.JAR_B_1);
+ public final static URL JAR_B_2 = getURLRelativeToProjectRoot(SupportClasses.JAR_B_2);
+ public final static URL JAR_C_1 = getURLRelativeToProjectRoot(SupportClasses.JAR_C_1);
+ public final static URL JAR_C_2 = getURLRelativeToProjectRoot(SupportClasses.JAR_C_2);
+
+ private MBeanServer server;
+ private LoaderRepository globalRepository;
+
+ //Keep a strong reference to the classloaders so that they are not garbage collected
+ final static Set<ClassLoader> registeredClassLoaders = new HashSet<ClassLoader>();
+
+ final static ObjectName MAIN_LOADER_REPOSITORY_OBJECT_NAME;
+ static
+ {
+ try
+ {
+ MAIN_LOADER_REPOSITORY_OBJECT_NAME = new ObjectName("JMImplementation:name=Default,service=LoaderRepository");
+ ClassPoolRepository.getInstance().setClassPoolFactory(new JBossUclDelegatingClassPoolFactory(new File(".")));
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ public UclClassPoolTest(String name)
+ {
+ super(name);
+ System.setProperty("javax.management.builder.initial", "org.jboss.mx.server.MBeanServerBuilderImpl");
+ server = MBeanServerFactory.createMBeanServer();
+ MBeanServerLocator.setJBoss(server);
+ try
+ {
+ globalRepository = (LoaderRepository)server.invoke(MAIN_LOADER_REPOSITORY_OBJECT_NAME, "getInstance", new Object[0], new String[0]);
+ }
+ catch(Exception e)
+ {
+
+ }
+ }
+
+ public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ AbstractTestDelegate delegate = new UclClassPoolTestDelegate(clazz);
+ String property = "false"; //System.getProperty("jboss.aop.secure", "false"); // TODO this value was true
+ boolean enableSecurity = Boolean.valueOf(property).booleanValue();
+ delegate.enableSecurity = enableSecurity;
+ return delegate;
+ }
+
+ protected static URL getURLRelativeToProjectRoot(String relativePath)
+ {
+ try
+ {
+ URL url = UclClassPoolTest.class.getProtectionDomain().getCodeSource().getLocation();
+ String location = url.toString();
+ int index = location.lastIndexOf("/target/") + "/target/".length();
+ location = location.substring(0, index);
+
+ location = location + relativePath;
+ return new URL(location);
+ }
+ catch (MalformedURLException e)
+ {
+ // AutoGenerated
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ //enableTrace("org.jboss.aop.classpool");
+ //enableTrace("org.jboss.classpool.ucl");
+ }
+
+ public MBeanServer getServer()
+ {
+ return server;
+ }
+
+
+ public LoaderRepository getGlobalRepository()
+ {
+ return globalRepository;
+ }
+
+ protected ClassLoader createGlobalClassLoader(URL url) throws Exception
+ {
+ ClassLoader cl = globalRepository.newClassLoader(url, true);
+ registeredClassLoaders.add(cl);
+ return cl;
+ }
+
+ protected ClassPool createGlobalClassPool(URL url) throws Exception
+ {
+ ClassLoader loader = createGlobalClassLoader(url);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassLoader createGlobalClassLoaderWithParent(URL url, ClassLoader parent) throws Exception
+ {
+ ClassLoader cl = new UnifiedClassLoader3(url, null, parent, globalRepository);
+ globalRepository.addClassLoader(cl);
+ registeredClassLoaders.add(cl);
+ return cl;
+ }
+
+ protected ClassPool createGlobalClassPoolWithParent(URL url, ClassPool parent) throws Exception
+ {
+ ClassLoader parentLoader = parent != null ? parent.getClassLoader() : null;
+ ClassLoader loader = createGlobalClassLoaderWithParent(url, parentLoader);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected void removeClassLoaderFromRepository(ClassLoader cl)
+ {
+ if (cl != null)
+ {
+ if (cl instanceof RepositoryClassLoader)
+ {
+ LoaderRepository repository = ((RepositoryClassLoader)cl).getLoaderRepository();
+ repository.removeClassLoader(cl);
+ }
+ }
+ }
+
+ protected void removeClassPool(ClassPool pool)
+ {
+ if (pool != null)
+ {
+ ClassLoader cl = pool.getClassLoader();
+ if (cl != null)
+ {
+ removeClassLoaderFromRepository(cl);
+ ClassPoolRepository.getInstance().unregisterClassLoader(cl);
+ registeredClassLoaders.remove(cl);
+ //Delete the temporary directory since running in Eclipse does not do this automatically
+ deleteTempDir();
+ }
+ }
+ }
+
+ private void deleteTempDir()
+ {
+ File dir = new File(".");
+ String[] uclFiles = dir.list(
+ new FilenameFilter()
+ {
+ public boolean accept(File dir, String name)
+ {
+ return name.startsWith("ucl");
+
+ }
+ });
+ for (String uclFile : uclFiles)
+ {
+ deleteRecursively(dir, uclFile);
+ }
+ }
+
+ private void deleteRecursively(File dir, String name)
+ {
+ File file = new File(dir, name);
+ if (file.isDirectory())
+ {
+ String[] fileNames = file.list();
+ for (String fileName : fileNames)
+ {
+ deleteRecursively(file, fileName);
+ }
+ }
+ file.delete();
+ }
+
+ protected void assertCannotLoadClass(ClassLoader cl, String className)
+ {
+ try
+ {
+ cl.loadClass(className);
+ fail("Should not have been able to load " + className);
+ }
+ catch(Exception expected)
+ {
+ }
+ }
+
+ protected void assertCannotLoadCtClass(ClassPool pool, String className)
+ {
+ try
+ {
+ pool.get(className);
+ }
+ catch(Exception e)
+ {
+ }
+ }
+
+ protected void assertCannotLoadClass(LoaderRepository repository, String className)
+ {
+ try
+ {
+ repository.loadClass(className);
+ fail("Should not have been able to load " + className);
+ }
+ catch(Exception expected)
+ {
+ }
+ }
+
+ protected ClassLoader createChildClassLoader(URL url, boolean parentFirst) throws Exception
+ {
+ HeirarchicalLoaderRepository3 repository = new HeirarchicalLoaderRepository3(getServer(), MAIN_LOADER_REPOSITORY_OBJECT_NAME);
+ repository.setUseParentFirst(parentFirst);
+ ClassLoader cl = repository.newClassLoader(url, true);
+ registeredClassLoaders.add(cl);
+ return cl;
+ }
+
+ protected ClassPool createChildClassPool(URL url, boolean parentFirst) throws Exception
+ {
+ ClassLoader loader = createChildClassLoader(url, parentFirst);
+ return ClassPoolRepository.getInstance().registerClassLoader(loader);
+ }
+
+ protected ClassLoader createChildURLClassLoader(ClassLoader parent, URL url)
+ {
+ ClassLoader cl = new URLClassLoader(new URL[] {url}, parent);
+ registeredClassLoaders.add(cl);
+ return cl;
+ }
+
+ protected ClassLoader createChildURLClassLoaderParentLast(ClassLoader parent, URL url)
+ {
+ ClassLoader cl = new ParentLastURLClassLoader(new URL[] {url}, parent);
+ registeredClassLoaders.add(cl);
+ return cl;
+ }
+
+ protected ClassPool createChildURLClassPool(ClassPool parent, URL url)
+ {
+ ClassLoader parentLoader = parent != null ? parent.getClassLoader() : null;
+ ClassLoader cl = createChildURLClassLoader(parentLoader, url);
+ registeredClassLoaders.add(cl);
+ return ClassPoolRepository.getInstance().registerClassLoader(cl);
+ }
+
+ protected ClassPool createChildURLClassPoolParentLast(ClassPool parent, URL url)
+ {
+ ClassLoader parentLoader = parent != null ? parent.getClassLoader() : null;
+ ClassLoader cl = createChildURLClassLoaderParentLast(parentLoader, url);
+ registeredClassLoaders.add(cl);
+ ClassPool pool = ClassPoolRepository.getInstance().registerClassLoader(cl);
+ pool.childFirstLookup = true;
+ return pool;
+ }
+
+ /**
+ * The test classes should not be on the launcher classpath
+ */
+ public void testClassesNotOnClasspath()
+ {
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_A);
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_B);
+ assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_C);
+ }
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl.test;
+
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UclClassPoolTestDelegate extends AbstractTestDelegate
+{
+
+ public UclClassPoolTestDelegate(Class<?> clazz)
+ {
+ super(clazz);
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestSuite.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestSuite.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestSuite.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UclClassPoolTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("UclClassPool All Tests");
+
+ suite.addTest(UclClassLoaderSanityTestCase.suite());
+ suite.addTest(UclDelegatingClassPoolTestCase.suite());
+
+
+ return suite;
+ }
+
+}
Added: projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclDelegatingClassPoolTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclDelegatingClassPoolTestCase.java (rev 0)
+++ projects/jboss-classpool/trunk/src/test/java/org/jboss/test/classpool/ucl/test/UclDelegatingClassPoolTestCase.java 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,801 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.classpool.ucl.test;
+
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.support.SupportClasses.CLASS_C;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.support.SupportClasses.PACKAGE_B;
+
+import java.util.ArrayList;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.test.classpool.common.ClassFactory;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UclDelegatingClassPoolTestCase extends UclClassPoolTest
+{
+
+ public UclDelegatingClassPoolTestCase(String name)
+ {
+ // FIXME SimpleUclDelegatingClassPoolTestCase constructor
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(UclDelegatingClassPoolTestCase.class);
+ }
+
+
+ public void testGlobalScope() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ try
+ {
+ try
+ {
+ globalA = createGlobalClassPool(JAR_A_1);
+ globalB = createGlobalClassPool(JAR_B_1);
+
+ //Call twice to ensure that we hit the cache as well as creating the CtClases
+ accessGlobalScope(globalA, globalB);
+ accessGlobalScope(globalA, globalB);
+ }
+ finally
+ {
+ removeClassPool(globalA);
+ }
+ assertCannotLoadCtClass(globalB, CLASS_A);
+ }
+ finally
+ {
+ removeClassPool(globalB);
+ }
+ }
+
+ private void accessGlobalScope(ClassPool globalA, ClassPool globalB) throws Exception
+ {
+ CtClass aFromA = globalA.get(CLASS_A);
+ assertNotNull(aFromA);
+ assertEquals(CLASS_A, aFromA.getName());
+ CtClass bFromA = globalA.get(CLASS_B);
+ assertNotNull(bFromA);
+ assertEquals(CLASS_B, bFromA.getName());
+ CtClass aFromB = globalB.get(CLASS_A);
+ assertNotNull(aFromB);
+ assertSame(aFromA, aFromB);
+ CtClass bFromB = globalB.get(CLASS_B);
+ assertNotNull(bFromB);
+ assertSame(bFromA, bFromB);
+ }
+
+ public void testChildDomain() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ ClassPool poolC = null;
+ try
+ {
+ poolA = createGlobalClassPool(JAR_A_1);
+ poolB = createGlobalClassPool(JAR_B_1);
+ poolC = createChildClassPool(JAR_C_1, false);
+
+ //Call twice to ensure that we hit the cache as well as creating the CtClases
+ accessChildDomain(poolA, poolB, poolC);
+ accessChildDomain(poolA, poolB, poolC);
+ }
+ finally
+ {
+ removeClassPool(poolA);
+ removeClassPool(poolB);
+ removeClassPool(poolC);
+ }
+ }
+
+ private void accessChildDomain(ClassPool poolA, ClassPool poolB, ClassPool poolC) throws Exception
+ {
+ CtClass aFromA = poolA.get(CLASS_A);
+ assertNotNull(aFromA);
+ CtClass bFromB = poolB.get(CLASS_B);
+ assertNotNull(bFromB);
+ CtClass cFromC = poolC.get(CLASS_C);
+ assertNotNull(cFromC);
+ CtClass aFromC = poolC.get(CLASS_A);
+ assertNotNull(aFromC);
+ CtClass bFromC = poolC.get(CLASS_B);
+ assertNotNull(bFromC);
+
+ assertSame(aFromA, aFromC);
+ assertSame(bFromB, bFromC);
+ assertSame(poolA, aFromA.getClassPool());
+ assertSame(poolB, bFromB.getClassPool());
+ assertSame(poolC, cFromC.getClassPool());
+
+ assertCannotLoadCtClass(poolA, CLASS_C);
+ assertCannotLoadCtClass(poolB, CLASS_C);
+ }
+
+ public void testSiblingDomains() throws Exception
+ {
+ ClassPool poolA = createChildClassPool(JAR_A_1, true);
+ ClassPool poolB = createChildClassPool(JAR_B_1, false);
+
+ try
+ {
+ accessSiblingDomains(poolA, poolB);
+ }
+ finally
+ {
+ removeClassPool(poolA);
+ removeClassPool(poolB);
+ }
+ }
+
+ private void accessSiblingDomains(ClassPool poolA, ClassPool poolB) throws Exception
+ {
+ CtClass clazzA = poolA.get(CLASS_A);
+ assertSame(poolA, clazzA.getClassPool());
+ CtClass clazzB = poolB.get(CLASS_B);
+ assertSame(poolB, clazzB.getClassPool());
+ assertCannotLoadCtClass(poolA, CLASS_B);
+ assertCannotLoadCtClass(poolB, CLASS_A);
+ }
+
+ public void testChildWithNewClassesInParent() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ scopedPool = createChildClassPool(JAR_B_1, true);
+ assertCannotLoadCtClass(scopedPool, CLASS_A);
+
+ globalPool = createGlobalClassPool(JAR_A_1);
+ CtClass aFromChild = scopedPool.get(CLASS_A);
+ assertNotNull(aFromChild);
+ CtClass aFromParent = globalPool.get(CLASS_A);
+ assertNotNull(aFromParent);
+ assertSame(aFromChild, aFromParent);
+ assertSame(globalPool, aFromParent.getClassPool());
+
+ CtClass aFromChild2 = scopedPool.get(CLASS_A);
+ assertSame(aFromChild, aFromChild2);
+ }
+ finally
+ {
+ removeClassPool(globalPool);
+ removeClassPool(scopedPool);
+ }
+ }
+
+ public void testChildOverrideWithParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ globalPool = createGlobalClassPool(JAR_A_1);
+ scopedPool = createChildClassPool(JAR_A_2, true);
+ CtClass aFromParent = globalPool.get(CLASS_A);
+ assertNotNull(aFromParent);
+ CtClass aFromChild = scopedPool.get(CLASS_A);
+ assertNotNull(aFromChild);
+ assertSame(aFromParent, aFromChild);
+ assertSame(globalPool, aFromParent.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(globalPool);
+ removeClassPool(scopedPool);
+ }
+ }
+
+ public void testChildOverrideWithNoParentDelegation() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool scopedPool = null;
+ try
+ {
+ globalPool = createGlobalClassPool(JAR_A_1);
+ scopedPool = createChildClassPool(JAR_A_2, false);
+ CtClass aFromParent = globalPool.get(CLASS_A);
+ assertNotNull(aFromParent);
+ CtClass aFromChild = scopedPool.get(CLASS_A);
+ assertNotNull(aFromChild);
+ assertNotSame(aFromParent, aFromChild);
+ assertSame(globalPool, aFromParent.getClassPool());
+ assertSame(scopedPool, aFromChild.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(globalPool);
+ removeClassPool(scopedPool);
+ }
+ }
+
+ public void testURLChildOfGlobalUclParentFirst() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool childA = null;
+ ClassPool childB = null;
+ try
+ {
+ globalPool = createGlobalClassPool(JAR_A_1);
+ childA = createChildURLClassPool(globalPool, JAR_B_1);
+
+ //Try loading A from child first
+ CtClass aFromA = childA.get(CLASS_A);
+ assertSame(globalPool, aFromA.getClassPool());
+
+ //Try loading A from global
+ CtClass aFromGlobal = globalPool.get(CLASS_A);
+ assertSame(aFromA, aFromGlobal);
+
+ //Try loading B from A
+ CtClass bFromA = childA.get(CLASS_B);
+ assertSame(childA, bFromA.getClassPool());
+
+ //Should get the cached copy from the parent
+ childB = createChildURLClassPool(globalPool, JAR_A_2);
+ CtClass aFromB = childB.get(CLASS_A);
+ assertSame(globalPool, aFromB.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(globalPool);
+ removeClassPool(childA);
+ removeClassPool(childB);
+ }
+ }
+
+
+ public void testURLChildOfGlobalUcParentLast() throws Exception
+ {
+ ClassPool globalPool = null;
+ ClassPool childA = null;
+ ClassPool childB = null;
+ try
+ {
+ globalPool = createGlobalClassPool(JAR_A_1);
+ childA = createChildURLClassPoolParentLast(globalPool, JAR_B_1);
+
+ //Try loading A from child first
+ CtClass aFromA = childA.get(CLASS_A);
+ assertSame(globalPool, aFromA.getClassPool());
+
+ //Try loading A from global
+ CtClass aFromGlobal = globalPool.get(CLASS_A);
+ assertSame(aFromA, aFromGlobal);
+
+ //Try loading B from A
+ CtClass bFromA = childA.get(CLASS_B);
+ assertSame(childA, bFromA.getClassPool());
+
+ //Should get the child copy
+ childB = createChildURLClassPoolParentLast(globalPool, JAR_A_2);
+ CtClass aFromB = childB.get(CLASS_A);
+ assertSame(childB, aFromB.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(globalPool);
+ removeClassPool(childA);
+ removeClassPool(childB);
+ }
+ }
+
+ public void testURLChildOfGlobalUclParentFirstWithClassInGlobalSibling() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ ClassPool childC = null;
+ ClassPool childB = null;
+ try
+ {
+ globalPoolA = createGlobalClassPool(JAR_A_1);
+ globalPoolB = createGlobalClassPool(JAR_B_1);
+ childC = createChildURLClassPool(globalPoolA, JAR_C_1);
+
+ //Try loading A from child first
+ CtClass bFromC = childC.get(CLASS_B);
+ assertSame(globalPoolB, bFromC.getClassPool());
+
+ //Try loading A from global
+ CtClass bFromGlobalA = globalPoolA.get(CLASS_B);
+ assertSame(bFromC, bFromGlobalA);
+
+ //Try loading B from A
+ CtClass cFromC = childC.get(CLASS_C);
+ assertSame(childC, cFromC.getClassPool());
+
+ //Should get the cached copy from the parent
+ childB = createChildURLClassPool(globalPoolA, JAR_B_2);
+ CtClass bFromB = childB.get(CLASS_B);
+ assertSame(globalPoolB, bFromB.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(globalPoolA);
+ removeClassPool(globalPoolB);
+ removeClassPool(childC);
+ removeClassPool(childB);
+ }
+ }
+
+ public void testUndeploySibling() throws Exception
+ {
+ ClassPool poolA = null;
+ ClassPool poolB = null;
+ try
+ {
+ try
+ {
+ poolA = createGlobalClassPool(JAR_A_1);
+ assertCannotLoadCtClass(poolA, CLASS_B);
+
+ poolB = createGlobalClassPool(JAR_B_1);
+ CtClass bFromA = poolA.get(CLASS_B);
+ assertSame(poolB, bFromA.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(poolB);
+ }
+ assertCannotLoadCtClass(poolA, CLASS_B);
+ }
+ finally
+ {
+ removeClassPool(poolA);
+ removeClassPool(poolB);
+ }
+ }
+
+
+// public void testUndeployParentDomainClassLoader() throws Exception
+// {
+// ClassLoader globalA = null;
+// ClassLoader globalB = null;
+// ClassLoader child = null;
+// try
+// {
+// try
+// {
+// globalA = createGlobalClassLoader(JAR_A_1);
+// assertCannotLoadClass(globalA, CLASS_B);
+//
+// child = createChildClassLoader(JAR_C_1, true);
+// assertCannotLoadClass(child, CLASS_B);
+//
+// globalB = createGlobalClassLoader(JAR_B_1);
+// Class<?> bFromChild = child.loadClass(CLASS_B);
+// Class<?> bFromA = globalA.loadClass(CLASS_B);
+// assertSame(globalB, bFromA.getClassLoader());
+// assertSame(bFromA, bFromChild);
+// }
+// finally
+// {
+// removeClassLoaderFromRepository(globalB);
+// }
+// assertCannotLoadClass(child, CLASS_B);
+// }
+// finally
+// {
+// removeClassLoaderFromRepository(globalA);
+// }
+// }
+
+ public void testUclWithParentClassLoader() throws Exception
+ {
+ ClassPool parent = null;
+ ClassPool global = null;
+ try
+ {
+ parent = createChildURLClassPool(null, JAR_B_1);
+ global = createGlobalClassPoolWithParent(JAR_A_1, parent);
+
+ CtClass aFromGlobal = global.get(CLASS_A);
+ assertSame(global, aFromGlobal.getClassPool());
+ CtClass aFromGlobal2 = global.get(CLASS_A);
+ assertSame(aFromGlobal, aFromGlobal2);
+
+ CtClass bFromGlobal = global.get(CLASS_B);
+ assertSame(parent, bFromGlobal.getClassPool());
+ CtClass bFromGlobal2 = global.get(CLASS_B);
+ assertSame(bFromGlobal, bFromGlobal2);
+
+ CtClass bFromParent = parent.get(CLASS_B);
+ assertSame(parent, bFromParent.getClassPool());
+ assertSame(bFromGlobal, bFromParent);
+ CtClass bFromParent2 = parent.get(CLASS_B);
+ assertSame(bFromParent, bFromParent2);
+ }
+ finally
+ {
+ removeClassPool(global);
+ removeClassPool(parent);
+ }
+ }
+
+ public void testUclWithParentClassLoaderAndSameClassInDomain() throws Exception
+ {
+ ClassPool parent = null;
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ try
+ {
+ parent = createChildURLClassPool(null, JAR_B_1);
+ globalA = createGlobalClassPoolWithParent(JAR_A_1, parent);
+
+ CtClass aFromGlobal = globalA.get(CLASS_A);
+ assertSame(globalA, aFromGlobal.getClassPool());
+ CtClass aFromGlobal2 = globalA.get(CLASS_A);
+ assertSame(aFromGlobal, aFromGlobal2);
+
+ globalB = createGlobalClassPool(JAR_B_2);
+ CtClass bFromGlobalA = globalA.get(CLASS_B);
+ assertSame(globalB, bFromGlobalA.getClassPool());
+ CtClass bFromGlobalA2 = globalA.get(CLASS_B);
+ assertSame(bFromGlobalA, bFromGlobalA2);
+
+
+ CtClass bFromParent = parent.get(CLASS_B);
+ assertSame(parent, bFromParent.getClassPool());
+ assertNotSame(bFromGlobalA, bFromParent);
+ CtClass bFromParent2 = parent.get(CLASS_B);
+ assertSame(bFromParent, bFromParent2);
+ }
+ finally
+ {
+ removeClassPool(globalA);
+ removeClassPool(globalB);
+ removeClassPool(parent);
+ }
+ }
+
+ public void testGeneratingClassInNonDelegatingPool() throws Exception
+ {
+ ClassPool parent = null;
+ ClassPool global = null;
+ ClassPool child = null;
+ try
+ {
+ final String PARENT = "parent.Parent";
+ final String CHILD = "child.Child";
+ parent = createChildURLClassPool(null, JAR_B_1);
+ global = createGlobalClassPoolWithParent(JAR_A_1, parent);
+ child = createChildURLClassPool(global, JAR_C_1);
+
+ assertCannotLoadCtClass(parent, PARENT);
+ assertCannotLoadCtClass(global, PARENT);
+ assertCannotLoadCtClass(child, PARENT);
+ assertCannotLoadCtClass(child, CHILD);
+
+ CtClass parentClass = parent.makeClass(PARENT);
+
+ CtClass childClass = child.makeClass(CHILD);
+ childClass.setSuperclass(parentClass);
+
+ CtClass parentFromParent = parent.get(PARENT);
+ assertSame(parent, parentFromParent.getClassPool());
+ assertSame(parentClass, parentFromParent);
+
+ CtClass childFromChild = child.get(CHILD);
+ assertSame(child, childFromChild.getClassPool());
+ assertSame(childClass, childFromChild);
+
+ assertCannotLoadCtClass(global, CHILD);
+
+ CtClass parentFromChildA = childClass.getSuperclass();
+ assertSame(parentClass, parentFromChildA);
+
+ CtClass parentFromChildB = child.get(PARENT);
+ assertSame(parentClass, parentFromChildB);
+
+ Class<?> parentClazz = parentClass.toClass();
+ assertSame(parent.getClassLoader(), parentClazz.getClassLoader());
+
+ Class<?> childClazz = childClass.toClass();
+ assertSame(child.getClassLoader(), childClazz.getClassLoader());
+
+ Class<?> parentClazzFromParent = parent.getClassLoader().loadClass(PARENT);
+ assertSame(parentClazz, parentClazzFromParent);
+
+ Class<?> parentClazzFromChild = parent.getClassLoader().loadClass(PARENT);
+ assertSame(parentClazz, parentClazzFromChild);
+
+ Class<?> childClazzFromChild = child.getClassLoader().loadClass(CHILD);
+ assertSame(childClazz, childClazzFromChild);
+
+
+ child.getClassLoader().loadClass(CLASS_A);
+ }
+ finally
+ {
+ removeClassPool(parent);
+ removeClassPool(global);
+ removeClassPool(child);
+ }
+ }
+
+ public void testGeneratingClassInDelegatingPool() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool child = null;
+ try
+ {
+ globalA = createGlobalClassPool(JAR_A_1);
+ globalB = createGlobalClassPool(JAR_B_1);
+ child = createChildURLClassPool(globalA, JAR_C_1);
+
+ final String A_CLASS = "a.Clazz";
+ final String B_CLASS = "b.Clazz";
+
+ assertCannotLoadCtClass(globalA, A_CLASS);
+ assertCannotLoadCtClass(globalB, A_CLASS);
+ assertCannotLoadCtClass(child, A_CLASS);
+ assertCannotLoadCtClass(globalA, B_CLASS);
+ assertCannotLoadCtClass(globalB, B_CLASS);
+ assertCannotLoadCtClass(child, B_CLASS);
+
+ CtClass a = globalA.makeClass(A_CLASS);
+ CtClass b = globalB.makeClass(B_CLASS);
+
+ CtClass aFromA = globalA.get(A_CLASS);
+ assertSame(a, aFromA);
+ assertSame(globalA, aFromA.getClassPool());
+ CtClass aFromB = globalB.get(A_CLASS);
+ assertSame(a, aFromB);
+ CtClass bFromA = globalA.get(B_CLASS);
+ assertSame(b, bFromA);
+ assertSame(globalB, bFromA.getClassPool());
+ CtClass bFromB = globalB.get(B_CLASS);
+ assertSame(b, bFromB);
+ CtClass aFromChild = child.get(A_CLASS);
+ assertSame(a, aFromChild);
+ CtClass bFromChild = child.get(B_CLASS);
+ assertSame(b, bFromChild);
+
+ Class<?> clazzA = a.toClass();
+ assertSame(globalA.getClassLoader(), clazzA.getClassLoader());
+
+ Class<?> clazzB = b.toClass();
+ assertSame(globalB.getClassLoader(), clazzB.getClassLoader());
+
+ Class<?> clazzAFromA = globalA.getClassLoader().loadClass(A_CLASS);
+ assertSame(clazzA, clazzAFromA);
+ Class<?> clazzAFromB = globalB.getClassLoader().loadClass(A_CLASS);
+ assertSame(clazzA, clazzAFromB);
+ Class<?> clazzAFromChild = child.getClassLoader().loadClass(A_CLASS);
+ assertSame(clazzA, clazzAFromChild);
+
+ Class<?> clazzBFromA = globalA.getClassLoader().loadClass(B_CLASS);
+ assertSame(clazzB, clazzBFromA);
+ Class<?> clazzBFromB = globalB.getClassLoader().loadClass(B_CLASS);
+ assertSame(clazzB, clazzBFromB);
+ Class<?> clazzBFromChild = child.getClassLoader().loadClass(B_CLASS);
+ assertSame(clazzB, clazzBFromChild);
+ }
+ finally
+ {
+ removeClassPool(globalA);
+ removeClassPool(globalB);
+ removeClassPool(child);
+ }
+ }
+
+ public void testUclLoaderOrdering() throws Exception
+ {
+ ClassPool globalA = null;
+ ClassPool globalB = null;
+ ClassPool globalC = null;
+ try
+ {
+ globalA = createGlobalClassPool(JAR_A_1);
+ globalB = createGlobalClassPool(JAR_A_1);
+ globalC = createGlobalClassPool(JAR_A_1);
+
+ CtClass aFromA = globalA.get(CLASS_A);
+ CtClass aFromB = globalB.get(CLASS_A);
+ CtClass aFromC = globalC.get(CLASS_A);
+ assertSame(aFromA, aFromB);
+ assertSame(aFromA, aFromC);
+ assertSame(globalA, aFromA.getClassPool());
+ }
+ finally
+ {
+ removeClassPool(globalA);
+ removeClassPool(globalB);
+ removeClassPool(globalC);
+ }
+ }
+
+ public void testCreateClassInSamePackage() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ globalPoolA = createGlobalClassPool(JAR_A_1);
+ globalPoolB = createGlobalClassPool(JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ Class<?> classA = loaderA.loadClass(CLASS_A);
+ Class<?> classB = loaderB.loadClass(CLASS_B);
+
+ Object createdA = ClassFactory.create(classA, loaderA);
+ Object createdB = ClassFactory.create(classB, loaderB);
+
+ Class<?> createdClassA = createdA.getClass();
+ Class<?> createdClassB = createdB.getClass();
+
+ assertTrue(classA.isAssignableFrom(createdClassA));
+ assertTrue(classB.isAssignableFrom(createdClassB));
+ assertTrue(createdClassA.getName().startsWith(PACKAGE_A));
+ assertTrue(createdClassB.getName().startsWith(PACKAGE_B));
+
+ assertSame(createdClassA, loaderA.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderA.loadClass(createdClassB.getName()));
+ assertSame(createdClassA, loaderB.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderB.loadClass(createdClassB.getName()));
+ }
+ finally
+ {
+ removeClassPool(globalPoolA);
+ removeClassPool(globalPoolB);
+ }
+ }
+
+ /*public void testMakeContainerProxyInSamePackage() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ globalPoolA = createGlobalClassPool(JAR_A_1);
+ globalPoolB = createGlobalClassPool(JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ Object proxyA = assertMakeContainerProxy(loaderA.loadClass(CLASS_A), loaderA);
+ Object proxyB = assertMakeContainerProxy(loaderB.loadClass(CLASS_B), loaderB);
+
+ Class<?> clazzA = proxyA.getClass();
+ Class<?> clazzB = proxyB.getClass();
+
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzA));
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzB));
+ assertTrue(clazzA.getName().startsWith(PACKAGE_A));
+ assertTrue(clazzB.getName().startsWith(PACKAGE_B));
+
+ assertSame(clazzA, loaderA.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderA.loadClass(clazzB.getName()));
+ assertSame(clazzA, loaderB.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderB.loadClass(clazzB.getName()));
+ }
+ finally
+ {
+ removeClassPool(globalPoolA);
+ removeClassPool(globalPoolB);
+ }
+ }*/
+
+ public void testCreatedClassForSystemClass() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ globalPoolA = createGlobalClassPool(JAR_A_1);
+ globalPoolB = createGlobalClassPool(JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ Object createdA = ClassFactory.create(ArrayList.class, loaderA);
+ Object createdB = ClassFactory.create(ArrayList.class, loaderB);
+
+ Class<?> createdClassA = createdA.getClass();
+ Class<?> createdClassB = createdB.getClass();
+
+ assertTrue(ArrayList.class.isAssignableFrom(createdClassA));
+ assertTrue(ArrayList.class.isAssignableFrom(createdClassB));
+ assertTrue(createdClassA.getName().startsWith(ClassFactory.PACKAGE));
+ assertTrue(createdClassB.getName().startsWith(ClassFactory.PACKAGE));
+
+ assertSame(createdClassA, loaderA.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderA.loadClass(createdClassB.getName()));
+ assertSame(createdClassA, loaderB.loadClass(createdClassA.getName()));
+ assertSame(createdClassB, loaderB.loadClass(createdClassB.getName()));
+ }
+ finally
+ {
+ removeClassPool(globalPoolA);
+ removeClassPool(globalPoolB);
+ }
+ }
+
+ /*public void testMakeContainerProxyForSystemClass() throws Exception
+ {
+ ClassPool globalPoolA = null;
+ ClassPool globalPoolB = null;
+ try
+ {
+ globalPoolA = createGlobalClassPool(JAR_A_1);
+ globalPoolB = createGlobalClassPool(JAR_B_1);
+
+ ClassLoader loaderA = globalPoolA.getClassLoader();
+ ClassLoader loaderB = globalPoolB.getClassLoader();
+
+ Object proxyA = assertMakeContainerProxy(ArrayList.class, loaderA);
+ Object proxyB = assertMakeContainerProxy(ArrayList.class, loaderB);
+
+ Class<?> clazzA = proxyA.getClass();
+ Class<?> clazzB = proxyB.getClass();
+
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzA));
+ assertTrue(AspectManaged.class.isAssignableFrom(clazzB));
+ assertTrue(clazzA.getName().startsWith(ContainerProxyFactory.PROXY_CLASSES_DEFAULT_PACKAGE));
+ assertTrue(clazzB.getName().startsWith(ContainerProxyFactory.PROXY_CLASSES_DEFAULT_PACKAGE));
+
+ assertSame(clazzA, loaderA.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderA.loadClass(clazzB.getName()));
+ assertSame(clazzA, loaderB.loadClass(clazzA.getName()));
+ assertSame(clazzB, loaderB.loadClass(clazzB.getName()));
+ }
+ finally
+ {
+ removeClassPool(globalPoolA);
+ removeClassPool(globalPoolB);
+ }
+ }*/
+
+ /*private Object assertMakeContainerProxy(Class<?> parent, ClassLoader loader) throws Exception
+ {
+ AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+ params.setProxiedClass(parent);
+ params.setTarget(parent.newInstance());
+ params.setClassLoader(loader);
+ params.setInterfaces(new Class<?>[] {java.io.Serializable.class});
+ GeneratedAOPProxyFactory factory = new GeneratedAOPProxyFactory();
+ Object proxy = factory.createAdvisedProxy(params);
+ assertFalse(parent.getName() == proxy.getClass().getName());
+ assertSame(loader, proxy.getClass().getClassLoader());
+ return proxy;
+ }*/
+
+
+}
Added: projects/jboss-classpool/trunk/src/test/resources/log4j.xml
===================================================================
--- projects/jboss-classpool/trunk/src/test/resources/log4j.xml (rev 0)
+++ projects/jboss-classpool/trunk/src/test/resources/log4j.xml 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.SimpleLayout"/>
+ </appender>
+
+ <root>
+ <priority value ="debug" />
+ <appender-ref ref="ConsoleAppender"/>
+ </root>
+
+</log4j:configuration>
Property changes on: projects/jboss-classpool/trunk/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:executable
+ *
Added: projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml
===================================================================
--- projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml (rev 0)
+++ projects/jboss-classpool/trunk/src/test/resources/org/jboss/test/classpool/jbosscl/Common.xml 2009-07-22 15:17:59 UTC (rev 91561)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="ClassLoaderSystem" class="org.jboss.classloader.spi.ClassLoaderSystem">
+ <constructor factoryClass="org.jboss.test.classpool.jbosscl.test.JBossClClassPoolTest" factoryMethod="getSystem"/>
+ </bean>
+
+ <bean name="ClassLoading" class="org.jboss.classloading.spi.dependency.ClassLoading">
+ <incallback method="addModule" state="Configured"/>
+ <uncallback method="removeModule" state="Configured"/>
+ </bean>
+
+</deployment>
More information about the jboss-cvs-commits
mailing list