summaryrefslogtreecommitdiffstats
path: root/tests/java5
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-10-28 12:07:14 +0000
committeravasseur <avasseur>2005-10-28 12:07:14 +0000
commit794f9b5eafe34a7dbb48cda3edaec59ff57afef5 (patch)
treee604dc616dec2d7525a9a9b1d8a0aea7817abf47 /tests/java5
parent8d479b227be4f8228265f37589b565b78f84d523 (diff)
downloadaspectj-794f9b5eafe34a7dbb48cda3edaec59ff57afef5.tar.gz
aspectj-794f9b5eafe34a7dbb48cda3edaec59ff57afef5.zip
#108892 cannot reproduce: hierarchy of aop.xml accross classloader test is fine
Diffstat (limited to 'tests/java5')
-rw-r--r--tests/java5/ataspectj/ajc-ant.xml27
-rw-r--r--tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java101
-rw-r--r--tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml6
-rw-r--r--tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml6
-rw-r--r--tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java42
5 files changed, 182 insertions, 0 deletions
diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml
index 077fc2667..5c4495be4 100644
--- a/tests/java5/ataspectj/ajc-ant.xml
+++ b/tests/java5/ataspectj/ajc-ant.xml
@@ -186,4 +186,31 @@
</java>
</target>
+ <target name="ltw.AppContainer">
+ <!-- mkdir the 2 sub app root folder -->
+ <mkdir dir="${aj.sandbox}/META-INF"/>
+ <mkdir dir="${aj.sandbox}/app_1"/>
+ <mkdir dir="${aj.sandbox}/app_1/META-INF"/>
+ <!-- install sub app -->
+ <copy todir="${aj.sandbox}/app_1">
+ <fileset dir="${aj.sandbox}" includes="ataspectj/hierarchy/app/*"/>
+ </copy>
+ <copy todir="${aj.sandbox}/app_2">
+ <fileset dir="${aj.sandbox}" includes="ataspectj/hierarchy/app/*"/>
+ </copy>
+ <delete dir="${aj.sandbox}/ataspectj/hierarchy/app"/>
+ <!-- install the aop.xml DD -->
+ <copy file="${aj.root}/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml"
+ tofile="${aj.sandbox}/META-INF/aop.xml"/>
+ <!-- only app1 gets local aspect -->
+ <copy file="${aj.root}/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml"
+ tofile="${aj.sandbox}/app_1/META-INF/aop.xml"/>
+ <!-- run -->
+ <java fork="yes" classname="ataspectj.hierarchy.AppContainerTest" failonerror="yes">
+ <classpath refid="aj.path"/>
+ <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+ <jvmarg value="-Daj.weaving.verbose=true"/>
+ </java>
+ </target>
+
</project> \ No newline at end of file
diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java b/tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java
new file mode 100644
index 000000000..5bd2330f4
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/hierarchy/AppContainerTest.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package ataspectj.hierarchy;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.io.File;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.ProceedingJoinPoint;
+import ataspectj.TestHelper;
+
+/**
+ * Assumes ataspect.hierarchy.app DOES NOT EXISTS in system classpath
+ * but exists in 2 folder located at "/app_1" and /app_2
+ * ie "/app_1/ataspect.hierarchy.app.*.class"
+ *
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class AppContainerTest extends TestCase {
+
+ public static interface IApp {
+
+ String invoke(String input);
+ }
+
+
+ IApp app1;
+ IApp app2;
+
+ public void setUp() throws Exception {
+ try {
+ Class k = Class.forName("ataspectj.hierarchy.app.SubApp");
+ throw new Exception("config error, app must not be in system classpath");
+ } catch (ClassNotFoundException e) {
+ ;//fine
+ }
+
+ //build path and app
+ URL path = AppContainerTest.class.getProtectionDomain().getCodeSource().getLocation();
+ String path1 = path.toString() + "app_1/";
+ String path2 = path.toString() + "app_2/";
+
+ URLClassLoader app1CL = new URLClassLoader(
+ new URL[]{new URL(path1)},
+ AppContainerTest.class.getClassLoader()
+ );
+ URLClassLoader app2CL = new URLClassLoader(
+ new URL[]{new URL(path2)},
+ AppContainerTest.class.getClassLoader()
+ );
+
+ app1 = (IApp)Class.forName("ataspectj.hierarchy.app.SubApp", false, app1CL).newInstance();
+ app2 = (IApp)Class.forName("ataspectj.hierarchy.app.SubApp", false, app2CL).newInstance();
+ }
+
+ public void testApp1LocalAspect() {
+ String res = app1.invoke("app1");
+ assertEquals("globalAspect[localAspect[app1]]", res);
+ }
+
+ public void testApp2NoLocalAspect() {
+ String res = app2.invoke("app2");
+ assertEquals("globalAspect[app2]", res);
+ }
+
+
+ @Aspect
+ public static class BaseAspect {
+
+ @Around("execution(* ataspectj.hierarchy.app.SubApp.invoke(..))")//TODO IApp
+ public Object around(ProceedingJoinPoint jp) throws Throwable {
+ String out = (String) jp.proceed();
+ return "globalAspect[" + out + "]";
+ }
+ }
+
+ public static void main(String[] args) {
+ TestHelper.runAndThrowOnFailure(suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(AppContainerTest.class);
+ }
+
+
+}
diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml b/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml
new file mode 100644
index 000000000..f17696441
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/hierarchy/aop-global.xml
@@ -0,0 +1,6 @@
+<aspectj>
+ <weaver options="-1.5 -XmessageHandlerClass:ataspectj.TestHelper -Xlint:ignore"/>
+ <aspects>
+ <aspect name="ataspectj.hierarchy.AppContainerTest.BaseAspect"/>
+ </aspects>
+</aspectj> \ No newline at end of file
diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml b/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml
new file mode 100644
index 000000000..384b77416
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/hierarchy/aop-local.xml
@@ -0,0 +1,6 @@
+<aspectj>
+ <weaver options="-1.5 -XmessageHandlerClass:ataspectj.TestHelper -Xlint:ignore"/>
+ <aspects>
+ <aspect name="ataspectj.hierarchy.app.SubApp.SubAspect"/>
+ </aspects>
+</aspectj> \ No newline at end of file
diff --git a/tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java b/tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java
new file mode 100644
index 000000000..e724c486d
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/hierarchy/app/SubApp.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package ataspectj.hierarchy.app;
+
+import ataspectj.hierarchy.AppContainerTest;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+/**
+ * Leaves in child classloader in two forms, like 2 webapp
+ *
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class SubApp implements AppContainerTest.IApp {
+
+ // simple echo. May be advised or not depending on the aspect deployed there
+ public String invoke(String input) {
+ return input;
+ }
+
+ // this child aspect will be LTW for only one variation of the SubApp
+ @Aspect
+ public static class SubAspect {
+
+ @Around("execution(* ataspectj.hierarchy.app.SubApp.invoke(..))")
+ public Object around(ProceedingJoinPoint jp) throws Throwable {
+ String out = (String) jp.proceed();
+ return "localAspect[" + out + "]";
+ }
+ }
+
+}