]> source.dussan.org Git - aspectj.git/commitdiff
Bug 176546 "Allow custom aop.xml provider through IWeavingContext"
authormwebster <mwebster>
Wed, 7 Mar 2007 01:29:16 +0000 (01:29 +0000)
committermwebster <mwebster>
Wed, 7 Mar 2007 01:29:16 +0000 (01:29 +0000)
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java
loadtime/testsrc/org/aspectj/weaver/loadtime/WeavingContextTest.java

index 40497e1031dcba395db4c82eea3b76c350255ebe..6aa2043930a6efb73a2436c184400689687f499d 100644 (file)
@@ -130,7 +130,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
             }
         };
 
-        List definitions = parseDefinitions(classLoader);
+        List definitions = weavingContext.getDefinitions(classLoader,this);
         if (definitions.isEmpty()) {
                disable(); // TODO maw Needed to ensure messages are flushed
                if (trace.isTraceEnabled()) trace.exit("initialize",definitions);
@@ -178,7 +178,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
      * @param weaver
      * @param loader
      */
-    private List parseDefinitions(final ClassLoader loader) {
+    List parseDefinitions(final ClassLoader loader) {
         if (trace.isTraceEnabled()) trace.enter("parseDefinitions",this,loader);
 
         List definitions = new ArrayList();
index 02c8a091e2c3efc528b7643c2aeb4bb9888ae64c..6ffd2cb283d09e4fcb5d6664c1082d4bc15f94b1 100644 (file)
@@ -14,6 +14,11 @@ package org.aspectj.weaver.loadtime;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Enumeration;
+import java.util.List;
+
+import org.aspectj.weaver.tools.Trace;
+import org.aspectj.weaver.tools.TraceFactory;
+import org.aspectj.weaver.tools.WeavingAdaptor;
 
 /**
  * Use in non-OSGi environment
@@ -21,17 +26,19 @@ import java.util.Enumeration;
  * @author David Knibb
  */
 public class DefaultWeavingContext implements IWeavingContext {
-       
+
        protected ClassLoader loader;
-       
        private String shortName;
 
+       private static Trace trace = TraceFactory.getTraceFactory().getTrace(DefaultWeavingContext.class);
+
        /**
         * Construct a new WeavingContext to use the specifed ClassLoader
         * This is the constructor which should be used.
         * @param loader
         */
        public DefaultWeavingContext(ClassLoader loader) {
+               super();
                this.loader = loader;
        }
 
@@ -93,4 +100,19 @@ public class DefaultWeavingContext implements IWeavingContext {
         } 
         return isLocallyDefined;
        }
+
+       /**
+        * Simply call weaving adaptor back to parse aop.xml
+        *
+        * @param weaver
+        * @param loader
+        */
+       public List getDefinitions(final ClassLoader loader, final WeavingAdaptor adaptor) {
+               if (trace.isTraceEnabled()) trace.enter("getDefinitions",this,new Object[] { loader, adaptor });
+       
+               List definitions = ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader);
+               
+               if (trace.isTraceEnabled()) trace.exit("getDefinitions",definitions);
+                       return definitions;
+           }
 }
index c056b9ee6acb2145e7d263b6eb279b70d9fa35dc..97e037317a1706bdd80675711b57a13df2d2eeef 100644 (file)
@@ -15,9 +15,12 @@ import java.io.IOException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Enumeration;
+import java.util.List;
 
 import junit.framework.TestCase;
 
+import org.aspectj.weaver.tools.WeavingAdaptor;
+
 public class WeavingContextTest extends TestCase {
 
        private boolean called;
@@ -115,6 +118,24 @@ public class WeavingContextTest extends TestCase {
                assertTrue("IWeavingContext not called",called);
        }
 
+       public void testGetDefinitions () throws Exception {
+               File file = new File("../loadtime/testdata");
+               URL fileURL = file.getCanonicalFile().toURL();
+               URLClassLoader loader = new URLClassLoader(new URL[] { fileURL },null);
+               IWeavingContext context = new TestWeavingContext(loader) {
+
+                       public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
+                               called = true;
+                       return super.getDefinitions(loader,adaptor);
+                       }
+                       
+               };
+               ClassLoaderWeavingAdaptor adaptor = new ClassLoaderWeavingAdaptor();
+               adaptor.initialize(loader,context);
+               
+               assertTrue("getDefinitions not called",called);
+       }
+       
        private static class TestWeavingContext implements IWeavingContext {
 
                private ClassLoader loader;
@@ -157,6 +178,10 @@ public class WeavingContextTest extends TestCase {
                } 
                return isLocallyDefined;
                }
+
+               public List getDefinitions(ClassLoader loader, WeavingAdaptor adaptor) {
+               return ((ClassLoaderWeavingAdaptor)adaptor).parseDefinitions(loader);
+               }
        }
 
        protected void setUp() throws Exception {