[jboss-cvs] JBossAS SVN: r75958 - in projects/jboss-deployers/trunk/deployers-vfs/src: resources/tests/bootstrap and 19 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 17 09:50:40 EDT 2008
Author: adrian at jboss.org
Date: 2008-07-17 09:50:40 -0400 (Thu, 17 Jul 2008)
New Revision: 75958
Added:
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bootstrap/test-assembled/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bootstrap/test-assembled/META-INF/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bootstrap/test-assembled/META-INF/test.xml
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/basic/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/basic/META-INF/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/basic/META-INF/MANIFEST.MF
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/dummyparent/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/dummyparent/META-INF/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/dummyparent/META-INF/jboss-classloading.xml
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/MANIFEST.MF
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/jboss-classloading.xml
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/MANIFEST.MF
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/jboss-classloading.xml
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/topscoped/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/topscoped/META-INF/
projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/topscoped/META-INF/jboss-classloading.xml
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/usea/
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/usea/UseA.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ManifestClassLoaderUnitTestCase.java
Modified:
projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTest.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTestDelegate.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java
projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/BootstrapDeployersSmokeTestUnitTestCase.java
Log:
[JBDEPLOY-59] - Weed out parent classpath elements from subdeployment classpaths
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java 2008-07-17 13:12:49 UTC (rev 75957)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -39,6 +39,7 @@
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.structure.helpers.ClassPathVisitor;
+import org.jboss.logging.Logger;
import org.jboss.virtual.VirtualFile;
/**
@@ -52,6 +53,12 @@
/** The serialVersionUID */
private static final long serialVersionUID = 1L;
+ /** The log */
+ private static final Logger log = Logger.getLogger(VFSDeploymentClassLoaderPolicyModule.class);
+
+ /** The attachment containing the final classpath */
+ public static final String VFS_CLASS_PATH = "VFSClassPath";
+
/** The cached roots */
private VirtualFile[] vfsRoots;
@@ -108,15 +115,17 @@
*
* @return the roots
*/
+ @SuppressWarnings("unchecked")
protected VirtualFile[] determineVFSRoots()
{
if (vfsRoots != null)
return vfsRoots;
- ClassPathVisitor visitor = new ClassPathVisitor(getDeploymentUnit());
+ DeploymentUnit unit = getDeploymentUnit();
+ ClassPathVisitor visitor = new ClassPathVisitor(unit);
try
{
- getDeploymentUnit().visit(visitor);
+ unit.visit(visitor);
}
catch (DeploymentException e)
{
@@ -124,6 +133,30 @@
}
Set<VirtualFile> classPath = visitor.getClassPath();
+ // Weed out parent classpaths
+ if (getParentDomainName() == null)
+ {
+ DeploymentUnit parent = unit.getParent();
+ while (parent != null)
+ {
+ Set<VirtualFile> parentClassPath = parent.getAttachment(VFS_CLASS_PATH, Set.class);
+ if (parentClassPath != null)
+ {
+ if (log.isTraceEnabled())
+ {
+ for (VirtualFile parentFile : parentClassPath)
+ {
+ if (classPath.contains(parentFile))
+ log.trace(unit + " weeding duplicate entry " + parentFile + " from classpath already in parent " + parent);
+ }
+ }
+ classPath.removeAll(parentClassPath);
+ }
+ parent = parent.getParent();
+ }
+ }
+ unit.addAttachment(VFS_CLASS_PATH, classPath);
+
vfsRoots = classPath.toArray(new VirtualFile[classPath.size()]);
return vfsRoots;
}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bootstrap/test-assembled/META-INF/test.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bootstrap/test-assembled/META-INF/test.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/bootstrap/test-assembled/META-INF/test.xml 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1 @@
+empty
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/basic/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/basic/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/basic/META-INF/MANIFEST.MF 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Created-By: hand
+Class-Path: util.jar
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/dummyparent/META-INF/jboss-classloading.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/dummyparent/META-INF/jboss-classloading.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/dummyparent/META-INF/jboss-classloading.xml 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,4 @@
+<classloading xmlns="urn:jboss:classloading:1.0"
+ domain="dummyParent"
+/>
+
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/MANIFEST.MF 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Created-By: hand
+Class-Path: util.jar
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/jboss-classloading.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/jboss-classloading.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scoped/META-INF/jboss-classloading.xml 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,5 @@
+<classloading xmlns="urn:jboss:classloading:1.0"
+ domain="test"
+ parent-first="false"
+/>
+
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/MANIFEST.MF 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Created-By: hand
+Class-Path: util.jar
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/jboss-classloading.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/jboss-classloading.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/scopednotparent/META-INF/jboss-classloading.xml 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,5 @@
+<classloading xmlns="urn:jboss:classloading:1.0"
+ domain="test"
+ parent-domain="dummyParent"
+/>
+
Added: projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/topscoped/META-INF/jboss-classloading.xml
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/topscoped/META-INF/jboss-classloading.xml (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/resources/tests/classloader/manifest/topscoped/META-INF/jboss-classloading.xml 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,4 @@
+<classloading xmlns="urn:jboss:classloading:1.0"
+ domain="testDomain"
+/>
+
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTest.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTest.java 2008-07-17 13:12:49 UTC (rev 75957)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTest.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -24,9 +24,12 @@
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
+import java.util.List;
import junit.framework.AssertionFailedError;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.jboss.classloader.plugins.ClassLoaderUtils;
import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
import org.jboss.dependency.spi.ControllerContext;
@@ -39,8 +42,15 @@
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
+import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.context.vfs.AssembledContext;
+import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
/**
* BootstrapDeployersTest.
@@ -107,6 +117,13 @@
return (VFSDeploymentUnit) getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
}
+ protected VFSDeploymentUnit assertDeploy(VirtualFile file) throws Exception
+ {
+ VFSDeployment deployment = createVFSDeployment(file);
+ getDeployerClient().deploy(deployment);
+ return (VFSDeploymentUnit) getMainDeployerStructure().getDeploymentUnit(deployment.getName(), true);
+ }
+
protected VFSDeploymentUnit addDeployment(String root, String child) throws Exception
{
VFSDeployment deployment = createVFSDeployment(root, child);
@@ -273,11 +290,74 @@
throw new RuntimeException("Unexpected error getting classloader", e);
}
}
+
+ // FIXME Missing factor method in the public api
+ protected AssembledDirectory createAssembledDirectory(String name) throws Exception
+ {
+ AssembledContext ctx = new AssembledContext(name, "");
+ return (AssembledDirectory) ctx.getRoot().getVirtualFile();
+ }
+
+ protected void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
+ {
+ String packagePath = ClassLoaderUtils.packageNameToPath(reference.getName());
+ dir.addResources(reference, new String[] { packagePath + "/*.class" } , new String[0]);
+ }
+
+ // FIXME why doesn't AssembledDirectory support this simple use case?
+ protected void addPath(final AssembledDirectory dir, String path, String name) throws Exception
+ {
+ URL url = getResource(path);
+ if (url == null)
+ fail(path + " not found");
+ VirtualFile file = VFS.getVirtualFile(url, name);
+
+ final VisitorAttributes va = new VisitorAttributes();
+ va.setLeavesOnly(true);
+ SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
+ va.setRecurseFilter(noJars);
+
+ VirtualFileVisitor visitor = new VirtualFileVisitor()
+ {
+ public VisitorAttributes getAttributes()
+ {
+ return va;
+ }
+
+ public void visit(VirtualFile virtualFile)
+ {
+ dir.mkdirs(virtualFile.getPathName()).addChild(virtualFile);
+ }
+ };
+ file.visit(visitor);
+ }
+ protected DeploymentUnit assertChild(DeploymentUnit parent, String name)
+ {
+ // FIXME AssembledContext URLs are broken
+ String parentName = parent.getName();
+ if (parentName.endsWith("/"))
+ parentName = parentName.substring(0, parentName.length()-1);
+ name = name + "/";
+
+ name = parentName + name ;
+ List<DeploymentUnit> children = parent.getChildren();
+ for (DeploymentUnit child : children)
+ {
+ if (name.equals(child.getName()))
+ return child;
+ }
+ throw new AssertionFailedError("Child " + name + " not found in " + children);
+ }
+
protected void setUp() throws Exception
{
super.setUp();
// This is a hack for a hack. ;-)
AbstractJDKChecker.getExcluded().add(BootstrapDeployersTest.class);
+
+ // Reduce the noise from the VFS
+ // FIXME add method change logging levels to AbstractTestCase
+ Logger.getLogger(FileSystemContext.class).setLevel(Level.INFO);
}
}
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTestDelegate.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTestDelegate.java 2008-07-17 13:12:49 UTC (rev 75957)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/BootstrapDeployersTestDelegate.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -23,6 +23,12 @@
import java.net.URL;
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+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.classloading.spi.metadata.ClassLoadingMetaData10;
import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory10;
import org.jboss.dependency.spi.ControllerState;
@@ -39,6 +45,8 @@
*/
public class BootstrapDeployersTestDelegate extends MicrocontainerTestDelegate
{
+ private static ParentPolicy parentPolicy;
+
private MainDeployerImpl mainDeployer;
static
@@ -46,6 +54,39 @@
DefaultSchemaResolver resolver = (DefaultSchemaResolver) SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
resolver.addClassBinding("urn:jboss:classloader:1.0", VFSClassLoaderFactory10.class);
resolver.addClassBinding("urn:jboss:classloading:1.0", ClassLoadingMetaData10.class);
+
+ // TODO add a negating class filter to jboss-classloader
+ ClassFilter classFilter = new ClassFilter()
+ {
+ String packageName = BootstrapDeployersTest.class.getPackage().getName();
+ String packagePath = ClassLoaderUtils.packageNameToPath(BootstrapDeployersTest.class.getName());
+ ClassFilter patternFilter = new PatternClassFilter(
+ new String[] { packageName + "\\..+" },
+ new String[] { packagePath + "/.+" },
+ new String[] { packageName, packageName + "\\..*"}
+ );
+ public boolean matchesClassName(String className)
+ {
+ return patternFilter.matchesClassName(className) == false;
+ }
+
+ public boolean matchesPackageName(String packageName)
+ {
+ return patternFilter.matchesPackageName(packageName) == false;
+ }
+
+ public boolean matchesResourcePath(String resourcePath)
+ {
+ return patternFilter.matchesResourcePath(resourcePath) == false;
+ }
+
+ public String toString()
+ {
+ return "EXCLUDE " + patternFilter;
+ }
+ };
+
+ parentPolicy = new ParentPolicy(classFilter, ClassFilter.NOTHING, "BEFORE");
}
public BootstrapDeployersTestDelegate(Class<?> clazz) throws Exception
@@ -61,6 +102,10 @@
throw new IllegalStateException(common + " not found");
deploy(url);
+ ClassLoaderSystem system = getBean("ClassLoaderSystem", ControllerState.INSTALLED, ClassLoaderSystem.class);
+ ClassLoaderDomain domain = system.getDefaultDomain();
+ domain.setParentPolicy(parentPolicy);
+
super.deploy();
}
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java 2008-07-17 13:12:49 UTC (rev 75957)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -26,6 +26,7 @@
import org.jboss.test.deployers.vfs.classloader.test.DeploymentDependsOnManualClassLoaderUnitTestCase;
import org.jboss.test.deployers.vfs.classloader.test.InMemoryClasesUnitTestCase;
import org.jboss.test.deployers.vfs.classloader.test.ManagedObjectClassLoadingParserUnitTestCase;
+import org.jboss.test.deployers.vfs.classloader.test.ManifestClassLoaderUnitTestCase;
import org.jboss.test.deployers.vfs.classloader.test.ManualDependsOnDeploymentClassLoaderUnitTestCase;
import org.jboss.test.deployers.vfs.classloader.test.NotVFSClassLoaderUnitTestCase;
import org.jboss.test.deployers.vfs.classloader.test.SubDeploymentClassLoaderUnitTestCase;
@@ -63,6 +64,7 @@
suite.addTest(ManagedObjectClassLoadingParserUnitTestCase.suite());
suite.addTest(SubDeploymentClassLoaderUnitTestCase.suite());
suite.addTest(NotVFSClassLoaderUnitTestCase.suite());
+ suite.addTest(ManifestClassLoaderUnitTestCase.suite());
return suite;
}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/usea/UseA.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/usea/UseA.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/usea/UseA.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.deployers.vfs.classloader.support.usea;
+
+import org.jboss.test.deployers.vfs.classloader.support.a.A;
+
+/**
+ * UseA.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class UseA
+{
+ public static Class<A> used = A.class;
+}
Modified: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/BootstrapDeployersSmokeTestUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/BootstrapDeployersSmokeTestUnitTestCase.java 2008-07-17 13:12:49 UTC (rev 75957)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/BootstrapDeployersSmokeTestUnitTestCase.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -31,6 +31,9 @@
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.test.deployers.BootstrapDeployersTest;
+import org.jboss.test.deployers.vfs.classloader.support.a.A;
+import org.jboss.test.deployers.vfs.classloader.support.b.B;
+import org.jboss.virtual.AssembledDirectory;
/**
* BootstrapDeployersSmokeTestUnitTestCase.
@@ -105,4 +108,48 @@
undeploy(unit);
}
}
+
+ public void testAssembledDirectory() throws Exception
+ {
+ AssembledDirectory dirA = createAssembledDirectory("a");
+ addPackage(dirA, A.class);
+ addPath(dirA, "/bootstrap/test-assembled", "META-INF");
+ VFSDeploymentUnit unitA = assertDeploy(dirA);
+ try
+ {
+ ClassLoader clA = getClassLoader(unitA);
+ assertLoadClass(A.class, clA);
+ assertLoadClassFail(B.class, clA);
+
+ assertNoResource("META-INF/test.xml", getClass().getClassLoader());
+ assertGetResource("META-INF/test.xml", clA);
+ }
+ finally
+ {
+ undeploy(unitA);
+ }
+ }
+
+ public void testAssembledSubDirectory() throws Exception
+ {
+ AssembledDirectory dirA = createAssembledDirectory("a");
+ addPackage(dirA, A.class);
+ AssembledDirectory dirB = dirA.mkdir("b");
+ addPackage(dirB, B.class);
+ addPath(dirB, "/bootstrap/test-assembled", "META-INF");
+ VFSDeploymentUnit unitA = assertDeploy(dirA);
+ try
+ {
+ ClassLoader clA = getClassLoader(unitA);
+ assertLoadClass(A.class, clA);
+ assertLoadClass(B.class, clA);
+
+ assertNoResource("META-INF/test.xml", getClass().getClassLoader());
+ assertGetResource("META-INF/test.xml", clA);
+ }
+ finally
+ {
+ undeploy(unitA);
+ }
+ }
}
Added: projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ManifestClassLoaderUnitTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ManifestClassLoaderUnitTestCase.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ManifestClassLoaderUnitTestCase.java 2008-07-17 13:50:40 UTC (rev 75958)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.deployers.vfs.classloader.test;
+
+import java.lang.reflect.Field;
+
+import junit.framework.Test;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.test.deployers.BootstrapDeployersTest;
+import org.jboss.test.deployers.vfs.classloader.support.a.A;
+import org.jboss.test.deployers.vfs.classloader.support.usea.UseA;
+import org.jboss.virtual.AssembledDirectory;
+
+/**
+ * ManifestClassLoaderUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ManifestClassLoaderUnitTestCase extends BootstrapDeployersTest
+{
+ public static Test suite()
+ {
+ return suite(ManifestClassLoaderUnitTestCase.class);
+ }
+
+ public ManifestClassLoaderUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testBasicManifest() throws Exception
+ {
+ AssembledDirectory topLevel = createTopLevelWithUtil();
+ AssembledDirectory sub = topLevel.mkdir("sub.jar");
+ addPackage(sub, UseA.class);
+ addPath(sub, "/classloader/manifest/basic", "META-INF");
+ VFSDeploymentUnit unit = assertDeploy(topLevel);
+ try
+ {
+ ClassLoader cl = getClassLoader(unit);
+ Class<?> expected = assertLoadClass(A.class, cl);
+ Class<?> actual = getUsedClass(UseA.class, cl);
+ assertClassEquality(expected, actual);
+ }
+ finally
+ {
+ undeploy(unit);
+ }
+ }
+
+ public void testScopedManifest() throws Exception
+ {
+ AssembledDirectory topLevel = createTopLevelWithUtil();
+ AssembledDirectory sub = topLevel.mkdir("sub.jar");
+ addPackage(sub, UseA.class);
+ addPath(sub, "/classloader/manifest/scoped", "META-INF");
+ VFSDeploymentUnit unit = assertDeploy(topLevel);
+ try
+ {
+ ClassLoader cl = getClassLoader(unit);
+ Class<?> expected = assertLoadClass(A.class, cl);
+ DeploymentUnit subUnit = assertChild(unit, "sub.jar");
+ ClassLoader clSub = getClassLoader(subUnit);
+ Class<?> actual = getUsedClass(UseA.class, clSub);
+ assertClassEquality(expected, actual);
+ }
+ finally
+ {
+ undeploy(unit);
+ }
+ }
+
+ public void testScopedManifests() throws Exception
+ {
+ AssembledDirectory topLevel = createTopLevelWithUtil();
+ AssembledDirectory sub1 = topLevel.mkdir("sub1.jar");
+ addPackage(sub1, UseA.class);
+ addPath(sub1, "/classloader/manifest/scoped", "META-INF");
+ AssembledDirectory sub2 = topLevel.mkdir("sub2.jar");
+ addPackage(sub2, UseA.class);
+ addPath(sub2, "/classloader/manifest/scoped", "META-INF");
+ VFSDeploymentUnit unit = assertDeploy(topLevel);
+ try
+ {
+ ClassLoader cl = getClassLoader(unit);
+ Class<?> expected = assertLoadClass(A.class, cl);
+ DeploymentUnit sub1Unit = assertChild(unit, "sub1.jar");
+ ClassLoader clSub1 = getClassLoader(sub1Unit);
+ Class<?> actual = getUsedClass(UseA.class, clSub1);
+ assertClassEquality(expected, actual);
+ DeploymentUnit sub2Unit = assertChild(unit, "sub2.jar");
+ ClassLoader clSub2 = getClassLoader(sub2Unit);
+ actual = getUsedClass(UseA.class, clSub2);
+ assertClassEquality(expected, actual);
+ }
+ finally
+ {
+ undeploy(unit);
+ }
+ }
+
+ public void testScopedManifestNotParent() throws Exception
+ {
+ // Dummy parent to create a different parent domain
+ AssembledDirectory dummyParent = createAssembledDirectory("dummyParent.jar");
+ addPath(dummyParent, "/classloader/manifest/dummyparent", "META-INF");
+ VFSDeploymentUnit dummy = assertDeploy(dummyParent);
+ try
+ {
+ AssembledDirectory topLevel = createTopLevelWithUtil();
+ addPath(topLevel, "/classloader/manifest/topscoped", "META-INF");
+ AssembledDirectory sub = topLevel.mkdir("sub.jar");
+ addPackage(sub, UseA.class);
+ addPath(sub, "/classloader/manifest/scopednotparent", "META-INF");
+ VFSDeploymentUnit unit = assertDeploy(topLevel);
+ try
+ {
+ ClassLoader cl = getClassLoader(unit);
+ Class<?> expected = assertLoadClass(A.class, cl);
+ DeploymentUnit subUnit = assertChild(unit, "sub.jar");
+ ClassLoader clSub = getClassLoader(subUnit);
+ Class<?> actual = getUsedClass(UseA.class, clSub);
+ assertNoClassEquality(expected, actual);
+ }
+ finally
+ {
+ undeploy(unit);
+ }
+ }
+ finally
+ {
+ undeploy(dummy);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Class<?> getUsedClass(Class<?> reference, ClassLoader start) throws Exception
+ {
+ Class<?> user = assertLoadClass(reference, start);
+ Field a = user.getField("used");
+ return (Class) a.get(null);
+ }
+
+ protected AssembledDirectory createTopLevelWithUtil() throws Exception
+ {
+ AssembledDirectory topLevel = createAssembledDirectory("top-level.jar");
+ AssembledDirectory util = topLevel.mkdir("util.jar");
+ addPackage(util, A.class);
+ return topLevel;
+ }
+}
More information about the jboss-cvs-commits
mailing list