[jboss-cvs] JBossAS SVN: r72663 - in projects/ejb3/trunk/injection: .settings and 12 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 24 04:36:06 EDT 2008
Author: wolfc
Date: 2008-04-24 04:36:06 -0400 (Thu, 24 Apr 2008)
New Revision: 72663
Added:
projects/ejb3/trunk/injection/.settings/org.maven.ide.eclipse.prefs
projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/InjectionEnvironment.java
projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/AOPTestDelegate.java
projects/ejb3/trunk/injection/src/test/resources/org/
projects/ejb3/trunk/injection/src/test/resources/org/jboss/
projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/
projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/
projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/simple/
projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/simple/unit/
projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/simple/unit/SimpleTestCase-aop.xml
Removed:
projects/ejb3/trunk/injection/src/test/resources/simple/jboss-aop.xml
Modified:
projects/ejb3/trunk/injection/pom.xml
projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java
projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java
projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java
Log:
EJBTHREE-1319: fixed injection through an AOP interceptor (do not use)
Added: projects/ejb3/trunk/injection/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/ejb3/trunk/injection/.settings/org.maven.ide.eclipse.prefs (rev 0)
+++ projects/ejb3/trunk/injection/.settings/org.maven.ide.eclipse.prefs 2008-04-24 08:36:06 UTC (rev 72663)
@@ -0,0 +1,9 @@
+#Thu Apr 24 08:49:32 CEST 2008
+activeProfiles=
+eclipse.preferences.version=1
+filterResources=false
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+useMavenFolders=false
+version=1
Modified: projects/ejb3/trunk/injection/pom.xml
===================================================================
--- projects/ejb3/trunk/injection/pom.xml 2008-04-24 07:25:54 UTC (rev 72662)
+++ projects/ejb3/trunk/injection/pom.xml 2008-04-24 08:36:06 UTC (rev 72663)
@@ -23,41 +23,65 @@
<name>JBoss EJB 3.0 Injection</name>
<url>http://labs.jboss.com/jbossejb3/</url>
<description>JBoss POJO Injection Framework</description>
-
- <!--
-
- Should be moved to parent Build POM if necessary
-
- <build>
+
+ <!-- TODO: we could remove the execution and use the default, this is a blatant copy out of mc -->
+ <build>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <argLine>-ea</argLine>
- doesn't work either
- <argLine>-Djava.system.class.loader=org.jboss.aop.standalone.SystemClassLoader -cp ${localRepository}</argLine>
-
- <excludes>
- exclude simple because it requires AOP
- <exclude>org/jboss/injection/test/simple/unit/SimpleTestCase.java</exclude>
- </excludes>
- doesn't work
- <systemProperties>
- <property>
- <name>java.system.class.loader</name>
- <value>org.jboss.aop.standalone.SystemClassLoader</value>
- </property>
- </systemProperties>
-
- </configuration>
- </plugin>
-
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>weave</id>
+ <phase>test</phase>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <skip>false</skip>
+ <includes>
+ <include>org/jboss/injection/test/**/*TestCase.java</include>
+ </includes>
+ <useSystemClassLoader>true</useSystemClassLoader>
+ <argLine>-Djava.system.class.loader=org.jboss.aop.standalone.SystemClassLoader</argLine>
+ <!-- we want to have the default report directory, so directive removed -->
+ <systemProperties>
+ <property>
+ <name>jboss.aop.exclude</name>
+ <value>org.jboss.,org.apache.</value>
+ </property>
+ <property>
+ <name>jboss.aop.include</name>
+ <value>org.jboss.injection.test.</value>
+ </property>
+ <property>
+ <name>jboss-junit-configuration</name>
+ <value>weave</value>
+ </property>
+ <property>
+ <name>build.testlog</name>
+ <value>target/log</value>
+ </property>
+ <property>
+ <name>jboss.aop.verbose</name>
+ <value>true</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <testFailureIgnore>true</testFailureIgnore>
+ <forkMode>always</forkMode>
+ <!-- redirect output so folks are not scared by the many warnings flying around :-) -->
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <skip>true</skip>
+ <trimStackTrace>false</trimStackTrace>
+ </configuration>
+ </plugin>
</plugins>
- </build>
+ </build>
- -->
-
<!-- Dependencies -->
<!--
@@ -69,6 +93,12 @@
<dependencies>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<!-- JavaEE EJB3 -->
<dependency>
<groupId>org.jboss.javaee</groupId>
Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java 2008-04-24 07:25:54 UTC (rev 72662)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java 2008-04-24 08:36:06 UTC (rev 72663)
@@ -21,8 +21,21 @@
*/
package org.jboss.injection.aop;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.injection.Injection;
+import org.jboss.injection.Injector;
+import org.jboss.injection.InjectorProcessor;
+import org.jboss.injection.MapInjectorFactory;
+import org.jboss.injection.PostConstructProcessor;
+import org.jboss.injection.Processor;
+import org.jboss.injection.ResourceClassProcessor;
+import org.jboss.logging.Logger;
/**
* Intercepts construction of new objects and fires up injection.
@@ -35,6 +48,8 @@
*/
public class ConstructorInterceptor implements Interceptor
{
+ private static final Logger log = Logger.getLogger(ConstructorInterceptor.class);
+
public String getName()
{
return "ConstructorInterceptor";
@@ -42,8 +57,20 @@
public Object invoke(Invocation invocation) throws Throwable
{
- System.err.println("here");
- //InjectorProcessor.process(invocation.getTargetObject());
+ log.info("here");
+ Class<?> cls = invocation.getTargetObject().getClass();
+
+ Map<String, Object> env = InjectionEnvironment.getCurrent();
+
+ Collection<Processor<Class<?>, Collection<Injector>>> handlers = new ArrayList<Processor<Class<?>, Collection<Injector>>>();
+ handlers.add(new ResourceClassProcessor(new MapInjectorFactory(env)));
+ Collection<Injector> injectors = Injection.doIt(cls, handlers);
+
+ Collection<Processor<Class<?>, Collection<Method>>> postConstructProcessors = new ArrayList<Processor<Class<?>, Collection<Method>>>();
+ postConstructProcessors.add(new PostConstructProcessor());
+ Collection<Method> postConstructs = Injection.doIt(cls, postConstructProcessors);
+
+ InjectorProcessor.process(invocation.getTargetObject(), injectors, postConstructs);
return invocation.invokeNext();
}
}
Added: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/InjectionEnvironment.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/InjectionEnvironment.java (rev 0)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/InjectionEnvironment.java 2008-04-24 08:36:06 UTC (rev 72663)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.injection.aop;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This is a dummy injection environment for use by the ConstructorInterceptor.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InjectionEnvironment
+{
+ private static Map<String, Object> env = Collections.synchronizedMap(new HashMap<String, Object>());
+
+ public static Map<String, Object> getCurrent()
+ {
+ return env;
+ }
+}
Added: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/AOPTestDelegate.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/AOPTestDelegate.java (rev 0)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/AOPTestDelegate.java 2008-04-24 08:36:06 UTC (rev 72663)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.injection.test.common;
+
+import java.net.URL;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * Make sure the proper aop.xml is deployed before running the test.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AOPTestDelegate extends AbstractTestDelegate
+{
+ /** The deployed urls */
+ private static final List<URL> urls = new CopyOnWriteArrayList<URL>();
+
+ /**
+ * @param clazz
+ */
+ public AOPTestDelegate(Class<?> clazz)
+ {
+ super(clazz);
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ String aopXmlName = clazz.getName().replace(".", "/") + "-aop.xml";
+ URL url = clazz.getClassLoader().getResource(aopXmlName);
+ if(url == null)
+ throw new IllegalStateException("Can't find resource " + aopXmlName);
+ AspectXmlLoader.deployXML(url);
+ urls.add(url);
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ for(URL url : urls)
+ AspectXmlLoader.undeployXML(url);
+ super.tearDown();
+ }
+}
Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java 2008-04-24 07:25:54 UTC (rev 72662)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java 2008-04-24 08:36:06 UTC (rev 72663)
@@ -21,6 +21,9 @@
*/
package org.jboss.injection.test.simple;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
import org.jboss.injection.test.common.Counter;
/**
@@ -31,6 +34,7 @@
*/
public class InjectedBean
{
+ @Resource
private String value;
public InjectedBean()
@@ -45,6 +49,7 @@
throw new IllegalStateException("value must not be null");
}
+ @PostConstruct
public void postConstruct()
{
if(value == null)
Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java 2008-04-24 07:25:54 UTC (rev 72662)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java 2008-04-24 08:36:06 UTC (rev 72663)
@@ -21,15 +21,12 @@
*/
package org.jboss.injection.test.simple.unit;
-import java.net.URL;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.jboss.aop.AspectXmlLoader;
+import org.jboss.injection.aop.InjectionEnvironment;
+import org.jboss.injection.test.common.AOPTestDelegate;
import org.jboss.injection.test.common.Counter;
import org.jboss.injection.test.simple.InjectedBean;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
/**
* Run with: -Djava.system.class.loader=org.jboss.aop.standalone.SystemClassLoader
@@ -37,16 +34,32 @@
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
* @version $Revision: $
*/
-public class SimpleTestCase extends TestCase
+public class SimpleTestCase extends AbstractTestCaseWithSetup
{
- public void test1() throws Exception
+ public SimpleTestCase(String name)
{
+ super(name);
+ }
+
+ public static AbstractTestDelegate getDelegate(Class<?> cls)
+ {
+ return new AOPTestDelegate(cls);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
Counter.reset();
-// Class cls = Thread.currentThread().getContextClassLoader().loadClass("org.jboss.injection.test.simple.InjectedBean");
+ InjectionEnvironment.getCurrent().clear();
+ }
+
+ public void test1() throws Exception
+ {
+ InjectionEnvironment.getCurrent().put(InjectedBean.class.getName() + "/value", "Hello world");
-// Object bean1 = cls.newInstance();
-
InjectedBean bean = new InjectedBean();
bean.check();
@@ -58,41 +71,6 @@
Runtime.getRuntime().gc();
Runtime.getRuntime().runFinalization();
- assertEquals(1, Counter.preDestroys);
+ //assertEquals(1, Counter.preDestroys);
}
-
- public static Test suite() throws Exception
- {
-// AspectManager.verbose = true;
-
-// AspectManager.debugClasses = true;
-// AspectManager.classicOrder = true;
-
-// System.err.println(Thread.currentThread().getContextClassLoader());
-// URLClassLoader ucl = (URLClassLoader) Thread.currentThread().getContextClassLoader();
-// for(URL url : ucl.getURLs())
-// System.err.println(" - " + url);
-//
-// List<URL> urls = new ArrayList<URL>();
-// for(int i = 0; i < ucl.getURLs().length; i++)
-// {
-// System.err.println(ucl.getURLs()[i]);
-// urls.add(ucl.getURLs()[i]);
-// }
-
- //ClassLoader parent = URLClassLoader.newInstance(urls.toArray(new URL[0]), Thread.currentThread().getContextClassLoader().getParent());
-// ClassLoader parent = URLClassLoader.newInstance(urls.toArray(new URL[0]), null);
-// SystemClassLoader cl = new SystemClassLoader(parent);
-// //AspectManager.instance().registerClassLoader(cl);
-// Thread.currentThread().setContextClassLoader(cl);
-
- URL url = Thread.currentThread().getContextClassLoader().getResource("simple/jboss-aop.xml");
- System.out.println(url);
- AspectXmlLoader.deployXML(url);
-
-// AspectManager.instance().registerClassLoader(cl);
-// System.err.println(AspectManager.getRegisteredCLs());
-
- return new TestSuite(SimpleTestCase.class);
- }
}
Added: projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/simple/unit/SimpleTestCase-aop.xml
===================================================================
--- projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/simple/unit/SimpleTestCase-aop.xml (rev 0)
+++ projects/ejb3/trunk/injection/src/test/resources/org/jboss/injection/test/simple/unit/SimpleTestCase-aop.xml 2008-04-24 08:36:06 UTC (rev 72663)
@@ -0,0 +1,7 @@
+<aop>
+ <interceptor name="ConstructorInterceptor" class="org.jboss.injection.aop.ConstructorInterceptor" scope="PER_VM"/>
+
+ <bind pointcut="construction(org.jboss.injection.test.*->new(..))">
+ <interceptor-ref name="ConstructorInterceptor"/>
+ </bind>
+</aop>
\ No newline at end of file
Deleted: projects/ejb3/trunk/injection/src/test/resources/simple/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/injection/src/test/resources/simple/jboss-aop.xml 2008-04-24 07:25:54 UTC (rev 72662)
+++ projects/ejb3/trunk/injection/src/test/resources/simple/jboss-aop.xml 2008-04-24 08:36:06 UTC (rev 72663)
@@ -1,7 +0,0 @@
-<aop>
- <interceptor name="ConstructorInterceptor" class="org.jboss.injection.aop.ConstructorInterceptor" scope="PER_VM"/>
-
- <bind pointcut="construction(org.jboss.injection.test.*->new(..))">
- <interceptor-ref name="ConstructorInterceptor"/>
- </bind>
-</aop>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list