]> source.dussan.org Git - aspectj.git/commitdiff
Code for enhancement 107741: Updated WeavingURLClassLoader (thanks to Matthew Webster...
authoraclement <aclement>
Fri, 14 Oct 2005 07:23:40 +0000 (07:23 +0000)
committeraclement <aclement>
Fri, 14 Oct 2005 07:23:40 +0000 (07:23 +0000)
21 files changed:
loadtime/.classpath
loadtime/src/org/aspectj/weaver/loadtime/WeavingURLClassLoader.java [new file with mode: 0644]
loadtime/testsrc/LoadtimeModuleTests.java
loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingURLClassLoaderTest.java [new file with mode: 0644]
org.aspectj.ajdt.core/.classpath
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java
testing/.classpath
testing/newsrc/org/aspectj/testing/RunSpec.java
testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java
testing/src/org/aspectj/testing/harness/bridge/JavaRun.java
tests/ltw/Aspect1.aj [new file with mode: 0644]
tests/ltw/Aspect2.aj [new file with mode: 0644]
tests/ltw/Main.java [new file with mode: 0644]
tests/ltw/aop-ltwreweavable.xml [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml [new file with mode: 0644]
weaver/src/org/aspectj/weaver/WeavingURLClassLoader.java [deleted file]
weaver/testsrc/org/aspectj/weaver/BcweaverTests.java
weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java [deleted file]

index 47982eb80a24d91a5e4a4c3e7a78e6a6be2d2dc5..5a9f37bcd6a5c23661dd523af5e9b71236996f87 100644 (file)
@@ -1,48 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry kind="src" path="src">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="testsrc">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry combineaccessrules="false" kind="src" path="/asm">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry combineaccessrules="false" kind="src" path="/bridge">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry combineaccessrules="false" kind="src" path="/util">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry combineaccessrules="false" kind="src" path="/weaver">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/ext/jrockit/managementapi-jrockit81.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/ant/lib/xml-apis.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/ant/lib/xercesImpl.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="testsrc"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/asm"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/bridge"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/util"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/weaver"/>
+       <classpathentry kind="lib" path="/lib/ext/jrockit/managementapi-jrockit81.jar"/>
+       <classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar"/>
+       <classpathentry kind="lib" path="/lib/ant/lib/xml-apis.jar"/>
+       <classpathentry kind="lib" path="/lib/ant/lib/xercesImpl.jar"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/testing-util"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/WeavingURLClassLoader.java b/loadtime/src/org/aspectj/weaver/loadtime/WeavingURLClassLoader.java
new file mode 100644 (file)
index 0000000..a80a4a9
--- /dev/null
@@ -0,0 +1,163 @@
+/* *******************************************************************
+ * Copyright (c) 2004 IBM Corporation
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Matthew Webster, Adrian Colyer, 
+ *     Martin Lippert     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.weaver.loadtime;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.CodeSource;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.aspectj.weaver.ExtensibleURLClassLoader;
+import org.aspectj.weaver.tools.WeavingAdaptor;
+import org.aspectj.weaver.tools.WeavingClassLoader;
+
+public class WeavingURLClassLoader extends ExtensibleURLClassLoader implements WeavingClassLoader {
+
+       public static final String WEAVING_CLASS_PATH = "aj.class.path"; 
+       public static final String WEAVING_ASPECT_PATH = "aj.aspect.path"; 
+       
+       private URL[] aspectURLs;
+       private WeavingAdaptor adaptor; 
+       private Map generatedClasses = new HashMap(); /* String -> byte[] */ 
+
+       /*
+        * This constructor is needed when using "-Djava.system.class.loader". 
+        */
+       public WeavingURLClassLoader (ClassLoader parent) {
+               this(getURLs(getClassPath()),getURLs(getAspectPath()),parent);
+//             System.err.println("? WeavingURLClassLoader.<init>(" + parent + ")");
+       }
+       
+       public WeavingURLClassLoader (URL[] urls, ClassLoader parent) {
+               super(urls,parent);
+//             System.out.println("WeavingURLClassLoader.WeavingURLClassLoader()");
+       }
+       
+       public WeavingURLClassLoader (URL[] classURLs, URL[] aspectURLs, ClassLoader parent) {
+               super(classURLs,parent);
+//             System.err.println("? WeavingURLClassLoader.<init>() classURLs=" + classURLs.length + ", aspectURLs=" + aspectURLs.length);
+               this.aspectURLs = aspectURLs;
+               
+               /* If either we nor our parent is using an ASPECT_PATH use a new-style
+                * adaptor
+                */ 
+               if (this.aspectURLs.length > 0 || parent instanceof WeavingClassLoader) {
+                       adaptor = new WeavingAdaptor(this);
+               }
+       }
+       
+       private static String getAspectPath () {
+               return System.getProperty(WEAVING_ASPECT_PATH,"");
+       }
+       
+       private static String getClassPath () {
+               return System.getProperty(WEAVING_CLASS_PATH,"");
+       }
+       
+       private static URL[] getURLs (String path) {
+               List urlList = new ArrayList();
+               for (StringTokenizer t = new StringTokenizer(path,File.pathSeparator);
+                        t.hasMoreTokens();) {
+                       File f = new File(t.nextToken().trim());
+                       try {
+                               if (f.exists()) {
+                                       URL url = f.toURL();
+                                       if (url != null) urlList.add(url);
+                               }
+                       } catch (MalformedURLException e) {}
+               }
+
+               URL[] urls = new URL[urlList.size()];
+               urlList.toArray(urls);
+               return urls;
+       }
+
+       protected void addURL(URL url) {
+               adaptor.addURL(url);
+               super.addURL(url);
+       }
+
+       /**
+        * Override to weave class using WeavingAdaptor 
+        */
+       protected Class defineClass(String name, byte[] b, CodeSource cs) throws IOException {
+//             System.err.println("? WeavingURLClassLoader.defineClass(" + name + ", [" + b.length + "])");
+               
+               /* Need to defer creation because of possible recursion during constructor execution */
+               if (adaptor == null) {
+                       ClassLoaderWeavingAdaptor clwAdaptor = new ClassLoaderWeavingAdaptor(this,null);
+                       clwAdaptor.initialize(this,null);
+                       adaptor = clwAdaptor;
+               }
+               
+               b = adaptor.weaveClass(name,b);
+               return super.defineClass(name, b, cs);
+       }
+
+       /**
+        * Override to find classes generated by WeavingAdaptor
+        */
+       protected byte[] getBytes (String name) throws IOException {
+               byte[] bytes = super.getBytes(name);
+               
+               if (bytes == null) {
+//                     return adaptor.findClass(name);
+                       return (byte[])generatedClasses.remove(name);
+               }
+               
+               return bytes;
+       }
+
+       /**
+        * Implement method from WeavingClassLoader
+        */
+       public URL[] getAspectURLs() {
+               return aspectURLs;
+       }
+
+       public void acceptClass (String name, byte[] bytes) {
+               generatedClasses.put(name,bytes);
+       }
+       
+//     private interface ClassPreProcessorAdaptor extends ClassPreProcessor {
+//             public void addURL(URL url);
+//     }
+//     
+//     private class WeavingAdaptorPreProcessor implements ClassPreProcessorAdaptor {
+//             
+//             private WeavingAdaptor adaptor;
+//             
+//             public WeavingAdaptorPreProcessor (WeavingClassLoader wcl) {
+//                     adaptor = new WeavingAdaptor(wcl);
+//             }
+//         
+//             public void initialize() {
+//             }
+//
+//         public byte[] preProcess(String className, byte[] bytes, ClassLoader classLoader) {
+//             return adaptor.weaveClass(className,bytes);
+//         }
+//
+//             public void addURL(URL url) {
+//                     
+//             }
+//     }
+
+}
index 4cf2326dcd23785f40aafdd6f067c02864da5435..ba89bb113611c8287bf81ddb25a8ba14ea14f657 100644 (file)
@@ -14,6 +14,8 @@ import junit.framework.TestCase;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
+
+import org.aspectj.weaver.loadtime.WeavingURLClassLoaderTest;
 import org.aspectj.weaver.loadtime.test.DocumentParserTest;
 
 /**
@@ -25,7 +27,7 @@ public class LoadtimeModuleTests extends TestCase {
         TestSuite suite = new TestSuite(LoadtimeModuleTests.class.getName());
 
         suite.addTestSuite(DocumentParserTest.class);
-
+        suite.addTestSuite(WeavingURLClassLoaderTest.class);
         return suite;
     }
 
diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingURLClassLoaderTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingURLClassLoaderTest.java
new file mode 100644 (file)
index 0000000..fe31393
--- /dev/null
@@ -0,0 +1,502 @@
+/* *******************************************************************
+ * Copyright (c) 2004 IBM Corporation
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Matthew Webster     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.weaver.loadtime;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.Enumeration;
+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.BcweaverTests;
+import org.aspectj.weaver.tools.WeavingAdaptor;
+
+/**
+ * @author websterm
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class WeavingURLClassLoaderTest extends TestCase {
+
+       private final static String ASPECTJRT = "../runtime/bin";
+       private final static String CLASSES_JAR = BcweaverTests.TESTDATA_PATH + "/ltw-classes.jar";
+       private final static String WOVEN_JAR = BcweaverTests.TESTDATA_PATH + "/ltw-woven.jar";
+       private final static String JUNK_JAR = BcweaverTests.TESTDATA_PATH + "/ltw-junk.jar";
+       private final static String ADVICE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-aspects.jar";
+       private final static String DW_ADVICE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-dwaspects.jar";
+       private final static String DE_ADVICE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-deaspects.jar";
+       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";
+
+       private Properties savedProperties;
+
+       public WeavingURLClassLoaderTest(String name) {
+               super(name);
+       }
+
+       public void testLoadClass () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,"");
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] {}); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testLoadWovenClass () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,"");
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,WOVEN_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeaveWovenClass () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + WOVEN_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       loader.loadClass("LTWHelloWorld");
+                       fail("Expecting org.aspectj.bridge.AbortException");
+               }
+               catch (Exception ex) {
+                       assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof AbortException));
+               }
+       }
+
+       public void testWeavingURLClassLoader () {
+               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
+               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
+               URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
+               URL[] classURLs = new URL[] { aspects, classes, aspectjrt };
+               URL[] aspectURLs = new URL[] { aspects };
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeaveAdvice () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeaveAdviceWithVerbose () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
+               setSystemProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true");
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeaveAdviceWithWeaveInfo () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
+               setSystemProperty(WeavingAdaptor.SHOW_WEAVE_INFO_PROPERTY,"true");
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeaveDeclareWarningAdvice () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DW_ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DW_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] {} ); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeaveDeclareErrorAdvice () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DE_ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DE_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] {} ); 
+                       fail("Expecting org.aspectj.bridge.AbortException");
+               }
+               catch (Exception ex) {
+                       assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof AbortException));
+               }
+       }
+
+       public void testWeaveAroundClosure () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,AROUNDCLOSURE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,AROUNDCLOSURE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAroundClosure" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeavingITD () {
+               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
+               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
+               URL aspects = FileUtil.getFileURL(new File(ITD_ASPECTS));
+               URL[] classURLs = new URL[] { aspects, classes, aspectjrt };
+               URL[] aspectURLs = new URL[] { aspects };
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWInterfaceITD", "LTWFieldITD", "LTWMethodITD" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeavingPer () {
+               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
+               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
+               URL aspects = FileUtil.getFileURL(new File(PER_ASPECTS));
+               URL[] classURLs = new URL[] { aspects, classes, aspectjrt };
+               URL[] aspectURLs = new URL[] { aspects };
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWPerthis" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testWeavingAspects () {
+               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
+               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
+               URL aspects1 = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
+               URL aspects2 = FileUtil.getFileURL(new File(AROUNDCLOSURE_ASPECTS));
+               URL aspects3 = FileUtil.getFileURL(new File(ITD_ASPECTS));
+               URL aspects4 = FileUtil.getFileURL(new File(PER_ASPECTS));
+               URL[] classURLs = new URL[] {  aspects1, aspects2, aspects3, aspects4, classes, aspectjrt };
+               URL[] aspectURLs = new URL[] { aspects1, aspects2, aspects3, aspects4 };
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect", "LTWAroundClosure", "LTWPerthis", "LTWInterfaceITD", "LTWFieldITD", "LTWMethodITD", "LTWPerthis"}); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testJunkJar () {            
+               File junkJar = new File(JUNK_JAR);
+               assertFalse(junkJar + " should not exist",junkJar.exists());
+               
+               URL classes = FileUtil.getFileURL(junkJar);
+               URL[] classURLs = new URL[] { classes };
+               URL[] aspectURLs = new URL[] { };
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+
+               try {
+                       loader.loadClass("LTWHelloWorld");
+                       fail("Expecting java.lang.ClassNotFoundException");
+               }
+               catch (Exception ex) {
+                       assertTrue("Expecting java.lang.ClassNotFoundException caught " + ex,(ex instanceof ClassNotFoundException));
+               }
+       }
+
+       public void testJunkAspectJar () {              
+               File junkJar = new File(JUNK_JAR);
+               assertFalse(junkJar + " should not exist",junkJar.exists());
+               
+               URL aspects = FileUtil.getFileURL(junkJar);
+               URL[] classURLs = new URL[] { aspects };
+               URL[] aspectURLs = new URL[] { aspects };
+               
+               try {
+                       new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+                       fail("Expecting org.aspectj.bridge.AbortException");
+               }
+               catch (Exception ex) {
+                       assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof org.aspectj.bridge.AbortException));
+               }
+       }
+
+       public void testAddURL () {
+               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
+               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
+               URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
+               URL[] classURLs = new URL[] { aspects, aspectjrt };
+               URL[] aspectURLs = new URL[] { aspects };
+
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+               loader.addURL(classes);
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       public void testParentChild() {
+               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
+               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
+               URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
+               
+               URL[] classURLs = new URL[] { aspects, aspectjrt };
+               URL[] aspectURLs = new URL[] { aspects };
+               WeavingURLClassLoader parent = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
+               
+               classURLs = new URL[] { classes };
+               aspectURLs = new URL[] { };
+               WeavingURLClassLoader child = new WeavingURLClassLoader(classURLs,aspectURLs,parent);
+
+               try {
+                       Class clazz = child.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+               }
+               catch (Exception ex) {
+                       fail(ex.toString());
+               }
+       }
+
+       /*
+        * Aspects on ASPECTPATH but missing from CLASSPATH
+        */
+       public void testIncompletePath () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("LTWHelloWorld");
+                       invokeMain(clazz,new String[] { "LTWAspect" }); 
+                       fail("Expecting java.lang.NoClassDefFoundError");
+               }
+               catch (Exception ex) {
+               }
+       }
+
+       /*
+        * Ensure package object is correct
+        */
+       public void testPackage () {
+               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,"");
+               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR);
+               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
+
+               try {
+                       Class clazz = loader.loadClass("ltw.LTWPackageTest");
+                       invokeMain(clazz,new String[] { }); 
+                       Package pakkage = clazz.getPackage();
+                       assertTrue("Expected 'ltw' got " + pakkage,(pakkage != null));
+               }
+               catch (Exception ex) {
+                       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];
+               paramTypes[0] = args.getClass();
+       
+               try {
+                       Method method = clazz.getDeclaredMethod("main",paramTypes);
+                       Object[] params = new Object[1];
+                       params[0] = args;
+                       method.invoke(null,params);
+               }
+               catch (InvocationTargetException ex) {
+                       throw new RuntimeException(ex.getTargetException().toString());
+               }
+               catch (Exception ex) {
+                       throw new RuntimeException(ex.toString());
+               }
+       }
+
+       private void setSystemProperty (String key, String value) {
+               Properties systemProperties = System.getProperties();
+               copyProperty(key,systemProperties,savedProperties);
+               systemProperties.setProperty(key,value);
+       }
+       
+       private static void copyProperty (String key, Properties from, Properties to) {
+               String value = from.getProperty(key,NULL);
+               to.setProperty(key,value);
+       }
+
+       protected void setUp() throws Exception {
+               super.setUp();
+               savedProperties = new Properties();
+       }
+
+       protected void tearDown() throws Exception {
+               super.tearDown();
+               
+               /* Restore system properties */
+               Properties systemProperties = System.getProperties();
+               for (Enumeration enu = savedProperties.keys(); enu.hasMoreElements(); ) {
+                       String key = (String)enu.nextElement();
+                       String value = savedProperties.getProperty(key);
+                       if (value == NULL) systemProperties.remove(key);
+                       else systemProperties.setProperty(key,value);
+               }
+       }
+
+}
index f31838dd6bdece649bf0d0700ebe2f83d293e5f2..eeb6941b2ac5ac566bc118cd97a61c32b5f7a7a1 100644 (file)
@@ -13,5 +13,6 @@
        <classpathentry kind="src" path="/testing-util"/>
        <classpathentry kind="src" path="/testing-client"/>
        <classpathentry kind="src" path="/org.eclipse.jdt.core"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/loadtime"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 58ea8e063ad17d4e07008a968e1d9fd122bc113e..14fad2ef59b22c4f65b754ecbdc69c2a0986dff7 100644 (file)
@@ -28,6 +28,7 @@ import java.util.StringTokenizer;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.testing.util.TestUtil;
+import org.aspectj.weaver.loadtime.WeavingURLClassLoader;
 
 import junit.framework.TestCase;
 
@@ -518,7 +519,7 @@ public class AjcTestCase extends TestCase {
                return lastRunResult;
        }
     public void testNothingForAntJUnit() {}
-       
+    
        /**
         * Run the given class (main method), and return the result in a RunResult. The program runs with
         * a classpath containing the sandbox directory, runtime, testing-client, bridge, and
@@ -527,6 +528,11 @@ public class AjcTestCase extends TestCase {
        public RunResult run(String className){
                return run(className,new String[0],null);
        }
+
+       public RunResult run(String className, String[] args, String classpath)  {
+               return run(className,args,null,false);
+       }
+
        
        /**
         * Run the given class, and return the result in a RunResult. The program runs with
@@ -537,7 +543,7 @@ public class AjcTestCase extends TestCase {
         * bridge, and util projects will all be appended to the classpath, as will any jars in
         * the sandbox.
         */
-       public RunResult run(String className, String[] args, String classpath)  {
+       public RunResult run(String className, String[] args, String classpath, boolean useLTW)  {
                lastRunResult = null;
                StringBuffer cp = new StringBuffer();
                if (classpath != null) {
@@ -569,8 +575,15 @@ public class AjcTestCase extends TestCase {
                } catch (Exception malEx) {
                        fail("Bad classpath specification: " + classpath);
                }
-               URLClassLoader cLoader = new URLClassLoader(urls,null);
-               //System.out.println(cLoader.getParent());
+               
+               URLClassLoader cLoader;
+               if (useLTW) {
+                       cLoader = new WeavingURLClassLoader(urls,null);
+               }
+               else {
+                       cLoader = new URLClassLoader(urls,null);
+               }
+
                try {
                        try {
                                Class testerClass = cLoader.loadClass("org.aspectj.testing.Tester");
index be4d3e954d32b82a2a776f62fdb717c082bcaae4..223b01f9b4dd84d8d1f5fbf9e262de774fcc315d 100644 (file)
@@ -1,84 +1,25 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry kind="src" path="src">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="testsrc">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry sourcepath="/lib/ant/ant-src.zip" kind="lib" path="/lib/ant/lib/ant.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/jdiff/jdiff.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/regexp/jakarta-regexp-1.2.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/bridge">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/util">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/testing-client">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/ant/lib/xercesImpl.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="lib" path="/lib/ant/lib/xml-apis.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry exported="true" sourcepath="/lib/commons/commons-src.zip" kind="lib" path="/lib/commons/commons.jar">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/testing-util">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/ajde">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/asm">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/taskdefs">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="newsrc">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry kind="src" path="/org.aspectj.ajdt.core">
-               <attributes>
-               </attributes>
-       </classpathentry>
-       <classpathentry combineaccessrules="false" kind="src" path="/weaver">
-               <attributes>
-               </attributes>
-       </classpathentry>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="testsrc"/>
+       <classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>
+       <classpathentry sourcepath="/lib/ant/ant-src.zip" kind="lib" path="/lib/ant/lib/ant.jar"/>
+       <classpathentry sourcepath="/lib/junit/junit-src.jar" kind="lib" path="/lib/junit/junit.jar"/>
+       <classpathentry kind="lib" path="/lib/jdiff/jdiff.jar"/>
+       <classpathentry kind="lib" path="/lib/regexp/jakarta-regexp-1.2.jar"/>
+       <classpathentry kind="src" path="/bridge"/>
+       <classpathentry kind="src" path="/util"/>
+       <classpathentry kind="src" path="/testing-client"/>
+       <classpathentry kind="lib" path="/lib/ant/lib/xercesImpl.jar"/>
+       <classpathentry kind="lib" path="/lib/ant/lib/xml-apis.jar"/>
+       <classpathentry exported="true" sourcepath="/lib/commons/commons-src.zip" kind="lib" path="/lib/commons/commons.jar"/>
+       <classpathentry kind="src" path="/testing-util"/>
+       <classpathentry kind="src" path="/ajde"/>
+       <classpathentry kind="src" path="/asm"/>
+       <classpathentry kind="src" path="/taskdefs"/>
+       <classpathentry kind="src" path="newsrc"/>
+       <classpathentry kind="src" path="/org.aspectj.ajdt.core"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/weaver"/>
+       <classpathentry combineaccessrules="false" kind="src" path="/loadtime"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index cb0d497a81981ddbf044a9b4c69292aa69508d28..0716b8362d5424aaf4a680d117533764caa2c1c6 100644 (file)
 package org.aspectj.testing;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.StringTokenizer;
 
 import org.aspectj.tools.ajc.AjcTestCase;
+import org.aspectj.util.FileUtil;
 
 /**
  * @author colyer
@@ -34,6 +36,7 @@ public class RunSpec implements ITestStep {
        private AjcTest myTest;
        private OutputSpec stdErrSpec;
        private OutputSpec stdOutSpec;
+       private String ltwFile;
        
        public RunSpec() {
        }
@@ -46,7 +49,9 @@ public class RunSpec implements ITestStep {
                        System.err.println("Warning, message spec for run command is currently ignored (org.aspectj.testing.RunSpec)");
                }
                String[] args = buildArgs();
-               AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(),args,getClasspath());
+//             System.err.println("? execute() inTestCase='" + inTestCase + "', ltwFile=" + ltwFile);
+               boolean useLtw = copyLtwFile(inTestCase.getSandboxDirectory());
+               AjcTestCase.RunResult rr = inTestCase.run(getClassToRun(),args,getClasspath(),useLtw);
                if (stdErrSpec != null) {
                        stdErrSpec.matchAgainst(rr.getStdErr());
                }
@@ -102,6 +107,14 @@ public class RunSpec implements ITestStep {
        public void setClassToRun(String classToRun) {
                this.classToRun = classToRun;
        }
+
+       public String getLtwFile() {
+               return ltwFile;
+       }
+
+       public void setLtwFile(String ltwFile) {
+               this.ltwFile = ltwFile;
+       }
        
        private String[] buildArgs() {
                if (options == null) return new String[0];
@@ -112,4 +125,23 @@ public class RunSpec implements ITestStep {
                }
                return ret;
        }
+       
+       private boolean copyLtwFile (File sandboxDirectory) {
+               boolean useLtw = false;
+               
+               if (ltwFile != null) {
+                       File from = new File(baseDir,ltwFile);
+                       File to = new File(sandboxDirectory,"META-INF" + File.separator + "aop.xml");
+//                     System.out.println("RunSpec.copyLtwFile() from=" + from.getAbsolutePath() + " to=" + to.getAbsolutePath());
+                       try {
+                               FileUtil.copyFile(from,to);
+                               useLtw = true;
+                       }
+                       catch (IOException ex) {
+                               ex.printStackTrace();
+                       }
+               }
+               
+               return useLtw;
+       }
 }
index 22cb30338db5f5b9c7a19517b41d7206d26bf08b..58a5f0d33038b318a96fe69b7315378056f150fe 100644 (file)
@@ -166,6 +166,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase {
                digester.addSetNext("suite/ajc-test/compile","addTestStep","org.aspectj.testing.ITestStep");
                digester.addObjectCreate("suite/ajc-test/run",RunSpec.class);
                digester.addSetProperties("suite/ajc-test/run","class","classToRun");
+               digester.addSetProperties("suite/ajc-test/run","ltw","ltwFile");
                digester.addSetNext("suite/ajc-test/run","addTestStep","org.aspectj.testing.ITestStep");
                digester.addObjectCreate("*/message",ExpectedMessageSpec.class);
                digester.addSetProperties("*/message");
index 223a0c8a680244bda28afef0d79b636d69b7349c..cbf353fac00e9d6181f513ccf30cf2cef1a9158d 100644 (file)
@@ -25,7 +25,7 @@ import org.aspectj.testing.xml.SoftMessage;
 import org.aspectj.testing.xml.XMLWriter;
 import org.aspectj.util.FileUtil;
 import org.aspectj.util.LangUtil;
-import org.aspectj.weaver.WeavingURLClassLoader;
+import org.aspectj.weaver.loadtime.WeavingURLClassLoader;
 
 import java.io.*;
 import java.lang.reflect.*;
diff --git a/tests/ltw/Aspect1.aj b/tests/ltw/Aspect1.aj
new file mode 100644 (file)
index 0000000..173cb86
--- /dev/null
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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:
+ *   Matthew Webster         initial implementation
+ *******************************************************************************/
+import org.aspectj.lang.JoinPoint;
+
+public aspect Aspect1 {
+       
+               before () : execution(void Main.test1()) {
+                       System.err.println("Aspect1.before_" + thisJoinPoint.getSignature().getName());
+               }
+}
diff --git a/tests/ltw/Aspect2.aj b/tests/ltw/Aspect2.aj
new file mode 100644 (file)
index 0000000..519a47e
--- /dev/null
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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:
+ *   Matthew Webster   initial implementation
+ *******************************************************************************/
+import org.aspectj.lang.JoinPoint;
+
+public aspect Aspect2 {
+       
+               before () : execution(void Main.test2()){
+                       System.err.println("Aspect2.before_" + thisJoinPoint.getSignature().getName());
+               }
+}
diff --git a/tests/ltw/Main.java b/tests/ltw/Main.java
new file mode 100644 (file)
index 0000000..fca018a
--- /dev/null
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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:
+ *   Matthew Webster         initial implementation
+ *******************************************************************************/
+
+public class Main {
+
+       public void test1 () {
+               System.out.println("Main.test1");
+       }
+
+       public void test2 () {
+               System.out.println("Main.test2");
+       }
+
+       public static void main (String[] args) {
+               System.out.println("Main.main");
+               new Main().test1();
+               new Main().test2();
+       }
+}
diff --git a/tests/ltw/aop-ltwreweavable.xml b/tests/ltw/aop-ltwreweavable.xml
new file mode 100644 (file)
index 0000000..9afd80e
--- /dev/null
@@ -0,0 +1,6 @@
+<aspectj>
+    <aspect name="Aspect1"/>
+    <aspect name="Aspect2"/>
+    
+    <weaver options="-showWeaveInfo"/>
+</aspectj>
index 0f457c739fd715850d2214f6c7d09d51327c6595..32748c45590aba89094ea4b759b80f44e7265d5f 100644 (file)
@@ -13,6 +13,7 @@ package org.aspectj.systemtest.ajc150;
 import org.aspectj.systemtest.ajc150.ataspectj.AtAjSyntaxTests;
 import org.aspectj.systemtest.ajc150.ataspectj.AtAjMisuseTests;
 import org.aspectj.systemtest.ajc150.ataspectj.AtAjLTWTests;
+import org.aspectj.systemtest.ajc150.ltw.LTWTests;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -52,7 +53,9 @@ public class AllTestsAspectJ150 {
         suite.addTest(AtAjMisuseTests.suite());
         suite.addTest(AtAjLTWTests.suite());
         suite.addTest(HasMember.suite());
-               //$JUnit-END$
+
+               suite.addTestSuite(LTWTests.class);
+        //$JUnit-END$
                return suite;
        }
 }
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java b/tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java
new file mode 100644 (file)
index 0000000..543d586
--- /dev/null
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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:
+ *   Matthew Webster         initial implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150.ltw;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase {
+
+  public static Test suite() {
+    return XMLBasedAjcTestCase.loadSuite(LTWTests.class);
+  }
+
+  protected File getSpecFile() {
+    return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml");
+  }
+
+
+  public void test001(){
+    runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect");
+  }
+}
+
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml b/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml
new file mode 100644 (file)
index 0000000..0e818af
--- /dev/null
@@ -0,0 +1,33 @@
+<!-- Load-time weaving tests -->
+
+       <ajc-test dir="ltw"
+      title="Ensure 1st aspect is rewoven when weaving 2nd aspect"
+      keywords="reweavable">
+        <compile
+               files="Main.java, Aspect1.aj"
+                       outjar="main1.jar"
+            options="-showWeaveInfo"
+        >
+               <message kind="weave" text="method-execution(void Main.test1())' in Type 'Main' (Main.java:15) advised by before advice from 'Aspect1' (Aspect1.aj:16)"/>
+        </compile>     
+        <compile
+               classpath="main1.jar"
+               files="Aspect2.aj"
+               outjar="aspect2.jar"
+            options="-showWeaveInfo"
+        >
+        </compile>     
+        <run class="Main" ltw="aop-ltwreweavable.xml">
+               <stdout>
+                <line text="Main.main"/>
+                <line text="Main.test1"/>
+                <line text="Main.test2"/>
+            </stdout>
+               <stderr>
+                <line text="Aspect1.before_test1"/>
+                <line text="Aspect2.before_test2"/>
+            </stderr>
+        </run>
+    </ajc-test>
+
+    
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml b/tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml
new file mode 100644 (file)
index 0000000..311872c
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[
+<!ENTITY tests SYSTEM "../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml">
+]>
+
+<!-- Load-time weaving tests -->
+
+<suite>
+
+&tests;
+
+</suite>
diff --git a/weaver/src/org/aspectj/weaver/WeavingURLClassLoader.java b/weaver/src/org/aspectj/weaver/WeavingURLClassLoader.java
deleted file mode 100644 (file)
index 347cb10..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2004 IBM Corporation
- * All rights reserved. 
- * This program and the accompanying materials are made available 
- * under the terms of the Common Public License v1.0 
- * which accompanies this distribution and is available at 
- * http://www.eclipse.org/legal/cpl-v10.html 
- *  
- * Contributors: 
- *     Matthew Webster, Adrian Colyer, 
- *     Martin Lippert     initial implementation 
- * ******************************************************************/
-
-package org.aspectj.weaver;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.CodeSource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.aspectj.weaver.tools.WeavingAdaptor;
-import org.aspectj.weaver.tools.WeavingClassLoader;
-
-public class WeavingURLClassLoader extends ExtensibleURLClassLoader implements WeavingClassLoader {
-
-       public static final String WEAVING_CLASS_PATH = "aj.class.path"; 
-       public static final String WEAVING_ASPECT_PATH = "aj.aspect.path"; 
-       
-       private URL[] aspectURLs;
-       private WeavingAdaptor adaptor; 
-       private Map generatedClasses = new HashMap(); /* String -> byte[] */ 
-
-       /*
-        * This constructor is needed when using "-Djava.system.class.loader". 
-        */
-       public WeavingURLClassLoader (ClassLoader parent) {
-               this(getURLs(getClassPath()),getURLs(getAspectPath()),parent);
-//             System.err.println("? WeavingURLClassLoader.<init>(" + parent + ")");
-       }
-       
-       public WeavingURLClassLoader (URL[] classURLs, URL[] aspectURLs, ClassLoader parent) {
-               super(classURLs,parent);
-//             System.err.println("? WeavingURLClassLoader.<init>()");
-               this.aspectURLs = aspectURLs;
-               adaptor = new WeavingAdaptor(this);
-       }
-       
-       private static String getAspectPath () {
-               return System.getProperty(WEAVING_ASPECT_PATH,"");
-       }
-       
-       private static String getClassPath () {
-               return System.getProperty(WEAVING_CLASS_PATH,"");
-       }
-       
-       private static URL[] getURLs (String path) {
-               List urlList = new ArrayList();
-               for (StringTokenizer t = new StringTokenizer(path,File.pathSeparator);
-                        t.hasMoreTokens();) {
-                       File f = new File(t.nextToken().trim());
-                       try {
-                               if (f.exists()) {
-                                       URL url = f.toURL();
-                                       if (url != null) urlList.add(url);
-                               }
-                       } catch (MalformedURLException e) {}
-               }
-
-               URL[] urls = new URL[urlList.size()];
-               urlList.toArray(urls);
-               return urls;
-       }
-
-       protected void addURL(URL url) {
-               adaptor.addURL(url);
-               super.addURL(url);
-       }
-
-       /**
-        * Override to weave class using WeavingAdaptor 
-        */
-       protected Class defineClass(String name, byte[] b, CodeSource cs) throws IOException {
-//             System.err.println("? WeavingURLClassLoader.defineClass(" + name + ", [" + b.length + "])");
-               b = adaptor.weaveClass(name,b);
-               return super.defineClass(name, b, cs);
-       }
-
-       /**
-        * Override to find classes generated by WeavingAdaptor
-        */
-       protected byte[] getBytes (String name) throws IOException {
-               byte[] bytes = super.getBytes(name);
-               
-               if (bytes == null) {
-//                     return adaptor.findClass(name);
-                       return (byte[])generatedClasses.remove(name);
-               }
-               
-               return bytes;
-       }
-
-       /**
-        * Implement method from WeavingClassLoader
-        */
-       public URL[] getAspectURLs() {
-               return aspectURLs;
-       }
-
-       public void acceptClass (String name, byte[] bytes) {
-               generatedClasses.put(name,bytes);
-       }
-
-}
index 94cb7ddacf611e32d21eeca876928f99d49e8695..1c59bd841cb88b36b50f10616b42b914568868fe 100644 (file)
@@ -52,7 +52,6 @@ public class BcweaverTests extends TestCase {
         //$JUnit-BEGIN$
         suite.addTestSuite(MemberTestCase.class); 
                suite.addTestSuite(TypeXTestCase.class); 
-               suite.addTestSuite(WeavingURLClassLoaderTest.class); 
                suite.addTestSuite(WeaverMessagesTestCase.class);
                suite.addTestSuite(DumpTestCase.class);
         //$JUnit-END$
diff --git a/weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java b/weaver/testsrc/org/aspectj/weaver/WeavingURLClassLoaderTest.java
deleted file mode 100644 (file)
index c211156..0000000
+++ /dev/null
@@ -1,501 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2004 IBM Corporation
- * All rights reserved. 
- * This program and the accompanying materials are made available 
- * under the terms of the Common Public License v1.0 
- * which accompanies this distribution and is available at 
- * http://www.eclipse.org/legal/cpl-v10.html 
- *  
- * Contributors: 
- *     Matthew Webster     initial implementation 
- * ******************************************************************/
-
-package org.aspectj.weaver;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.util.Enumeration;
-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;
-
-/**
- * @author websterm
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class WeavingURLClassLoaderTest extends TestCase {
-
-       private final static String ASPECTJRT = "../runtime/bin";
-       private final static String CLASSES_JAR = BcweaverTests.TESTDATA_PATH + "/ltw-classes.jar";
-       private final static String WOVEN_JAR = BcweaverTests.TESTDATA_PATH + "/ltw-woven.jar";
-       private final static String JUNK_JAR = BcweaverTests.TESTDATA_PATH + "/ltw-junk.jar";
-       private final static String ADVICE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-aspects.jar";
-       private final static String DW_ADVICE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-dwaspects.jar";
-       private final static String DE_ADVICE_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-deaspects.jar";
-       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";
-
-       private Properties savedProperties;
-
-       public WeavingURLClassLoaderTest(String name) {
-               super(name);
-       }
-
-       public void testLoadClass () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,"");
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] {}); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testLoadWovenClass () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,"");
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,WOVEN_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeaveWovenClass () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + WOVEN_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       loader.loadClass("LTWHelloWorld");
-                       fail("Expecting org.aspectj.bridge.AbortException");
-               }
-               catch (Exception ex) {
-                       assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof AbortException));
-               }
-       }
-
-       public void testWeavingURLClassLoader () {
-               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
-               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
-               URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
-               URL[] classURLs = new URL[] { aspects, classes, aspectjrt };
-               URL[] aspectURLs = new URL[] { aspects };
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeaveAdvice () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeaveAdviceWithVerbose () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
-               setSystemProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true");
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeaveAdviceWithWeaveInfo () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
-               setSystemProperty(WeavingAdaptor.SHOW_WEAVE_INFO_PROPERTY,"true");
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeaveDeclareWarningAdvice () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DW_ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DW_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] {} ); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeaveDeclareErrorAdvice () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DE_ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DE_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] {} ); 
-                       fail("Expecting org.aspectj.bridge.AbortException");
-               }
-               catch (Exception ex) {
-                       assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof AbortException));
-               }
-       }
-
-       public void testWeaveAroundClosure () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,AROUNDCLOSURE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,AROUNDCLOSURE_ASPECTS + File.pathSeparator + CLASSES_JAR + File.pathSeparator + ASPECTJRT);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAroundClosure" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeavingITD () {
-               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
-               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
-               URL aspects = FileUtil.getFileURL(new File(ITD_ASPECTS));
-               URL[] classURLs = new URL[] { aspects, classes, aspectjrt };
-               URL[] aspectURLs = new URL[] { aspects };
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWInterfaceITD", "LTWFieldITD", "LTWMethodITD" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeavingPer () {
-               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
-               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
-               URL aspects = FileUtil.getFileURL(new File(PER_ASPECTS));
-               URL[] classURLs = new URL[] { aspects, classes, aspectjrt };
-               URL[] aspectURLs = new URL[] { aspects };
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWPerthis" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testWeavingAspects () {
-               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
-               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
-               URL aspects1 = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
-               URL aspects2 = FileUtil.getFileURL(new File(AROUNDCLOSURE_ASPECTS));
-               URL aspects3 = FileUtil.getFileURL(new File(ITD_ASPECTS));
-               URL aspects4 = FileUtil.getFileURL(new File(PER_ASPECTS));
-               URL[] classURLs = new URL[] {  aspects1, aspects2, aspects3, aspects4, classes, aspectjrt };
-               URL[] aspectURLs = new URL[] { aspects1, aspects2, aspects3, aspects4 };
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect", "LTWAroundClosure", "LTWPerthis", "LTWInterfaceITD", "LTWFieldITD", "LTWMethodITD", "LTWPerthis"}); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testJunkJar () {            
-               File junkJar = new File(JUNK_JAR);
-               assertFalse(junkJar + " should not exist",junkJar.exists());
-               
-               URL classes = FileUtil.getFileURL(junkJar);
-               URL[] classURLs = new URL[] { classes };
-               URL[] aspectURLs = new URL[] { };
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-
-               try {
-                       loader.loadClass("LTWHelloWorld");
-                       fail("Expecting java.lang.ClassNotFoundException");
-               }
-               catch (Exception ex) {
-                       assertTrue("Expecting java.lang.ClassNotFoundException caught " + ex,(ex instanceof ClassNotFoundException));
-               }
-       }
-
-       public void testJunkAspectJar () {              
-               File junkJar = new File(JUNK_JAR);
-               assertFalse(junkJar + " should not exist",junkJar.exists());
-               
-               URL aspects = FileUtil.getFileURL(junkJar);
-               URL[] classURLs = new URL[] { aspects };
-               URL[] aspectURLs = new URL[] { aspects };
-               
-               try {
-                       new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-                       fail("Expecting org.aspectj.bridge.AbortException");
-               }
-               catch (Exception ex) {
-                       assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof org.aspectj.bridge.AbortException));
-               }
-       }
-
-       public void testAddURL () {
-               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
-               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
-               URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
-               URL[] classURLs = new URL[] { aspects, aspectjrt };
-               URL[] aspectURLs = new URL[] { aspects };
-
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-               loader.addURL(classes);
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       public void testParentChild() {
-               URL classes = FileUtil.getFileURL(new File(CLASSES_JAR));
-               URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT));
-               URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS));
-               
-               URL[] classURLs = new URL[] { aspects, aspectjrt };
-               URL[] aspectURLs = new URL[] { aspects };
-               WeavingURLClassLoader parent = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader());
-               
-               classURLs = new URL[] { classes };
-               aspectURLs = new URL[] { };
-               WeavingURLClassLoader child = new WeavingURLClassLoader(classURLs,aspectURLs,parent);
-
-               try {
-                       Class clazz = child.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-               }
-               catch (Exception ex) {
-                       fail(ex.toString());
-               }
-       }
-
-       /*
-        * Aspects on ASPECTPATH but missing from CLASSPATH
-        */
-       public void testIncompletePath () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS);
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("LTWHelloWorld");
-                       invokeMain(clazz,new String[] { "LTWAspect" }); 
-                       fail("Expecting java.lang.NoClassDefFoundError");
-               }
-               catch (Exception ex) {
-               }
-       }
-
-       /*
-        * Ensure package object is correct
-        */
-       public void testPackage () {
-               setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,"");
-               setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR);
-               WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
-               try {
-                       Class clazz = loader.loadClass("ltw.LTWPackageTest");
-                       invokeMain(clazz,new String[] { }); 
-                       Package pakkage = clazz.getPackage();
-                       assertTrue("Expected 'ltw' got " + pakkage,(pakkage != null));
-               }
-               catch (Exception ex) {
-                       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];
-               paramTypes[0] = args.getClass();
-       
-               try {
-                       Method method = clazz.getDeclaredMethod("main",paramTypes);
-                       Object[] params = new Object[1];
-                       params[0] = args;
-                       method.invoke(null,params);
-               }
-               catch (InvocationTargetException ex) {
-                       throw new RuntimeException(ex.getTargetException().toString());
-               }
-               catch (Exception ex) {
-                       throw new RuntimeException(ex.toString());
-               }
-       }
-
-       private void setSystemProperty (String key, String value) {
-               Properties systemProperties = System.getProperties();
-               copyProperty(key,systemProperties,savedProperties);
-               systemProperties.setProperty(key,value);
-       }
-       
-       private static void copyProperty (String key, Properties from, Properties to) {
-               String value = from.getProperty(key,NULL);
-               to.setProperty(key,value);
-       }
-
-       protected void setUp() throws Exception {
-               super.setUp();
-               savedProperties = new Properties();
-       }
-
-       protected void tearDown() throws Exception {
-               super.tearDown();
-               
-               /* Restore system properties */
-               Properties systemProperties = System.getProperties();
-               for (Enumeration enu = savedProperties.keys(); enu.hasMoreElements(); ) {
-                       String key = (String)enu.nextElement();
-                       String value = savedProperties.getProperty(key);
-                       if (value == NULL) systemProperties.remove(key);
-                       else systemProperties.setProperty(key,value);
-               }
-       }
-
-}