diff options
author | wisberg <wisberg> | 2005-08-18 07:25:35 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2005-08-18 07:25:35 +0000 |
commit | 84542fbb09189dbce642123ef4f41a5c77416cb1 (patch) | |
tree | 2699d58d1d2aa53533d3395aa66fa673da159bfd /weaver | |
parent | 73748ff36ec8767fc6bb07e2aca5c6fdc1310bea (diff) | |
download | aspectj-84542fbb09189dbce642123ef4f41a5c77416cb1.tar.gz aspectj-84542fbb09189dbce642123ef4f41a5c77416cb1.zip |
tests for Fix 106736 - permitting classes dir as aspect URL (also permitting .zip files)
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/build.xml | 65 | ||||
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.jar | bin | 0 -> 1379 bytes | |||
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.zip | bin | 0 -> 1379 bytes | |||
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/builtLibs/classes/packag/Aspect.class | bin | 0 -> 3874 bytes | |||
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/builtLibs/main.zip | bin | 0 -> 698 bytes | |||
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/packag/Aspect.aj | 7 | ||||
-rw-r--r-- | weaver/testdata/WeavingURLClassLoaderTest/packag/Main.java | 7 | ||||
-rw-r--r-- | weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java | 94 |
8 files changed, 169 insertions, 4 deletions
diff --git a/weaver/testdata/WeavingURLClassLoaderTest/build.xml b/weaver/testdata/WeavingURLClassLoaderTest/build.xml new file mode 100644 index 000000000..753f99328 --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/build.xml @@ -0,0 +1,65 @@ + +<!-- + bug 106736 (classes dir); also permitting .zip variants + To upgrade binary input form, reset ${aspectj.lib.dir} below. +--> +<project name="WeavingURLClassLoaderTest" default="all" basedir="."> + + <target name="all" depends="init" + description="build libs, test that failure works"> + <property name="out.lib.dir" + location="${basedir}/builtLibs"/> + <iajc outjar="${out.lib.dir}/main.zip" + srcdir="${basedir}" + classpath="${aspectjrt.jar}" + includes="packag/Main.java"/> + <iajc outjar="${out.lib.dir}/aspect.zip" + classpath="${aspectjrt.jar}" + srcdir="${basedir}" + includes="packag/Aspect.aj"/> + <iajc outjar="${out.lib.dir}/aspect.jar" + classpath="${aspectjrt.jar}" + srcdir="${basedir}" + includes="packag/Aspect.aj"/> + <iajc destDir="${out.lib.dir}/classes" + classpath="${aspectjrt.jar}" + srcdir="${basedir}" + includes="packag/Aspect.aj"/> + + <iajc outjar="${out.lib.dir}/test.jar" + classpath="${aspectjrt.jar}" + aspectpath="${out.lib.dir}/aspect.jar" + inpath="${out.lib.dir}/main.zip"/> + <java classname="packag.Main"> + <classpath> + <pathelement location="${out.lib.dir}/test.jar"/> + <pathelement location="${out.lib.dir}/aspect.jar"/> + <pathelement location="${aspectjrt.jar}"/> + </classpath> + </java> + <delete file="${out.lib.dir}/test.jar"/> + + </target> + + <target name="init" depends=""> + <!-- + warning: checked-in aspectjtools.jar is from last release, + but current (HEAD) ltw requires aspect binaries to be built + with the current weaver, not last release. I use + location="${basedir}/../../../lib/aspectj/lib"/> + --> + <property name="aspectj.lib.dir" + location="${basedir}/../../../aj-build/install/lib"/> + <property name="aspectjtools.jar" + location="${aspectj.lib.dir}/aspectjtools.jar"/> + <property name="aspectjrt.jar" + location="${aspectj.lib.dir}/aspectjrt.jar"/> + <taskdef + resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"> + <classpath> + <pathelement path="${aspectjtools.jar}"/> + </classpath> + </taskdef> + </target> + +</project>
\ No newline at end of file diff --git a/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.jar b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.jar Binary files differnew file mode 100644 index 000000000..77469d6f0 --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.jar diff --git a/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.zip b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.zip Binary files differnew file mode 100644 index 000000000..a5aebe491 --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/aspect.zip diff --git a/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/classes/packag/Aspect.class b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/classes/packag/Aspect.class Binary files differnew file mode 100644 index 000000000..57b29b005 --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/classes/packag/Aspect.class diff --git a/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/main.zip b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/main.zip Binary files differnew file mode 100644 index 000000000..e0204709e --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/builtLibs/main.zip diff --git a/weaver/testdata/WeavingURLClassLoaderTest/packag/Aspect.aj b/weaver/testdata/WeavingURLClassLoaderTest/packag/Aspect.aj new file mode 100644 index 000000000..02eb2b822 --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/packag/Aspect.aj @@ -0,0 +1,7 @@ +package packag; + +public aspect Aspect { + void around() : execution(public static void *.main(String[])) { + // don't proceed, avoid exception + } +} diff --git a/weaver/testdata/WeavingURLClassLoaderTest/packag/Main.java b/weaver/testdata/WeavingURLClassLoaderTest/packag/Main.java new file mode 100644 index 000000000..cd0452056 --- /dev/null +++ b/weaver/testdata/WeavingURLClassLoaderTest/packag/Main.java @@ -0,0 +1,7 @@ +package packag; + +public class Main { + public static void main(String[] args) { + throw new Error("around advice should have applied here"); + } +}
\ No newline at end of file diff --git a/weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java b/weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java index 64c18524f..c21115619 100644 --- a/weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java +++ b/weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java @@ -22,6 +22,7 @@ import java.util.Properties; import junit.framework.TestCase; import org.aspectj.bridge.AbortException; +import org.aspectj.testing.util.TestUtil.TestError; import org.aspectj.util.FileUtil; import org.aspectj.weaver.tools.WeavingAdaptor; @@ -43,6 +44,7 @@ public class WeavingURLClassLoaderTest extends TestCase { private final static String AROUNDCLOSURE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-acaspects.jar"; private final static String ITD_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-itdaspects.jar"; private final static String PER_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-peraspects.jar"; + private final static String TEST_BASE = BcweaverTests.TESTDATA_PATH + "/WeavingURLClassLoaderTest/builtLibs"; private final static String NULL = "null"; @@ -86,7 +88,7 @@ public class WeavingURLClassLoaderTest extends TestCase { WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); try { - Class clazz = loader.loadClass("LTWHelloWorld"); + loader.loadClass("LTWHelloWorld"); fail("Expecting org.aspectj.bridge.AbortException"); } catch (Exception ex) { @@ -262,7 +264,7 @@ public class WeavingURLClassLoaderTest extends TestCase { WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader()); try { - Class clazz = loader.loadClass("LTWHelloWorld"); + loader.loadClass("LTWHelloWorld"); fail("Expecting java.lang.ClassNotFoundException"); } catch (Exception ex) { @@ -279,7 +281,7 @@ public class WeavingURLClassLoaderTest extends TestCase { URL[] aspectURLs = new URL[] { aspects }; try { - WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader()); + new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader()); fail("Expecting org.aspectj.bridge.AbortException"); } catch (Exception ex) { @@ -363,7 +365,91 @@ public class WeavingURLClassLoaderTest extends TestCase { fail(ex.toString()); } } - + + public void testZipAspects() { + try { + doTestZipAspects(TEST_BASE + "/aspect.zip"); + } catch (Error ex) { + failWithException(ex); + } catch (Exception ex) { + failWithException(ex); + } + } + + public void testJarAspects() { + try { + doTestZipAspects(TEST_BASE + "/aspect.jar"); + } catch (Error ex) { + failWithException(ex); + } catch (Exception ex) { + failWithException(ex); + } + } + + /** PR#106736 */ + public void testClassAspects() { + try { + doTestZipAspects(TEST_BASE + "/classes"); + } catch (Error ex) { + failWithException(ex); + } catch (Exception ex) { + failWithException(ex); + } + } + + public void testZipJarAspectsTest() { + try { + doTestZipAspectsTest(); + // bug: doTestZipAspects("") attempts to load packag.Aspect? + fail("expected error to be thrown"); + } catch (InvocationTargetException ex) { + // expecting error + assertTrue(ex.getTargetException() instanceof Error); + } catch (RuntimeException ex) { + // expecting error + String message = ex.getMessage(); + // expecting error - seems to be wrapped wrong + if (-1 == message.indexOf("around advice")) { + failWithException(ex); + } + } catch (Error ex) { + failWithException(ex); + } catch (Exception ex) { + failWithException(ex); + } + } + + private void doTestZipAspects(String aspectLib) throws Exception { + File classZip = new File(TEST_BASE + "/main.zip"); + File zipLib = new File(aspectLib); + URL classes = FileUtil.getFileURL(classZip); + URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT)); + URL aspects = FileUtil.getFileURL(zipLib); + URL[] classURLs = new URL[] { aspects, classes, aspectjrt }; + URL[] aspectURLs = new URL[] { aspects }; + ClassLoader parent = getClass().getClassLoader(); + WeavingURLClassLoader loader + = new WeavingURLClassLoader(classURLs, aspectURLs, parent); + Class clazz = loader.loadClass("packag.Main"); + invokeMain(clazz,new String[] { }); + // throws Error unless advice applies + } + + private void doTestZipAspectsTest() throws Exception { + URL classes = FileUtil.getFileURL(new File(TEST_BASE + "/main.zip")); + URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT)); + URL[] classURLs = new URL[] { classes, aspectjrt }; + ClassLoader parent = getClass().getClassLoader(); + WeavingURLClassLoader loader + = new WeavingURLClassLoader(classURLs, new URL[] { }, parent); + Class clazz = loader.loadClass("packag.Main"); + invokeMain(clazz,new String[] { }); + // throws Error because advice does not apply + } + + private void failWithException(Throwable t) { + throw new TestError(t.getMessage(), t); + } public static void invokeMain (Class clazz, String[] args) { Class[] paramTypes = new Class[1]; |