[jboss-cvs] JBossAS SVN: r78758 - in branches/Branch_AOP_1_5/aop: src/main/org/jboss/aop/annotation and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 22 12:24:30 EDT 2008
Author: kabir.khan at jboss.com
Date: 2008-09-22 12:24:29 -0400 (Mon, 22 Sep 2008)
New Revision: 78758
Added:
branches/Branch_AOP_1_5/aop/src/resources/test/annotationproperty/
branches/Branch_AOP_1_5/aop/src/resources/test/annotationproperty/annotations-aop.xml
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java
Modified:
branches/Branch_AOP_1_5/aop/build.xml
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/annotation/AnnotationCreator.java
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java
Log:
[JBAOP-633] system properties replacement in jboss-aop.xml
Modified: branches/Branch_AOP_1_5/aop/build.xml
===================================================================
--- branches/Branch_AOP_1_5/aop/build.xml 2008-09-22 15:07:56 UTC (rev 78757)
+++ branches/Branch_AOP_1_5/aop/build.xml 2008-09-22 16:24:29 UTC (rev 78758)
@@ -789,7 +789,6 @@
<antcall target="_run-bootclasspath-test" inheritRefs="true">
<param name="test" value="precedence"/>
</antcall>
-
</target>
<target name="_run-bootclasspath-test">
@@ -1195,6 +1194,16 @@
<formatter type="plain" extension="-jdk50.txt"/>
<test name="org.jboss.test.aop.container.ContainerTestCase" todir="${build.reports}"/>
</junit>
+ <junit printsummary="yes" fork="no" haltonfailure="no" >
+ <classpath>
+ <path refid="test.classpath"/>
+ <pathelement location="${build.tests.classes}"/>
+ <pathelement location="docs"/>
+ </classpath>
+ <formatter type="plain"/>
+ <formatter type="xml"/>
+ <test fork="yes" name="org.jboss.test.aop.annotationproperty.AnnotationPropertyReplacementTestCase" todir="${build.reports}"/>
+ </junit>
</target>
<!-- ==================================================================================== -->
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/annotation/AnnotationCreator.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/annotation/AnnotationCreator.java 2008-09-22 15:07:56 UTC (rev 78757)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/annotation/AnnotationCreator.java 2008-09-22 16:24:29 UTC (rev 78758)
@@ -34,6 +34,7 @@
import org.jboss.aop.annotation.ast.AnnotationParserVisitor;
import org.jboss.aop.annotation.ast.Node;
import org.jboss.aop.annotation.ast.SimpleNode;
+import org.jboss.util.StringPropertyReplacer;
import java.io.StringReader;
import java.lang.reflect.Array;
@@ -301,7 +302,8 @@
public static Object createAnnotation(String annotationExpr, Class annotation) throws Exception
{
- AnnotationParser parser = new AnnotationParser(new StringReader(annotationExpr));
+ String expr = StringPropertyReplacer.replaceProperties(annotationExpr);
+ AnnotationParser parser = new AnnotationParser(new StringReader(expr));
org.jboss.aop.annotation.ast.ASTStart start = parser.Start();
ASTAnnotation node = (ASTAnnotation) start.jjtGetChild(0);
return createAnnotation(node, annotation);
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java 2008-09-22 15:07:56 UTC (rev 78757)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/introduction/AnnotationIntroduction.java 2008-09-22 16:24:29 UTC (rev 78758)
@@ -26,12 +26,14 @@
import javassist.CtField;
import javassist.CtMethod;
import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
import org.jboss.aop.annotation.ast.ASTAnnotation;
import org.jboss.aop.annotation.ast.AnnotationParser;
import org.jboss.aop.annotation.ast.ParseException;
import org.jboss.aop.pointcut.AnnotationMatcher;
import org.jboss.aop.pointcut.ast.ASTStart;
import org.jboss.aop.pointcut.ast.TypeExpressionParser;
+import org.jboss.util.StringPropertyReplacer;
import java.io.StringReader;
import java.lang.reflect.Constructor;
@@ -85,11 +87,15 @@
private AnnotationIntroduction(String expr, String annotationExpr, boolean invisible)
{
this.invisible = invisible;
- originalAnnotationExpr = annotationExpr;
+ originalAnnotationExpr = StringPropertyReplacer.replaceProperties(annotationExpr);
originalExpression = expr;
try
{
- AnnotationParser parser = new AnnotationParser(new StringReader(annotationExpr));
+ if (AspectManager.verbose)
+ {
+ System.out.println("Creating annotation from " + originalAnnotationExpr);
+ }
+ AnnotationParser parser = new AnnotationParser(new StringReader(originalAnnotationExpr));
org.jboss.aop.annotation.ast.ASTStart start = parser.Start();
annotation = (ASTAnnotation) start.jjtGetChild(0);
}
Added: branches/Branch_AOP_1_5/aop/src/resources/test/annotationproperty/annotations-aop.xml
===================================================================
--- branches/Branch_AOP_1_5/aop/src/resources/test/annotationproperty/annotations-aop.xml (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/resources/test/annotationproperty/annotations-aop.xml 2008-09-22 16:24:29 UTC (rev 78758)
@@ -0,0 +1,8 @@
+<aop>
+ <annotation-introduction expr="class(org.jboss.test.aop.annotationproperty.POJO)">
+ @org.jboss.test.aop.annotationproperty.SimpleValue("${value1}")
+ </annotation-introduction>
+ <annotation expr="class(org.jboss.test.aop.annotationproperty.POJO)">
+ @org.jboss.test.aop.annotationproperty.Complex(ch='${ch}', string="${string}", flt=${flt}, dbl=${dbl}, shrt=${shrt}, lng=${lng}, integer=${integer}, bool=${bool}, annotation=${annotation}, array=${array}, clazz=${clazz})
+ </annotation>
+</aop>
\ No newline at end of file
Added: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/AnnotationPropertyReplacementTestCase.java 2008-09-22 16:24:29 UTC (rev 78758)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.test.aop.annotationproperty;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.aop.annotation.AnnotationCreator;
+import org.jboss.aop.introduction.AnnotationIntroduction;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
+ * @version $Revision: 75505 $
+ */
+public class AnnotationPropertyReplacementTestCase extends TestCase
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("AOPTester");
+ suite.addTestSuite(AnnotationPropertyReplacementTestCase.class);
+ return suite;
+ }
+
+ public AnnotationPropertyReplacementTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ public void testPropertyReplacement() throws Exception
+ {
+ AccessController.doPrivileged(new PrivilegedAction() {
+
+ public Object run()
+ {
+ //Properties for the @SimpleValue
+ System.setProperty("value1", "Test");
+
+ //Properties for the @Complex
+ System.setProperty("ch", "a");
+ System.setProperty("string", "Test123");
+ System.setProperty("flt", "9.9");
+ System.setProperty("dbl", "123456789.99");
+ System.setProperty("shrt", "1");
+ System.setProperty("lng", "987654321");
+ System.setProperty("integer", "123");
+ System.setProperty("bool", "true");
+ System.setProperty("annotation", "@org.jboss.test.aop.annotationproperty.SimpleValue(\"Yes\")");
+ System.setProperty("array", "{\"Test\", \"123\"}");
+ System.setProperty("clazz", "java.lang.Long.class");
+ return null;
+ }});
+
+ URL url = getURLRelativeToProjectRoot("/src/resources/test/annotationproperty/annotations-aop.xml");
+ AspectXmlLoader.deployXML(url);
+
+ List introductions = AspectManager.instance().getAnnotationIntroductions();
+ assertEquals(1, introductions.size());
+
+ SimpleValue value = (SimpleValue)AnnotationCreator.createAnnotation(((AnnotationIntroduction)introductions.get(0)).getOriginalAnnotationExpr(), SimpleValue.class);
+ assertNotNull(value);
+ assertEquals("Test", value.value());
+
+ List overrides = AspectManager.instance().getAnnotationOverrides();
+ assertEquals(1, overrides.size());
+
+ Complex complex = (Complex)AnnotationCreator.createAnnotation(((AnnotationIntroduction)overrides.get(0)).getOriginalAnnotationExpr(), Complex.class);
+ assertNotNull(complex);
+ assertEquals('a', complex.ch());
+ assertEquals("Test123", complex.string());
+ assertEquals(9,9, complex.flt());
+ assertTrue(123456789.99 == complex.dbl());
+ assertEquals(1, complex.shrt());
+ assertEquals(987654321, complex.lng());
+ assertEquals(123, complex.integer());
+ assertEquals(true, complex.bool());
+ assertEquals(Long.class, complex.clazz());
+ assertEquals("Yes", complex.annotation().value());
+
+ assertEquals(2, complex.array().length);
+ assertEquals("Test", complex.array()[0]);
+ assertEquals("123", complex.array()[1]);
+ }
+
+
+
+ protected URL getURLRelativeToProjectRoot(String relativePath) throws IOException
+ {
+ URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation();
+ String location = url.toString();
+ int index = location.indexOf("/output/");
+ location = location.substring(0, index);
+
+ location = location + relativePath;
+ return new URL(location);
+ }
+
+}
+
Added: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/Complex.java 2008-09-22 16:24:29 UTC (rev 78758)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.test.aop.annotationproperty;
+
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 69888 $
+ */
+public interface Complex
+{
+ char ch();
+
+ String string();
+
+ float flt();
+
+ double dbl();
+
+ short shrt();
+
+ long lng();
+
+ int integer();
+
+ boolean bool();
+
+ SimpleValue annotation();
+
+ String[] array();
+
+ Class clazz();
+}
Added: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/annotationproperty/SimpleValue.java 2008-09-22 16:24:29 UTC (rev 78758)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.test.aop.annotationproperty;
+
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 46363 $
+ */
+public interface SimpleValue
+{
+ String value();
+}
More information about the jboss-cvs-commits
mailing list