import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.security.ProtectionDomain;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import org.aspectj.bridge.context.CompilationAndWeavingContext;
import org.aspectj.weaver.Dump;
* @param className
* @param bytes
* @param loader
- * @return weaved bytes
+ * @return woven bytes
*/
public byte[] preProcess(String className, byte[] bytes, ClassLoader loader, ProtectionDomain protectionDomain) {
// TODO AV needs to doc that
// skip boot loader, null classes (hibernate), or those from a reflection loader
return bytes;
}
+
+ if (loadersToSkip != null) {
+ // Check whether to reject it
+ if (loadersToSkip.contains(loader.getClass().getName())) {
+// System.out.println("debug: no weaver created for loader '"+loader.getClass().getName()+"'");
+ return bytes;
+ }
+ }
if (trace.isTraceEnabled())
trace.enter("preProcess", this, new Object[] { className, bytes, loader });
}
}
}
+
+ public static List<String> loadersToSkip = null;
static {
// pr271840 - touch the types early and outside the locks
new ExplicitlyInitializedClassLoaderWeavingAdaptor(new ClassLoaderWeavingAdaptor());
+ try {
+ String loadersToSkipProperty = System.getProperty("aj.weaving.loadersToSkip","");
+ StringTokenizer st = new StringTokenizer(loadersToSkipProperty, ",");
+ if (loadersToSkipProperty != null && loadersToSkip == null) {
+ if (st.hasMoreTokens()) {
+// System.out.println("aj.weaving.loadersToSkip is set. Skipping loaders: '"+loadersToSkipProperty+"'");
+ loadersToSkip = new ArrayList<String>();
+ }
+ while (st.hasMoreTokens()) {
+ String nextLoader = st.nextToken();
+ loadersToSkip.add(nextLoader);
+ }
+ }
+ } catch (Exception e) {
+ // Likely security issue related to property access...
+ }
}
/**
import org.aspectj.bridge.AbortException;
import org.aspectj.bridge.Constants;
+import org.aspectj.bridge.MessageUtil;
import org.aspectj.util.LangUtil;
import org.aspectj.weaver.Lint;
import org.aspectj.weaver.Lint.Kind;
world.setOptionalJoinpoints(weaverOption.optionalJoinpoints);
world.setPinpointMode(weaverOption.pinpoint);
weaver.setReweavableMode(weaverOption.notReWeavable);
+ if (weaverOption.loadersToSkip != null && weaverOption.loadersToSkip.length() > 0) {
+ Aj.loadersToSkip = LangUtil.anySplit(weaverOption.loadersToSkip, ",");
+ }
+ if (Aj.loadersToSkip != null) {
+ MessageUtil.info(world.getMessageHandler(),"no longer creating weavers for these classloaders: "+Aj.loadersToSkip);
+ }
world.performExtraConfiguration(weaverOption.xSet);
world.setXnoInline(weaverOption.noInline);
// AMC - autodetect as per line below, needed for AtAjLTWTests.testLTWUnweavable
private static final String OPTIONVALUED_joinpoints = "-Xjoinpoints:";
private static final String OPTIONVALUED_Xset = "-Xset:";
private static final String OPTION_timers = "-timers";
+ private static final String OPTIONVALUED_loadersToSkip = "-loadersToSkip:";
public static WeaverOption parse(String options, ClassLoader laoder, IMessageHandler imh) {
WeaverOption weaverOption = new WeaverOption(imh);
return weaverOption;
}
// the first option wins
- List flags = LangUtil.anySplit(options, " ");
+ List<String> flags = LangUtil.anySplit(options, " ");
Collections.reverse(flags);
// do a first round on the message handler since it will report the options themselves
- for (Iterator iterator = flags.iterator(); iterator.hasNext();) {
- String arg = (String) iterator.next();
+ for (Iterator<String> iterator = flags.iterator(); iterator.hasNext();) {
+ String arg = iterator.next();
if (arg.startsWith(OPTIONVALUED_messageHandler)) {
if (arg.length() > OPTIONVALUED_messageHandler.length()) {
String handlerClass = arg.substring(OPTIONVALUED_messageHandler.length()).trim();
}
// configure the other options
- for (Iterator iterator = flags.iterator(); iterator.hasNext();) {
+ for (Iterator<String> iterator = flags.iterator(); iterator.hasNext();) {
String arg = (String) iterator.next();
if (arg.equals(OPTION_15)) {
weaverOption.java5 = true;
}
} else if (arg.equalsIgnoreCase(OPTION_timers)) {
weaverOption.timers = true;
+ } else if (arg.startsWith(OPTIONVALUED_loadersToSkip)) {
+ if (arg.length() > OPTIONVALUED_loadersToSkip.length()) {
+ String value = arg.substring(OPTIONVALUED_loadersToSkip.length()).trim();
+ weaverOption.loadersToSkip = value;
+ }
} else {
weaverOption.messageHandler.handleMessage(new Message("Cannot configure weaver with option '" + arg
+ "': unknown option", IMessage.WARNING, null, null));
String lint;
String lintFile;
String xSet;
+ String loadersToSkip;
public WeaverOption(IMessageHandler imh) {
// messageHandler = new DefaultMessageHandler();//default
--- /dev/null
+public aspect Azpect {
+ before(): execution(* *(..)) {
+ System.out.println("advice");
+ }
+}
--- /dev/null
+public class Code {
+ public static void main(String []argv) {
+ System.out.println("running");
+ }
+}
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="Azpect"/>
+ </aspects>
+ <weaver options="-verbose"/>
+</aspectj>
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="Azpect"/>
+ </aspects>
+ <weaver options="-verbose -loadersToSkip:com.foo.Bar"/>
+</aspectj>
--- /dev/null
+<aspectj>
+ <aspects>
+ <aspect name="Azpect"/>
+ </aspects>
+ <weaver options="-verbose -loadersToSkip:org.aspectj.weaver.loadtime.WeavingURLClassLoader"/>
+</aspectj>
runTest("super itd ctor");
}
+ // no exclusion, this is how it should work
+ public void testCLExclusion_pr368046_1_noskippedloaders() {
+ runTest("classloader exclusion - 1");
+ }
+
+ public void testCLExclusion_pr368046_1_syspropset() {
+ try {
+ System.setProperty("aj.weaving.loadersToSkip", "foo");
+ runTest("classloader exclusion - 2");
+ } finally {
+ System.setProperty("aj.weaving.loadersToSkip", "");
+ }
+ }
+
+ // final repeat this test, to confirm no lingering static
+ public void testCLExclusion_pr368046_1_again_noskippedloaders() {
+ runTest("classloader exclusion - 3");
+ }
+
+ public void testCLExclusion_pr368046_2_usingaopxml() {
+ runTest("classloader exclusion - 4");
+ }
+
+ public void testCLExclusion_pr368046_2_usingaopxmlReal() {
+ runTest("classloader exclusion - 5");
+ }
+
// ---
public static Test suite() {
</stdout>
</run>
</ajc-test>
+
+ <ajc-test dir="bugs174/pr368046" title="classloader exclusion - 1">
+ <compile files="Azpect.java" outjar="foo.jar"/>
+ <compile files="Code.java" classpath="$sandbox/foo.jar"/>
+ <run class="Code" classpath="$sandbox/foo.jar" ltw="aop1.xml">
+ <stdout>
+ <line text="advice"/>
+ <line text="running"/>
+ </stdout>
+ <stderr>
+ <line text="AspectJ Weaver"/>
+ <line text="register classloader"/>
+ <line text="using configuration"/>
+ <line text="register aspect"/>
+ <line text="processing reweavable"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs174/pr368046" title="classloader exclusion - 2">
+ <compile files="Azpect.java" outjar="foo.jar"/>
+ <compile files="Code.java" classpath="$sandbox/foo.jar"/>
+ <run class="Code" classpath="$sandbox/foo.jar" ltw="aop1.xml">
+ <stdout>
+ <line text="advice"/>
+ <line text="running"/>
+ </stdout>
+ <stderr>
+ <line text="AspectJ Weaver"/>
+ <line text="register classloader"/>
+ <line text="using configuration"/>
+ <line text="no longer creating weavers for these classloaders: [foo]"/>
+ <line text="register aspect"/>
+ <line text="processing reweavable"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs174/pr368046" title="classloader exclusion - 3">
+ <compile files="Azpect.java" outjar="foo.jar"/>
+ <compile files="Code.java" classpath="$sandbox/foo.jar"/>
+ <run class="Code" classpath="$sandbox/foo.jar" ltw="aop1.xml">
+ <stdout>
+ <line text="advice"/>
+ <line text="running"/>
+ </stdout>
+ <stderr>
+ <line text="AspectJ Weaver"/>
+ <line text="register classloader"/>
+ <line text="using configuration"/>
+ <line text="register aspect"/>
+ <line text="processing reweavable"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs174/pr368046" title="classloader exclusion - 4">
+ <compile files="Azpect.java" outjar="foo.jar"/>
+ <compile files="Code.java" classpath="$sandbox/foo.jar"/>
+ <run class="Code" classpath="$sandbox/foo.jar" ltw="aop2.xml">
+ <stdout>
+ <line text="advice"/>
+ <line text="running"/>
+ </stdout>
+ <stderr>
+ <line text="AspectJ Weaver"/>
+ <line text="register classloader"/>
+ <line text="using configuration"/>
+ <line text="no longer creating weavers for these classloaders: [com.foo.Bar]"/>
+ <line text="register aspect"/>
+ <line text="processing reweavable"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="bugs174/pr368046" title="classloader exclusion - 5">
+ <compile files="Azpect.java" outjar="foo.jar"/>
+ <compile files="Code.java" classpath="$sandbox/foo.jar"/>
+ <run class="Code" classpath="$sandbox/foo.jar" ltw="aop3.xml">
+ <stdout>
+ <line text="advice"/>
+ <line text="running"/>
+ </stdout>
+ <stderr>
+ <line text="AspectJ Weaver"/>
+ <line text="register classloader"/>
+ <line text="using configuration"/>
+ <line text="no longer creating weavers for these classloaders: [org.aspectj.weaver.loadtime.WeavingURLClassLoader]"/>
+ <line text="register aspect"/>
+ <line text="processing reweavable"/>
+ </stderr>
+ </run>
+ </ajc-test>
</suite>