]> source.dussan.org Git - aspectj.git/commitdiff
Matthews patches for 115275
authoraclement <aclement>
Tue, 15 Nov 2005 14:34:45 +0000 (14:34 +0000)
committeraclement <aclement>
Tue, 15 Nov 2005 14:34:45 +0000 (14:34 +0000)
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
tests/ltw/aop-aspectsinclude.xml [new file with mode: 0644]
tests/ltw/aop-aspectsincludewithlintwarning.xml [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml
weaver/src/org/aspectj/weaver/Lint.java
weaver/src/org/aspectj/weaver/XlintDefault.properties
weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java

index 3ca6d69cfed48281f670d5dfb17ba980abb6eecb..bbbbc7bfa88c4350b84c9fc94ec9775afe794f75 100644 (file)
@@ -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) });
+                }
             }
         }
 
diff --git a/tests/ltw/aop-aspectsinclude.xml b/tests/ltw/aop-aspectsinclude.xml
new file mode 100644 (file)
index 0000000..95f73f6
--- /dev/null
@@ -0,0 +1,5 @@
+<aspectj>
+       <aspects>
+               <include within="pakkage.*"/>
+       </aspects>
+</aspectj>
diff --git a/tests/ltw/aop-aspectsincludewithlintwarning.xml b/tests/ltw/aop-aspectsincludewithlintwarning.xml
new file mode 100644 (file)
index 0000000..8939234
--- /dev/null
@@ -0,0 +1,8 @@
+<aspectj>
+       <aspects>
+               <include within="pakkage.*"/>
+       </aspects>
+
+       <weaver options="-Xlint:warning">
+       </weaver>
+</aspectj>
index 66eb92c68d41fb91e5a5cce9403b224ec1fa942a..ffb52a905ef35214433699f86b9cd310464e9549 100644 (file)
@@ -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
index 6a8fe18812cf6984c0fcb2191a68f56dc820887c..69eff31ee6961d9d1b821a040eef11b3d9347452 100644 (file)
             </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>
     
index d0b22e47ce3728c88baf542c3341cbc69c6cc19f..e8b237079f27823108eba3949605c3eb4e670bde 100644 (file)
@@ -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;
        }
index da3856a79c7465bfca6757b2c016acf1fc85ad1f..bb40c00cde4a16f6c69905b659ac7a98869fee59 100644 (file)
@@ -30,3 +30,5 @@ elementAlreadyAnnotated = warning
 runtimeExceptionNotSoftened = warning
 uncheckedArgument = warning
 noExplicitConstructorCall = warning
+
+aspectExcludedByConfiguration = ignore
index b59ec5564fd8788268727886c5e4e757a528e4c9..ea75902738c27222381e1fae587a6e6d4713686a 100644 (file)
@@ -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);
        }