import java.util.Map;
import java.util.WeakHashMap;
+import org.aspectj.bridge.context.CompilationAndWeavingContext;
import org.aspectj.weaver.Dump;
import org.aspectj.weaver.tools.Trace;
import org.aspectj.weaver.tools.TraceFactory;
if (trace.isTraceEnabled()) trace.exit("preProcess");
return bytes;
}
- byte[] newBytes = weavingAdaptor.weaveClass(className, bytes);
+ byte[] newBytes = weavingAdaptor.weaveClass(className, bytes,false);
Dump.dumpOnExit(weavingAdaptor.getMessageHolder(), true);
if (trace.isTraceEnabled()) trace.exit("preProcess",newBytes);
return newBytes;
// would make sense at least in test f.e. see TestHelper.handleMessage()
if (trace.isTraceEnabled()) trace.exit("preProcess",th);
return bytes;
+ } finally {
+ CompilationAndWeavingContext.resetForThread();
}
}
*/
static class WeaverContainer {
- private static Map weavingAdaptors = new WeakHashMap();
+ private final static Map weavingAdaptors = new WeakHashMap();
static WeavingAdaptor getWeaver(ClassLoader loader, IWeavingContext weavingContext) {
ExplicitlyInitializedClassLoaderWeavingAdaptor adaptor = null;
import org.aspectj.asm.IRelationship;
import org.aspectj.bridge.AbortException;
import org.aspectj.bridge.Constants;
+import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.util.LangUtil;
import org.aspectj.weaver.ICrossReferenceHandler;
}
};
- List definitions = parseDefinitions(classLoader);
+ List definitions = weavingContext.getDefinitions(classLoader,this);
if (definitions.isEmpty()) {
disable(); // TODO maw Needed to ensure messages are flushed
if (trace.isTraceEnabled()) trace.exit("initialize",definitions);
bcelWorld = new LTWWorld(
classLoader, weavingContext, // TODO when the world works in terms of the context, we can remove the loader...
- getMessageHandler(), new ICrossReferenceHandler() {
- public void addCrossReference(ISourceLocation from, ISourceLocation to, IRelationship.Kind kind, boolean runtimeTest) {
- ;// for tools only
- }
- }
- );
+ getMessageHandler(), null);
+// new ICrossReferenceHandler() {
+// public void addCrossReference(ISourceLocation from, ISourceLocation to, IRelationship.Kind kind, boolean runtimeTest) {
+// ;// for tools only
+// }
+// }
+// );
weaver = new BcelWeaver(bcelWorld);
* @param weaver
* @param loader
*/
- private List parseDefinitions(final ClassLoader loader) {
+ List parseDefinitions(final ClassLoader loader) {
if (trace.isTraceEnabled()) trace.enter("parseDefinitions",this,loader);
List definitions = new ArrayList();
try {
- info("register classloader " + getClassLoaderName(loader));
- //TODO av underoptimized: we will parse each XML once per CL that see it
+ info("register classloader " + getClassLoaderName(loader));
+ //TODO av underoptimized: we will parse each XML once per CL that see it
//TODO av dev mode needed ? TBD -Daj5.def=...
if (loader.equals(ClassLoader.getSystemClassLoader())) {
String file = System.getProperty("aj5.def", null);
if (file != null) {
- info("using (-Daj5.def) " + file);
+ info("using (-Daj5.def) " + file);
definitions.add(DocumentParser.parse((new File(file)).toURL()));
}
}
seenBefore.add(xml);
}
else {
- warn("ignoring duplicate definition: " + xml);
+ warn("ignoring duplicate definition: " + xml);
}
}
}
if (definitions.isEmpty()) {
- info("no configuration found. Disabling weaver for class loader " + getClassLoaderName(loader));
+ info("no configuration found. Disabling weaver for class loader " + getClassLoaderName(loader));
}
} catch (Exception e) {
definitions.clear();
- warn("parse definitions failed",e);
+ warn("parse definitions failed",e);
}
if (trace.isTraceEnabled()) trace.exit("parseDefinitions",definitions);
} catch (Exception ex) {
trace.error("register definition failed",ex);
success = false;
- warn("register definition failed",(ex instanceof AbortException)?null:ex);
+ warn("register definition failed",(ex instanceof AbortException)?null:ex);
}
if (trace.isTraceEnabled()) trace.exit("registerDefinitions",success);
}
}
if (failure != null || resource == null) {
- warn("Cannot access resource for -Xlintfile:"+weaverOption.lintFile,failure);
+ warn("Cannot access resource for -Xlintfile:"+weaverOption.lintFile,failure);
// world.getMessageHandler().handleMessage(new Message(
// "Cannot access resource for -Xlintfile:"+weaverOption.lintFile,
// IMessage.WARNING,
info("define aspect " + concreteAspect.name);
ConcreteAspectCodeGen gen = new ConcreteAspectCodeGen(concreteAspect, weaver.getWorld());
if (!gen.validate()) {
- error("Concrete-aspect '"+concreteAspect.name+"' could not be registered");
+ error("Concrete-aspect '"+concreteAspect.name+"' could not be registered");
success = false;
break;
}
/* We didn't register any aspects so disable the adaptor */
else if (namespace == null) {
success = false;
- info("no aspects registered. Disabling weaver for class loader " + getClassLoaderName(loader));
+ info("no aspects registered. Disabling weaver for class loader " + getClassLoaderName(loader));
}
if (trace.isTraceEnabled()) trace.exit("registerAspects",success);
byte[] bytes = gen.getBytes();
try {
- byte[] newBytes = weaveClass(name, bytes);
+ byte[] newBytes = weaveClass(name, bytes,true);
this.generatedClassHandler.acceptClass(name,newBytes);
}
catch (IOException ex) {
trace.error("weaveAndDefineConceteAspects",ex);
- error("exception weaving aspect '" + name + "'",ex);
+ error("exception weaving aspect '" + name + "'",ex);
}
}
private void defineClass(ClassLoader loader, String name, byte[] bytes) {
if (trace.isTraceEnabled()) trace.enter("defineClass",this,new Object[] {loader,name,bytes});
Object clazz = null;
- debug("generating class '" + name + "'");
+ debug("generating class '" + name + "'");
try {
//TODO av protection domain, and optimize
new Integer(0), new Integer(bytes.length) });
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof LinkageError) {
- warn("define generated class failed",e.getTargetException());
+ warn("define generated class failed",e.getTargetException());
//is already defined (happens for X$ajcMightHaveAspect interfaces since aspects are reweaved)
// TODO maw I don't think this is OK and
} else {
- warn("define generated class failed",e.getTargetException());
+ warn("define generated class failed",e.getTargetException());
}
} catch (Exception e) {
- warn("define generated class failed",e);
+ warn("define generated class failed",e);
}
if (trace.isTraceEnabled()) trace.exit("defineClass",clazz);
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;
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;
}
return isLocallyDefined;
}
+
+ public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
+ return ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader);
+ }
}
protected void setUp() throws Exception {