@@ -19,9 +19,11 @@ import org.aspectj.bridge.Message; | |||
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; | |||
@@ -175,9 +177,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { | |||
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); | |||
} | |||
} | |||
@@ -284,6 +285,12 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { | |||
} | |||
} | |||
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 | |||
* | |||
@@ -312,6 +319,10 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { | |||
namespace = namespace.append(";"+aspectClassName); | |||
} | |||
} | |||
else { | |||
// warn("aspect excluded: " + aspectClassName); | |||
lint("aspectExcludedByConfiguration", new String[] { aspectClassName, getClassLoaderName(loader) }); | |||
} | |||
} | |||
} | |||
@@ -0,0 +1,5 @@ | |||
<aspectj> | |||
<aspects> | |||
<include within="pakkage.*"/> | |||
</aspects> | |||
</aspectj> |
@@ -0,0 +1,8 @@ | |||
<aspectj> | |||
<aspects> | |||
<include within="pakkage.*"/> | |||
</aspects> | |||
<weaver options="-Xlint:warning"> | |||
</weaver> | |||
</aspectj> |
@@ -57,6 +57,14 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
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 |
@@ -158,4 +158,60 @@ | |||
</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> | |||
@@ -102,6 +102,9 @@ public class Lint { | |||
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; | |||
} |
@@ -30,3 +30,5 @@ elementAlreadyAnnotated = warning | |||
runtimeExceptionNotSoftened = warning | |||
uncheckedArgument = warning | |||
noExplicitConstructorCall = warning | |||
aspectExcludedByConfiguration = ignore |
@@ -31,6 +31,7 @@ import java.util.StringTokenizer; | |||
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; | |||
@@ -327,6 +328,10 @@ public class WeavingAdaptor { | |||
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); | |||
} |