--- /dev/null
+/*******************************************************************************
+ * 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();
+ }
+
+}
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;
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;
--- /dev/null
+/*******************************************************************************
+ * 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);
+ }
+
+}
public void testDefaultTracing () {
runTest("Default tracing");
}
+
+ public void testDefaultTracingMessageHandler () {
+ runTest("Default TraceMessageHandler");
+ }
}
<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>
--- /dev/null
+public aspect ExcludedAspect {
+
+}
\ No newline at end of file
--- /dev/null
+public aspect IncludedAspect {
+
+}
\ No newline at end of file
--- /dev/null
+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
--- /dev/null
+<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