[jboss-cvs] JBossAS SVN: r57565 - in trunk: aspects/src/jdk15/org/jboss/aop/deployers testsuite/src/jdk15/org/jboss/test/aop/deployers testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations testsuite/src/jdk15/org/jboss/test/aop/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 11 11:23:30 EDT 2006
Author: kabir.khan at jboss.com
Date: 2006-10-11 11:23:22 -0400 (Wed, 11 Oct 2006)
New Revision: 57565
Added:
trunk/aspects/src/jdk15/org/jboss/aop/deployers/ClassFileFilter.java
trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeAspect.java
trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeInterceptor.java
Modified:
trunk/aspects/src/jdk15/org/jboss/aop/deployers/AspectDeployer.java
trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/DeployersMonitor.java
trunk/testsuite/src/jdk15/org/jboss/test/aop/test/DeployersInitialTestCase.java
Log:
Get new AspectDeployer working with annotations and test
Modified: trunk/aspects/src/jdk15/org/jboss/aop/deployers/AspectDeployer.java
===================================================================
--- trunk/aspects/src/jdk15/org/jboss/aop/deployers/AspectDeployer.java 2006-10-11 15:00:33 UTC (rev 57564)
+++ trunk/aspects/src/jdk15/org/jboss/aop/deployers/AspectDeployer.java 2006-10-11 15:23:22 UTC (rev 57565)
@@ -21,19 +21,26 @@
*/
package org.jboss.aop.deployers;
+import org.jboss.aop.AspectAnnotationLoader;
import org.jboss.aop.AspectManager;
import org.jboss.aop.AspectXmlLoader;
import org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
import org.jboss.deployers.spi.deployer.DeploymentUnit;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
import org.jboss.virtual.plugins.context.jar.JarUtils;
+import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;
import org.jboss.logging.Logger;
import org.w3c.dom.Document;
+import java.io.DataInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import javassist.bytecode.ClassFile;
+
/**
* Deployer for Aspects
*
@@ -44,6 +51,7 @@
{
private static final Logger log = Logger.getLogger(AspectDeployer.class);
private static final String AOP_JAR_SUFFIX = ".aop";
+ private static final String AOP_DD_SUFFIX = "-aop.xml";
@Override
public int getRelativeOrder()
@@ -54,15 +62,41 @@
public void deploy(DeploymentUnit unit) throws DeploymentException
{
-// System.out.println("-------> ASPECT DEPLOYER!!!!!!!!!!!!!!!" + unit.getName());
- List<VirtualFile> files = unit.getMetaDataFiles(null, "-aop.xml");//WILL THIS FIND THINGS LIKE jboss-aop.xml files in the root of a sar?
+ List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
+ if (isAopArchiveOrFolder(unit))
+ {
+ deployAnnotations(unit);
+ }
+
+ if (files.size() > 0)
+ {
+ deployXml(unit, files);
+ }
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ List<VirtualFile> files = unit.getMetaDataFiles(null, AOP_DD_SUFFIX);
+
+ if (isAopArchiveOrFolder(unit))
+ {
+ undeployAnnotations(unit);
+ }
+
+ if (files.size() > 0)
+ {
+ undeployXml(unit, files);
+ }
+ }
+
+ private void deployXml(DeploymentUnit unit, List<VirtualFile> files) throws DeploymentException
+ {
for (VirtualFile vf : files)
{
-// System.out.println("-------> FOUND VIRTUAL FILE " + vf);
try
{
- log.info("************************************** deploying: " + vf.toURL());
+ log.debug("deploying: " + vf.toURL());
InputStream is = vf.openStream();
try
{
@@ -70,21 +104,6 @@
AspectXmlLoader loader = new AspectXmlLoader();
loader.setManager(AspectManager.instance());
loader.deployXML(doc, vf.toURL(), unit.getClassLoader());
-
-
-
- /* TODO need some way of handling annotations
- if (!di.isXML)
- {
- Iterator it = ArchiveBrowser.getBrowser(di.localUrl, new ClassFileFilter());
- AspectAnnotationLoader loader = new AspectAnnotationLoader(AspectManager.instance());
- loader.deployInputStreamIterator(it);
- }
-
- AspectXmlLoader.deployXML(docURL, scl);
- Notification msg = new Notification("AOP Deploy", this, getNextNotificationSequenceNumber());
- sendNotification(msg);
- */
}
finally
{
@@ -98,14 +117,13 @@
}
}
- public void undeploy(DeploymentUnit unit)
+ private void undeployXml(DeploymentUnit unit, List<VirtualFile> files)
{
- List<VirtualFile> files = unit.getMetaDataFiles(null, "-aop.xml");
for (VirtualFile vf : files)
{
try
{
- log.info("************************************** undeploying: " + vf.toURL());
+ log.debug("undeploying: " + vf.toURL());
InputStream is = vf.openStream();
try
{
@@ -113,21 +131,10 @@
AspectXmlLoader loader = new AspectXmlLoader();
loader.setManager(AspectManager.instance());
loader.undeployXML(doc, vf.toURL());
- /* TODO need some way of handling annotations
- if (!di.isXML)
- {
- Iterator it = ArchiveBrowser.getBrowser(di.localUrl, new ClassFileFilter());
- AspectAnnotationLoader loader = new AspectAnnotationLoader(AspectManager.instance());
- loader.undeployInputStreamIterator(it);
- }
-
- Notification msg = new Notification("AOP Undeploy", this, getNextNotificationSequenceNumber());
- sendNotification(msg);
- */
}
finally
{
- is.close();
+ is.close();
}
}
catch (Exception e)
@@ -137,4 +144,115 @@
}
}
+ private void deployAnnotations(DeploymentUnit unit) throws DeploymentException
+ {
+ AspectAnnotationLoader loader = new AspectAnnotationLoader(AspectManager.instance());
+ List<VirtualFile> files = getClasses(unit);
+ for(VirtualFile file : files)
+ {
+ ClassFile cf = loadClassFile(file);
+
+ try
+ {
+ log.debug("Deploying possibly annotated class " + cf.getName());
+ loader.deployClassFile(cf);
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException("Error reading annotations for " + file, e);
+ }
+ }
+ }
+
+ private void undeployAnnotations(DeploymentUnit unit)
+ {
+ AspectAnnotationLoader loader = new AspectAnnotationLoader(AspectManager.instance());
+ List<VirtualFile> files = getClasses(unit);
+ for(VirtualFile file : files)
+ {
+ ClassFile cf = loadClassFile(file);
+
+ try
+ {
+ log.debug("Undeploying possibly annotated class " + cf.getName());
+ loader.undeployClassFile(cf);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error reading annotations for " + file, e);
+ }
+ }
+ }
+
+ private ClassFile loadClassFile(VirtualFile file)
+ {
+ DataInputStream din = null;
+ ClassFile cf = null;
+ try
+ {
+ InputStream in = file.openStream();
+ din = new DataInputStream(in);
+ cf = new ClassFile(din);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error reading " + file, e);
+ }
+ finally
+ {
+ try
+ {
+ din.close();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Error closing input stream for " + file, e);
+ }
+ }
+
+ return cf;
+ }
+
+ private List<VirtualFile> getClasses(DeploymentUnit unit)
+ {
+ VisitorAttributes va = new VisitorAttributes();
+ va.setRecurse(true);
+ va.setLeavesOnly(true);
+ va.setRecurseArchives(false);
+ ClassFileFilter filter = new ClassFileFilter();
+ FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va);
+
+ for (VirtualFile vf : unit.getDeploymentContext().getClassPath())
+ {
+ try
+ {
+ vf.visit(visitor);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return visitor.getMatched();
+
+ }
+
+ private boolean isAopArchiveOrFolder(DeploymentUnit unit)
+ {
+ String name = unit.getName();
+
+ //If name is of format 'blah-blah.aop!/' get rid of the trailing '!' and '/', and see if it ends with .aop
+ int index = name.length();
+ if (name.charAt(name.length() - 1) == '/')
+ {
+ index--;
+ }
+ if (name.charAt(name.length() - 2) == '!')
+ {
+ index--;
+ }
+ String realName = (index == name.length()) ? name : name.substring(0, index);
+
+ return (realName.endsWith(AOP_JAR_SUFFIX));
+ }
}
Added: trunk/aspects/src/jdk15/org/jboss/aop/deployers/ClassFileFilter.java
===================================================================
--- trunk/aspects/src/jdk15/org/jboss/aop/deployers/ClassFileFilter.java 2006-10-11 15:00:33 UTC (rev 57564)
+++ trunk/aspects/src/jdk15/org/jboss/aop/deployers/ClassFileFilter.java 2006-10-11 15:23:22 UTC (rev 57565)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.aop.deployers;
+
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFile;
+
+import java.io.IOException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 44334 $
+ */
+public class ClassFileFilter implements VirtualFileFilter
+{
+ public boolean accepts(VirtualFile file)
+ {
+ try
+ {
+ return !file.isArchive() && file.isLeaf() && file.getName().endsWith(".class");
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Modified: trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/DeployersMonitor.java
===================================================================
--- trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/DeployersMonitor.java 2006-10-11 15:00:33 UTC (rev 57564)
+++ trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/DeployersMonitor.java 2006-10-11 15:23:22 UTC (rev 57565)
@@ -88,5 +88,15 @@
public void invokeAnnotationPOJO() throws Exception
{
+ org.jboss.test.aop.deployers.annotations.POJO pojo = new org.jboss.test.aop.deployers.annotations.POJO();
+ org.jboss.test.aop.deployers.annotations.POJO.invoked = false;
+ org.jboss.test.aop.deployers.annotations.SomeInterceptor.invoked = 0;
+ org.jboss.test.aop.deployers.annotations.SomeAspect.invoked = 0;
+
+ pojo.someMethod();
+
+ if (org.jboss.test.aop.deployers.annotations.SomeInterceptor.invoked != 1) throw new RuntimeException("SomeInterceptor should have intercepted 1 times not " + org.jboss.test.aop.deployers.annotations.SomeInterceptor.invoked);
+ if (org.jboss.test.aop.deployers.annotations.SomeAspect.invoked != 1) throw new RuntimeException("SomeAspect should have intercepted 1 times not " + org.jboss.test.aop.deployers.annotations.SomeAspect.invoked);
+ if (!org.jboss.test.aop.deployers.annotations.POJO.invoked) throw new RuntimeException("POJO was not called");
}
}
Added: trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeAspect.java
===================================================================
--- trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeAspect.java 2006-10-11 15:00:33 UTC (rev 57564)
+++ trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeAspect.java 2006-10-11 15:23:22 UTC (rev 57565)
@@ -0,0 +1,45 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.aop.deployers.annotations;
+
+import org.jboss.aop.Aspect;
+import org.jboss.aop.Bind;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Aspect
+public class SomeAspect
+{
+ public static int invoked;
+
+ @Bind(pointcut="execution(* org.jboss.test.aop.deployers.annotations.POJO->someMethod())")
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ invoked++;
+ return invocation.invokeNext();
+ }
+
+}
Added: trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeInterceptor.java
===================================================================
--- trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeInterceptor.java 2006-10-11 15:00:33 UTC (rev 57564)
+++ trunk/testsuite/src/jdk15/org/jboss/test/aop/deployers/annotations/SomeInterceptor.java 2006-10-11 15:23:22 UTC (rev 57565)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.aop.deployers.annotations;
+
+import org.jboss.aop.Bind;
+import org.jboss.aop.InterceptorDef;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at InterceptorDef
+ at Bind(pointcut="execution(void org.jboss.test.aop.deployers.annotations.POJO->someMethod())")
+public class SomeInterceptor implements Interceptor
+{
+ public static int invoked;
+ public String getName()
+ {
+ return this.getClass().getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ invoked++;
+ return invocation.invokeNext();
+ }
+
+}
Modified: trunk/testsuite/src/jdk15/org/jboss/test/aop/test/DeployersInitialTestCase.java
===================================================================
--- trunk/testsuite/src/jdk15/org/jboss/test/aop/test/DeployersInitialTestCase.java 2006-10-11 15:00:33 UTC (rev 57564)
+++ trunk/testsuite/src/jdk15/org/jboss/test/aop/test/DeployersInitialTestCase.java 2006-10-11 15:23:22 UTC (rev 57565)
@@ -122,19 +122,47 @@
public void testAddAnnotationBindings() throws Exception
{
-// try
-// {
-// deploy("aop-deployertest-annotations.aop");
-// }
-// catch(Exception e)
-// {
-// throw e;
-// }
-// finally
-// {
-// undeploy("aop-deployertest-annotations.aop");
-// }
- throw new RuntimeException("Not yet implemented");
+ Map<String, String> initialBindings = (Map<String, String>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
+ Map<String, String> initialDefinitiona = (Map<String, String>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
+
+ try
+ {
+ deploy("aop-deployertest-annotations.aop");
+ Map<String, String> deployedBindings = (Map<String, String>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
+ Map<String, String> deployedDefinitiona = (Map<String, String>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
+
+ Map<String, String> newBindings = getInEndOnly(initialBindings, deployedBindings);
+ assertEquals("Wrong number of new bindings", 2, newBindings.size());
+
+ Map<String, String> newDefinitions = getInEndOnly(initialDefinitiona, deployedDefinitiona);
+ assertEquals("Wrong number of new aspect definitions", 2, newDefinitions.size());
+
+ HashSet<String> bindings = new HashSet<String>();
+ bindings.addAll(newBindings.values());
+ assertTrue("Could not find 'execution(* org.jboss.test.aop.deployers.annotations.POJO->someMethod())'", bindings.remove("execution(* org.jboss.test.aop.deployers.annotations.POJO->someMethod())"));
+ assertTrue("Could not find 'execution(void org.jboss.test.aop.deployers.annotations.POJO->someMethod())'", bindings.remove("execution(void org.jboss.test.aop.deployers.annotations.POJO->someMethod())"));
+
+ HashSet<String> definitions = new HashSet<String>();
+ definitions.addAll(newDefinitions.values());
+ assertTrue("Could not find 'org.jboss.test.aop.deployers.annotations.SomeInterceptor'", definitions.remove("org.jboss.test.aop.deployers.annotations.SomeInterceptor"));
+ assertTrue("Could not find 'org.jboss.test.aop.deployers.annotations.SomeAspect'", definitions.remove("org.jboss.test.aop.deployers.annotations.SomeAspect"));
+
+ getServer().invoke(DEPLOYER_MONITOR, "invokeAnnotationPOJO", new Object[0], new String[0]);
+ }
+ catch(Exception e)
+ {
+ throw e;
+ }
+ finally
+ {
+ undeploy("aop-deployertest-annotations.aop");
+ }
+
+ Map<String, String> finalBindings = (Map<String, String>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentBindings");
+ Map<String, String> finalAspectDefinitiona = (Map<String, String>)getServer().getAttribute(DEPLOYER_MONITOR, "CurrentAspectDefinitions");
+
+ compareSame(initialBindings, finalBindings);
+ compareSame(initialDefinitiona, finalAspectDefinitiona);
}
private static void compareSame(Map<String, String> initial, Map<String, String> end) throws Exception
More information about the jboss-cvs-commits
mailing list