commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1424830 - in /commons/sandbox/privilizer/trunk: maven-plugin/src/main/java/org/apache/commons/weaver/maven/ modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ processor/src/main/java/org/apache/commons/weaver/ pr...
Date Fri, 21 Dec 2012 09:53:50 GMT
Author: struberg
Date: Fri Dec 21 09:53:50 2012
New Revision: 1424830

URL: http://svn.apache.org/viewvc?rev=1424830&view=rev
Log:
re-add classpath and target configuration

Modified:
    commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java
    commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java
    commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java
    commons/sandbox/privilizer/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
    commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java
    commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java
    commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
    commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java
    commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java

Modified: commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java
(original)
+++ commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java
Fri Dec 21 09:53:50 2012
@@ -18,8 +18,12 @@ package org.apache.commons.weaver.maven;
 import java.io.File;
 import java.net.URLClassLoader;
 import java.util.List;
+import java.util.Properties;
 
+import org.apache.commons.weaver.WeaveProcessor;
+import org.apache.commons.weaver.utils.URLArray;
 import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Parameter;
 
 
@@ -27,21 +31,17 @@ import org.apache.maven.plugins.annotati
  * Defines common properties.
  */
 public abstract class AbstractWeaveMojo extends AbstractMojo {
-    /**
-     * Weaving policy to use.
-     */
-    @Parameter(property = "privilizer.policy", required = true, defaultValue = "DYNAMIC")
-    protected Policy policy;
 
     @Parameter(defaultValue = "false")
     protected boolean verbose;
 
+    @Parameter(property = "weaver.properties", required = false)
+    protected Properties properties;
+
     protected abstract List<String> getClasspath();
 
     protected abstract File getTarget();
 
-    protected abstract AccessLevel getAccessLevel();
-
     protected FilesystemPrivilizer createWeaver() {
         return new FilesystemPrivilizer(policy, new URLClassLoader(URLArray.fromPaths(getClasspath())),
getTarget()) {
             @Override
@@ -81,4 +81,19 @@ public abstract class AbstractWeaveMojo 
         });
     }
 
+
+    @Override
+    public void execute() throws MojoFailureException {
+        try {
+            WeaveProcessor wp = WeaveProcessor.getInstance();
+            configure(wp);
+            wp.weave();
+        } catch (Exception e) {
+            throw new MojoFailureException("weaving failed", e);
+        }
+    }
+
+    protected void configure(WeaveProcessor wp) {
+
+    }
 }

Modified: commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java
(original)
+++ commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/TestWeaveMojo.java
Fri Dec 21 09:53:50 2012
@@ -18,8 +18,6 @@ package org.apache.commons.weaver.maven;
 import java.io.File;
 import java.util.List;
 
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -38,8 +36,6 @@ public class TestWeaveMojo extends Abstr
     @Parameter(readonly = true, required = true, defaultValue = "${project.build.testOutputDirectory}")
     protected File target;
 
-    @Parameter(readonly = false, required = true, defaultValue = "PUBLIC")
-    protected AccessLevel accessLevel;
 
     @Override
     protected List<String> getClasspath() {
@@ -51,18 +47,4 @@ public class TestWeaveMojo extends Abstr
         return target;
     }
 
-    @Override
-    protected AccessLevel getAccessLevel() {
-        return accessLevel;
-    }
-
-    @Override
-    public void execute() throws MojoExecutionException
-    {
-        try {
-            createWeaver().weaveAll();
-        } catch (Exception e) {
-            throw new MojoFailureException("failed", e);
-        }
-    }
 }

Modified: commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java
(original)
+++ commons/sandbox/privilizer/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java
Fri Dec 21 09:53:50 2012
@@ -18,8 +18,6 @@ package org.apache.commons.weaver.maven;
 import java.io.File;
 import java.util.List;
 
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -38,9 +36,6 @@ public class WeaveMojo extends AbstractW
     @Parameter(readonly = true, required = true, defaultValue = "${project.build.outputDirectory}")
     protected File target;
 
-    @Parameter(readonly = false, required = true, defaultValue = "PACKAGE")
-    protected AccessLevel accessLevel;
-
     @Override
     protected List<String> getClasspath() {
         return classpath;
@@ -51,17 +46,6 @@ public class WeaveMojo extends AbstractW
         return target;
     }
 
-    @Override
-    protected AccessLevel getAccessLevel() {
-        return accessLevel;
-    }
-    @Override
-    public void execute() throws MojoExecutionException
-    {
-        try {
-            createWeaver().weaveAll();
-        } catch (Exception e) {
-            throw new MojoFailureException("failed", e);
-        }
-    }
+
+
 }

Modified: commons/sandbox/privilizer/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
(original)
+++ commons/sandbox/privilizer/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
Fri Dec 21 09:53:50 2012
@@ -13,10 +13,14 @@ import java.util.logging.Logger;
 import javassist.CannotCompileException;
 import javassist.NotFoundException;
 import org.apache.commons.weaver.spi.Weaver;
+import org.apache.commons.weaver.utils.URLArray;
 
 /**
  * Weaver which adds doPrivileged blocks for each method annotated with
- * {@link Privileged}
+ * {@link Privileged}.
+ * An instance of this class will automatically get picked up by the
+ * {@link org.apache.commons.weaver.WeaveProcessor} via the
+ * {@link java.util.ServiceLoader}.
  */
 public class PrivilizerWeaver implements Weaver
 {
@@ -28,10 +32,6 @@ public class PrivilizerWeaver implements
 
     private AccessLevel targetAccessLevel;
 
-    private URLClassLoader urlClassLoader;
-
-    private File target;
-
     @Override
     public void setLogger(Logger customLogger)
     {
@@ -39,9 +39,9 @@ public class PrivilizerWeaver implements
     }
 
     @Override
-    public void configure(Map<String, Object> config)
+    public void configure(List<String> classPath, File target, Map<String, Object>
config)
     {
-        privilizer = new FilesystemPrivilizer(policy, urlClassLoader, target) {
+        privilizer = new FilesystemPrivilizer(policy, new URLClassLoader(URLArray.fromPaths(classPath)),
target) {
             @Override
             protected boolean permitMethodWeaving(final AccessLevel accessLevel) {
                 return targetAccessLevel.compareTo(accessLevel) <= 0;

Modified: commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java
(original)
+++ commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java
Fri Dec 21 09:53:50 2012
@@ -40,11 +40,20 @@ public class WeaveProcessor {
 
     private static WeaveProcessor instance;
 
+    /**
+     * The classpath which will be used to look up cross references during weaving.
+     */
+    private List<String> classPath;
+
+    /**
+     * The actual path which gets weaved. All the classes in this path
+     * will get weaved. The weaved classes will replace the original classes.
+     */
+    private File target;
+
     /** List of picked up weaver plugins */
     private List<Weaver> weavers = new ArrayList<Weaver>();
 
-    /** List of classpath entries to perform weaving on*/
-    private List<File> classPathsToWeave = new ArrayList<File>();
 
     public static synchronized WeaveProcessor getInstance() {
         if (instance == null) {
@@ -65,19 +74,18 @@ public class WeaveProcessor {
     }
 
     /**
-     * All the class paths which should get weaved.
-     * This e.g. contains target/classes in a typical maven installation.
+     * Configure all Weavers.
+     * @param classPath the classpath to look up cross-references in during weaving
+     * @param target the File path where the classes to weave reside
+     * @param config additional configuration for all plugins.
+     *
      */
-    public void addClassPath(File classPath) {
-        classPathsToWeave.add(classPath);
-    }
+    public void configure(List<String> classPath, File target, Map<String, Object>
config) {
+        this.classPath = classPath;
+        this.target = target;
 
-    /**
-     * configure all Weavers.
-     */
-    public void configure(Map<String, Object> config) {
         for (Weaver weaver : weavers) {
-            weaver.configure(config);
+            weaver.configure(classPath, target, config);
         }
     }
 
@@ -101,11 +109,9 @@ public class WeaveProcessor {
     private void weave(Weaver weaver) {
         List<Class<? extends Annotation>> interest = weaver.getInterest();
 
-        ClassLoader classLoader = new URLClassLoader(URLArray.fromFiles(classPathsToWeave));
+        ClassLoader classLoader = new URLClassLoader(URLArray.fromPaths(classPath));
 
-        //X ORIGINAL AnnotationFinder annotationFinder = new AnnotationFinder(new FileArchive(classLoader,
target), false);
-        //X TODO this is a hack for now!
-        AnnotationFinder annotationFinder = new AnnotationFinder(new FileArchive(classLoader,
classPathsToWeave.get(0)), false);
+        AnnotationFinder annotationFinder = new AnnotationFinder(new FileArchive(classLoader,
target), false);
         for (Class<? extends Annotation> annotation : interest) {
             List<Class<?>> annotatedClasses = annotationFinder.findAnnotatedClasses(annotation);
 

Modified: commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java
(original)
+++ commons/sandbox/privilizer/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java
Fri Dec 21 09:53:50 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.commons.weaver.spi;
 
+import java.io.File;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.List;
@@ -37,8 +38,11 @@ public interface Weaver
      * This is for now a simple way to configure any weaver.
      * Any configuration property of a weaver should start with it's 'name'
      * e.g. 'privilizer'
+     * @param classPath the classpath to look up cross-references in during weaving
+     * @param target the File path where the classes to weave reside
+     * @param config additional configuration for all plugins.
      */
-    void configure(Map<String, Object> config);
+    void configure(List<String> classPath, File target, Map<String, Object> config);
 
     /**
      * This method can be used to set a custom logger
@@ -72,9 +76,9 @@ public interface Weaver
      */
     boolean weave(Method methodToWeave, Class<? extends Annotation> processingAnnotation);
 
-
     /**
-     * This method will get invoked after all {@link #weave(Class)} methods got invoked
+     * This method will get invoked after all {@link #weave(Class, Class)} and
+     * {@link #weave(java.lang.reflect.Method, Class)} methods got invoked
      * for all classes on every weaver.
      */
     void postWeave();

Modified: commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
(original)
+++ commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
Fri Dec 21 09:53:50 2012
@@ -44,9 +44,11 @@ public class WeaveProcessorTest extends 
 
         Map<String, Object> config = new HashMap<String, Object>();
         config.put("configKey", "configValue");
-        wp.configure(config);
 
-        wp.addClassPath(getTargetFolder());
+        getTargetFolder();
+
+        wp.configure(getClassPathEntries(), getTargetFolder(), config);
+
 
         TestWeaver.postWeaveExecuted = false;
         TestWeaver.preWeaveExecuted = false;

Modified: commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java
(original)
+++ commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java
Fri Dec 21 09:53:50 2012
@@ -23,6 +23,8 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.junit.Rule;
 import org.junit.rules.TemporaryFolder;
@@ -35,7 +37,16 @@ public abstract class WeaverTestBase {
     @Rule
     public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
+    private File targetFolder;
+
+    private List<String> classPathEntries;
+
     private static final String TARGET_FOLDER = "target";
+
+    public void cleanup() {
+        targetFolder = null;
+    }
+
     /**
      * Add a class to the temporary folder.
      * @param clazz
@@ -66,6 +77,27 @@ public abstract class WeaverTestBase {
      * Resolves the 'target' folder where the classes should get placed
      */
     protected File getTargetFolder() {
-        return new File(temporaryFolder.getRoot(), TARGET_FOLDER);
+        if (targetFolder == null) {
+            targetFolder =  new File(temporaryFolder.getRoot(), TARGET_FOLDER);
+        }
+        return targetFolder;
     }
+
+    protected List<String> getClassPathEntries() {
+        if (classPathEntries == null) {
+            classPathEntries = new ArrayList<String>(1);
+            try
+            {
+                classPathEntries.add(getTargetFolder().getCanonicalPath());
+            }
+            catch (IOException ioe)
+            {
+                throw new RuntimeException(ioe);
+            }
+        }
+
+        return classPathEntries;
+    }
+
+
 }

Modified: commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java?rev=1424830&r1=1424829&r2=1424830&view=diff
==============================================================================
--- commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
(original)
+++ commons/sandbox/privilizer/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
Fri Dec 21 09:53:50 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.commons.weaver.test.weaver;
 
+import java.io.File;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
@@ -45,7 +46,7 @@ public class TestWeaver implements Weave
     }
 
     @Override
-    public void configure(Map<String, Object> config)
+    public void configure(List<String> classPath, File target, Map<String, Object>
config)
     {
         Assert.assertNotNull(config);
         Assert.assertEquals(1, config.size());



Mime
View raw message