]> source.dussan.org Git - aspectj.git/commitdiff
Bug 151938 "Handle Duplicate -javaagent entries more gracefully" (ignore duplicate...
authormwebster <mwebster>
Tue, 1 Aug 2006 20:41:52 +0000 (20:41 +0000)
committermwebster <mwebster>
Tue, 1 Aug 2006 20:41:52 +0000 (20:41 +0000)
lib/test/loadtime5.jar
loadtime5/java5-src/org/aspectj/weaver/loadtime/Agent.java
tests/java5/ataspectj/Aspect.aj [new file with mode: 0644]
tests/java5/ataspectj/HelloWorld.java [new file with mode: 0644]
tests/java5/ataspectj/MessageHandler.java [new file with mode: 0644]
tests/java5/ataspectj/ajc-ant.xml
tests/java5/ataspectj/aop-messagehandler.xml [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
tests/src/org/aspectj/systemtest/ajc153/ajc153.xml
weaver5/testdata/logging.properties

index 18892227d292a0c79e96278ab731579b1e9c0ec9..ed95dc5c4ca6bd784a61b058d67b3c0be6243882 100644 (file)
Binary files a/lib/test/loadtime5.jar and b/lib/test/loadtime5.jar differ
index bb3489841132902f61e41ef1d80c92168b4c3050..4989c0275d0693dcaa193bdb8f881ade84c4524b 100644 (file)
@@ -39,6 +39,10 @@ public class Agent {
      * @param instrumentation
      */
     public static void premain(String options, Instrumentation instrumentation) {
+       /* Handle duplicate agents */
+       if (s_instrumentation != null) {
+               return;
+       }
         s_instrumentation = instrumentation;
         s_instrumentation.addTransformer(s_transformer);
     }
diff --git a/tests/java5/ataspectj/Aspect.aj b/tests/java5/ataspectj/Aspect.aj
new file mode 100644 (file)
index 0000000..03a4403
--- /dev/null
@@ -0,0 +1,5 @@
+public aspect Aspect {
+       before () : execution(public static void main(String[])) {
+               System.out.println(thisJoinPoint);
+       }
+}
\ No newline at end of file
diff --git a/tests/java5/ataspectj/HelloWorld.java b/tests/java5/ataspectj/HelloWorld.java
new file mode 100644 (file)
index 0000000..58cd142
--- /dev/null
@@ -0,0 +1,7 @@
+public class HelloWorld {
+
+       public static void main (String[] args) {
+               System.out.println("Hello World!");
+       }
+       
+}
\ No newline at end of file
diff --git a/tests/java5/ataspectj/MessageHandler.java b/tests/java5/ataspectj/MessageHandler.java
new file mode 100644 (file)
index 0000000..111b32f
--- /dev/null
@@ -0,0 +1,27 @@
+import org.aspectj.bridge.AbortException;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.IMessage.Kind;
+
+public class MessageHandler implements IMessageHandler {
+
+       public boolean handleMessage(IMessage message) throws AbortException {
+               System.out.println(message);
+               if (message.getKind() == IMessage.ERROR) {
+                       System.exit(-1);
+               }
+               else if (message.getKind() == IMessage.ABORT) {
+                       throw new AbortException(message.toString());
+               }
+               return true;
+       }
+
+       public boolean isIgnoring(IMessage.Kind kind) {
+               return false;
+       }
+
+    public void dontIgnore(IMessage.Kind kind) {
+       
+    }
+       
+}
\ No newline at end of file
index 695e8ac0762f4b365fdbc38847b3017040b35482..8dccebac7e1711c4f0ac7b3de0ae4658c48351df 100644 (file)
         </java>
     </target>
 
+    <target name="Duplicate JVMTI agents">
+        <copy file="${aj.root}/tests/java5/ataspectj/aop-messagehandler.xml"
+              tofile="${aj.sandbox}/META-INF/aop.xml"/>
+        <java fork="yes" classname="HelloWorld" failonerror="yes">
+            <classpath refid="aj.path"/>
+            <!-- use META-INF/aop.xml style -->
+            <classpath>
+                <pathelement path="${aj.sandbox}/aspects.jar"/>
+            </classpath>
+            <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+<!--           
+-->            
+            <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+            <jvmarg value="-Daj.weaving.verbose=true"/>
+            <jvmarg value="-Djava.util.logging.config.file=${aj.root}/weaver5/testdata/logging.properties"/>
+<!--            <jvmarg line="${jdwp}"/>-->
+        </java>
+    </target>
+
 </project>
\ No newline at end of file
diff --git a/tests/java5/ataspectj/aop-messagehandler.xml b/tests/java5/ataspectj/aop-messagehandler.xml
new file mode 100644 (file)
index 0000000..9d7c34b
--- /dev/null
@@ -0,0 +1,3 @@
+<aspectj>
+       <weaver options="-XmessageHandlerClass:MessageHandler"/>
+</aspectj>
\ No newline at end of file
index 1004267624347c60eeeca9fd0e8d0b72024869d9..954e223f78fb2ff99b544d6db47a536bfbb82f8c 100644 (file)
@@ -48,7 +48,9 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testCantFindType_pr149322_03() {runTest("can't find type on interface call 3");}
 
   public void testMatchVolatileField_pr150671() {runTest("match volatile field");};
-  
+
+  public void testDuplicateJVMTIAgents_pr151938() {runTest("Duplicate JVMTI agents");};
+
   /////////////////////////////////////////
   public static Test suite() {
     return XMLBasedAjcTestCase.loadSuite(Ajc153Tests.class);
index 46b3db42a5f9857c9e9132116413e330e0e09f2d..7a8c501312ff7cffff6f4d37b2057ac6876f85d4 100644 (file)
         <message kind="error" line="8" text="test"/>
       </compile>
     </ajc-test>
+
+    <ajc-test dir="java5/ataspectj" title="Duplicate JVMTI agents">
+        <compile files="HelloWorld.java"/>
+        <compile files="MessageHandler.java"/>
+<!--        <compile files="Aspect.aj" options="-outxml"/> -->
+        <compile files="Aspect.aj" options="-outxml -outjar aspects.jar"/>
+        <ant file="ajc-ant.xml" target="Duplicate JVMTI agents" verbose="true"/>
+    </ajc-test>
     
     <ajc-test dir="bugs153/pr151978" title="generics problem">
       <compile files="IMessage.java" options="-1.5">
index fb96358eb038271ef29fb6ad3c74003e40e55e93..b65bfeaa570f52966b145154dcf72bb3eaaf844f 100644 (file)
@@ -57,3 +57,4 @@ java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
 #com.xyz.foo.level = SEVERE
 org.aspectj.weaver.level = FINER
 org.aspectj.weaver.loadtime.level = FINER
+org.aspectj.weaver.weaver.level = FINER