]> source.dussan.org Git - aspectj.git/commitdiff
Bug 150487 "Tracing and Logging Framework" (lazy initialize SimpleDateFormat to preve...
authormwebster <mwebster>
Tue, 1 Aug 2006 13:09:06 +0000 (13:09 +0000)
committermwebster <mwebster>
Tue, 1 Aug 2006 13:09:06 +0000 (13:09 +0000)
loadtime/src/org/aspectj/weaver/loadtime/WeavingURLClassLoader.java
tests/ltw/ExceptionHandler.aj [new file with mode: 0644]
tests/ltw/HelloWorld.java
tests/ltw/ant.xml
tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml
weaver/src/org/aspectj/weaver/ExtensibleURLClassLoader.java
weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java
weaver/src/org/aspectj/weaver/tools/AbstractTrace.java

index 2a3d193812dd05cd26771446717faee0b8ee1853..0dc1506df2441bec191182134d99a2d91cd63dd7 100644 (file)
@@ -43,7 +43,7 @@ public class WeavingURLClassLoader extends ExtensibleURLClassLoader implements W
         */
        public WeavingURLClassLoader (ClassLoader parent) {
                this(getURLs(getClassPath()),getURLs(getAspectPath()),parent);
-//             System.err.println("? WeavingURLClassLoader.<init>(" + m_parent + ")");
+//             System.out.println("? WeavingURLClassLoader.WeavingURLClassLoader()");
        }
        
        public WeavingURLClassLoader (URL[] urls, ClassLoader parent) {
@@ -53,15 +53,22 @@ public class WeavingURLClassLoader extends ExtensibleURLClassLoader implements W
        
        public WeavingURLClassLoader (URL[] classURLs, URL[] aspectURLs, ClassLoader parent) {
                super(classURLs,parent);
-//             System.err.println("? WeavingURLClassLoader.<init>() classURLs=" + classURLs.length + ", aspectURLs=" + aspectURLs.length);
+//             System.out.println("> WeavingURLClassLoader.WeavingURLClassLoader() classURLs=" + Arrays.asList(classURLs));
                this.aspectURLs = aspectURLs;
                
-               /* If either we nor our m_parent is using an ASPECT_PATH use a new-style
+               /* If either we nor our parent is using an ASPECT_PATH use a new-style
                 * adaptor
                 */ 
-               if (this.aspectURLs.length > 0 || parent instanceof WeavingClassLoader) {
-                       adaptor = new WeavingAdaptor(this);
+               if (this.aspectURLs.length > 0 || getParent() instanceof WeavingClassLoader) {
+                       try {
+                               adaptor = new WeavingAdaptor(this);
+                       }
+                       catch (ExceptionInInitializerError ex) {
+                               ex.printStackTrace(System.out);
+                               throw ex;
+                       }
                }
+//             System.out.println("< WeavingURLClassLoader.WeavingURLClassLoader() adaptor=" + adaptor);
        }
        
        private static String getAspectPath () {
@@ -106,26 +113,30 @@ public class WeavingURLClassLoader extends ExtensibleURLClassLoader implements W
                        
                        /* Need to defer creation because of possible recursion during constructor execution */
                        if (adaptor == null && !initializingAdaptor) {
-                               DefaultWeavingContext weavingContext = new DefaultWeavingContext (this) {
-
-                                       /* Ensures consistent LTW messages for testing */
-                                       public String getClassLoaderName() {
-                                               return loader.getClass().getName();
-                                       }
-                                       
-                               };
-                               
-                               ClassLoaderWeavingAdaptor clwAdaptor = new ClassLoaderWeavingAdaptor();
-                               initializingAdaptor = true;
-                               clwAdaptor.initialize(this,weavingContext);
-                               initializingAdaptor = false;
-                               adaptor = clwAdaptor;
+                               createAdaptor();
                        }
                        
                        b = adaptor.weaveClass(name,b);
                }
                return super.defineClass(name, b, cs);
        }
+       
+       private void createAdaptor () {
+               DefaultWeavingContext weavingContext = new DefaultWeavingContext (this) {
+
+                       /* Ensures consistent LTW messages for testing */
+                       public String getClassLoaderName() {
+                               return loader.getClass().getName();
+                       }
+                       
+               };
+               
+               ClassLoaderWeavingAdaptor clwAdaptor = new ClassLoaderWeavingAdaptor();
+               initializingAdaptor = true;
+               clwAdaptor.initialize(this,weavingContext);
+               initializingAdaptor = false;
+               adaptor = clwAdaptor;
+       }
 
        /**
         * Override to find classes generated by WeavingAdaptor
diff --git a/tests/ltw/ExceptionHandler.aj b/tests/ltw/ExceptionHandler.aj
new file mode 100644 (file)
index 0000000..447b595
--- /dev/null
@@ -0,0 +1,9 @@
+public aspect ExceptionHandler {
+       void around() : execution(public void main(String[])) {
+               try {
+                       proceed();
+               }
+               catch (Exception ex) {
+               }
+       }
+}
\ No newline at end of file
index 8e5a1fdd7ba327dc2d45a8f5805dbfb2a36656c3..9c810cf25874bda5bf74dda9a9128b548c3ce8ea 100644 (file)
@@ -2,6 +2,7 @@ public class HelloWorld {
        
        public static void main (String[] args) throws Exception {
                System.out.println("Hello World!");
+               throw new Exception();
        }
        
 }
\ No newline at end of file
index 6f7971d963ccb01773ceb4f638b89457717bdcd3..38f51fd49f93644f9b2e0ed10b5442fa3d220af7 100644 (file)
@@ -6,16 +6,38 @@
         name="jdwp"
         value="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>
 
-    <target name="JDK14 LTW">
+    <target name="JDK14 LTW with XML">
         <java fork="yes" classname="HelloWorld" failonerror="yes">
             <classpath refid="aj.path"/>
+<!--           
             <classpath>
                 <pathelement path="${aj.sandbox}/hello.jar"/>
             </classpath>
+-->            
             <jvmarg value="-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader"/>
+            <jvmarg value="-Daj.class.path=${aj.sandbox}/hello.jar;${aj.sandbox}/handler.jar"/>
+            <jvmarg value="-Daj.weaving.verbose=true"/>
+            <jvmarg value="-Dorg.aspectj.weaver.showWeaveInfo=true"/>
+            <jvmarg value="-Dorg.aspectj.tracing.debug=true"/>
+            <!-- use META-INF/aop.xml style -->
+<!--            <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>-->
+<!--            <jvmarg line="${jdwp}"/>-->
+        </java>
+    </target>
+
+    <target name="JDK14 LTW with ASPECTPATH">
+        <java fork="yes" classname="HelloWorld" failonerror="yes">
+            <classpath refid="aj.path"/>
                <!--            
+            <classpath>
+                <pathelement path="${aj.sandbox}/hello.jar"/>
+            </classpath>
 -->            
-            <jvmarg value="-Daj.class.path=${aj.sandbox}/hello.jar"/>
+            <jvmarg value="-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader"/>
+            <jvmarg value="-Daj.class.path=${aj.sandbox}/hello.jar;${aj.sandbox}/handler.jar"/>
+            <jvmarg value="-Daj.aspect.path=${aj.sandbox}/handler.jar"/>
+            <jvmarg value="-Daj.weaving.verbose=true"/>
+            <jvmarg value="-Dorg.aspectj.weaver.showWeaveInfo=true"/>
             <jvmarg value="-Dorg.aspectj.tracing.debug=true"/>
             <!-- use META-INF/aop.xml style -->
 <!--            <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>-->
index 4a5a7e0ee6d482e0f42bc4765a1046e193acb780..73b6eebd14b7ec306fb3e4ab7cf4edb7e5c16435 100644 (file)
@@ -97,8 +97,12 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase {
                runTest("Odd zip on classpath");                
        }
        
-       public void testJDK14LTW() {    
-               runTest("JDK14 LTW");           
+       public void testJ14LTWWithXML() {       
+               runTest("JDK14 LTW with XML");                  
+       }
+       
+       public void testJ14LTWWithASPECTPATH() {        
+               runTest("JDK14 LTW with ASPECTPATH");           
        }
        
        // separate bugzilla patch has this one... commented out
index 57946c186d590c304ee87fe40544a8f06293c16b..bc71208702321e8835c2156834123e8a8b0425cc 100644 (file)
@@ -470,11 +470,16 @@ commented out: reported in another bugzilla bug...
         </run>
     </ajc-test>
 -->
-       <ajc-test dir="ltw" title="JDK14 LTW" keywords="ltw">
-        <compile
-               files="HelloWorld.java"
-               options="-outjar hello.jar"
-        />
-        <ant file="ant.xml" target="JDK14 LTW" verbose="true"/>
+       <ajc-test dir="ltw" title="JDK14 LTW with XML" keywords="ltw">
+        <compile files="HelloWorld.java" options="-outjar hello.jar"/>
+        <compile files="ExceptionHandler.aj" options="-outxml -outjar handler.jar"/>
+        <ant file="ant.xml" target="JDK14 LTW with XML" verbose="true"/>
+    </ajc-test>
+    
+       <ajc-test dir="ltw" title="JDK14 LTW with ASPECTPATH" keywords="ltw">
+        <compile files="HelloWorld.java" options="-outjar hello.jar"/>
+        <compile files="ExceptionHandler.aj" options="-outjar handler.jar"/>
+        <ant file="ant.xml" target="JDK14 LTW with ASPECTPATH" verbose="true"/>
     </ajc-test>
     
+    
\ No newline at end of file
index 74d68703dfa948f723a30464d545399341e30943..e35d95eb30607a07bb5afc4179285d6b3b5787a5 100644 (file)
@@ -29,7 +29,13 @@ public abstract class ExtensibleURLClassLoader extends URLClassLoader {
                super(urls,parent);
 
 //             System.err.println("? ExtensibleURLClassLoader.<init>() path=" + WeavingAdaptor.makeClasspath(urls));
-               classPath = new ClassPathManager(FileUtil.makeClasspath(urls),null);
+               try {
+                       classPath = new ClassPathManager(FileUtil.makeClasspath(urls),null);
+               }
+               catch (ExceptionInInitializerError ex) {
+                       ex.printStackTrace(System.out);
+                       throw ex;
+               }
        }
 
        protected void addURL(URL url) {
index 6f9025e20caf67154f01d6c3d97cc3b0e0c09e40..5f06c0e6f17a4477f86d49a486b928b19f6feb68 100644 (file)
@@ -46,11 +46,7 @@ public class ClassPathManager {
        private static int maxOpenArchives       = -1;
     private static final int MAXOPEN_DEFAULT = 1000;
 
-    /*
-     * FIXME maw Tracing ClassPathManager can cause recursion for JDK 1.4 
-     * LTW i.e. -Djava.system.class.loader
-     */
-//    private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassPathManager.class);
+    private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassPathManager.class);
        
        static {
                String openzipsString = getSystemPropertyWithoutSecurityException("org.aspectj.weaver.openarchives",Integer.toString(MAXOPEN_DEFAULT));
@@ -61,13 +57,13 @@ public class ClassPathManager {
        
        
        public ClassPathManager(List classpath, IMessageHandler handler) {
-//             if (trace.isTraceEnabled()) trace.enter("<init>",this,new Object[] { classpath, handler });
+               if (trace.isTraceEnabled()) trace.enter("<init>",this,new Object[] { classpath, handler });
                entries = new ArrayList();
                for (Iterator i = classpath.iterator(); i.hasNext();) {
                        String name = (String) i.next();
                        addPath(name, handler);
                }
-//             if (trace.isTraceEnabled()) trace.exit("<init>");
+               if (trace.isTraceEnabled()) trace.exit("<init>");
        }
 
        protected ClassPathManager() {};
index 877fc79ddc65b372ba1b9ed34ebf8131ec19741c..4b421f2aeb18fccaabcdeb63af75366022c2d4d0 100644 (file)
@@ -18,7 +18,7 @@ public abstract class AbstractTrace implements Trace {
 
        protected Class tracedClass;
 
-       private static SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss.SSS");
+       private static SimpleDateFormat timeFormat;
        
        protected AbstractTrace (Class clazz) {
                this.tracedClass = clazz;
@@ -94,7 +94,7 @@ public abstract class AbstractTrace implements Trace {
        protected String formatMessage(String kind, String className, String methodName, Object thiz, Object[] args) {
                StringBuffer message = new StringBuffer();
                Date now = new Date();
-               message.append(time.format(now)).append(" ");
+               message.append(formatDate(now)).append(" ");
                message.append(Thread.currentThread().getName()).append(" ");
                message.append(kind).append(" ");
                message.append(className);
@@ -103,6 +103,14 @@ public abstract class AbstractTrace implements Trace {
                if (args != null) message.append(" ").append(formatArgs(args));
                return message.toString();
        }
+       
+       private static String formatDate (Date date) {
+               if (timeFormat == null) {
+                       timeFormat = new SimpleDateFormat("HH:mm:ss.SSS");
+               }
+               
+               return timeFormat.format(date);
+       }
 
        /**
         * Format objects safely avoiding toString which can cause recursion,