import org.aspectj.bridge.MessageUtil;
import org.aspectj.util.LangUtil;
import org.aspectj.weaver.ICrossReferenceHandler;
+import org.aspectj.weaver.Lint;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
+import org.aspectj.weaver.Lint.Kind;
import org.aspectj.weaver.bcel.BcelWeaver;
import org.aspectj.weaver.bcel.BcelWorld;
import org.aspectj.weaver.bcel.Utility;
info("no configuration found. Disabling weaver for class loader " + getClassLoaderName(loader));
}
} catch (Exception e) {
- weaver.getWorld().getMessageHandler().handleMessage(
- new Message("Register definition failed", IMessage.WARNING, e, null)
- );
+ enabled = false;// will allow very fast skip in shouldWeave()
+ warn("register definition failed",e);
}
}
}
}
+ protected void lint (String name, String[] infos) {
+ Lint lint = bcelWorld.getLint();
+ Kind kind = lint.getLintKind(name);
+ kind.signal(infos,null,null);
+ }
+
/**
* Register the aspect, following include / exclude rules
*
namespace = namespace.append(";"+aspectClassName);
}
}
+ else {
+// warn("aspect excluded: " + aspectClassName);
+ lint("aspectExcludedByConfiguration", new String[] { aspectClassName, getClassLoaderName(loader) });
+ }
}
}
--- /dev/null
+<aspectj>
+ <aspects>
+ <include within="pakkage.*"/>
+ </aspects>
+</aspectj>
--- /dev/null
+<aspectj>
+ <aspects>
+ <include within="pakkage.*"/>
+ </aspects>
+
+ <weaver options="-Xlint:warning">
+ </weaver>
+</aspectj>
runTest("Use abstract aspect for ITD using aop.xml");
}
+ public void testAspectsInclude () {
+ runTest("Ensure a subset of inherited aspects is used for weaving");
+ }
+
+ public void testAspectsIncludeWithLintWarning () {
+ runTest("Ensure weaver lint warning issued when an aspect is not used for weaving");
+ }
+
/*
* Allow system properties to be set and restored
* TODO maw move to XMLBasedAjcTestCase or RunSpec
</stderr>
</run>
</ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Ensure a subset of inherited aspects is used for weaving"
+ keywords="aspects, include">
+ <compile
+ files="Main.java"
+ outjar="main.jar"
+ >
+ </compile>
+ <compile
+ classpath="main.jar"
+ files="Aspect1.aj, Aspect2.aj, pakkage/Aspect3.aj"
+ outjar="aspects.jar"
+ options="-outxml"
+ >
+ </compile>
+ <run class="Main" ltw="aop-aspectsinclude.xml">
+ <stdout>
+ <line text="Main.main"/>
+ <line text="Main.test1"/>
+ <line text="Main.test2"/>
+ </stdout>
+ <stderr>
+ <line text="pakkage.Aspect3.before_test2"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="ltw"
+ title="Ensure weaver lint warning issued when an aspect is not used for weaving"
+ keywords="aspects, include, lint">
+ <compile
+ files="Main.java"
+ outjar="main.jar"
+ >
+ </compile>
+ <compile
+ classpath="main.jar"
+ files="Aspect1.aj, Aspect2.aj, pakkage/Aspect3.aj"
+ outjar="aspects.jar"
+ options="-outxml"
+ >
+ </compile>
+ <run class="Main" ltw="aop-aspectsincludewithlintwarning.xml">
+ <stdout>
+ <line text="Main.main"/>
+ <line text="Main.test1"/>
+ <line text="Main.test2"/>
+ </stdout>
+ <stderr>
+ <line text="warning aspect Aspect1 exluded for class loader org.aspectj.weaver.loadtime.WeavingURLClassLoader [Xlint:aspectExcludedByConfiguration]"/>
+ <line text="warning aspect Aspect2 exluded for class loader org.aspectj.weaver.loadtime.WeavingURLClassLoader [Xlint:aspectExcludedByConfiguration]"/>
+ <line text="pakkage.Aspect3.before_test2"/>
+ </stderr>
+ </run>
+ </ajc-test>
public final Kind noExplicitConstructorCall =
new Kind("noExplicitConstructorCall","inter-type constructor does not contain explicit constructor call: field initializers in the target type will not be executed");
+ public final Kind aspectExcludedByConfiguration =
+ new Kind("aspectExcludedByConfiguration","aspect {0} exluded for class loader {1}");
+
public Lint(World world) {
this.world = world;
}
runtimeExceptionNotSoftened = warning
uncheckedArgument = warning
noExplicitConstructorCall = warning
+
+aspectExcludedByConfiguration = ignore
import org.aspectj.bridge.AbortException;
import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.MessageWriter;
import org.aspectj.bridge.IMessage.Kind;
return MessageUtil.warn(messageHandler,message);
}
+ protected boolean warn (String message, Throwable th) {
+ return messageHandler.handleMessage(new Message("Register definition failed", IMessage.WARNING, th, null));
+ }
+
protected boolean error (String message) {
return MessageUtil.error(messageHandler,message);
}