]> source.dussan.org Git - aspectj.git/commitdiff
Bug 150487 "Tracing and Logging Framework" (TraceMessageHandler)
authormwebster <mwebster>
Wed, 9 Aug 2006 15:52:23 +0000 (15:52 +0000)
committermwebster <mwebster>
Wed, 9 Aug 2006 15:52:23 +0000 (15:52 +0000)
loadtime/src/org/aspectj/weaver/loadtime/TraceMessageHandler.java [new file with mode: 0644]
loadtime/testsrc/org/aspectj/loadtime/LoadtimeModuleTests.java
loadtime/testsrc/org/aspectj/weaver/loadtime/TraceMessageHandlerTest.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/tracing/TracingTests.java
tests/src/org/aspectj/systemtest/tracing/tracing.xml
tests/tracing/ExcludedAspect.aj [new file with mode: 0644]
tests/tracing/IncludedAspect.aj [new file with mode: 0644]
tests/tracing/MyDefaultTraceMessageHandler.java [new file with mode: 0644]
tests/tracing/aop-defaulttracemessagehandler.xml [new file with mode: 0644]

diff --git a/loadtime/src/org/aspectj/weaver/loadtime/TraceMessageHandler.java b/loadtime/src/org/aspectj/weaver/loadtime/TraceMessageHandler.java
new file mode 100644 (file)
index 0000000..b661bc7
--- /dev/null
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     Matthew Webster - initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver.loadtime;
+
+import org.aspectj.bridge.AbortException;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.WeaveMessage;
+import org.aspectj.bridge.IMessage.Kind;
+import org.aspectj.weaver.tools.Trace;
+import org.aspectj.weaver.tools.TraceFactory;
+
+public class TraceMessageHandler implements IMessageHandler {
+
+       private Trace trace;
+
+       public TraceMessageHandler () {
+               this(TraceFactory.getTraceFactory().getTrace(TraceMessageHandler.class));
+       }
+
+       /**
+        * Used for testing
+        *
+        */
+       protected TraceMessageHandler (Trace t) {
+               this.trace = t;
+       }
+       
+       /* Ignore this and defer all decisions about what we log to the Trace
+        * configuration
+        */
+       public void dontIgnore(Kind kind) {
+       }
+
+       public boolean handleMessage(IMessage message) throws AbortException {
+               if (message instanceof WeaveMessage) {
+                       trace.debug(render(message));
+               }
+               else if (message.isDebug()) {
+                       trace.debug(render(message));
+               }
+               else if (message.isInfo()) {
+                       trace.info(render(message));
+               }
+               else if (message.isWarning()) {
+                       trace.warn(render(message),message.getThrown());
+               }
+               else if (message.isError()) {
+                       trace.error(render(message),message.getThrown());
+               }
+               else if (message.isFailed()) {
+                       trace.fatal(render(message),message.getThrown());
+               }
+               else if (message.isAbort()) {
+                       trace.fatal(render(message),message.getThrown());
+               }
+               else return false;
+               
+               return true;
+       }
+
+       /* Ignore this and defer all decisions about what we log to the Trace
+        * configuration
+        */
+       public boolean isIgnoring(Kind kind) {
+               return false;
+       }
+
+    protected String render(IMessage message) {
+        return message.toString();    
+    }
+
+}
index da7509b6f5bd28b1d5db2ab7418892334618de9b..bfd89b8de9fb84502e768560bbb6310a78d57234 100644 (file)
@@ -19,6 +19,7 @@ import junit.textui.TestRunner;
 import org.aspectj.weaver.loadtime.AjTest;
 import org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest;
 import org.aspectj.weaver.loadtime.JRockitAgentTest;
+import org.aspectj.weaver.loadtime.TraceMessageHandlerTest;
 import org.aspectj.weaver.loadtime.WeavingContextTest;
 import org.aspectj.weaver.loadtime.WeavingURLClassLoaderTest;
 import org.aspectj.weaver.loadtime.test.DocumentParserTest;
@@ -35,6 +36,7 @@ public class LoadtimeModuleTests extends TestCase {
         suite.addTestSuite(AjTest.class);
         suite.addTestSuite(ClassLoaderWeavingAdaptorTest.class);
         suite.addTestSuite(JRockitAgentTest.class);
+        suite.addTestSuite(TraceMessageHandlerTest.class);
         suite.addTestSuite(WeavingContextTest.class);
         suite.addTestSuite(WeavingURLClassLoaderTest.class);
         return suite;
diff --git a/loadtime/testsrc/org/aspectj/weaver/loadtime/TraceMessageHandlerTest.java b/loadtime/testsrc/org/aspectj/weaver/loadtime/TraceMessageHandlerTest.java
new file mode 100644 (file)
index 0000000..7bd499a
--- /dev/null
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     Matthew Webster - initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver.loadtime;
+
+import junit.framework.TestCase;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.MessageUtil;
+import org.aspectj.bridge.IMessage.Kind;
+
+public class TraceMessageHandlerTest extends TestCase {
+
+       private TraceMessageHandler messageHandler;
+       
+       protected void setUp() throws Exception {
+               super.setUp();
+               messageHandler = new TraceMessageHandler();
+       }
+
+       public void testTraceMessageHandler() {
+               TraceMessageHandler tmh = new TraceMessageHandler();
+       }
+
+       public void testDontIgnore() {
+               Kind kind = IMessage.WEAVEINFO;
+               messageHandler.dontIgnore(kind);
+               boolean b = messageHandler.isIgnoring(kind);
+               assertFalse("Don't filter message kinds",b);
+       }
+
+       public void testHandleMessageInfo () {
+               IMessage message = MessageUtil.info("testHandleMessage");
+               boolean b = messageHandler.handleMessage(message);
+               assertTrue("Message not handled",b);
+       }
+
+       public void testIsIgnoring() {
+               Kind kind = IMessage.WEAVEINFO;
+               boolean b = messageHandler.isIgnoring(kind);
+               assertFalse("Don't filter message kinds",b);
+       }
+
+       public void testRender() {
+               String text = "testRender";
+               IMessage message = MessageUtil.info(text);
+               String s = messageHandler.render(message);
+               assertTrue("Message not rendered correctly",s.indexOf(text) != -1);
+       }
+
+}
index 0153d757d0a51821224e65dfa841a43b42a4d784..e782e08870e5e61efa7bb330b0687759c2dbba14 100644 (file)
@@ -33,5 +33,9 @@ public class TracingTests extends org.aspectj.testing.XMLBasedAjcTestCase {
        public void testDefaultTracing () {
                runTest("Default tracing");
        }
+       
+       public void testDefaultTracingMessageHandler () {
+               runTest("Default TraceMessageHandler");
+       }
 
 }
index 8528761caa12ffc56cd973c0778e48cdc7cc370a..b0dca8d8cc2277b817ee9c5e07ce76ea472905a5 100644 (file)
         <ant file="ant.xml" target="Default tracing" verbose="true"/>
     </ajc-test>
 
+       <ajc-test dir="tracing" title="Default TraceMessageHandler" keywords="tracing">
+        <compile
+               files="HelloWorld.java, MyDefaultTraceMessageHandler.java"
+        />
+        <compile
+               files="IncludedAspect.aj, ExcludedAspect.aj"
+        />
+        <run class="HelloWorld" ltw="aop-defaulttracemessagehandler.xml">
+               <stdout>
+                <line text="Hello World!"/>
+            </stdout>
+               <stderr>
+                       <line text="info register aspect IncludedAspect"/>
+                       <line text="warning aspect ExcludedAspect exluded"/>
+                       <line text="error Cannot find m_parent aspect"/>
+                       <line text="error Concrete-aspect 'IncludedMissingAspect' could not be registered"/>
+                       <line text="info weaving 'HelloWorld'"/>
+            </stderr>
+        </run>
+    </ajc-test>
+
 </suite>
diff --git a/tests/tracing/ExcludedAspect.aj b/tests/tracing/ExcludedAspect.aj
new file mode 100644 (file)
index 0000000..13cf4b7
--- /dev/null
@@ -0,0 +1,3 @@
+public aspect ExcludedAspect {
+       
+}
\ No newline at end of file
diff --git a/tests/tracing/IncludedAspect.aj b/tests/tracing/IncludedAspect.aj
new file mode 100644 (file)
index 0000000..3bd4d70
--- /dev/null
@@ -0,0 +1,3 @@
+public aspect IncludedAspect {
+       
+}
\ No newline at end of file
diff --git a/tests/tracing/MyDefaultTraceMessageHandler.java b/tests/tracing/MyDefaultTraceMessageHandler.java
new file mode 100644 (file)
index 0000000..b617568
--- /dev/null
@@ -0,0 +1,12 @@
+import org.aspectj.weaver.loadtime.TraceMessageHandler;
+import org.aspectj.weaver.tools.*;
+
+public class MyDefaultTraceMessageHandler extends TraceMessageHandler {
+       
+       private static Trace trace = new DefaultTrace(MyDefaultTraceMessageHandler.class);
+       
+       public MyDefaultTraceMessageHandler () {
+               super(trace);
+               trace.setTraceEnabled(true);
+       }
+}
\ No newline at end of file
diff --git a/tests/tracing/aop-defaulttracemessagehandler.xml b/tests/tracing/aop-defaulttracemessagehandler.xml
new file mode 100644 (file)
index 0000000..bf1a587
--- /dev/null
@@ -0,0 +1,13 @@
+<aspectj>
+       <aspects>
+               <aspect name="IncludedAspect"/>
+               <aspect name="ExcludedAspect"/>
+               
+        <concrete-aspect name="IncludedMissingAspect" extends="MissingAbstractAspect">
+               <pointcut name="pointcut" expression="within(*)"/>
+        </concrete-aspect>
+               
+               <include within="Included*"/>
+       </aspects>
+    <weaver options="-verbose -Xlint:warning -XmessageHandlerClass:MyDefaultTraceMessageHandler"/>
+</aspectj>
\ No newline at end of file