[jboss-cvs] JBossAS SVN: r72804 - in projects/jboss-deployers/trunk: deployers-impl/src/main/org/jboss/deployers/plugins and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 28 19:45:39 EDT 2008
Author: alesj
Date: 2008-04-28 19:45:38 -0400 (Mon, 28 Apr 2008)
New Revision: 72804
Added:
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/
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/GenericAnnotationResourceVisitor.java
projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractResourceVisitorDeployer.java
Modified:
projects/jboss-deployers/trunk/build/pom.xml
Log:
[JBDEPLOY-13]; Initial annotation scanning.
TODO on tests.
Modified: projects/jboss-deployers/trunk/build/pom.xml
===================================================================
--- projects/jboss-deployers/trunk/build/pom.xml 2008-04-28 23:37:04 UTC (rev 72803)
+++ projects/jboss-deployers/trunk/build/pom.xml 2008-04-28 23:45:38 UTC (rev 72804)
@@ -23,7 +23,7 @@
<properties>
<version.jboss.man>2.0.0.Beta12</version.jboss.man>
<version.jboss.microcontainer>2.0.0.Beta13</version.jboss.microcontainer>
- <version.jboss.classloader>2.0.0.Beta11</version.jboss.classloader>
+ <version.jboss.classloader>2.0.0-SNAPSHOT</version.jboss.classloader>
<version.jboss.common.core>2.2.4.GA</version.jboss.common.core>
<version.jboss.common.logging.spi>2.0.4.GA</version.jboss.common.logging.spi>
<version.jboss.common.logging.log4j>2.0.4.GA</version.jboss.common.logging.log4j>
Added: 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 (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationDeployer.java 2008-04-28 23:45:38 UTC (rev 72804)
@@ -0,0 +1,53 @@
+/*
+* 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.plugins.annotations;
+
+import org.jboss.deployers.plugins.classloading.AbstractResourceVisitorDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+
+/**
+ * Generic annotation scanner deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GenericAnnotationDeployer extends AbstractResourceVisitorDeployer
+{
+ private boolean forceAnnotations;
+
+ /**
+ * Should we force all annotations to be available.
+ *
+ * @param forceAnnotations the force annotations flag
+ */
+ public void setForceAnnotations(boolean forceAnnotations)
+ {
+ this.forceAnnotations = forceAnnotations;
+ }
+
+ protected ResourceVisitor createVisitor(DeploymentUnit unit)
+ {
+ GenericAnnotationResourceVisitor visitor = new GenericAnnotationResourceVisitor(unit);
+ visitor.setForceAnnotations(forceAnnotations);
+ return visitor;
+ }
+}
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/annotations/GenericAnnotationResourceVisitor.java 2008-04-28 23:45:38 UTC (rev 72804)
@@ -0,0 +1,161 @@
+/*
+* 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.plugins.annotations;
+
+import java.lang.annotation.ElementType;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtMember;
+import javassist.NotFoundException;
+import org.jboss.classloading.spi.visitor.ClassFilter;
+import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+
+/**
+ * Generic annotation scanner deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class GenericAnnotationResourceVisitor implements ResourceVisitor
+{
+ private static final Logger log = Logger.getLogger(GenericAnnotationResourceVisitor.class);
+ private static final ClassPool pool = ClassPool.getDefault();
+
+ private DeploymentUnit unit;
+ private boolean forceAnnotations;
+
+ public GenericAnnotationResourceVisitor(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null deployment unit");
+ this.unit = unit;
+ }
+
+ public ResourceFilter getFilter()
+ {
+ return ClassFilter.INSTANCE;
+ }
+
+ public void visit(ResourceContext resource)
+ {
+ try
+ {
+ CtClass ctClass = pool.makeClass(resource.getInputStream());
+ try
+ {
+ handleCtClass(ctClass, resource);
+ }
+ finally
+ {
+ ctClass.detach();
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ if (forceAnnotations)
+ throw new RuntimeException(e);
+ else if (log.isTraceEnabled())
+ log.trace("Exception reading resource: " + resource.getResourceName(), e);
+ }
+ catch (Throwable t)
+ {
+ if (log.isTraceEnabled())
+ log.trace("Exception reading resource: " + resource.getResourceName(), t);
+ }
+ }
+
+ /**
+ * Handle CtClass for annotations.
+ *
+ * @param ctClass the ct class instance
+ * @param resource the resource we're visiting
+ * @throws ClassNotFoundException for any annotations lookup problems
+ * @throws NotFoundException for any annotations lookup problems
+ */
+ protected void handleCtClass(CtClass ctClass, ResourceContext resource) throws ClassNotFoundException, NotFoundException
+ {
+ Object[] annotations = forceAnnotations ? ctClass.getAnnotations() : ctClass.getAvailableAnnotations();
+ handleAnnotations(ElementType.TYPE, annotations, resource);
+ handleCtMembers(ElementType.CONSTRUCTOR, ctClass.getDeclaredConstructors(), resource);
+ handleCtMembers(ElementType.METHOD, ctClass.getDeclaredMethods(), resource);
+ handleCtMembers(ElementType.FIELD, ctClass.getDeclaredFields(), resource);
+
+ // interfaces
+ CtClass[] interfaces = ctClass.getInterfaces();
+ if (interfaces != null && interfaces.length > 0)
+ {
+ for (CtClass intf : interfaces)
+ handleCtClass(intf, resource);
+ }
+
+ // super class
+ ctClass = ctClass.getSuperclass();
+ if (ctClass != null)
+ handleCtClass(ctClass, resource);
+ }
+
+ /**
+ * Handle CtMembers for annotations.
+ *
+ * @param type where we found the annotations
+ * @param members the ct member instances
+ * @param resource the resource we're visiting
+ * @throws ClassNotFoundException for any annotations lookup problems
+ */
+ protected void handleCtMembers(ElementType type, CtMember[] members, ResourceContext resource) throws ClassNotFoundException
+ {
+ if (members != null && members.length > 0)
+ {
+ for (CtMember member : members)
+ {
+ Object[] annotations = forceAnnotations ? member.getAnnotations() : member.getAvailableAnnotations();
+ handleAnnotations(type, annotations, resource);
+ }
+ }
+ }
+
+ /**
+ * Handle annotations.
+ *
+ * @param type where we found the annotations
+ * @param annotations the actual annotations
+ * @param resource the resource we're visiting
+ */
+ protected void handleAnnotations(ElementType type, Object[] annotations, ResourceContext resource)
+ {
+ // todo
+ }
+
+ /**
+ * Should we force all annotations to be available.
+ *
+ * @param forceAnnotations the force annotations flag
+ */
+ public void setForceAnnotations(boolean forceAnnotations)
+ {
+ this.forceAnnotations = forceAnnotations;
+ }
+}
\ No newline at end of file
Added: projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractResourceVisitorDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractResourceVisitorDeployer.java (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractResourceVisitorDeployer.java 2008-04-28 23:45:38 UTC (rev 72804)
@@ -0,0 +1,96 @@
+/*
+* 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.plugins.classloading;
+
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+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;
+
+/**
+ * Abstract resource visitor deployer.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class AbstractResourceVisitorDeployer extends AbstractSimpleRealDeployer<Module>
+{
+ private ResourceVisitor visitor;
+ private ResourceFilter filter;
+
+ public AbstractResourceVisitorDeployer()
+ {
+ super(Module.class);
+ setStage(DeploymentStages.POST_CLASSLOADER);
+ }
+
+ public AbstractResourceVisitorDeployer(ResourceVisitor visitor)
+ {
+ this();
+ this.visitor = visitor;
+ }
+
+ public AbstractResourceVisitorDeployer(ResourceVisitor visitor, ResourceFilter filter)
+ {
+ this(visitor);
+ this.filter = filter;
+ }
+
+ public void deploy(DeploymentUnit unit, Module module) throws DeploymentException
+ {
+ ResourceVisitor currentVisitor = visitor;
+ if (currentVisitor == null)
+ currentVisitor = createVisitor(unit);
+ ResourceFilter currentFilter = filter;
+ if (currentFilter == null)
+ currentFilter = createFilter(unit);
+
+ if (currentFilter != null)
+ module.visit(currentVisitor, currentFilter);
+ else
+ module.visit(currentVisitor);
+ }
+
+ /**
+ * Create resource visitor from unit.
+ *
+ * @param unit the deployment unit
+ * @return new resource visitor
+ */
+ protected ResourceVisitor createVisitor(DeploymentUnit unit)
+ {
+ throw new UnsupportedOperationException("Missing resource visitor");
+ }
+
+ /**
+ * Create resource filter from unit.
+ *
+ * @param unit the deployment unit
+ * @return new resource filter
+ */
+ protected ResourceFilter createFilter(DeploymentUnit unit)
+ {
+ return null;
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list