diff options
author | mwebster <mwebster> | 2006-06-15 16:32:39 +0000 |
---|---|---|
committer | mwebster <mwebster> | 2006-06-15 16:32:39 +0000 |
commit | fdbae3fda3e572ea35ac4a73373896b9b5cff8f7 (patch) | |
tree | 5433af7f17e1b96d05fe541a1bca017b12a6ac81 /loadtime/testsrc | |
parent | 81abede5115df2b032b846c5ff8bf23050f68e34 (diff) | |
download | aspectj-fdbae3fda3e572ea35ac4a73373896b9b5cff8f7.tar.gz aspectj-fdbae3fda3e572ea35ac4a73373896b9b5cff8f7.zip |
Fix for 139936 "[ltw] WeavingAdaptor.generatedClassesExist() cannot cope with additional class weaving"
Diffstat (limited to 'loadtime/testsrc')
3 files changed, 129 insertions, 2 deletions
diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java new file mode 100644 index 000000000..e55ce2ced --- /dev/null +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/AjTest.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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); + } + + 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/testsrc/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java new file mode 100644 index 000000000..a2a07c89a --- /dev/null +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * 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 ClassLoaderWeavingAdaptorTest extends TestCase { + + public void testClassLoaderWeavingAdaptor() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,null); + } + + public void testGetNamespace() { + ClassLoader loader = new URLClassLoader(new URL[] {}, null); + ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(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(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(loader,null); + adaptor.flushGeneratedClasses(); + boolean exist = adaptor.generatedClassesExistFor("Junk"); + assertFalse("There should be no generated classes",exist); + } + +} diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java index a3fd2cd10..1bc41b3cc 100644 --- a/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java +++ b/loadtime/testsrc/org/aspectj/weaver/loadtime/JRockitAgentTest.java @@ -82,10 +82,11 @@ public class JRockitAgentTest extends TestCase { for (int i = 0; i < urls.length; i++) { Object pathElement; URL url = urls[i]; - File file = new File(url.getFile()); + 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.getName().endsWith(".jar")) pathElement = new JarFile(file); + else if (file.exists() && file.getName().endsWith(".jar")) pathElement = new JarFile(file); else throw new RuntimeException(file.getAbsolutePath().toString()); path.add(pathElement); } @@ -99,6 +100,22 @@ public class JRockitAgentTest extends TestCase { 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; |