private final static String AOP_XML = "META-INF/aop.xml";
+ private boolean initialized;
+
private List m_dumpTypePattern = new ArrayList();
private boolean m_dumpBefore = false;
private List m_includeTypePattern = new ArrayList();
private List m_aspectIncludeStartsWith = new ArrayList();
private StringBuffer namespace;
+ private ClassLoader classLoader;
private IWeavingContext weavingContext;
public ClassLoaderWeavingAdaptor(final ClassLoader loader, IWeavingContext wContext) {
+ super();
+ this.classLoader = loader;
this.weavingContext = wContext;
}
- protected void initialize(final ClassLoader loader, IWeavingContext wContext) {
+ protected void initialize (final ClassLoader deprecatedLoader, IWeavingContext deprecatedContext) {
//super(null);// at this stage we don't have yet a generatedClassHandler to define to the VM the closures
+ if (initialized) return;
+
+ if (weavingContext == null) {
+ weavingContext = new DefaultWeavingContext(classLoader);
+ }
+
+ createMessageHandler();
+
this.generatedClassHandler = new GeneratedClassHandler() {
/**
* Callback when we need to define a Closure in the JVM
throwable.printStackTrace();
}
- defineClass(loader, name, bytes);// could be done lazily using the hook
+ defineClass(classLoader, name, bytes);// could be done lazily using the hook
}
};
- if(wContext==null){
- weavingContext = new DefaultWeavingContext(loader);
- }else{
- weavingContext = wContext ;
- }
-
- List definitions = parseDefinitions(loader);
+ List definitions = parseDefinitions(classLoader);
if (!enabled) {
return;
}
bcelWorld = new LTWWorld(
- loader, getMessageHandler(), new ICrossReferenceHandler() {
+ classLoader, getMessageHandler(), new ICrossReferenceHandler() {
public void addCrossReference(ISourceLocation from, ISourceLocation to, IRelationship.Kind kind, boolean runtimeTest) {
;// for tools only
}
weaver = new BcelWeaver(bcelWorld);
// register the definitions
- registerDefinitions(weaver, loader, definitions);
+ registerDefinitions(weaver, classLoader, definitions);
if (enabled) {
//bcelWorld.setResolutionLoader(loader.getParent());//(ClassLoader)null);//
bcelWorld = null;
weaver = null;
}
+
+ initialized = true;
}
/**
Kind kind = lint.getLintKind(name);
kind.signal(infos,null,null);
}
+
+ protected String getContextId () {
+ return weavingContext.getId();
+ }
/**
* Register the aspect, following include / exclude rules
--- /dev/null
+/*******************************************************************************
+ * 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 junit.framework.TestCase;
+
+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(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(loader,context);
+ adaptor.initialize(null,null);
+
+ 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(loader,context);
+ try {
+ adaptor.initialize(null,null);
+ }
+ 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(loader,context);
+ adaptor.initialize(null,null);
+
+ 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(loader,context);
+ adaptor.initialize(null,null);
+
+ 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(loader,context);
+ adaptor.initialize(null,null);
+
+ assertTrue("IWeavingContext 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 String getFile(URL url) {
+ return "File";
+ }
+
+ public String getId() {
+ return "Id";
+ }
+
+ public Enumeration getResources(String name) throws IOException {
+ return loader.getResources(name);
+ }
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.called = false;
+ }
+
+}