[jboss-cvs] JBossAS SVN: r103312 - in projects/scanning/trunk: plugins/src/main/java/org/jboss/scanning/annotations/plugins and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 31 07:59:35 EDT 2010


Author: alesj
Date: 2010-03-31 07:59:33 -0400 (Wed, 31 Mar 2010)
New Revision: 103312

Added:
   projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanner.java
   projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanningPlugin.java
   projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningPluginWrapper.java
   projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java
Removed:
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java
Modified:
   projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java
   projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java
   projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java
Log:
Move spi helper classes to spi module.

Modified: projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java
===================================================================
--- projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/deployers/src/main/java/org/jboss/scanning/deployers/ScanningDeployer.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -34,10 +34,10 @@
 import org.jboss.deployers.vfs.plugins.util.ClasspathUtils;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnitFilter;
-import org.jboss.scanning.plugins.AbstractScanner;
 import org.jboss.scanning.plugins.DeploymentScanningPluginFactory;
 import org.jboss.scanning.plugins.DeploymentUnitScanner;
 import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.scanning.spi.helpers.AbstractScanner;
 
 /**
  * Scanning deployer.

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/annotations/plugins/AnnotationsScanningPlugin.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -26,9 +26,9 @@
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.classloading.spi.visitor.ResourceVisitor;
 import org.jboss.scanning.annotations.spi.AnnotationIndex;
-import org.jboss.scanning.plugins.AbstractScanningPlugin;
 import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
 import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.spi.helpers.AbstractScanningPlugin;
 
 /**
  * Annotations scanning plugin.

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/HibernateScanningPlugin.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -31,9 +31,9 @@
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.classloading.spi.visitor.ResourceVisitor;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.scanning.plugins.AbstractScanningPlugin;
 import org.jboss.scanning.plugins.helpers.DeploymentUtilsFactory;
 import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.spi.helpers.AbstractScanningPlugin;
 
 import org.hibernate.ejb.packaging.Scanner;
 

Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/web/plugins/ResourcesIndexScanningPlugin.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -27,9 +27,9 @@
 import org.jboss.classloading.spi.visitor.ResourceFilter;
 import org.jboss.classloading.spi.visitor.ResourceVisitor;
 import org.jboss.scanning.annotations.spi.AnnotationIndex;
-import org.jboss.scanning.plugins.AbstractScanningPlugin;
 import org.jboss.scanning.plugins.helpers.ResourceOwnerFinder;
 import org.jboss.scanning.plugins.visitor.ReflectProvider;
+import org.jboss.scanning.spi.helpers.AbstractScanningPlugin;
 import org.jboss.scanning.web.spi.ResourcesIndex;
 
 /**

Deleted: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -1,89 +0,0 @@
-/*
- * 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.scanning.plugins;
-
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.jboss.scanning.spi.Scanner;
-import org.jboss.scanning.spi.ScanningPlugin;
-
-/**
- * Abstract scanner.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public abstract class AbstractScanner implements Scanner
-{
-   /** The plugins */
-   private Set<ScanningPlugin> plugins = new CopyOnWriteArraySet<ScanningPlugin>();
-
-   /**
-    * Add plugin.
-    *
-    * @param plugin the plugin
-    */
-   public void addPlugin(ScanningPlugin plugin)
-   {
-      if (plugin == null)
-         throw new IllegalArgumentException("Null plugin");
-
-      plugins.add(plugin);
-   }
-
-   /**
-    * Remove the plugin.
-    *
-    * @param plugin the plugin
-    */
-   public void removePlugin(ScanningPlugin plugin)
-   {
-      if (plugin == null)
-         return;
-
-      plugins.remove(plugin);
-   }
-
-   /**
-    * Get plugins.
-    *
-    * @return the plugins
-    */
-   public Set<ScanningPlugin> getPlugins()
-   {
-      return Collections.unmodifiableSet(plugins);
-   }
-
-   /**
-    * Set the plugins.
-    *
-    * @param plugins the plugins
-    */
-   public void setPlugins(Set<ScanningPlugin> plugins)
-   {
-      if (plugins == null)
-         throw new IllegalArgumentException("Null plugins");
-      this.plugins = plugins;
-   }
-}

Deleted: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -1,60 +0,0 @@
-/*
- * 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.scanning.plugins;
-
-import org.jboss.classloading.spi.visitor.ResourceContext;
-import org.jboss.scanning.spi.ScanningHandle;
-import org.jboss.scanning.spi.ScanningPlugin;
-
-/**
- * Abstract scanning plugin wrapper
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public abstract class AbstractScanningPlugin<T extends ScanningHandle, U> implements ScanningPlugin<T, U>
-{
-   public T createHandle()
-   {
-      T handle = doCreateHandle();
-      if (getHandleInterface().isInstance(handle) == false)
-         throw new IllegalArgumentException("Illegal handle type: " + handle + " != " + getHandleInterface());
-      return handle;
-   }
-
-   protected abstract T doCreateHandle();
-
-   public void cleanupHandle(U handle)
-   {
-      // by default, do nothing
-   }
-
-   public String getHandleKey()
-   {
-      return getHandleInterface().getName();
-   }
-
-   public boolean accepts(ResourceContext resource)
-   {
-      return getFilter().accepts(resource);
-   }
-}
\ No newline at end of file

Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DefaultScanner.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -32,6 +32,7 @@
 import org.jboss.classloading.spi.visitor.ResourceVisitor;
 import org.jboss.scanning.spi.ScanningHandle;
 import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.scanning.spi.helpers.UrlScanner;
 import org.jboss.vfs.VFS;
 import org.jboss.vfs.VirtualFile;
 

Modified: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/DeploymentUnitScanner.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -32,6 +32,7 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.scanning.spi.ScanningHandle;
 import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.scanning.spi.helpers.UrlScanner;
 
 /**
  * Per deployment unit scanner.

Deleted: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -1,97 +0,0 @@
-/*
- * 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.scanning.plugins;
-
-import java.net.URL;
-import java.util.List;
-
-import org.jboss.classloading.spi.visitor.ResourceContext;
-import org.jboss.classloading.spi.visitor.ResourceFilter;
-import org.jboss.scanning.spi.ScanningHandle;
-import org.jboss.scanning.spi.ScanningPlugin;
-import org.jboss.util.collection.CollectionsFactory;
-
-/**
- * Scanning plugin wrapper
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public class ScanningPluginWrapper<T extends ScanningHandle, U> implements ScanningPlugin<T, U>
-{
-   private ScanningPlugin<T, U> delegate;
-   private List<URL> excudedUrls = CollectionsFactory.createLazyList();
-
-   public ScanningPluginWrapper(ScanningPlugin<T, U> delegate)
-   {
-      this.delegate = delegate;
-   }
-
-   void addURL(URL url)
-   {
-      excudedUrls.add(url);
-   }
-
-   public T createHandle()
-   {
-      return delegate.createHandle();
-   }
-
-   public void cleanupHandle(U handle)
-   {
-      delegate.cleanupHandle(handle);
-   }
-
-   public Class<U> getHandleInterface()
-   {
-      return delegate.getHandleInterface();
-   }
-
-   public String getHandleKey()
-   {
-      return delegate.getHandleKey();
-   }
-
-   public boolean accepts(ResourceContext resource)
-   {
-      URL url = resource.getUrl();
-      String urlString = url.toString();
-      for (URL exceluded : excudedUrls)
-      {
-         String path = exceluded.getPath();
-         if (urlString.contains(path))
-            return false;
-      }
-
-      return delegate.accepts(resource);
-   }
-
-   public ResourceFilter getFilter()
-   {
-      return this;
-   }
-
-   public void visit(ResourceContext resource)
-   {
-      delegate.visit(resource);
-   }
-}
\ No newline at end of file

Deleted: projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java
===================================================================
--- projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java	2010-03-31 11:24:51 UTC (rev 103311)
+++ projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -1,120 +0,0 @@
-/*
- * 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.scanning.plugins;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.zip.GZIPInputStream;
-
-import org.jboss.logging.Logger;
-import org.jboss.scanning.spi.ScanningHandle;
-import org.jboss.scanning.spi.ScanningPlugin;
-
-/**
- * Url based scanner.
- *
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public abstract class UrlScanner extends AbstractScanner
-{
-   private Logger log = Logger.getLogger(getClass());
-   private URL[] roots;
-
-   protected UrlScanner(URL... roots)
-   {
-      if (roots == null)
-         throw new IllegalArgumentException("Null roots");
-      this.roots = roots;
-   }
-
-   protected URL[] getRoots()
-   {
-      return roots;
-   }
-
-   @SuppressWarnings("unchecked")
-   public void scan() throws Exception
-   {
-      Set<ScanningPlugin> federatedPlugins = new HashSet<ScanningPlugin>();
-      for (ScanningPlugin plugin : getPlugins())
-      {
-         ScanningHandle handle = createHandle(plugin);
-         ScanningPluginWrapper wrapper = new ScanningPluginWrapper(plugin);
-         federatedPlugins.add(wrapper);
-         String handleKey = plugin.getHandleKey();
-         for (URL root : roots)
-         {
-            InputStream is = getInputStream(root, handleKey + SUFFIX);
-            if (is != null)
-            {
-               ScanningHandle pre = readHandle(is);
-               handle.merge(pre);
-               wrapper.addURL(root); // exclude this url -- we already have pre-existing handle
-            }
-         }
-      }
-      scan(federatedPlugins);
-   }
-
-   protected abstract void scan(Set<ScanningPlugin> plugins) throws Exception;
-
-   protected InputStream getInputStream(URL url, String key)
-   {
-      try
-      {
-         String urlString = url.toExternalForm();
-         if (urlString.endsWith("/") == false)
-            urlString += "/";
-         urlString += key;
-         URL scanURL = new URL(urlString);
-         return scanURL.openStream();
-      }
-      catch (IOException e)
-      {
-         if (log.isTraceEnabled())
-            log.trace("Cannot access mcann.ser file: " + e);
-         return null;
-      }
-   }
-
-   protected ScanningHandle readHandle(InputStream is) throws Exception
-   {
-      ObjectInputStream ois;
-      try
-      {
-         GZIPInputStream gis = new GZIPInputStream(is);
-         ois = new ObjectInputStream(gis);
-      }
-      finally
-      {
-         is.close();
-      }
-      return (ScanningHandle) ois.readObject();
-   }
-
-   protected abstract ScanningHandle createHandle(ScanningPlugin plugin);
-}

Copied: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanner.java (from rev 103262, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanner.java)
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanner.java	                        (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanner.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -0,0 +1,89 @@
+/*
+ * 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.scanning.spi.helpers;
+
+import java.util.Collections;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import org.jboss.scanning.spi.Scanner;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Abstract scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractScanner implements Scanner
+{
+   /** The plugins */
+   private Set<ScanningPlugin> plugins = new CopyOnWriteArraySet<ScanningPlugin>();
+
+   /**
+    * Add plugin.
+    *
+    * @param plugin the plugin
+    */
+   public void addPlugin(ScanningPlugin plugin)
+   {
+      if (plugin == null)
+         throw new IllegalArgumentException("Null plugin");
+
+      plugins.add(plugin);
+   }
+
+   /**
+    * Remove the plugin.
+    *
+    * @param plugin the plugin
+    */
+   public void removePlugin(ScanningPlugin plugin)
+   {
+      if (plugin == null)
+         return;
+
+      plugins.remove(plugin);
+   }
+
+   /**
+    * Get plugins.
+    *
+    * @return the plugins
+    */
+   public Set<ScanningPlugin> getPlugins()
+   {
+      return Collections.unmodifiableSet(plugins);
+   }
+
+   /**
+    * Set the plugins.
+    *
+    * @param plugins the plugins
+    */
+   public void setPlugins(Set<ScanningPlugin> plugins)
+   {
+      if (plugins == null)
+         throw new IllegalArgumentException("Null plugins");
+      this.plugins = plugins;
+   }
+}

Copied: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanningPlugin.java (from rev 102852, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/AbstractScanningPlugin.java)
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanningPlugin.java	                        (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/AbstractScanningPlugin.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -0,0 +1,60 @@
+/*
+ * 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.scanning.spi.helpers;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Abstract scanning plugin wrapper
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractScanningPlugin<T extends ScanningHandle, U> implements ScanningPlugin<T, U>
+{
+   public T createHandle()
+   {
+      T handle = doCreateHandle();
+      if (getHandleInterface().isInstance(handle) == false)
+         throw new IllegalArgumentException("Illegal handle type: " + handle + " != " + getHandleInterface());
+      return handle;
+   }
+
+   protected abstract T doCreateHandle();
+
+   public void cleanupHandle(U handle)
+   {
+      // by default, do nothing
+   }
+
+   public String getHandleKey()
+   {
+      return getHandleInterface().getName();
+   }
+
+   public boolean accepts(ResourceContext resource)
+   {
+      return getFilter().accepts(resource);
+   }
+}
\ No newline at end of file

Copied: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningPluginWrapper.java (from rev 102852, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/ScanningPluginWrapper.java)
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningPluginWrapper.java	                        (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/ScanningPluginWrapper.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -0,0 +1,97 @@
+/*
+ * 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.scanning.spi.helpers;
+
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+import org.jboss.util.collection.CollectionsFactory;
+
+/**
+ * Scanning plugin wrapper
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ScanningPluginWrapper<T extends ScanningHandle, U> implements ScanningPlugin<T, U>
+{
+   private ScanningPlugin<T, U> delegate;
+   private List<URL> excudedUrls = CollectionsFactory.createLazyList();
+
+   public ScanningPluginWrapper(ScanningPlugin<T, U> delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   void addURL(URL url)
+   {
+      excudedUrls.add(url);
+   }
+
+   public T createHandle()
+   {
+      return delegate.createHandle();
+   }
+
+   public void cleanupHandle(U handle)
+   {
+      delegate.cleanupHandle(handle);
+   }
+
+   public Class<U> getHandleInterface()
+   {
+      return delegate.getHandleInterface();
+   }
+
+   public String getHandleKey()
+   {
+      return delegate.getHandleKey();
+   }
+
+   public boolean accepts(ResourceContext resource)
+   {
+      URL url = resource.getUrl();
+      String urlString = url.toString();
+      for (URL exceluded : excudedUrls)
+      {
+         String path = exceluded.getPath();
+         if (urlString.contains(path))
+            return false;
+      }
+
+      return delegate.accepts(resource);
+   }
+
+   public ResourceFilter getFilter()
+   {
+      return this;
+   }
+
+   public void visit(ResourceContext resource)
+   {
+      delegate.visit(resource);
+   }
+}
\ No newline at end of file

Copied: projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java (from rev 102600, projects/scanning/trunk/scanning-impl/src/main/java/org/jboss/scanning/plugins/UrlScanner.java)
===================================================================
--- projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java	                        (rev 0)
+++ projects/scanning/trunk/scanning-spi/src/main/java/org/jboss/scanning/spi/helpers/UrlScanner.java	2010-03-31 11:59:33 UTC (rev 103312)
@@ -0,0 +1,120 @@
+/*
+ * 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.scanning.spi.helpers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.zip.GZIPInputStream;
+
+import org.jboss.logging.Logger;
+import org.jboss.scanning.spi.ScanningHandle;
+import org.jboss.scanning.spi.ScanningPlugin;
+
+/**
+ * Url based scanner.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class UrlScanner extends AbstractScanner
+{
+   private Logger log = Logger.getLogger(getClass());
+   private URL[] roots;
+
+   protected UrlScanner(URL... roots)
+   {
+      if (roots == null)
+         throw new IllegalArgumentException("Null roots");
+      this.roots = roots;
+   }
+
+   protected URL[] getRoots()
+   {
+      return roots;
+   }
+
+   @SuppressWarnings("unchecked")
+   public void scan() throws Exception
+   {
+      Set<ScanningPlugin> federatedPlugins = new HashSet<ScanningPlugin>();
+      for (ScanningPlugin plugin : getPlugins())
+      {
+         ScanningHandle handle = createHandle(plugin);
+         ScanningPluginWrapper wrapper = new ScanningPluginWrapper(plugin);
+         federatedPlugins.add(wrapper);
+         String handleKey = plugin.getHandleKey();
+         for (URL root : roots)
+         {
+            InputStream is = getInputStream(root, handleKey + SUFFIX);
+            if (is != null)
+            {
+               ScanningHandle pre = readHandle(is);
+               handle.merge(pre);
+               wrapper.addURL(root); // exclude this url -- we already have pre-existing handle
+            }
+         }
+      }
+      scan(federatedPlugins);
+   }
+
+   protected abstract void scan(Set<ScanningPlugin> plugins) throws Exception;
+
+   protected InputStream getInputStream(URL url, String key)
+   {
+      try
+      {
+         String urlString = url.toExternalForm();
+         if (urlString.endsWith("/") == false)
+            urlString += "/";
+         urlString += key;
+         URL scanURL = new URL(urlString);
+         return scanURL.openStream();
+      }
+      catch (IOException e)
+      {
+         if (log.isTraceEnabled())
+            log.trace("Cannot access mcann.ser file: " + e);
+         return null;
+      }
+   }
+
+   protected ScanningHandle readHandle(InputStream is) throws Exception
+   {
+      ObjectInputStream ois;
+      try
+      {
+         GZIPInputStream gis = new GZIPInputStream(is);
+         ois = new ObjectInputStream(gis);
+      }
+      finally
+      {
+         is.close();
+      }
+      return (ScanningHandle) ois.readObject();
+   }
+
+   protected abstract ScanningHandle createHandle(ScanningPlugin plugin);
+}




More information about the jboss-cvs-commits mailing list