]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bug 150254 "Provide context for LTW verbose messages" (tidy up ClassLoaderWea...
authormwebster <mwebster>
Tue, 18 Jul 2006 10:18:05 +0000 (10:18 +0000)
committermwebster <mwebster>
Tue, 18 Jul 2006 10:18:05 +0000 (10:18 +0000)
loadtime/src/org/aspectj/weaver/loadtime/Aj.java
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
loadtime/src/org/aspectj/weaver/loadtime/WeavingURLClassLoader.java
loadtime/testsrc/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptorTest.java
loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingContextTest.java

index 015a245b386dedeba1478c8b76dec66ac159b9d7..33398f0c5c2c0a84ecc7f06594e54ac440d50278 100644 (file)
@@ -103,7 +103,7 @@ public class Aj implements ClassPreProcessor {
                        } else {
                            // create it and put it back in the weavingAdaptors map but avoid any kind of instantiation
                            // within the synchronized block
-                           ClassLoaderWeavingAdaptor weavingAdaptor = new ClassLoaderWeavingAdaptor(loader, weavingContext);
+                           ClassLoaderWeavingAdaptor weavingAdaptor = new ClassLoaderWeavingAdaptor();
                            adaptor = new ExplicitlyInitializedClassLoaderWeavingAdaptor(weavingAdaptor);
                            weavingAdaptors.put(loader, adaptor);
                        }
index 7f65023613bcd508cfd77f740a7204197dde27c0..1ea1397ca862eeab13fcca7ff18bf8726787ff21 100644 (file)
@@ -71,23 +71,35 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
     private List m_aspectIncludeStartsWith = new ArrayList();
 
     private StringBuffer namespace;
-    private ClassLoader classLoader;
     private IWeavingContext weavingContext;
 
        private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassLoaderWeavingAdaptor.class);
     
-    public ClassLoaderWeavingAdaptor(final ClassLoader loader, IWeavingContext wContext) {
+    public ClassLoaderWeavingAdaptor() {
        super();
        if (trace.isTraceEnabled()) trace.enter("<init>",this);
-       this.classLoader = loader;
-       this.weavingContext = wContext;
+       if (trace.isTraceEnabled()) trace.exit("<init>");
+    }
+    
+    /**
+     * We don't need a reference to the class loader and using it during 
+     * construction can cause problems with recursion. It also makes sense
+     * to supply the weaving context during initialization to. 
+     * @deprecated
+     */
+    public ClassLoaderWeavingAdaptor(final ClassLoader deprecatedLoader, final IWeavingContext deprecatedContext) {
+       super();
+       if (trace.isTraceEnabled()) trace.enter("<init>",this,new Object[] { deprecatedLoader, deprecatedContext });
        if (trace.isTraceEnabled()) trace.exit("<init>");
     }
 
-    protected void initialize (final ClassLoader deprecatedLoader, IWeavingContext deprecatedContext) {
+    protected void initialize (final ClassLoader classLoader, IWeavingContext context) {
         //super(null);// at this stage we don't have yet a generatedClassHandler to define to the VM the closures
        if (initialized) return;
 
+       if (trace.isTraceEnabled()) trace.enter("initialize",this,new Object[] { classLoader, context });
+
+       this.weavingContext = context;
         if (weavingContext == null) {
                weavingContext = new DefaultWeavingContext(classLoader);
         }
@@ -116,6 +128,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
 
         List definitions = parseDefinitions(classLoader);
         if (!enabled) {
+               if (trace.isTraceEnabled()) trace.exit("initialize",enabled);
                return;
         }
         
@@ -149,6 +162,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
         }
         
         initialized = true;
+       if (trace.isTraceEnabled()) trace.exit("initialize",enabled);
     }
 
     /**
index 671b8e17aa6096ab74bedc1602d5c72a161b2213..2a3d193812dd05cd26771446717faee0b8ee1853 100644 (file)
@@ -115,7 +115,7 @@ public class WeavingURLClassLoader extends ExtensibleURLClassLoader implements W
                                        
                                };
                                
-                               ClassLoaderWeavingAdaptor clwAdaptor = new ClassLoaderWeavingAdaptor(this,weavingContext);
+                               ClassLoaderWeavingAdaptor clwAdaptor = new ClassLoaderWeavingAdaptor();
                                initializingAdaptor = true;
                                clwAdaptor.initialize(this,weavingContext);
                                initializingAdaptor = false;
index a2a07c89a4382c92bceca26ae8996488c81cf36b..805b989a6620f446d9ae3fcf3a43eacf3e1c520d 100644 (file)
@@ -19,26 +19,30 @@ public class ClassLoaderWeavingAdaptorTest extends TestCase {
 
        public void testClassLoaderWeavingAdaptor() {
                ClassLoader loader = new URLClassLoader(new URL[] {}, null);
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,null);
        }
 
        public void testGetNamespace() {
                ClassLoader loader = new URLClassLoader(new URL[] {}, null);
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,null);
                String namespace = adaptor.getNamespace();
                assertEquals("Namespace should be empty","",namespace);
        }
 
        public void testGeneratedClassesExistFor() {
                ClassLoader loader = new URLClassLoader(new URL[] {}, null);
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,null);
                boolean exist = adaptor.generatedClassesExistFor("Junk");
                assertFalse("There should be no generated classes",exist);
        }
 
        public void testFlushGeneratedClasses() {
                ClassLoader loader = new URLClassLoader(new URL[] {}, null);
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,null);
                adaptor.flushGeneratedClasses();
                boolean exist = adaptor.generatedClassesExistFor("Junk");
                assertFalse("There should be no generated classes",exist);
index 7d53182193ede59dfb70a353919c2c8ceeec5388..af2e49182a58f09bf6fa82ba7761b58c3597a3c6 100644 (file)
@@ -25,7 +25,8 @@ public class WeavingContextTest extends TestCase {
        public void testWeavingContext() {
                URLClassLoader loader = new URLClassLoader(new URL[] {},null);
                IWeavingContext context = new TestWeavingContext(loader);
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,context);
        }
 
        public void testGetResources() {
@@ -38,8 +39,8 @@ public class WeavingContextTest extends TestCase {
                        }
                        
                };
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context);
-               adaptor.initialize(null,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,context);
                
                assertTrue("IWeavingContext not called",called);
        }
@@ -53,9 +54,9 @@ public class WeavingContextTest extends TestCase {
                        }
                        
                };
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
                try {
-                       adaptor.initialize(null,null);
+                       adaptor.initialize(loader,context);
                }
                catch (UnsupportedOperationException ex) {
                        fail("IWeavingContect.getBundleIdFromURL() is deprecated");
@@ -72,8 +73,8 @@ public class WeavingContextTest extends TestCase {
                        }
                        
                };
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context);
-               adaptor.initialize(null,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,context);
                
                assertTrue("IWeavingContext not called",called);
        }
@@ -90,8 +91,8 @@ public class WeavingContextTest extends TestCase {
                        }
                        
                };
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context);
-               adaptor.initialize(null,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,context);
                
                assertTrue("IWeavingContext not called",called);
        }
@@ -108,8 +109,8 @@ public class WeavingContextTest extends TestCase {
                        }
                        
                };
-               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor(loader,context);
-               adaptor.initialize(null,null);
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,context);
                
                assertTrue("IWeavingContext not called",called);
        }