[jboss-cvs] JBossAS SVN: r103833 - in projects/scanning/trunk: testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 12 10:25:30 EDT 2010
Author: alesj
Date: 2010-04-12 10:25:29 -0400 (Mon, 12 Apr 2010)
New Revision: 103833
Added:
projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinder.java
projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinderDeployer.java
Modified:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java
projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java
projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.xml
Log:
Proper hierarchy tests.
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java 2010-04-12 14:21:54 UTC (rev 103832)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hierarchy/plugins/HierarchyIndexImpl.java 2010-04-12 14:25:29 UTC (rev 103833)
@@ -66,13 +66,16 @@
map = new HashMap<TypeInfo, Set<TypeInfo>>();
cache.put(path, map);
}
- Set<TypeInfo> infos = map.get(key);
- if (infos == null)
+ for (TypeInfo superType : classes)
{
- infos = new HashSet<TypeInfo>();
- map.put(key, infos);
+ Set<TypeInfo> infos = map.get(superType);
+ if (infos == null)
+ {
+ infos = new HashSet<TypeInfo>();
+ map.put(superType, infos);
+ }
+ infos.add(key);
}
- infos.addAll(Arrays.asList(classes));
}
public Set<TypeInfo> getInheritedClasses(String path, TypeInfo superTypeToLookFor)
Added: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinder.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinder.java (rev 0)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinder.java 2010-04-12 14:25:29 UTC (rev 103833)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.hierarchy.support;
+
+import java.io.File;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SuffixResourceOwnerFinder implements ResourceOwnerFinder
+{
+ public static final ResourceOwnerFinder INSTANCE = new SuffixResourceOwnerFinder();
+
+ /** The archive suffixes */
+ private Set<String> suffixes = new HashSet<String>(Arrays.asList(".jar", ".war", ".ear", ".sar", "classes"));
+
+ private SuffixResourceOwnerFinder()
+ {
+ }
+
+ public URL findOwnerURL(ResourceContext resource)
+ {
+ URL url = resource.getUrl();
+ File file = new File(url.getPath());
+ while(isKnownSuffix(file) == false && file != null)
+ file = file.getParentFile();
+
+ if (file == null)
+ throw new IllegalArgumentException("No archive in resource path: " + resource.getUrl());
+
+ try
+ {
+ return file.toURI().toURL();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected boolean isKnownSuffix(File file)
+ {
+ String name = file.getName();
+ for (String suffix : suffixes)
+ if (name.endsWith(suffix))
+ return true;
+ return false;
+ }
+}
Added: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinderDeployer.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinderDeployer.java (rev 0)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/support/SuffixResourceOwnerFinderDeployer.java 2010-04-12 14:25:29 UTC (rev 103833)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.scanning.hierarchy.support;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SuffixResourceOwnerFinderDeployer extends AbstractSimpleRealDeployer<Module>
+{
+ public SuffixResourceOwnerFinderDeployer()
+ {
+ super(Module.class);
+ setStage(DeploymentStages.CLASSLOADER);
+ }
+
+ @Override
+ public void deploy(DeploymentUnit unit, Module deployment) throws DeploymentException
+ {
+ unit.addAttachment(ResourceOwnerFinder.class, SuffixResourceOwnerFinder.INSTANCE);
+ }
+}
\ No newline at end of file
Modified: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java 2010-04-12 14:21:54 UTC (rev 103832)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.java 2010-04-12 14:25:29 UTC (rev 103833)
@@ -24,17 +24,21 @@
import java.util.Set;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.reflect.spi.ClassInfo;
import org.jboss.reflect.spi.TypeInfo;
import org.jboss.scanning.hierarchy.spi.HierarchyIndex;
import org.jboss.test.deployers.BootstrapDeployersTest;
import org.jboss.test.scanning.annotations.support.NoExtRecurseFilter;
import org.jboss.test.scanning.annotations.support.ext.External;
import org.jboss.test.scanning.annotations.support.jar.JarMarkOnClass;
+import org.jboss.test.scanning.annotations.support.jar.JarMarkOnClassSuperAnnotated;
import org.jboss.test.scanning.annotations.support.jar.impl.JarMarkOnClassImpl;
import org.jboss.test.scanning.annotations.support.util.Util;
import org.jboss.test.scanning.annotations.support.war.WebMarkOnClass;
+import org.jboss.test.scanning.annotations.support.war.WebMarkOnClassSuperAnnotated;
import org.jboss.test.scanning.annotations.support.war.impl.WebMarkOnClassImpl;
import org.jboss.test.scanning.annotations.support.warlib.SomeUIClass;
import org.jboss.vfs.VFS;
@@ -94,14 +98,33 @@
protected void assertEar(DeploymentUnit ear) throws Exception
{
+ VirtualFile annJar = getRoot(ear).getChild("/lib/ann.jar");
+ Set<TypeInfo> inherited = getInheritedClasses(ear, annJar, ResourceFilter.class);
+ assertNotNull(inherited);
+ assertEquals(2, inherited.size()); // also anonymous class
+ for (TypeInfo ti : inherited)
+ {
+ if (ti instanceof ClassInfo)
+ {
+ ClassInfo ci = (ClassInfo) ti;
+ if (ci.isPublic())
+ assertEquals(ci.getName(), NoExtRecurseFilter.class.getName());
+ }
+ }
}
protected void assertJar(DeploymentUnit jar) throws Exception
{
+ Set<TypeInfo> inherited = getInheritedClasses(jar, getRoot(jar), JarMarkOnClassSuperAnnotated.class);
+ assertNotNull(inherited);
+ assertEquals(3, inherited.size());
}
protected void assertWar(DeploymentUnit war) throws Exception
{
+ Set<TypeInfo> inherited = getInheritedClasses(war, getRoot(war).getChild("/WEB-INF/classes"), WebMarkOnClassSuperAnnotated.class);
+ assertNotNull(inherited);
+ assertEquals(3, inherited.size());
}
protected HierarchyIndex getIndex(DeploymentUnit unit)
@@ -113,6 +136,9 @@
protected VirtualFile getRoot(DeploymentUnit unit)
{
+ if (unit == null)
+ return null;
+
if (unit instanceof VFSDeploymentUnit == false)
throw new IllegalArgumentException("Illegal unit type");
@@ -120,11 +146,12 @@
return vdu.getRoot();
}
- protected Set<TypeInfo> getInheritedClasses(DeploymentUnit unit, Class<?> superType)
+ protected Set<TypeInfo> getInheritedClasses(DeploymentUnit unit, VirtualFile cpEntry, Class<?> ref) throws Exception
{
HierarchyIndex index = getIndex(unit);
- VirtualFile root = getRoot(unit);
- return index.getInheritedClasses(root.getPathName(), superType);
+ String path = cpEntry.getPathName();
+ Class<?> superType = unit.getClassLoader().loadClass(ref.getName());
+ return index.getInheritedClasses(path, superType);
}
protected VirtualFile createTopLevelWithUtil() throws Exception
Modified: projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.xml
===================================================================
--- projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.xml 2010-04-12 14:21:54 UTC (rev 103832)
+++ projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/hierarchy/test/HierarchyUnitTestCase.xml 2010-04-12 14:25:29 UTC (rev 103833)
@@ -3,6 +3,8 @@
<bean name="EarStructure" class="org.jboss.test.deployers.vfs.structure.ear.support.MockEarStructureDeployer"/>
<bean name="WarStructure" class="org.jboss.deployers.vfs.plugins.structure.war.WARStructure"/>
+ <bean name="SuffixROFDeployer" class="org.jboss.test.scanning.hierarchy.support.SuffixResourceOwnerFinderDeployer"/>
+
<bean name="AnnEnvDeployer" class="org.jboss.scanning.deployers.ScanningDeployer">
<incallback method="addFactory" />
<uncallback method="removeFactory" />
More information about the jboss-cvs-commits
mailing list