diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-25 15:49:50 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-25 15:49:50 -0800 |
commit | 38a19ea6a0b864447883328fe1103fd991a308f0 (patch) | |
tree | 78736cef5e004315a6cdbe4071de92c10c663353 /loadtime/src/test | |
parent | b30dde96344652cf514342b0ca597e37fe9181a0 (diff) | |
download | aspectj-38a19ea6a0b864447883328fe1103fd991a308f0.tar.gz aspectj-38a19ea6a0b864447883328fe1103fd991a308f0.zip |
mavenizing loadtime - wip
Diffstat (limited to 'loadtime/src/test')
17 files changed, 2175 insertions, 0 deletions
diff --git a/loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java b/loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java new file mode 100644 index 000000000..8b4c58446 --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/bea/jvm/ClassLibraryImpl.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.bea.jvm; + +import com.bea.jvm.ClassLibrary; +import com.bea.jvm.ClassPreProcessor; +import com.bea.jvm.NotAvailableException; + +public class ClassLibraryImpl implements ClassLibrary { + + private ClassPreProcessor preProcessor; + + public ClassPreProcessor getClassPreProcessor() throws NotAvailableException { + return preProcessor; + } + + public void setClassPreProcessor(ClassPreProcessor classPreProcessor) { + this.preProcessor = classPreProcessor; + } + +} diff --git a/loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java b/loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java new file mode 100644 index 000000000..caae32e6f --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/bea/jvm/JVMImpl.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.bea.jvm; + +import com.bea.jvm.ClassLibrary; +import com.bea.jvm.JVM; + +public class JVMImpl implements JVM { + + private ClassLibrary libarary = new ClassLibraryImpl(); + + public ClassLibrary getClassLibrary() { + return libarary; + } + +} diff --git a/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java b/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java new file mode 100644 index 000000000..f325ad804 --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/loadtime/LoadtimeModuleTests.java @@ -0,0 +1,47 @@ +package org.aspectj.loadtime; + +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +import org.aspectj.weaver.loadtime.AjTest; +import org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest; +import org.aspectj.weaver.loadtime.WeavingContextTest; +import org.aspectj.weaver.loadtime.WeavingURLClassLoaderTest; +import org.aspectj.weaver.loadtime.test.DocumentParserTest; + +/** + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public class LoadtimeModuleTests extends TestCase { + + public static Test suite() { + TestSuite suite = new TestSuite(LoadtimeModuleTests.class.getName()); + + suite.addTestSuite(DocumentParserTest.class); + suite.addTestSuite(AjTest.class); + suite.addTestSuite(ClassLoaderWeavingAdaptorTest.class); + // suite.addTestSuite(JRockitAgentTest.class); + suite.addTestSuite(WeavingContextTest.class); + suite.addTestSuite(WeavingURLClassLoaderTest.class); + return suite; + } + + public static void main(String args[]) throws Throwable { + TestRunner.run(suite()); + } + +} diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/AjTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/AjTest.java new file mode 100644 index 000000000..d8f8fa85a --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/AjTest.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.weaver.loadtime; + +import java.net.URL; +import java.net.URLClassLoader; + +import junit.framework.TestCase; + +public class AjTest extends TestCase { + + public void testAj() { + // Aj aj = + new Aj(); + } + + public void testAjIWeavingContext() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + IWeavingContext weavingContext = new DefaultWeavingContext(loader); + // Aj aj = + new Aj(weavingContext); + } + + public void testInitialize() { + Aj aj = new Aj(); + aj.initialize(); + } + + public void testPreProcess() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + Aj aj = new Aj(); + aj.preProcess("Junk", new byte[] {}, loader, null); + } + + public void testGetNamespace() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + Aj aj = new Aj(); + String namespace = aj.getNamespace(loader); + assertEquals("Namespace should be empty", "", namespace); + } + + public void testGeneratedClassesExist() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + Aj aj = new Aj(); + boolean exist = aj.generatedClassesExist(loader); + assertFalse("There should be no generated classes", exist); + } + + public void testFlushGeneratedClasses() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + Aj aj = new Aj(); + aj.flushGeneratedClasses(loader); + boolean exist = aj.generatedClassesExist(loader); + assertFalse("There should be no generated classes", exist); + } + +} diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java new file mode 100644 index 000000000..456fde121 --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java @@ -0,0 +1,706 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.weaver.loadtime; + +import java.io.File; +import java.lang.ref.Reference; +import java.lang.reflect.Field; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.util.ClassPath; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.World.TypeMap; +import org.aspectj.weaver.bcel.BcelWorld; +import org.aspectj.weaver.loadtime.definition.Definition; +import org.aspectj.weaver.tools.WeavingAdaptor; + +public class ClassLoaderWeavingAdaptorTest extends TestCase { + + public void testClassLoaderWeavingAdaptor() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, null); + } + + public void testGetNamespace() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, null); + String namespace = adaptor.getNamespace(); + assertEquals("Namespace should be empty", "", namespace); + } + + public void testGeneratedClassesExistFor() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, null); + boolean exist = adaptor.generatedClassesExistFor("Junk"); + assertFalse("There should be no generated classes", exist); + } + + public void testFlushGeneratedClasses() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, null); + adaptor.flushGeneratedClasses(); + boolean exist = adaptor.generatedClassesExistFor("Junk"); + assertFalse("There should be no generated classes", exist); + } + + /** + * Testing fast excludes of the pattern "com.foo..*". World should not have any new types in it after rejection. + */ + public void testFastExclusionOne() throws Exception { + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(null, "testdata..*"); + + String orangesSub = "testdata.sub.Oranges"; + JavaClass orangesClass = getClassFrom(orangesSub); + byte[] orangesBytes = orangesClass.getBytes(); + + boolean accepted = adaptor.accept(orangesSub, orangesBytes); + assertFalse("Should not be accepted", accepted); + TypeMap map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + // Important thing here is that the rejection of testdata.sub.Oranges did not require it to be loaded into the world at all + } + + /** + * Testing fast includes of the pattern "*". World should not have any new types in it after inclusion. + */ + public void testFastInclusionOne() throws Exception { + TestClassLoaderWeavingAdaptor adaptor = getAdaptor("*", null); + + String orangesSub = "testdata.sub.Oranges"; + JavaClass orangesClass = getClassFrom(orangesSub); + byte[] orangesBytes = orangesClass.getBytes(); + + boolean accepted = adaptor.accept(orangesSub, orangesBytes); + assertTrue("Should be accepted", accepted); + TypeMap map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + // Important thing here is that the rejection of testdata.sub.Oranges did not require it to be loaded into the world at all + } + + /** + * Testing fast excludes of the pattern "*Oranges". World should not have any new types in it after rejection. + */ + public void testFastExclusionTwo() throws Exception { + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(null, "*Oranges"); + + String oranges = "testdata.Oranges"; + JavaClass orangesClass = getClassFrom(oranges); + byte[] orangesBytes = orangesClass.getBytes(); + + boolean accepted = adaptor.accept(oranges, orangesBytes); + assertFalse("Should not be accepted", accepted); + TypeMap map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + String orangesSub = "testdata.sub.Oranges"; + + JavaClass orangesSubClass = getClassFrom(orangesSub); + byte[] orangesSubBytes = orangesSubClass.getBytes(); + + accepted = adaptor.accept(orangesSub, orangesSubBytes); + assertFalse("Should not be accepted", accepted); + map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + } + + /** + * Testing fast excludes of the pattern "*..*Oranges*". World should not have any new types in it after rejection. + */ + public void testFastExclusionThree() throws Exception { + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(null, "*..*ran*"); + + String oranges = "testdata.Oranges"; + JavaClass orangesClass = getClassFrom(oranges); + byte[] orangesBytes = orangesClass.getBytes(); + + boolean accepted = adaptor.accept(oranges, orangesBytes); + assertFalse("Should not be accepted", accepted); + TypeMap map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + String orangesSub = "testdata.sub.Oranges"; + JavaClass orangesSubClass = getClassFrom(orangesSub); + byte[] orangesSubBytes = orangesSubClass.getBytes(); + + accepted = adaptor.accept(orangesSub, orangesSubBytes); + assertFalse("Should not be accepted", accepted); + map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + String apples = "testdata.Apples"; + JavaClass applesClass = getClassFrom(apples); + byte[] applesBytes = applesClass.getBytes(); + + accepted = adaptor.accept(apples, applesBytes); + assertTrue("Should be accepted", accepted); + map = accessTypeMap(adaptor); + + // The aspect and the Apples type + assertEquals(1, map.getExpendableMap().size()); + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + } + + public void testIncludedWhenNonOptimalExclusion() throws Exception { + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(new String[] { "*", "FooBar" }, new String[] { "*..*ran*es*" }); + + String oranges = "testdata.Oranges"; + JavaClass orangesClass = getClassFrom(oranges); + byte[] orangesBytes = orangesClass.getBytes(); + + boolean accepted = false; + // adaptor.accept(oranges, orangesBytes); + // assertFalse("Should not be accepted", accepted); + TypeMap map = accessTypeMap(adaptor); + + // // The aspect + // assertEquals(1, map.getExpendableMap().size()); + + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + String apples = "testdata.Apples"; + JavaClass applesClass = getClassFrom(apples); + byte[] applesBytes = applesClass.getBytes(); + + accepted = adaptor.accept(apples, applesBytes); + assertTrue("Should be accepted", accepted); + map = accessTypeMap(adaptor); + + // // The aspect + // assertEquals(1, map.getExpendableMap().size()); + // // primitives, void and jlObject + // assertEquals(10, map.getMainMap().size()); + // + // String apples = "testdata.Apples"; + // JavaClass applesClass = getClassFrom(apples); + // byte[] applesBytes = applesClass.getBytes(); + // + // accepted = adaptor.accept(apples, applesBytes); + // assertTrue("Should be accepted", accepted); + // map = accessTypeMap(adaptor); + // + // // The aspect and the Apples type + // assertEquals(1, map.getExpendableMap().size()); + // // primitives, void and jlObject + // assertEquals(10, map.getMainMap().size()); + } + + private void checkAccept(ClassLoaderWeavingAdaptor adaptor, String name) throws Exception { + JavaClass clazz = getClassFrom(name); + byte[] bytes = clazz.getBytes(); + + boolean accepted = adaptor.accept(name, bytes); + assertTrue("Should be accepted", accepted); + } + + private void checkNotAccept(ClassLoaderWeavingAdaptor adaptor, String name) throws Exception { + JavaClass clazz = getClassFrom(name); + byte[] bytes = clazz.getBytes(); + + boolean accepted = adaptor.accept(name, bytes); + assertFalse("Should not be accepted", accepted); + } + + /** + * Test how multiple definitions are merged. Each Definition represents a different aop.xml file. + */ + public void testIncludedWhenNonOptimalExclusion2() throws Exception { + Definition aopOne = new Definition(); + aopOne.getIncludePatterns().add("*"); + + Definition aopTwo = new Definition(); + aopTwo.getIncludePatterns().add("testdata.Apples+"); + + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(aopOne, aopTwo); + + checkAccept(adaptor, "testdata.Oranges"); + checkAccept(adaptor, "testdata.Apples"); + + adaptor = getAdaptor(aopTwo, aopOne); + + checkAccept(adaptor, "testdata.Oranges"); + checkAccept(adaptor, "testdata.Apples"); + } + + public void testIncludedWhenNonOptimalExclusion3() throws Exception { + Definition aopOne = new Definition(); + aopOne.getIncludePatterns().add("*"); + + Definition aopTwo = new Definition(); + aopTwo.getIncludePatterns().add("java.sql.Connection+"); + aopTwo.getIncludePatterns().add("java.sql.Statement+"); + + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(aopOne, aopTwo); + + checkAccept(adaptor, "testdata.Apples"); + checkAccept(adaptor, "testdata.MySqlStatement"); + + adaptor = getAdaptor(aopTwo, aopOne); + + checkAccept(adaptor, "testdata.Apples"); + checkAccept(adaptor, "testdata.MySqlStatement"); + } + + // Some excludes defined and some includes but importantly a star include + public void testIncludedWhenNonOptimalExclusion4() throws Exception { + Definition aopOne = new Definition(); + aopOne.getIncludePatterns().add("*"); + + Definition aopTwo = new Definition(); + aopTwo.getIncludePatterns().add("java.sql.Connection+"); + aopTwo.getIncludePatterns().add("java.sql.Statement+"); + + Definition aopThree = new Definition(); + aopThree.getExcludePatterns().add("com.jinspired..*"); + aopThree.getExcludePatterns().add("$com.jinspired..*"); + aopThree.getExcludePatterns().add("com.jinspired.jxinsight.server..*+"); + + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(aopOne, aopTwo, aopThree); + + checkAccept(adaptor, "testdata.Apples"); + checkAccept(adaptor, "testdata.MySqlStatement"); + + adaptor = getAdaptor(aopThree, aopTwo, aopOne); + + checkAccept(adaptor, "testdata.Apples"); + checkAccept(adaptor, "testdata.MySqlStatement"); + } + + // Some excludes defined and some includes but importantly an exact includename + public void testIncludedWhenNonOptimalExclusion5() throws Exception { + Definition aopOne = new Definition(); + aopOne.getIncludePatterns().add("testdata.Apples"); + + Definition aopTwo = new Definition(); + aopTwo.getIncludePatterns().add("java.sql.Connection+"); + aopTwo.getIncludePatterns().add("java.sql.Statement+"); + + Definition aopThree = new Definition(); + aopThree.getExcludePatterns().add("com.jinspired..*"); + aopThree.getExcludePatterns().add("$com.jinspired..*"); + aopThree.getExcludePatterns().add("com.jinspired.jxinsight.server..*+"); + + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(aopOne, aopTwo, aopThree); + + checkAccept(adaptor, "testdata.Apples"); + + adaptor = getAdaptor(aopThree, aopTwo, aopOne); + + checkAccept(adaptor, "testdata.Apples"); + } + + public void testIncludedWhenNonOptimalExclusion7() throws Exception { + Definition aopOne = new Definition(); + aopOne.getIncludePatterns().add("*"); + aopOne.getExcludePatterns().add("*Fun*ky*"); + + // Definition aopTwo = new Definition(); + // aopTwo.getIncludePatterns().add("java.sql.Connection+"); + // aopTwo.getIncludePatterns().add("java.sql.Statement+"); + // + // Definition aopThree = new Definition(); + // aopThree.getExcludePatterns().add("com.jinspired..*"); + // aopThree.getExcludePatterns().add("$com.jinspired..*"); + // aopThree.getExcludePatterns().add("com.jinspired.jxinsight.server..*+"); + + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(aopOne); + + checkAccept(adaptor, "testdata.Apples"); + + // adaptor = getAdaptor(aopThree, aopTwo, aopOne); + // + // checkAccept(adaptor, "testdata.Apples"); + } + + public void testIncludedWhenNonOptimalExclusion6() throws Exception { + Definition aopOne = new Definition(); + aopOne.getIncludePatterns().add("testdata..*"); + + Definition aopTwo = new Definition(); + aopTwo.getIncludePatterns().add("java.sql.Connection+"); + aopTwo.getIncludePatterns().add("java.sql.Statement+"); + + Definition aopThree = new Definition(); + aopThree.getExcludePatterns().add("com.jinspired..*"); + aopThree.getExcludePatterns().add("$com.jinspired..*"); + aopThree.getExcludePatterns().add("com.jinspired.jxinsight.server..*+"); + + TestClassLoaderWeavingAdaptor adaptor = getAdaptor(aopOne, aopTwo, aopThree); + + checkAccept(adaptor, "testdata.Apples"); + + adaptor = getAdaptor(aopThree, aopTwo, aopOne); + + checkAccept(adaptor, "testdata.Apples"); + } + + /** + * Testing fast inclusion checking of exact include names eg. "testdata.sub.Oranges" + */ + public void testFastInclusionTwo() throws Exception { + TestClassLoaderWeavingAdaptor adaptor = getAdaptor("testdata.sub.Oranges", null); + + String oranges = "testdata.Oranges"; + JavaClass orangesClass = getClassFrom(oranges); + byte[] orangesBytes = orangesClass.getBytes(); + + boolean accepted = adaptor.accept(oranges, orangesBytes); + assertFalse("Should not be accepted", accepted); + TypeMap map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + String orangesSub = "testdata.sub.Oranges"; + JavaClass orangesSubClass = getClassFrom(orangesSub); + byte[] orangesSubBytes = orangesSubClass.getBytes(); + + accepted = adaptor.accept(orangesSub, orangesSubBytes); + assertTrue("Should be accepted", accepted); + map = accessTypeMap(adaptor); + + // The aspect + assertEquals(1, map.getExpendableMap().size()); + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + + String apples = "testdata.Apples"; + JavaClass applesClass = getClassFrom(apples); + byte[] applesBytes = applesClass.getBytes(); + + accepted = adaptor.accept(apples, applesBytes); + assertFalse("Should not be accepted", accepted); + map = accessTypeMap(adaptor); + + // The aspect and the Apples type + assertEquals(1, map.getExpendableMap().size()); + // primitives, void and jlObject + assertEquals(10, map.getMainMap().size()); + } + + /** + * Testing fast excludes of the pattern groovy related pattern - + */ + // public void testFastExclusionFour() throws Exception { + // TestClassLoaderWeavingAdaptor adaptor = getAdaptor("*", "testdata..* && !testdata.sub.Oran*"); + // + // String oranges = "testdata.Oranges"; + // JavaClass orangesClass = getClassFrom(oranges); + // byte[] orangesBytes = orangesClass.getBytes(); + // + // boolean accepted = adaptor.accept(oranges, orangesBytes); + // assertFalse("Should not be accepted", accepted); + // TypeMap map = accessTypeMap(adaptor); + // + // // The aspect + // assertEquals(1, map.getExpendableMap().size()); + // + // // primitives, void and jlObject + // assertEquals(10, map.getMainMap().size()); + // + // String orangesSub = "testdata.sub.Oranges"; + // JavaClass orangesSubClass = getClassFrom(orangesSub); + // byte[] orangesSubBytes = orangesSubClass.getBytes(); + // + // accepted = adaptor.accept(orangesSub, orangesSubBytes); + // assertTrue("Should be accepted", accepted); + // map = accessTypeMap(adaptor); + // + // // The aspect + // assertEquals(1, map.getExpendableMap().size()); + // // primitives, void and jlObject + // assertEquals(10, map.getMainMap().size()); + // } + + public void testAcceptanceSpeedStarDotDotStar() throws Exception { + URLClassLoader loader = new URLClassLoader(new URL[] { new File("../loadtime/bin").toURI().toURL(), + new File("../loadtime/testdata/anaspect.jar").toURI().toURL() }, null); + + JavaClass jc = getClassFrom("../loadtime/bin", "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOne"); + byte[] bs = jc.getBytes(); + jc = getClassFrom("../loadtime/bin", "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOneCGLIB"); + byte[] bs2 = jc.getBytes(); + // InputStream is = loader.getResourceAsStream("org.aspectj.weaver.loadtime.ClassLoaderWeaverAdaptorTests$TestOne"); + assertNotNull(bs); + TestWeavingContext wc = new TestWeavingContext(loader); + Definition d = new Definition(); + d.getExcludePatterns().add("*..*CGLIB*"); + d.getAspectClassNames().add("AnAspect"); + wc.addDefinition(d); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, wc); + boolean exist = adaptor.generatedClassesExistFor("Junk"); + assertFalse("There should be no generated classes", exist); + + // before: + // Acceptance 331ms + // Rejection 3368ms + + // after: + // Acceptance 343ms + // Rejection 80ms + + long stime = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + boolean b = adaptor.accept("org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOne", bs); + assertTrue("Should be accepted", b); + } + long etime = System.currentTimeMillis(); + System.out.println("Acceptance " + (etime - stime) + "ms"); + stime = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + adaptor.delegateForCurrentClass = null; + boolean b = adaptor.accept("org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOneCGLIB", bs2); + assertFalse("Should not be accepting CGLIB", b); + } + etime = System.currentTimeMillis(); + System.out.println("Rejection " + (etime - stime) + "ms"); + + jc = getClassFrom("../loadtime/bin", "testdata.MessageService$$EnhancerByCGLIB$$6dd4e683"); + byte[] bs3 = jc.getBytes(); + boolean b = adaptor.accept("testdata.MessageService$$EnhancerByCGLIB$$6dd4e683", bs3); + assertFalse(b); + } + + // TODO + // shouldn't add it to the type patterns if we are going to fast handle it + // include for exact name, what does it mean? + // excludes="!xxxx" should also be fast matched... + + public void testAcceptanceSpeedExactName() throws Exception { + URLClassLoader loader = new URLClassLoader(new URL[] { new File("../loadtime/bin").toURI().toURL(), + new File("../loadtime/testdata/anaspect.jar").toURI().toURL() }, null); + + JavaClass jc = getClassFrom("../loadtime/bin", "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOne"); + byte[] bs = jc.getBytes(); + jc = getClassFrom("../loadtime/bin", "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOneCGLIB"); + byte[] bs2 = jc.getBytes(); + // InputStream is = loader.getResourceAsStream("org.aspectj.weaver.loadtime.ClassLoaderWeaverAdaptorTests$TestOne"); + assertNotNull(bs); + TestWeavingContext wc = new TestWeavingContext(loader); + Definition d = new Definition(); + d.getExcludePatterns().add("org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest.TestOneCGLIB"); + d.getAspectClassNames().add("AnAspect"); + wc.addDefinition(d); + TestClassLoaderWeavingAdaptor adaptor = new TestClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, wc); + boolean exist = adaptor.generatedClassesExistFor("Junk"); + assertFalse("There should be no generated classes", exist); + + // before: + // Acceptance 331ms + // Rejection 3160ms + + // after: + // Acceptance 379ms + // Rejection 103ms + + long stime = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + boolean b = adaptor.accept("org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOne", bs); + assertTrue("Should be accepted", b); + } + long etime = System.currentTimeMillis(); + System.out.println("Acceptance " + (etime - stime) + "ms"); + stime = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + adaptor.delegateForCurrentClass = null; + boolean b = adaptor.accept("org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest$TestOneCGLIB", bs2); + assertFalse("Should not be accepting CGLIB", b); + } + etime = System.currentTimeMillis(); + System.out.println("Rejection " + (etime - stime) + "ms"); + BcelWorld world = adaptor.getWorld(); + Field f = World.class.getDeclaredField("typeMap"); + f.setAccessible(true); + TypeMap typeMap = (TypeMap) f.get(world); + System.out.println(typeMap.getExpendableMap().size()); + System.out.println(typeMap.getMainMap().size()); + printExpendableMap(typeMap.getExpendableMap()); + printMainMap(typeMap.getMainMap()); + } + + // --- infrastructure --- + + private TypeMap accessTypeMap(TestClassLoaderWeavingAdaptor adaptor) { + return adaptor.getWorld().getTypeMap(); + } + + public TestClassLoaderWeavingAdaptor getAdaptor(String includePattern, String excludePattern) { + return getAdaptor(includePattern == null ? null : new String[] { includePattern }, excludePattern == null ? null + : new String[] { excludePattern }); + } + + public TestClassLoaderWeavingAdaptor getAdaptor(Definition... definitions) { + try { + URLClassLoader loader = new URLClassLoader(new URL[] { new File("../loadtime/bin").toURI().toURL(), + new File("../loadtime/testdata/anaspect.jar").toURI().toURL() }, null); + TestWeavingContext wc = new TestWeavingContext(loader); + for (Definition definition : definitions) { + // need some random aspect or the weaver will shut down! + definition.getAspectClassNames().add("AnAspect"); + wc.addDefinition(definition); + } + TestClassLoaderWeavingAdaptor adaptor = new TestClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, wc); + return adaptor; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public TestClassLoaderWeavingAdaptor getAdaptor(String[] includePatterns, String[] excludePatterns) { + try { + URLClassLoader loader = new URLClassLoader(new URL[] { new File("../loadtime/bin").toURI().toURL(), + new File("../loadtime/testdata/anaspect.jar").toURI().toURL() }, null); + TestWeavingContext wc = new TestWeavingContext(loader); + Definition d = new Definition(); + if (includePatterns != null) { + for (String s : includePatterns) { + d.getIncludePatterns().add(s); + } + } + if (excludePatterns != null) { + for (String s : excludePatterns) { + d.getExcludePatterns().add(s); + } + } + // need some random aspect or the weaver will shut down! + d.getAspectClassNames().add("AnAspect"); + wc.addDefinition(d); + TestClassLoaderWeavingAdaptor adaptor = new TestClassLoaderWeavingAdaptor(); + adaptor.initialize(loader, wc); + return adaptor; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @SuppressWarnings("unused") + private void printMaps(TypeMap map) { + printExpendableMap(map.getExpendableMap()); + printMainMap(map.getMainMap()); + } + + private void printExpendableMap(Map<String, Reference<ResolvedType>> m) { + for (String sig : m.keySet()) { + System.out.println(sig + "=" + m.get(sig)); + } + } + + private void printMainMap(Map<String, ResolvedType> m) { + for (Object o : m.keySet()) { + String sig = (String) o; + System.out.println(sig + "=" + m.get(sig)); + } + } + + static class TestClassLoaderWeavingAdaptor extends ClassLoaderWeavingAdaptor { + + public BcelWorld getWorld() { + return bcelWorld; + } + } + + public static JavaClass getClassFrom(String clazzname) throws ClassNotFoundException { + return getClassFrom("../loadtime/bin", clazzname); + } + + public static JavaClass getClassFrom(String frompath, String clazzname) throws ClassNotFoundException { + SyntheticRepository repos = createRepos(frompath); + return repos.loadClass(clazzname); + } + + public static SyntheticRepository createRepos(String cpentry) { + ClassPath cp = new ClassPath(cpentry + File.pathSeparator + System.getProperty("java.class.path")); + return SyntheticRepository.getInstance(cp); + } + + // + // @Aspect + // static class AnAspect { + // + // } + + class TestOne { + + } + + class TestOneCGLIB { + + } + + static class TestWeavingContext extends DefaultWeavingContext { + + List<Definition> testList = new ArrayList<Definition>(); + + public TestWeavingContext(ClassLoader loader) { + super(loader); + } + + public void addDefinition(Definition d) { + testList.add(d); + } + + @Override + public List<Definition> getDefinitions(final ClassLoader loader, final WeavingAdaptor adaptor) { + return testList; + } + } +} + +// --- testclasses and aspects ---
\ No newline at end of file diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java new file mode 100644 index 000000000..133387cf4 --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java @@ -0,0 +1,231 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.weaver.loadtime; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.jar.JarFile; +import java.util.zip.ZipEntry; + +import junit.framework.TestCase; + +import com.bea.jvm.ClassPreProcessor; +import com.bea.jvm.JVMFactory; + +public class JRockitAgentTest extends TestCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testJRockitAgent() { + ClassPreProcessor preProcessor = new JRockitAgent(); + ClassPreProcessor expectedPreProcessor = JVMFactory.getJVM().getClassLibrary().getClassPreProcessor(); + assertEquals("JRocketAgent must be registered", expectedPreProcessor, preProcessor); + } + + public void testPreProcess() { + ClassPreProcessor preProcessor = new JRockitAgent(); + preProcessor.preProcess(null, "foo.Bar", new byte[] {}); + } + + public void testJrockitRecursionProtection() { + URLClassLoader thisLoader = (URLClassLoader) getClass().getClassLoader(); + ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); + + try { + /* Needed by Commons Logging */ + Thread.currentThread().setContextClassLoader(thisLoader.getParent()); + + ClassLoader loader = new JRockitClassLoader(thisLoader); + + Class.forName("java.lang.Object", false, loader); + Class.forName("junit.framework.TestCase", false, loader); + } catch (Exception ex) { + ex.printStackTrace(); + fail(ex.toString()); + } finally { + Thread.currentThread().setContextClassLoader(contextLoader); + } + } + + private class JRockitClassLoader extends ClassLoader { + + public final static boolean debug = false; + + private List path = new LinkedList(); + // private com.bea.jvm.ClassPreProcessor agent; + private Object agent; + private Method preProcess; + + public JRockitClassLoader(URLClassLoader clone) throws Exception { + /* Use extensions loader */ + super(clone.getParent()); + + URL[] urls = clone.getURLs(); + for (int i = 0; i < urls.length; i++) { + Object pathElement; + URL url = urls[i]; + if (debug) + System.out.println("JRockitClassLoader.JRockitClassLoader() url=" + url.getPath()); + File file = new File(encode(url.getFile())); + if (debug) + System.out.println("JRockitClassLoader.JRockitClassLoader() file" + file); + if (file.isDirectory()) + pathElement = file; + else if (file.exists() && file.getName().endsWith(".jar")) + pathElement = new JarFile(file); + else + throw new RuntimeException(file.getAbsolutePath()); + path.add(pathElement); + } + + Class agentClazz = Class.forName("org.aspectj.weaver.loadtime.JRockitAgent", false, this); + Object obj = agentClazz.newInstance(); + if (debug) + System.out.println("JRockitClassLoader.JRockitClassLoader() obj=" + obj); + this.agent = obj; + byte[] bytes = new byte[] {}; + Class[] parameterTypes = new Class[] { java.lang.ClassLoader.class, java.lang.String.class, bytes.getClass() }; + preProcess = agentClazz.getMethod("preProcess", parameterTypes); + } + + /* Get rid of escaped characters */ + private String encode(String s) { + StringBuffer result = new StringBuffer(); + int i = s.indexOf("%"); + while (i != -1) { + result.append(s.substring(0, i)); + String escaped = s.substring(i + 1, i + 3); + s = s.substring(i + 3); + Integer value = Integer.valueOf(escaped, 16); + result.append(new Character((char) value.intValue())); + i = s.indexOf("%"); + } + result.append(s); + return result.toString(); + } + + protected Class findClass(String name) throws ClassNotFoundException { + if (debug) + System.out.println("> JRockitClassLoader.findClass() name=" + name); + Class clazz = null; + try { + clazz = super.findClass(name); + } catch (ClassNotFoundException ex) { + for (Iterator i = path.iterator(); clazz == null && i.hasNext();) { + byte[] classBytes = null; + try { + Object pathElement = i.next(); + if (pathElement instanceof File) { + File dir = (File) pathElement; + String className = name.replace('.', '/') + ".class"; + File classFile = new File(dir, className); + if (classFile.exists()) + classBytes = loadClassFromFile(name, classFile); + } else { + JarFile jar = (JarFile) pathElement; + String className = name.replace('.', '/') + ".class"; + ZipEntry entry = jar.getEntry(className); + if (entry != null) + classBytes = loadBytesFromZipEntry(jar, entry); + } + + if (classBytes != null) { + clazz = defineClass(name, classBytes); + } + } catch (IOException ioException) { + ex.printStackTrace(); + } + } + } + + if (debug) + System.out.println("< JRockitClassLoader.findClass() name=" + name); + return clazz; + } + + private Class defineClass(String name, byte[] bytes) { + if (debug) + System.out.println("> JRockitClassLoader.defineClass() name=" + name); + try { + if (agent != null) + preProcess.invoke(agent, new Object[] { this, name, bytes }); + } catch (IllegalAccessException iae) { + iae.printStackTrace(); + throw new ClassFormatError(iae.getMessage()); + } catch (InvocationTargetException ite) { + ite.printStackTrace(); + throw new ClassFormatError(ite.getTargetException().getMessage()); + } + if (debug) + System.out.println("< JRockitClassLoader.defineClass() name=" + name); + return super.defineClass(name, bytes, 0, bytes.length); + } + + private byte[] loadClassFromFile(String name, File file) throws IOException { + if (debug) + System.out.println("JRockitClassLoader.loadClassFromFile() file=" + file); + + byte[] bytes; + bytes = new byte[(int) file.length()]; + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + bytes = readBytes(fis, bytes); + } finally { + if (fis != null) + fis.close(); + } + + return bytes; + } + + private byte[] loadBytesFromZipEntry(JarFile jar, ZipEntry entry) throws IOException { + if (debug) + System.out.println("JRockitClassLoader.loadBytesFromZipEntry() entry=" + entry); + + byte[] bytes; + bytes = new byte[(int) entry.getSize()]; + InputStream is = null; + try { + is = jar.getInputStream(entry); + bytes = readBytes(is, bytes); + } finally { + if (is != null) + is.close(); + } + + return bytes; + } + + private byte[] readBytes(InputStream is, byte[] bytes) throws IOException { + for (int offset = 0; offset < bytes.length;) { + int read = is.read(bytes, offset, bytes.length - offset); + offset += read; + } + return bytes; + } + } +} diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/WeavingContextTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/WeavingContextTest.java new file mode 100644 index 000000000..ea787dac8 --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/WeavingContextTest.java @@ -0,0 +1,195 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * 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://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster - initial implementation + *******************************************************************************/ +package org.aspectj.weaver.loadtime; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Enumeration; +import java.util.List; + +import junit.framework.TestCase; + +import org.aspectj.weaver.tools.WeavingAdaptor; + +public class WeavingContextTest extends TestCase { + + private boolean called; + + public void testWeavingContext() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader,context); + } + + public void testGetResources() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader) { + + public Enumeration getResources(String name) throws IOException { + called = true; + return super.getResources(name); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader,context); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetBundleIdFromURL() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getBundleIdFromURL(URL url) { + throw new UnsupportedOperationException(); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + try { + adaptor.initialize(loader,context); + } + catch (UnsupportedOperationException ex) { + fail("IWeavingContect.getBundleIdFromURL() is deprecated"); + } + } + + public void testGetClassLoaderName() { + URLClassLoader loader = new URLClassLoader(new URL[] {},null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getClassLoaderName () { + called = true; + return super.getClassLoaderName(); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader,context); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetFile() throws IOException { + File file = new File("../loadtime/testdata"); + URL fileURL = file.getCanonicalFile().toURL(); + URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getFile (URL url) { + called = true; + return super.getFile(url); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader,context); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetId() throws IOException { + File file = new File("../loadtime/testdata"); + URL fileURL = file.getCanonicalFile().toURL(); + URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null); + IWeavingContext context = new TestWeavingContext(loader) { + + public String getId () { + called = true; + return super.getId(); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader,context); + + assertTrue("IWeavingContext not called",called); + } + + public void testGetDefinitions () throws Exception { + File file = new File("../loadtime/testdata"); + URL fileURL = file.getCanonicalFile().toURL(); + URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null); + IWeavingContext context = new TestWeavingContext(loader) { + + public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) { + called = true; + return super.getDefinitions(loader,adaptor); + } + + }; + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(); + adaptor.initialize(loader,context); + + assertTrue("getDefinitions not called",called); + } + + private static class TestWeavingContext implements IWeavingContext { + + private ClassLoader loader; + + public TestWeavingContext (ClassLoader classLoader) { + this.loader = classLoader; + } + + public String getBundleIdFromURL(URL url) { + return null; + } + + public String getClassLoaderName() { + return "ClassLoaderName"; + } + + public ClassLoader getClassLoader() { return this.loader;} + + public String getFile(URL url) { + return "File"; + } + + public String getId() { + return "Id"; + } + + public Enumeration getResources(String name) throws IOException { + return loader.getResources(name); + } + + public boolean isLocallyDefined(String classname) { + String asResource = classname.replace('.', '/').concat(".class"); + + URL localURL = loader.getResource(asResource); + if (localURL == null) return false; + + boolean isLocallyDefined = true; + ClassLoader parent = loader.getParent(); + if (parent != null) { + URL parentURL = parent.getResource(asResource); + if (localURL.equals(parentURL)) isLocallyDefined = false; + } + return isLocallyDefined; + } + + public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) { + return ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader); + } + } + + protected void setUp() throws Exception { + super.setUp(); + + this.called = false; + } + +} diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/WeavingURLClassLoaderTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/WeavingURLClassLoaderTest.java new file mode 100644 index 000000000..187de37ba --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/WeavingURLClassLoaderTest.java @@ -0,0 +1,550 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * 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://www.eclipse.org/legal/epl-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 + * + */ +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()); + } + } + + /* + * We won't get an exception because the aspect path is empty and there is no aop.xml file so the weaver will be disabled and no + * reweaving will take place + */ + 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 testGarbageName() { + setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH, ""); + setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH, WOVEN_JAR); + WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); + + try { + loader.loadClass("[Lorg.springframework.webflow.config.FlowLocation;Editor"); + } catch (ClassNotFoundException cnfe) { + // success! + } catch (Exception ex) { + fail(ex.toString()); + } + } + + /* + * We get an exception because the class was not built reweavable + */ + 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) { + ex.printStackTrace(); + // throw new RuntimeException("Failed!", ex); + fail(ex.toString()); + // } finally { + // System.exit(0); + } + } + + 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) { + // Expecting: java.lang.NoClassDefFoundError: LTWAspect + String m = ex.getMessage(); + if (-1 == m.indexOf("java.lang.NoClassDefFoundError")) { + fail("Expecting java.lang.NoClassDefFoundError but caught " + 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); + } + } + + public void testWeavingURLClassLoaderOddJars() throws Exception { + URL classes = FileUtil.getFileURL(new File(TEST_BASE + "/test.jar/main.file")); + URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT)); + URL aspects = FileUtil.getFileURL(new File(TEST_BASE + "/aspectNoExt")); + URL[] classURLs = new URL[] { aspects, classes, aspectjrt }; + URL[] aspectURLs = new URL[] { aspects }; + WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs, aspectURLs, getClass().getClassLoader()); + + Class<?> clazz = loader.loadClass("packag.Main"); + invokeMain(clazz, new String[] {}); + } + + public void testWeavingURLClassLoaderMissingJars() throws Exception { + try { + URL classes = FileUtil.getFileURL(new File(TEST_BASE + "/test.jar/main.file")); + URL aspectjrt = FileUtil.getFileURL(new File(ASPECTJRT)); + URL aspects = FileUtil.getFileURL(new File(TEST_BASE + "/MissingFile")); + URL[] classURLs = new URL[] { aspects, classes, aspectjrt }; + URL[] aspectURLs = new URL[] { aspects }; + WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs, aspectURLs, getClass().getClassLoader()); + + Class<?> clazz = loader.loadClass("packag.Main"); + invokeMain(clazz, new String[] {}); + fail("Should reject bad aspect MissingFile"); + } catch (AbortException ae) { + assertTrue("Unexpected cause: " + ae.getMessage(), ae.getMessage().indexOf("bad aspect library") != -1); + } + } + + 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) { + Throwable targetException = ex.getTargetException(); + if (targetException instanceof RuntimeException) { + throw (RuntimeException) ex.getTargetException(); + } else { + 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<Object> 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); + } + } + } + +} diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/DocumentParserTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/DocumentParserTest.java new file mode 100644 index 000000000..92d35983f --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/DocumentParserTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package org.aspectj.weaver.loadtime.test; + +import junit.framework.TestCase; + +import java.net.URL; + +import org.aspectj.weaver.loadtime.definition.Definition; +import org.aspectj.weaver.loadtime.definition.DocumentParser; + +/** + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public class DocumentParserTest extends TestCase { + + public void testSimple() throws Throwable { + URL url = DocumentParserTest.class.getResource("simple.xml"); + Definition def = DocumentParser.parse(url); + assertEquals("-showWeaveInfo", def.getWeaverOptions().trim()); + } + + public void testSimpleWithDtd() throws Throwable { + URL url = DocumentParserTest.class.getResource("simpleWithDtd.xml"); + Definition def = DocumentParser.parse(url); + assertEquals("-showWeaveInfo", def.getWeaverOptions().trim()); + assertTrue(def.getAspectClassNames().contains("test.Aspect")); + + assertEquals("foo..bar.Goo+", def.getIncludePatterns().get(0)); + assertEquals("@Baz", def.getAspectExcludePatterns().get(0)); + assertEquals("@Whoo", def.getAspectIncludePatterns().get(0)); + assertEquals("foo..*", def.getDumpPatterns().get(0)); + assertEquals(true,def.shouldDumpBefore()); + } + +} diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/simple.xml b/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/simple.xml new file mode 100644 index 000000000..54d3dd7af --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/simple.xml @@ -0,0 +1,7 @@ +<aspectj> + <weaver options="-showWeaveInfo"> + </weaver> + <aspects> + <aspect name="test.Aspect"/> + </aspects> +</aspectj> diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml b/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml new file mode 100644 index 000000000..252bc0136 --- /dev/null +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/test/simpleWithDtd.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://sswww.aspectj.org/dtd/aspectj_1_5_0.dtd"> +<aspectj> + <weaver options="-showWeaveInfo"> + <include within="foo..bar.Goo+"/> + <dump within="foo..*" beforeandafter="true"/> + </weaver> + <aspects> + <exclude within="@Baz"/> + <include within="@Whoo"/> + <aspect name="test.Aspect"/> + </aspects> +</aspectj> diff --git a/loadtime/src/test/java/testdata/Apples.java b/loadtime/src/test/java/testdata/Apples.java new file mode 100644 index 000000000..2d216c1ea --- /dev/null +++ b/loadtime/src/test/java/testdata/Apples.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Andy Clement + *******************************************************************************/ +package testdata; + +public class Apples { + +} diff --git a/loadtime/src/test/java/testdata/MessageService$$EnhancerByCGLIB$$6dd4e683.java b/loadtime/src/test/java/testdata/MessageService$$EnhancerByCGLIB$$6dd4e683.java new file mode 100644 index 000000000..4efd665eb --- /dev/null +++ b/loadtime/src/test/java/testdata/MessageService$$EnhancerByCGLIB$$6dd4e683.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Andy Clement + *******************************************************************************/ +package testdata; + +public class MessageService$$EnhancerByCGLIB$$6dd4e683 { + +} diff --git a/loadtime/src/test/java/testdata/MySqlStatement.java b/loadtime/src/test/java/testdata/MySqlStatement.java new file mode 100644 index 000000000..3f7048610 --- /dev/null +++ b/loadtime/src/test/java/testdata/MySqlStatement.java @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Andy Clement + *******************************************************************************/ +package testdata; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; + +public abstract class MySqlStatement implements Statement { + + public void addBatch(String sql) throws SQLException { + } + + public void cancel() throws SQLException { + } + + public void clearBatch() throws SQLException { + } + + public void clearWarnings() throws SQLException { + } + + public void close() throws SQLException { + } + + public boolean execute(String sql) throws SQLException { + return false; + } + + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + return false; + } + + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + return false; + } + + public boolean execute(String sql, String[] columnNames) throws SQLException { + return false; + } + + public int[] executeBatch() throws SQLException { + return null; + } + + public ResultSet executeQuery(String sql) throws SQLException { + return null; + } + + public int executeUpdate(String sql) throws SQLException { + return 0; + } + + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + return 0; + } + + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + return 0; + } + + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + return 0; + } + + public Connection getConnection() throws SQLException { + return null; + } + + public int getFetchDirection() throws SQLException { + return 0; + } + + public int getFetchSize() throws SQLException { + return 0; + } + + public ResultSet getGeneratedKeys() throws SQLException { + return null; + } + + public int getMaxFieldSize() throws SQLException { + return 0; + } + + public int getMaxRows() throws SQLException { + return 0; + } + + public boolean getMoreResults() throws SQLException { + return false; + } + + public boolean getMoreResults(int current) throws SQLException { + return false; + } + + public int getQueryTimeout() throws SQLException { + return 0; + } + + public ResultSet getResultSet() throws SQLException { + return null; + } + + public int getResultSetConcurrency() throws SQLException { + return 0; + } + + public int getResultSetHoldability() throws SQLException { + return 0; + } + + public int getResultSetType() throws SQLException { + return 0; + } + + public int getUpdateCount() throws SQLException { + return 0; + } + + public SQLWarning getWarnings() throws SQLException { + return null; + } + + public void setCursorName(String name) throws SQLException { + } + + public void setEscapeProcessing(boolean enable) throws SQLException { + } + + public void setFetchDirection(int direction) throws SQLException { + } + + public void setFetchSize(int rows) throws SQLException { + } + + public void setMaxFieldSize(int max) throws SQLException { + } + + public void setMaxRows(int max) throws SQLException { + } + + public void setQueryTimeout(int seconds) throws SQLException { + } + + public boolean isClosed() throws SQLException { + // TODO Auto-generated method stub + return false; + } + + public boolean isPoolable() throws SQLException { + // TODO Auto-generated method stub + return false; + } + + public void setPoolable(boolean poolable) throws SQLException { + // TODO Auto-generated method stub + + } + + public boolean isWrapperFor(Class<?> iface) throws SQLException { + // TODO Auto-generated method stub + return false; + } + + public <T> T unwrap(Class<T> iface) throws SQLException { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/loadtime/src/test/java/testdata/Oranges.java b/loadtime/src/test/java/testdata/Oranges.java new file mode 100644 index 000000000..d634bb8db --- /dev/null +++ b/loadtime/src/test/java/testdata/Oranges.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Andy Clement + *******************************************************************************/ +package testdata; + +public class Oranges { + +} diff --git a/loadtime/src/test/java/testdata/sub/Apples.java b/loadtime/src/test/java/testdata/sub/Apples.java new file mode 100644 index 000000000..6f666892f --- /dev/null +++ b/loadtime/src/test/java/testdata/sub/Apples.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Andy Clement + *******************************************************************************/ +package testdata.sub; + +public class Apples { + +} diff --git a/loadtime/src/test/java/testdata/sub/Oranges.java b/loadtime/src/test/java/testdata/sub/Oranges.java new file mode 100644 index 000000000..f1828c001 --- /dev/null +++ b/loadtime/src/test/java/testdata/sub/Oranges.java @@ -0,0 +1,16 @@ +/******************************************************************************* + * Copyright (c) 2009 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: + * Andy Clement + *******************************************************************************/ +package testdata.sub; + +public class Oranges { + +} |