[jboss-cvs] JBossAS SVN: r103693 - in projects/scanning/trunk: testsuite/src/test/java/org/jboss/test/scanning/metadata/support and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 8 07:17:21 EDT 2010


Author: alesj
Date: 2010-04-08 07:17:21 -0400 (Thu, 08 Apr 2010)
New Revision: 103693

Added:
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/DeploymentFilter.java
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/VisitedFilter.java
Modified:
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/filter/ScanningDeploymentUnitFilter.java
   projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.java
   projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.xml
Log:
Proper recurse tests.

Modified: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/filter/ScanningDeploymentUnitFilter.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/filter/ScanningDeploymentUnitFilter.java	2010-04-08 11:01:06 UTC (rev 103692)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/filter/ScanningDeploymentUnitFilter.java	2010-04-08 11:17:21 UTC (rev 103693)
@@ -24,9 +24,9 @@
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.helpers.VFS2BaseBridgeDeploymentUnitFilter;
-import org.jboss.logging.Logger;
 import org.jboss.scanning.plugins.filter.ScanningMetaDataRecurseFilter;
 import org.jboss.scanning.plugins.filter.ScanningMetaDataResourceFilter;
+import org.jboss.scanning.plugins.helpers.DelegateResourceFilter;
 import org.jboss.scanning.spi.metadata.ScanningMetaData;
 
 /**
@@ -36,8 +36,6 @@
  */
 public class ScanningDeploymentUnitFilter extends VFS2BaseBridgeDeploymentUnitFilter
 {
-   private Logger log = Logger.getLogger(getClass());
-
    protected boolean doAccepts(DeploymentUnit unit)
    {
       ScanningMetaData smd = unit.getAttachment(ScanningMetaData.class);
@@ -47,18 +45,22 @@
          ResourceFilter recurse = createRecurseFilter(smd);
          if (recurse != null)
          {
-            ResourceFilter previousRecurse = unit.addAttachment(ResourceFilter.class.getName() + ".recurse", recurse, ResourceFilter.class);
+            ResourceFilter previousRecurse = unit.getAttachment(ResourceFilter.class.getName() + ".recurse", ResourceFilter.class);
             if (previousRecurse != null)
-               log.debugf("Overridding previous recurse filter: %1s", previousRecurse);
+               recurse = new DelegateResourceFilter(previousRecurse, recurse);
+
+            unit.addAttachment(ResourceFilter.class.getName() + ".recurse", recurse, ResourceFilter.class);
          }
 
          // resource
          ResourceFilter filter = createResourceFilter(smd);
          if (filter != null)
          {
-            ResourceFilter previousFilter = unit.addAttachment(ResourceFilter.class.getName() + ".resource", filter, ResourceFilter.class);
+            ResourceFilter previousFilter = unit.getAttachment(ResourceFilter.class.getName() + ".resource", ResourceFilter.class);
             if (previousFilter != null)
-               log.debugf("Overridding previous resource filter: %1s", previousFilter);
+               filter = new DelegateResourceFilter(previousFilter, filter);
+
+            unit.addAttachment(ResourceFilter.class.getName() + ".resource", filter, ResourceFilter.class);
          }
       }
       return true;

Added: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/DeploymentFilter.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/DeploymentFilter.java	                        (rev 0)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/DeploymentFilter.java	2010-04-08 11:17:21 UTC (rev 103693)
@@ -0,0 +1,45 @@
+/*
+ * 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.metadata.support;
+
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.scanning.deployers.filter.ScanningDeploymentUnitFilter;
+import org.jboss.scanning.spi.metadata.ScanningMetaData;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeploymentFilter extends ScanningDeploymentUnitFilter
+{
+   @Override
+   protected ResourceFilter createRecurseFilter(ScanningMetaData smd)
+   {
+      return new VisitedFilter(super.createRecurseFilter(smd));
+   }
+
+   @Override
+   protected ResourceFilter createResourceFilter(ScanningMetaData smd)
+   {
+      return new VisitedFilter(super.createResourceFilter(smd));
+   }
+}

Copied: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/VisitedFilter.java (from rev 103689, projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/SingletonVisitor.java)
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/VisitedFilter.java	                        (rev 0)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/support/VisitedFilter.java	2010-04-08 11:17:21 UTC (rev 103693)
@@ -0,0 +1,69 @@
+/*
+ * 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.metadata.support;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.scanning.spi.helpers.AllRecurseFilter;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VisitedFilter implements ResourceFilter
+{
+   private Set<String> filtered = new HashSet<String>();
+   private ResourceFilter delegate;
+
+   public VisitedFilter()
+   {
+      this(null);
+   }
+
+   public VisitedFilter(ResourceFilter delegate)
+   {
+      if (delegate == null)
+         delegate = AllRecurseFilter.INSTANCE;
+      this.delegate = delegate;
+   }
+
+   public boolean accepts(ResourceContext resource)
+   {
+      boolean result = delegate.accepts(resource);
+      if (result)
+         filtered.add(resource.getResourceName());
+      return result;
+   }
+
+   public Set<String> getFiltered()
+   {
+      return filtered;
+   }
+
+   public void clear()
+   {
+      filtered.clear();
+   }
+}
\ No newline at end of file

Modified: projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.java
===================================================================
--- projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.java	2010-04-08 11:01:06 UTC (rev 103692)
+++ projects/scanning/trunk/testsuite/src/test/java/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.java	2010-04-08 11:17:21 UTC (rev 103693)
@@ -24,6 +24,8 @@
 
 import java.util.Set;
 
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.test.deployers.BootstrapDeployersTest;
 import org.jboss.test.scanning.annotations.support.jar.JarMarkOnClass;
@@ -31,6 +33,7 @@
 import org.jboss.test.scanning.annotations.support.war.WebMarkOnClass;
 import org.jboss.test.scanning.annotations.support.war.impl.WebMarkOnClassImpl;
 import org.jboss.test.scanning.metadata.support.SingletonVisitor;
+import org.jboss.test.scanning.metadata.support.VisitedFilter;
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 
@@ -67,9 +70,15 @@
       SingletonVisitor visitor = SingletonVisitor.INSTANCE;
       try
       {
+         VisitedFilter filter = unit.getAttachment(ResourceFilter.class.getName() + ".recurse", VisitedFilter.class);
+         assertNotNull(filter);
+         Set<String> filtered = filter.getFiltered();
+         String warPckg = ClassLoaderUtils.packageNameToPath(WebMarkOnClass.class.getName());
+         assertFalse(filtered.contains(warPckg));
+         String jarPckg = ClassLoaderUtils.packageNameToPath(JarMarkOnClass.class.getName());
+         assertTrue(filtered.contains(jarPckg));
          Set<String> visited = visitor.getVisited();
          assertEquals(5, visited.size());
-         // TODO -- check we don't recurse into war packages
       }
       finally
       {

Modified: projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.xml
===================================================================
--- projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.xml	2010-04-08 11:01:06 UTC (rev 103692)
+++ projects/scanning/trunk/testsuite/src/test/resources/org/jboss/test/scanning/metadata/test/ScanningUnitTestCase.xml	2010-04-08 11:17:21 UTC (rev 103693)
@@ -7,7 +7,7 @@
 
   <bean name="AnnEnvDeployer" class="org.jboss.scanning.deployers.ScanningDeployer">
     <property name="filter">
-      <bean class="org.jboss.scanning.deployers.filter.ScanningDeploymentUnitFilter"/>
+      <bean class="org.jboss.test.scanning.metadata.support.DeploymentFilter"/>
     </property>
     <incallback method="addFactory" />
     <uncallback method="removeFactory" />




More information about the jboss-cvs-commits mailing list