aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2016-03-08 08:52:39 -0800
committerAndy Clement <aclement@pivotal.io>2016-03-08 08:52:39 -0800
commit9216ef518ac4c9af48c559ee8a6966164ddbb237 (patch)
tree262906377027fa2269a6c118daeab95d9df80955 /org.aspectj.matcher
parentbead7e3a57b0f41c49365b37a5eb431dc5faa081 (diff)
downloadaspectj-9216ef518ac4c9af48c559ee8a6966164ddbb237.tar.gz
aspectj-9216ef518ac4c9af48c559ee8a6966164ddbb237.zip
Fix 488216: Load-time weaver loses class changes of preceding -javaagent
Diffstat (limited to 'org.aspectj.matcher')
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java26
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/tools/DefaultTrace.java93
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/tools/Trace.java56
3 files changed, 92 insertions, 83 deletions
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java
index 2ec0aa3a9..c736de886 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/AbstractTrace.java
@@ -16,12 +16,15 @@ import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
+import java.util.regex.Pattern;
import org.aspectj.bridge.IMessage.Kind;
public abstract class AbstractTrace implements Trace {
- protected Class tracedClass;
+ private static final Pattern packagePrefixPattern = Pattern.compile("([^.])[^.]*(\\.)");
+
+ protected Class<?> tracedClass;
private static SimpleDateFormat timeFormat;
@@ -85,13 +88,21 @@ public abstract class AbstractTrace implements Trace {
message.append(formatDate(now)).append(" ");
message.append(Thread.currentThread().getName()).append(" ");
message.append(kind).append(" ");
- message.append(className);
+ message.append(formatClassName(className));
message.append(".").append(methodName);
if (thiz != null) message.append(" ").append(formatObj(thiz));
if (args != null) message.append(" ").append(formatArgs(args));
return message.toString();
}
+ /**
+ * @param className full dotted class name
+ * @return short version of class name with package collapse to initials
+ */
+ private String formatClassName(String className) {
+ return packagePrefixPattern.matcher(className).replaceAll("$1.");
+ }
+
protected String formatMessage(String kind, String text, Throwable th) {
StringBuffer message = new StringBuffer();
Date now = new Date();
@@ -116,7 +127,7 @@ public abstract class AbstractTrace implements Trace {
* NullPointerExceptions or highly verbose results.
*
* @param obj parameter to be formatted
- * @return the formated parameter
+ * @return the formatted parameter
*/
protected Object formatObj(Object obj) {
@@ -141,14 +152,13 @@ public abstract class AbstractTrace implements Trace {
}
else try {
- /* Classes can provide an alternative implementation of toString() */
+ // Classes can provide an alternative implementation of toString()
if (obj instanceof Traceable) {
- Traceable t = (Traceable)obj;
- return t.toTraceString();
+ return ((Traceable)obj).toTraceString();
}
- /* Use classname@hashcode */
- else return obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
+ // classname@hashcode
+ else return formatClassName(obj.getClass().getName()) + "@" + Integer.toHexString(System.identityHashCode(obj));
/* Object.hashCode() can be override and may thow an exception */
} catch (Exception ex) {
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/DefaultTrace.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/DefaultTrace.java
index ad95bbb3e..7e2ab0d8f 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/DefaultTrace.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/DefaultTrace.java
@@ -12,109 +12,112 @@ package org.aspectj.weaver.tools;
import java.io.PrintStream;
-
public class DefaultTrace extends AbstractTrace {
-
+
private boolean traceEnabled = false;
private PrintStream print = System.err;
-
- public DefaultTrace (Class clazz) {
+
+ public DefaultTrace(Class clazz) {
super(clazz);
}
-
- public boolean isTraceEnabled () {
+
+ public boolean isTraceEnabled() {
return traceEnabled;
}
-
- public void setTraceEnabled (boolean b) {
+
+ public void setTraceEnabled(boolean b) {
traceEnabled = b;
}
-
- public void enter (String methodName, Object thiz, Object[] args) {
+
+ public void enter(String methodName, Object thiz, Object[] args) {
if (traceEnabled) {
- println(formatMessage(">",tracedClass.getName(),methodName,thiz, args));
+ println(formatMessage(">", tracedClass.getName(), methodName, thiz, args));
}
}
-
- public void enter (String methodName, Object thiz) {
+
+ public void enter(String methodName, Object thiz) {
if (traceEnabled) {
- println(formatMessage(">",tracedClass.getName(),methodName,thiz, null));
+ println(formatMessage(">", tracedClass.getName(), methodName, thiz, null));
}
}
- public void exit (String methodName, Object ret) {
+ public void exit(String methodName, Object ret) {
if (traceEnabled) {
- println(formatMessage("<",tracedClass.getName(),methodName,ret, null));
+ println(formatMessage("<", tracedClass.getName(), methodName, ret, null));
}
}
- public void exit (String methodName) {
+ public void exit(String methodName) {
if (traceEnabled) {
- println(formatMessage("<",tracedClass.getName(),methodName,null, null));
+ println(formatMessage("<", tracedClass.getName(), methodName, null, null));
}
}
public void exit(String methodName, Throwable th) {
if (traceEnabled) {
- println(formatMessage("<",tracedClass.getName(),methodName,th, null));
+ println(formatMessage("<", tracedClass.getName(), methodName, th, null));
}
}
-
+
public void event(String methodName, Object thiz, Object[] args) {
if (traceEnabled) {
- println(formatMessage("-",tracedClass.getName(),methodName,thiz, args));
+ println(formatMessage("-", tracedClass.getName(), methodName, thiz, args));
}
}
public void event(String methodName) {
if (traceEnabled) {
- println(formatMessage("-",tracedClass.getName(),methodName,null,null));
+ println(formatMessage("-", tracedClass.getName(), methodName, null, null));
}
}
- public void debug (String message) {
- println(formatMessage("?",message,null));
+ public void debug(String message) {
+ println(formatMessage("?", message, null));
}
public void info(String message) {
- println(formatMessage("I",message,null));
+ println(formatMessage("I", message, null));
}
- public void warn (String message, Throwable th) {
- println(formatMessage("W",message,th));
- if (th != null) th.printStackTrace();
+ public void warn(String message, Throwable th) {
+ println(formatMessage("W", message, th));
+ if (th != null)
+ th.printStackTrace();
}
-
- public void error (String message, Throwable th) {
- println(formatMessage("E",message,th));
- if (th != null) th.printStackTrace();
+ public void error(String message, Throwable th) {
+ println(formatMessage("E", message, th));
+ if (th != null)
+ th.printStackTrace();
}
- public void fatal (String message, Throwable th) {
- println(formatMessage("X",message,th));
- if (th != null) th.printStackTrace();
+ public void fatal(String message, Throwable th) {
+ println(formatMessage("X", message, th));
+ if (th != null)
+ th.printStackTrace();
}
/**
* Template method that allows choice of destination for output
*
- * @param s message to be traced
+ * @param s
+ * message to be traced
*/
- protected void println (String s) {
+ protected void println(String s) {
print.println(s);
}
- public void setPrintStream (PrintStream printStream) {
+ public void setPrintStream(PrintStream printStream) {
this.print = printStream;
}
-// private static boolean isTracingEnabled = getBoolean("org.aspectj.weaver.tools.tracing",false);
-//
-// private static boolean getBoolean (String name, boolean def) {
-// String defaultValue = String.valueOf(def);
-// String value = System.getProperty(name,defaultValue);
-// return Boolean.valueOf(value).booleanValue();
-// }
+ // private static boolean isTracingEnabled =
+ // getBoolean("org.aspectj.weaver.tools.tracing",false);
+ //
+ // private static boolean getBoolean (String name, boolean def) {
+ // String defaultValue = String.valueOf(def);
+ // String value = System.getProperty(name,defaultValue);
+ // return Boolean.valueOf(value).booleanValue();
+ // }
}
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/Trace.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/Trace.java
index c1a040d36..8b20032aa 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/Trace.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/Trace.java
@@ -12,51 +12,47 @@ package org.aspectj.weaver.tools;
public interface Trace {
- public void enter (String methodName, Object thiz, Object[] args);
+ public void enter(String methodName, Object thiz, Object[] args);
- public void enter (String methodName, Object thiz);
+ public void enter(String methodName, Object thiz);
- public void exit (String methodName, Object ret);
+ public void exit(String methodName, Object ret);
- public void exit (String methodName, Throwable th);
+ public void exit(String methodName, Throwable th);
- public void exit (String methodName);
+ public void exit(String methodName);
- public void event (String methodName);
+ public void event(String methodName);
- public void event (String methodName, Object thiz, Object[] args);
-
- public void debug (String message);
-
- public void info (String message);
+ public void event(String methodName, Object thiz, Object[] args);
- public void warn (String message);
+ public void debug(String message);
- public void warn (String message, Throwable th);
+ public void info(String message);
- public void error (String message);
+ public void warn(String message);
- public void error (String message, Throwable th);
+ public void warn(String message, Throwable th);
- public void fatal (String message);
+ public void error(String message);
- public void fatal (String message, Throwable th);
-
-
- /*
- * Convenience methods
- */
- public void enter (String methodName, Object thiz, Object arg);
+ public void error(String message, Throwable th);
- public void enter (String methodName, Object thiz, boolean z);
+ public void fatal(String message);
- public void exit (String methodName, boolean b);
+ public void fatal(String message, Throwable th);
- public void exit (String methodName, int i);
+ public void enter(String methodName, Object thiz, Object arg);
- public void event (String methodName, Object thiz, Object arg);
-
- public boolean isTraceEnabled ();
+ public void enter(String methodName, Object thiz, boolean z);
- public void setTraceEnabled (boolean b);
+ public void exit(String methodName, boolean b);
+
+ public void exit(String methodName, int i);
+
+ public void event(String methodName, Object thiz, Object arg);
+
+ public boolean isTraceEnabled();
+
+ public void setTraceEnabled(boolean b);
} \ No newline at end of file