[jboss-cvs] JBossAS SVN: r76568 - in projects/jboss-deployers/trunk: deployers-vfs/src/main/org/jboss/deployers/vfs/plugins and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 1 07:45:56 EDT 2008
Author: alesj
Date: 2008-08-01 07:45:56 -0400 (Fri, 01 Aug 2008)
New Revision: 76568
Added:
projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/annotations/
projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java
Modified:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java
projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java
Log:
Initial AnnEnv deployer.
Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java 2008-08-01 11:42:05 UTC (rev 76567)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java 2008-08-01 11:45:56 UTC (rev 76568)
@@ -128,15 +128,16 @@
*/
protected void visitModule(DeploymentUnit unit, Module module, GenericAnnotationResourceVisitor visitor)
{
- module.visit(visitor, null, null, getUrls());
+ module.visit(visitor, null, null, getUrls(unit));
}
/**
* Get the new root urls.
*
+ * @param unit the deployment unit
* @return the new root urls
*/
- protected URL[] getUrls()
+ protected URL[] getUrls(DeploymentUnit unit)
{
return null;
}
@@ -147,7 +148,6 @@
log.trace("Creating AnnotationEnvironment for " + unit.getName() + ", module: " + module + ", force annotations: " + forceAnnotations);
ClassLoader classLoader = unit.getClassLoader();
-
ClassPool pool = createClassPool(classLoader);
GenericAnnotationResourceVisitor visitor = createGenericAnnotationResourceVisitor(unit, pool, classLoader);
Added: projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/annotations/AnnotationEnvironmentDeployer.java 2008-08-01 11:45:56 UTC (rev 76568)
@@ -0,0 +1,210 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.deployers.vfs.plugins.annotations;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.ClassPath;
+import javassist.ClassPool;
+import javassist.LoaderClassPath;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.plugins.annotations.GenericAnnotationResourceVisitor;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.annotations.AnnotationEnvironment;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.deployer.AbstractOptionalVFSRealDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A POST_CLASSLOADER deployer which creates AnnotationEnvironment for sub-deployments.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AnnotationEnvironmentDeployer extends AbstractOptionalVFSRealDeployer<Module>
+{
+ private boolean forceAnnotations;
+ private boolean keepAnnotations;
+ private boolean checkInterfaces;
+
+ public AnnotationEnvironmentDeployer()
+ {
+ super(Module.class);
+ setStage(DeploymentStages.POST_CLASSLOADER);
+ setOutput(AnnotationEnvironment.class);
+ checkInterfaces = true;
+ }
+
+ /**
+ * Should we force all annotations to be available.
+ *
+ * @param forceAnnotations the force annotations flag
+ */
+ public void setForceAnnotations(boolean forceAnnotations)
+ {
+ this.forceAnnotations = forceAnnotations;
+ }
+
+ /**
+ * Set the keep annotations flag.
+ *
+ * @param keepAnnotations the keep annotations flag
+ */
+ public void setKeepAnnotations(boolean keepAnnotations)
+ {
+ this.keepAnnotations = keepAnnotations;
+ }
+
+ /**
+ * Should we check interfaces for annotations as well.
+ *
+ * @param checkInterfaces the check interfaces flag
+ */
+ public void setCheckInterfaces(boolean checkInterfaces)
+ {
+ this.checkInterfaces = checkInterfaces;
+ }
+
+ /**
+ * Create GenericAnnotationResourceVisitor.
+ *
+ * Can be used change existing GARV's filter.
+ * Or determin if we need to force/keep annotations.
+ *
+ * @param unit the deployment unit
+ * @param pool the class pool
+ * @param classLoader the classloader
+ * @return new generic annotation visitor
+ */
+ protected GenericAnnotationResourceVisitor createGenericAnnotationResourceVisitor(DeploymentUnit unit, ClassPool pool, ClassLoader classLoader)
+ {
+ GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(pool, classLoader);
+ visitor.setForceAnnotations(forceAnnotations);
+ visitor.setKeepAnnotations(keepAnnotations);
+ visitor.setCheckInterfaces(checkInterfaces);
+ return visitor;
+ }
+
+ /**
+ * Create class pool.
+ *
+ * @param classLoader the class loader
+ * @return javassist class pool
+ */
+ protected ClassPool createClassPool(ClassLoader classLoader)
+ {
+ ClassPool pool = new ClassPool();
+ ClassPath classPath = new LoaderClassPath(classLoader);
+ pool.insertClassPath(classPath);
+ return pool;
+ }
+
+ /**
+ * Visit module.
+ *
+ * Util method to add some behavior to Module
+ * before we visit it.
+ *
+ * @param unit the deployment unit
+ * @param module the module
+ * @param visitor the resource visitor
+ * @throws DeploymentException for any error
+ */
+ protected void visitModule(VFSDeploymentUnit unit, Module module, GenericAnnotationResourceVisitor visitor) throws DeploymentException
+ {
+ try
+ {
+ module.visit(visitor, null, null, getURL(unit));
+ }
+ catch (Exception e)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Exception visiting module", e);
+ }
+ }
+
+ /**
+ * Get the matching urls.
+ *
+ * @param unit the deployment unit
+ * @return matching urls
+ * @throws Exception for any error
+ */
+ protected static URL[] getURL(VFSDeploymentUnit unit) throws Exception
+ {
+ List<VirtualFile> classpath = unit.getClassPath();
+ if (classpath != null && classpath.isEmpty() == false)
+ {
+ List<URL> urls = new ArrayList<URL>();
+ VirtualFile root = unit.getRoot();
+ for (VirtualFile cp : classpath)
+ {
+ VirtualFile check = cp;
+ while(check != null && check.equals(root) == false)
+ check = check.getParent();
+
+ if (check != null)
+ urls.add(cp.toURL());
+ }
+ return urls.toArray(new URL[urls.size()]);
+ }
+ return new URL[0];
+ }
+
+ public void deploy(VFSDeploymentUnit unit, Module module) throws DeploymentException
+ {
+ if (module == null)
+ {
+ VFSDeploymentUnit parent = unit.getParent();
+ while(parent != null && module == null)
+ {
+ module = parent.getAttachment(Module.class);
+ parent = parent.getParent();
+ }
+ if (module == null)
+ throw new IllegalArgumentException("No module in deployment unit's hierarchy: " + unit.getName());
+ }
+
+ if (log.isTraceEnabled())
+ log.trace("Creating AnnotationEnvironment for " + unit.getName() + ", module: " + module + ", force annotations: " + forceAnnotations);
+
+ ClassLoader classLoader = unit.getClassLoader();
+ ClassPool pool = createClassPool(classLoader);
+ GenericAnnotationResourceVisitor visitor = createGenericAnnotationResourceVisitor(unit, pool, classLoader);
+
+ // something in javassist uses TCL
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(classLoader);
+ try
+ {
+ visitModule(unit, module, visitor);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+
+ unit.addAttachment(AnnotationEnvironment.class, visitor.getEnv());
+ }
+}
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-08-01 11:42:05 UTC (rev 76567)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java 2008-08-01 11:45:56 UTC (rev 76568)
@@ -24,7 +24,6 @@
import java.net.URL;
import java.util.List;
import java.util.Set;
-import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jboss.classloader.spi.filter.ClassFilter;
@@ -39,7 +38,6 @@
import org.jboss.deployers.plugins.classloading.AbstractDeploymentClassLoaderPolicyModule;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VFS;
/**
* VFSDeploymentClassLoaderPolicyModule.
@@ -157,65 +155,9 @@
VirtualFile[] roots = vfsRoots;
if (roots != null && roots.length > 0)
{
- if (urls != null && urls.length > 0)
- roots = matchUrlsWithRoots(urls, roots);
-
ClassFilter included = getIncluded();
ClassFilter excluded = getExcluded();
- VFSResourceVisitor.visit(roots, excludedRoots, included, excluded, classLoader, visitor, filter, recurseFilter);
+ VFSResourceVisitor.visit(roots, excludedRoots, included, excluded, classLoader, visitor, filter, recurseFilter, urls);
}
}
-
- /**
- * Match urls with roots.
- *
- * @param urls the urls
- * @param roots the old roots
- * @return new roots
- */
- protected static VirtualFile[] matchUrlsWithRoots(URL[] urls, VirtualFile[] roots)
- {
- try
- {
- String[] rootURLStrings = new String[urls.length];
- List<VirtualFile> newRoots = new ArrayList<VirtualFile>(urls.length);
- for (URL url : urls)
- {
- String urlString = stripProtocol(url);
- for(int i=0; i < roots.length; i++)
- {
- if (rootURLStrings[i] == null)
- rootURLStrings[i] = stripProtocol(roots[i].toURL());
-
- if (urlString.startsWith(rootURLStrings[i]))
- {
- VirtualFile newRoot = VFS.getRoot(url);
- newRoots.add(newRoot);
- break;
- }
- }
- }
- return newRoots.toArray(new VirtualFile[newRoots.size()]);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Cannot match urls to roots.", e);
- }
- }
-
- /**
- * Strip the url protocol.
- *
- * @param url the url
- * @return url external form w/o protocol
- */
- protected static String stripProtocol(URL url)
- {
- if (url == null)
- throw new IllegalArgumentException("Null url");
-
- String urlString = url.toExternalForm();
- int p = urlString.indexOf(":/");
- return urlString.substring(p + 2);
- }
}
More information about the jboss-cvs-commits
mailing list