You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2013/02/28 08:08:48 UTC
svn commit: r1451121 - in /commons/sandbox/weaver/trunk: ./ example/
example/src/main/java/org/apache/commons/weaver/privilizer/example/
example/src/test/java/org/apache/commons/weaver/privilizer/example/
maven-plugin/src/main/java/org/apache/commons/w...
Author: mbenson
Date: Thu Feb 28 07:08:48 2013
New Revision: 1451121
URL: http://svn.apache.org/r1451121
Log:
merge branch to trunk
Added:
commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingBlueprints.java
commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/example/src/main/java/org/apache/commons/weaver/privilizer/example/Utils.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingBlueprintsTest.java
commons/sandbox/weaver/trunk/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/modules/privilizer/api/src/main/java/org/apache/commons/weaver/privilizer/Privilizing.java
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/Finder.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/Finder.java
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/
- copied from r1451119, commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/model/
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/utils/Annotations.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/utils/Annotations.java
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/utils/Args.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/processor/src/main/java/org/apache/commons/weaver/utils/Args.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/FinderTest.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/processor/src/test/java/org/apache/commons/weaver/FinderTest.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/beans/ComplexAnnotations.java
- copied unchanged from r1451119, commons/sandbox/weaver/branches/mjb/processor/src/test/java/org/apache/commons/weaver/test/beans/ComplexAnnotations.java
Removed:
commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/test/
Modified:
commons/sandbox/weaver/trunk/ (props changed)
commons/sandbox/weaver/trunk/example/pom.xml
commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingArgs.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java
commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java
commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java
commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java
commons/sandbox/weaver/trunk/modules/privilizer/weaver/pom.xml
commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java
commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java
commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
commons/sandbox/weaver/trunk/pom.xml
commons/sandbox/weaver/trunk/processor/pom.xml
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java
commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java
commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
Propchange: commons/sandbox/weaver/trunk/
------------------------------------------------------------------------------
svn:mergeinfo = /commons/sandbox/weaver/branches/mjb:1437127-1451119
Modified: commons/sandbox/weaver/trunk/example/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/pom.xml?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/pom.xml (original)
+++ commons/sandbox/weaver/trunk/example/pom.xml Thu Feb 28 07:08:48 2013
@@ -31,9 +31,14 @@
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
- <artifactId>commons-weaver-privilizer</artifactId>
+ <artifactId>commons-weaver-privilizer-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified: commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingArgs.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingArgs.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingArgs.java (original)
+++ commons/sandbox/weaver/trunk/example/src/main/java/org/apache/commons/weaver/privilizer/example/UsingArgs.java Thu Feb 28 07:08:48 2013
@@ -19,8 +19,6 @@ import java.util.ArrayList;
import org.apache.commons.weaver.privilizer.Privileged;
-
-
public class UsingArgs {
@Privileged
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/NoArgsTest.java Thu Feb 28 07:08:48 2013
@@ -15,21 +15,21 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.apache.commons.weaver.privilizer.example.NoArgs.CheckedException1;
import org.apache.commons.weaver.privilizer.example.NoArgs.CheckedException2;
-import junit.framework.TestCase;
-
-
-public class NoArgsTest extends TestCase {
+public class NoArgsTest {
private NoArgs noArgs;
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/OverloadingTest.java Thu Feb 28 07:08:48 2013
@@ -15,17 +15,15 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
-import junit.framework.TestCase;
-
-public class OverloadingTest extends TestCase {
+public class OverloadingTest {
private Overloading overloading;
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/PrivateMethodsTest.java Thu Feb 28 07:08:48 2013
@@ -15,17 +15,15 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
-import junit.framework.TestCase;
-
-public class PrivateMethodsTest extends TestCase {
+public class PrivateMethodsTest {
private PrivateMethods privateMethods;
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticNoArgsTest.java Thu Feb 28 07:08:48 2013
@@ -15,19 +15,19 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.apache.commons.weaver.privilizer.example.StaticNoArgs.CheckedException1;
import org.apache.commons.weaver.privilizer.example.StaticNoArgs.CheckedException2;
-import junit.framework.TestCase;
-
-
-public class StaticNoArgsTest extends TestCase {
- @Override
+public class StaticNoArgsTest {
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticOverloadingTest.java Thu Feb 28 07:08:48 2013
@@ -15,16 +15,14 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
-import junit.framework.TestCase;
-
-public class StaticOverloadingTest extends TestCase {
+public class StaticOverloadingTest {
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticPrivateMethodsTest.java Thu Feb 28 07:08:48 2013
@@ -15,16 +15,14 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
-import junit.framework.TestCase;
-
-public class StaticPrivateMethodsTest extends TestCase {
+public class StaticPrivateMethodsTest {
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/StaticUsingArgsTest.java Thu Feb 28 07:08:48 2013
@@ -15,6 +15,10 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
@@ -22,14 +26,9 @@ import java.util.Arrays;
import org.apache.commons.weaver.privilizer.example.StaticUsingArgs.CheckedException1;
import org.apache.commons.weaver.privilizer.example.StaticUsingArgs.CheckedException2;
-import junit.framework.TestCase;
-
-
-public class StaticUsingArgsTest extends TestCase {
+public class StaticUsingArgsTest {
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Modified: commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java (original)
+++ commons/sandbox/weaver/trunk/example/src/test/java/org/apache/commons/weaver/privilizer/example/UsingArgsTest.java Thu Feb 28 07:08:48 2013
@@ -15,6 +15,10 @@
*/
package org.apache.commons.weaver.privilizer.example;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
@@ -22,15 +26,10 @@ import java.util.Arrays;
import org.apache.commons.weaver.privilizer.example.UsingArgs.CheckedException1;
import org.apache.commons.weaver.privilizer.example.UsingArgs.CheckedException2;
-import junit.framework.TestCase;
-
-
-public class UsingArgsTest extends TestCase {
+public class UsingArgsTest {
private UsingArgs usingArgs;
- @Override
public void setUp() throws Exception {
- super.setUp();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
Modified: commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java (original)
+++ commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/AbstractWeaveMojo.java Thu Feb 28 07:08:48 2013
@@ -25,7 +25,6 @@ import org.apache.maven.plugin.MojoExecu
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Parameter;
-
/**
* Defines common properties.
*/
Modified: commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java (original)
+++ commons/sandbox/weaver/trunk/maven-plugin/src/main/java/org/apache/commons/weaver/maven/WeaveMojo.java Thu Feb 28 07:08:48 2013
@@ -46,6 +46,4 @@ public class WeaveMojo extends AbstractW
return target;
}
-
-
}
Modified: commons/sandbox/weaver/trunk/modules/privilizer/weaver/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/privilizer/weaver/pom.xml?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/privilizer/weaver/pom.xml (original)
+++ commons/sandbox/weaver/trunk/modules/privilizer/weaver/pom.xml Thu Feb 28 07:08:48 2013
@@ -39,22 +39,15 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-weaver-processor</artifactId>
- <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
- <version>3.1</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
- <version>3.16.1-GA</version>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
+ <version>3.17.1-GA</version>
</dependency>
</dependencies>
@@ -63,7 +56,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
- <version>1.8</version>
<configuration>
<debug>true</debug>
<projectsDirectory>src/it</projectsDirectory>
Modified: commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java (original)
+++ commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FilesystemPrivilizer.java Thu Feb 28 07:08:48 2013
@@ -17,9 +17,6 @@ package org.apache.commons.weaver.privil
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
import javassist.CannotCompileException;
import javassist.ClassPool;
@@ -35,7 +32,6 @@ import org.apache.commons.lang3.Validate
*/
public class FilesystemPrivilizer extends Privilizer<FilesystemPrivilizer> {
-
private static ClassPool createClassPool(ClassLoader classpath, File target) {
final ClassPool result = new ClassPool();
try {
@@ -48,27 +44,12 @@ public class FilesystemPrivilizer extend
return result;
}
- private static Set<Class<?>> getDeclaringClasses(Iterable<Method> methods) {
- final Set<Class<?>> declaringClasses = new HashSet<Class<?>>();
- for (final Method method : methods) {
- declaringClasses.add(method.getDeclaringClass());
- }
- return declaringClasses;
- }
-
- private static Class<?> getOutermost(Class<?> type) {
- Class<?> enclosing = type.getEnclosingClass();
- return enclosing == null ? type : getOutermost(enclosing);
- }
-
private static File validTarget(File target) {
Validate.notNull(target, "target");
Validate.isTrue(target.isDirectory(), "not a directory");
return target;
}
- private final ClassLoader classpath;
-
private final File target;
private final ClassFileWriter classFileWriter = new ClassFileWriter() {
@@ -80,29 +61,14 @@ public class FilesystemPrivilizer extend
public FilesystemPrivilizer(ClassLoader classpath, File target) {
super(createClassPool(classpath, target));
- this.classpath = classpath;
this.target = target;
}
public FilesystemPrivilizer(Policy policy, ClassLoader classpath, File target) {
super(policy, createClassPool(classpath, target));
- this.classpath = classpath;
this.target = target;
}
- /**
- * Weave all {@link Privileged} methods found.
- *
- * @throws NotFoundException
- * @throws IOException
- * @throws CannotCompileException
- * @throws ClassNotFoundException
- */
- public boolean weaveClass(Class<?> clazz)
- throws NotFoundException, IOException, CannotCompileException, ClassNotFoundException, IllegalAccessException {
- return weave(classPool.get(clazz.getName()));
- }
-
@Override
protected ClassFileWriter getClassFileWriter() {
return classFileWriter;
Modified: commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java (original)
+++ commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Privilizer.java Thu Feb 28 07:08:48 2013
@@ -31,6 +31,7 @@ import java.util.logging.Logger;
import javassist.CannotCompileException;
import javassist.ClassPool;
+import javassist.CodeConverter;
import javassist.CtClass;
import javassist.CtField;
import javassist.CtMethod;
@@ -39,12 +40,14 @@ import javassist.CtNewMethod;
import javassist.CtPrimitiveType;
import javassist.NotFoundException;
import javassist.bytecode.Descriptor;
+import javassist.expr.ExprEditor;
+import javassist.expr.MethodCall;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.text.StrBuilder;
-
+import org.apache.commons.weaver.privilizer.Privilizing.CallTo;
/**
* Handles weaving of methods annotated with {@link Privileged}.
@@ -76,20 +79,18 @@ public abstract class Privilizer<SELF ex
NEVER,
/**
- * Weaves such that the check for an active {@link SecurityManager} is
- * done once only.
+ * Weaves such that the check for an active {@link SecurityManager} is done once only.
*/
ON_INIT(generateName("hasSecurityManager")),
/**
- * Weaves such that the check for an active {@link SecurityManager} is
- * done for each {@link Privileged} method execution.
+ * Weaves such that the check for an active {@link SecurityManager} is done for each {@link Privileged} method
+ * execution.
*/
DYNAMIC(HAS_SECURITY_MANAGER_CONDITION),
/**
- * Weaves such that {@link Privileged} methods are always executed as
- * such.
+ * Weaves such that {@link Privileged} methods are always executed as such.
*/
ALWAYS;
@@ -170,17 +171,33 @@ public abstract class Privilizer<SELF ex
}
/**
+ * Weave all {@link Privileged} methods found.
+ *
+ * @param privilizing
+ *
+ * @throws NotFoundException
+ * @throws IOException
+ * @throws CannotCompileException
+ * @throws ClassNotFoundException
+ */
+ public boolean weaveClass(Class<?> clazz, Privilizing privilizing) throws NotFoundException, IOException,
+ CannotCompileException, ClassNotFoundException, IllegalAccessException {
+ return weave(classPool.get(clazz.getName()), privilizing);
+ }
+
+ /**
* Weave the specified class.
*
* @param type
+ * @param privilizing
* @return whether any work was done
* @throws NotFoundException
* @throws IOException
* @throws CannotCompileException
* @throws ClassNotFoundException
*/
- public boolean weave(CtClass type)
- throws NotFoundException, IOException, CannotCompileException, ClassNotFoundException, IllegalAccessException {
+ private boolean weave(CtClass type, Privilizing privilizing) throws NotFoundException, IOException,
+ CannotCompileException, ClassNotFoundException, IllegalAccessException {
reportSettings();
final String policyName = generateName(POLICY_NAME);
final String policyValue = toString(type.getAttribute(policyName));
@@ -205,8 +222,11 @@ public abstract class Privilizer<SELF ex
securityManager.setModifiers(Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL);
type.addField(securityManager, CtField.Initializer.byExpr(HAS_SECURITY_MANAGER_CONDITION));
}
+
+ result = privilizeBlueprints(type, privilizing) | result;
+
for (final CtMethod m : getPrivilegedMethods(type)) {
- result |= weave(type, m);
+ result = weave(type, m) | result;
}
if (result) {
type.setAttribute(policyName, policy.name().getBytes(Charset.forName("UTF-8")));
@@ -217,6 +237,160 @@ public abstract class Privilizer<SELF ex
return result;
}
+ private boolean privilizeBlueprints(CtClass type, Privilizing annotation) throws CannotCompileException,
+ ClassNotFoundException, NotFoundException, IOException, IllegalAccessException {
+ boolean result = false;
+ if (annotation != null) {
+ final CallTo[] blueprintCalls = annotation.value();
+ for (CallTo callTo : blueprintCalls) {
+ Validate.isTrue(!callTo.value().equals(type.getName()),
+ "Type %s cannot use itself as a privilizer blueprint", callTo.value());
+ }
+ for (CtMethod method : type.getDeclaredMethods()) {
+ result = privilizeBlueprints(type, method, blueprintCalls) | result;
+ }
+ }
+ return result;
+ }
+
+ private boolean privilizeBlueprints(final CtClass type, final CtMethod method, final CallTo[] blueprintCalls)
+ throws CannotCompileException, ClassNotFoundException, NotFoundException, IOException, IllegalAccessException {
+ boolean result = false;
+
+ final List<CtMethod> blueprints = new ArrayList<CtMethod>();
+ class CollectBlueprints extends ExprEditor {
+ @Override
+ public void edit(MethodCall call) throws CannotCompileException {
+ super.edit(call);
+ CtMethod called;
+ try {
+ called = call.getMethod();
+ if (!Modifier.isStatic(called.getModifiers())) {
+ return;
+ }
+ } catch (NotFoundException e) {
+ return;
+ }
+ for (CallTo callTo : blueprintCalls) {
+ final Class<?> owner = callTo.value();
+ if (owner.getName().equals(call.getClassName())) {
+ if (callTo.methods().length > 0) {
+ boolean found = false;
+ for (String m : callTo.methods()) {
+ found = StringUtils.equals(call.getMethodName(), m);
+ if (found) {
+ break;
+ }
+ }
+ if (!found) {
+ continue;
+ }
+ }
+ blueprints.add(called);
+ break;
+ }
+ }
+ }
+ }
+ method.instrument(new CollectBlueprints());
+
+ for (CtMethod blueprint : blueprints) {
+ final String name = importedMethodName(blueprint);
+
+ CtMethod copy = copyBlueprintTo(type, name, blueprint, blueprintCalls);
+ method.instrument(redirect(blueprint, copy));
+ result = true;
+ }
+ return result;
+ }
+
+ private static String importedMethodName(CtMethod blueprint) {
+ return new StringBuilder(blueprint.getDeclaringClass().getName().replace('.', '_')).append('$')
+ .append(blueprint.getName()).toString();
+ }
+
+ /*
+ * This design is almost certainly non-optimal. Basically, we have:
+ *
+ * for a declared method, look for calls to blueprint methods for each blueprint method, copy it when copying,
+ * inspect blueprint method's code and recursively copy in methods from the source class of *that particular method*
+ * because otherwise CtNewMethod will do it for us and we'll miss our window of opportunity now that we have a
+ * copied blueprint method, inspect it for blueprint calls from other classes and do this whole thing recursively.
+ *
+ * It would *seem* that we could combine the recursion/copying of methods from all blueprint classes but I can't get
+ * my head around it right now. -MJB
+ */
+ private CtMethod copyBlueprintTo(final CtClass target, final String toName, final CtMethod method,
+ final CallTo[] blueprintCalls) throws ClassNotFoundException, NotFoundException, IOException,
+ IllegalAccessException {
+ if (!Modifier.isStatic(method.getModifiers())) {
+ return null;
+ }
+
+ try {
+ final CtMethod done = target.getDeclaredMethod(toName, method.getParameterTypes());
+ return done;
+ } catch (NotFoundException e1) {
+ }
+ final CtClass declaring = method.getDeclaringClass();
+
+ final List<CtMethod> ownBlueprints = new ArrayList<CtMethod>();
+ class CollectBlueprints extends ExprEditor {
+ @Override
+ public void edit(MethodCall m) throws CannotCompileException {
+ super.edit(m);
+ CtMethod called;
+ try {
+ called = m.getMethod();
+ } catch (NotFoundException e) {
+ return;
+ }
+ if (called.getDeclaringClass().equals(declaring)) {
+ ownBlueprints.add(called);
+ }
+ }
+ }
+ try {
+ method.instrument(new CollectBlueprints());
+
+ boolean isRecursive = false;
+
+ for (CtMethod blueprint : ownBlueprints) {
+ if (blueprint.equals(method)) {
+ // recursive method call identified:
+ isRecursive = true;
+ continue;
+ }
+ CtMethod local = copyBlueprintTo(target, importedMethodName(blueprint), blueprint, blueprintCalls);
+ if (local != null) {
+ method.instrument(redirect(blueprint, local));
+ }
+ }
+ final CtMethod result = CtNewMethod.copy(method, toName, target, null);
+ result.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
+ target.addMethod(result);
+ if (isRecursive) {
+ CodeConverter redirect = new CodeConverter();
+ redirect.redirectMethodCall(method.getName(), result);
+ result.instrument(redirect);
+ }
+ // privilize other classes' blueprint methods recursively:
+ privilizeBlueprints(target, result, blueprintCalls);
+ // privilize:
+ weave(target, result);
+
+ return result;
+ } catch (CannotCompileException e) {
+ return null;
+ }
+ }
+
+ private static CodeConverter redirect(CtMethod origMethod, CtMethod substMethod) throws CannotCompileException {
+ final CodeConverter result = new CodeConverter();
+ result.redirectMethodCall(origMethod, substMethod);
+ return result;
+ }
+
protected void debug(String message, Object... args) {
log.fine(String.format(message, args));
}
@@ -350,9 +524,9 @@ public abstract class Privilizer<SELF ex
NotFoundException, IOException, IllegalAccessException {
final AccessLevel accessLevel = AccessLevel.of(method.getModifiers());
if (!permitMethodWeaving(accessLevel)) {
- throw new IllegalAccessException("Method " + type.getName() + "#" + toString(method)
- + " must have maximum access level '" + getTargetAccessLevel()
- + "' but is defined wider ('" + accessLevel + "')");
+ throw new IllegalAccessException("Method " + type.getName() + "#" + toString(method)
+ + " must have maximum access level '" + getTargetAccessLevel() + "' but is defined wider ('"
+ + accessLevel + "')");
}
if (AccessLevel.PACKAGE.compareTo(accessLevel) > 0) {
warn("Possible security leak: granting privileges to %s method %s.%s", accessLevel, type.getName(),
@@ -462,4 +636,5 @@ public abstract class Privilizer<SELF ex
debug("Weave policy == %s", policy);
}
}
+
}
Modified: commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java (original)
+++ commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerWeaver.java Thu Feb 28 07:08:48 2013
@@ -1,47 +1,36 @@
package org.apache.commons.weaver.privilizer;
import java.io.File;
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
+import java.lang.annotation.ElementType;
import java.net.URLClassLoader;
-import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import java.util.logging.Logger;
-import javassist.CannotCompileException;
-import javassist.NotFoundException;
+import org.apache.commons.weaver.model.ScanRequest;
+import org.apache.commons.weaver.model.ScanResult;
+import org.apache.commons.weaver.model.WeavableClass;
+import org.apache.commons.weaver.model.WeaveInterest;
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}.
- * An instance of this class will automatically get picked up by the
- * {@link org.apache.commons.weaver.WeaveProcessor} via the
+ * Weaver which adds doPrivileged blocks for each method annotated with {@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
-{
+public class PrivilizerWeaver implements Weaver {
public static final String CONFIG_WEAVER = "privilizer.";
public static final String CONFIG_ACCESS_LEVEL = CONFIG_WEAVER + "accessLevel";
public static final String CONFIG_POLICY = CONFIG_WEAVER + "policy";
- private static final Logger LOG = Logger.getLogger(PrivilizerWeaver.class.getName());
-
- private FilesystemPrivilizer privilizer;
+ private Privilizer<FilesystemPrivilizer> privilizer;
private Privilizer.Policy policy;
private AccessLevel targetAccessLevel;
-
@Override
- public void configure(List<String> classPath, File target, Properties config)
- {
- LOG.info("");
-
+ public void configure(List<String> classPath, File target, Properties config) {
String accessLevel = config.getProperty(CONFIG_ACCESS_LEVEL);
if (accessLevel == null || accessLevel.length() == 0) {
throw new IllegalArgumentException(CONFIG_ACCESS_LEVEL + " property is missing!");
@@ -61,8 +50,7 @@ public class PrivilizerWeaver implements
}
@Override
- protected AccessLevel getTargetAccessLevel()
- {
+ protected AccessLevel getTargetAccessLevel() {
return targetAccessLevel;
}
};
@@ -70,60 +58,23 @@ public class PrivilizerWeaver implements
}
@Override
- public List<Class<? extends Annotation>> getInterest()
- {
- List<Class<? extends Annotation>> interest = new ArrayList<Class<? extends Annotation>>();
- interest.add(Privileged.class);
- return interest;
- }
-
- @Override
- public void preWeave()
- {
- // nothing to do
+ public ScanRequest getScanRequest() {
+ return new ScanRequest().add(WeaveInterest.of(Privileged.class, ElementType.METHOD)).add(
+ WeaveInterest.of(Privilizing.class, ElementType.TYPE));
}
@Override
- public boolean weave(Class classToWeave, Class<? extends Annotation> processingAnnotation)
- {
- // Privilizer does not weave classes
- return false;
- }
-
- @Override
- public boolean weave(Method methodToWeave, Class<? extends Annotation> processingAnnotation)
- {
- try
- {
- privilizer.weaveClass(methodToWeave.getDeclaringClass());
- }
- catch (NotFoundException e)
- {
- throw new RuntimeException(e);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- catch (CannotCompileException e)
- {
- throw new RuntimeException(e);
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(e);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException(e);
+ public boolean process(ScanResult scanResult) {
+ boolean result = false;
+ for (WeavableClass<?> weavableClass : scanResult.getClasses()) {
+ try {
+ result =
+ privilizer.weaveClass(weavableClass.getTarget(), weavableClass.getAnnotation(Privilizing.class))
+ | result;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
-
- return true;
- }
-
- @Override
- public void postWeave()
- {
- // nothing to do
+ return result;
}
}
Modified: commons/sandbox/weaver/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/pom.xml?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/pom.xml (original)
+++ commons/sandbox/weaver/trunk/pom.xml Thu Feb 28 07:08:48 2013
@@ -41,10 +41,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compile.source>1.6</maven.compile.source>
<maven.compile.target>1.6</maven.compile.target>
- <commons.componentid>privilizer</commons.componentid>
+ <commons.componentid>weaver</commons.componentid>
<commons.release.version>1.0</commons.release.version>
<commons.rc.version>RC1</commons.rc.version>
- <!--commons.jira.id>PRIVILIZER</commons.jira.id>
+ <!--commons.jira.id>WEAVER</commons.jira.id>
<commons.jira.pid>666</commons.jira.pid-->
</properties>
@@ -64,27 +64,44 @@
</developers>
<scm>
- <connection>scm:svn:http://svn.apache.org/repos/asf/commons/sandbox/privilizer/trunk/</connection>
- <developerConnection>scm:svn:https://svn.apache.org/repos/asf/commons/sandbox/privilizer/trunk/</developerConnection>
- <url>http://svn.apache.org/viewvc/commons/sandbox/privilizer/trunk/</url>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/commons/sandbox/weaver/trunk/</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/commons/sandbox/weaver/trunk/</developerConnection>
+ <url>http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/</url>
</scm>
<distributionManagement>
<site>
<id>website</id>
<name>Apache Website</name>
- <url>scp://people.apache.org/www/commons.apache.org/sandbox/privilizer/</url>
+ <url>scp://people.apache.org/www/commons.apache.org/sandbox/weaver/</url>
</site>
</distributionManagement>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.10</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-weaver-processor</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-finder-shaded</artifactId>
+ <version>3.13-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
<build>
<pluginManagement>
@@ -117,7 +134,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
- <version>2.5.1</version>
+ <version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -167,11 +184,34 @@
</plugins>
</build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <linksource>true</linksource>
+ <links>
+ <link>http://docs.oracle.com/javase/6/docs/api/</link>
+ </links>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-report-plugin</artifactId>
+ <configuration>
+ <aggregate>true</aggregate>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
<modules>
<module>processor</module>
<module>modules</module>
- <module>example</module>
<module>maven-plugin</module>
+ <module>example</module>
<module>ant</module>
</modules>
</project>
Modified: commons/sandbox/weaver/trunk/processor/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/pom.xml?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/pom.xml (original)
+++ commons/sandbox/weaver/trunk/processor/pom.xml Thu Feb 28 07:08:48 2013
@@ -28,7 +28,7 @@ under the License.
<artifactId>commons-weaver-processor</artifactId>
<name>Commons Privilizer Processor</name>
<description>
- The 'Processor' is responsible for picking up all Waeavers
+ The 'Processor' is responsible for picking up all Weavers
configure them and make them perform the actual bytecode
enhancing.
</description>
@@ -37,9 +37,16 @@ under the License.
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-finder-shaded</artifactId>
- <version>3.13-SNAPSHOT</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/WeaveProcessor.java Thu Feb 28 07:08:48 2013
@@ -19,7 +19,8 @@
package org.apache.commons.weaver;
import java.io.File;
-import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URLClassLoader;
import java.util.ArrayList;
@@ -28,9 +29,12 @@ import java.util.List;
import java.util.Properties;
import java.util.ServiceLoader;
+import org.apache.commons.weaver.model.ScanResult;
+import org.apache.commons.weaver.model.WeaveInterest;
import org.apache.commons.weaver.spi.Weaver;
import org.apache.commons.weaver.utils.URLArray;
-import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.Annotated;
+import org.apache.xbean.finder.Parameter;
import org.apache.xbean.finder.archive.FileArchive;
/**
@@ -41,29 +45,31 @@ public class WeaveProcessor {
private static WeaveProcessor instance;
/**
- * The classpath which will be used to look up cross references during weaving.
+ * 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.
+ * 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>();
-
public static synchronized WeaveProcessor getInstance() {
if (instance == null) {
instance = new WeaveProcessor();
instance.init();
}
-
return instance;
}
+ private WeaveProcessor() {
+ }
+
private void init() {
ServiceLoader<Weaver> loader = ServiceLoader.load(Weaver.class);
Iterator<Weaver> it = loader.iterator();
@@ -75,10 +81,13 @@ public class WeaveProcessor {
/**
* 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.
- *
+ *
+ * @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 configure(List<String> classPath, File target, Properties config) {
this.classPath = classPath;
@@ -93,36 +102,62 @@ public class WeaveProcessor {
* perform the weaving on all specified classpath entries
*/
public void weave() {
+ final ClassLoader classLoader = new URLClassLoader(URLArray.fromPaths(classPath));
+ final Finder finder = new Finder(new FileArchive(classLoader, target));
for (Weaver weaver : weavers) {
- weaver.preWeave();
- }
-
- for (Weaver weaver : weavers) {
- weave(weaver);
- }
-
- for (Weaver weaver : weavers) {
- weaver.postWeave();
+ weave(finder, weaver);
}
}
- private void weave(Weaver weaver) {
- List<Class<? extends Annotation>> interest = weaver.getInterest();
-
- ClassLoader classLoader = new URLClassLoader(URLArray.fromPaths(classPath));
-
- AnnotationFinder annotationFinder = new AnnotationFinder(new FileArchive(classLoader, target), false);
- for (Class<? extends Annotation> annotation : interest) {
- List<Class<?>> annotatedClasses = annotationFinder.findAnnotatedClasses(annotation);
-
- for (Class<?> annotatedClass : annotatedClasses) {
- weaver.weave(annotatedClass, annotation);
- }
+ private void weave(Finder finder, Weaver weaver) {
+ final ScanResult result = new ScanResult();
- List<Method> annotateMethods = annotationFinder.findAnnotatedMethods(annotation);
- for (Method annotatedMethod : annotateMethods) {
- weaver.weave(annotatedMethod, annotation);
+ for (WeaveInterest interest : weaver.getScanRequest().getInterests()) {
+ switch (interest.target) {
+ case PACKAGE:
+ for (Annotated<Package> pkg : finder.withAnnotations().findAnnotatedPackages(interest.annotationType)) {
+ result.getWeavable(pkg.get()).addAnnotations(pkg.getAnnotation(interest.annotationType));
+ }
+ case TYPE:
+ for (Annotated<Class<?>> type : finder.withAnnotations().findAnnotatedClasses(interest.annotationType)) {
+ result.getWeavable(type.get()).addAnnotations(type.getAnnotation(interest.annotationType));
+ }
+ break;
+ case METHOD:
+ for (Annotated<Method> method : finder.withAnnotations().findAnnotatedMethods(interest.annotationType)) {
+ result.getWeavable(method.get()).addAnnotations(method.getAnnotation(interest.annotationType));
+ }
+ break;
+ case CONSTRUCTOR:
+ for (Annotated<Constructor<?>> cs : finder.withAnnotations().findAnnotatedConstructors(
+ interest.annotationType)) {
+ result.getWeavable(cs.get()).addAnnotations(cs.getAnnotation(interest.annotationType));
+ }
+ break;
+ case FIELD:
+ for (Annotated<Field> fld : finder.withAnnotations().findAnnotatedFields(interest.annotationType)) {
+ result.getWeavable(fld.get()).addAnnotations(fld.getAnnotation(interest.annotationType));
+ }
+ break;
+ case PARAMETER:
+ for (Annotated<Parameter<Method>> parameter : finder.withAnnotations().findAnnotatedMethodParameters(
+ interest.annotationType)) {
+ result.getWeavable(parameter.get().getDeclaringExecutable())
+ .getWeavableParameter(parameter.get().getIndex())
+ .addAnnotations(parameter.getAnnotation(interest.annotationType));
+ }
+ for (Annotated<Parameter<Constructor<?>>> parameter : finder.withAnnotations()
+ .findAnnotatedConstructorParameters(interest.annotationType)) {
+ result.getWeavable(parameter.get().getDeclaringExecutable())
+ .getWeavableParameter(parameter.get().getIndex())
+ .addAnnotations(parameter.getAnnotation(interest.annotationType));
+ }
+ break;
+ default:
+ // should we log something?
+ break;
}
}
+ weaver.process(result);
}
}
Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/spi/Weaver.java Thu Feb 28 07:08:48 2013
@@ -19,17 +19,16 @@
package org.apache.commons.weaver.spi;
import java.io.File;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
import java.util.List;
import java.util.Properties;
+import org.apache.commons.weaver.model.ScanRequest;
+import org.apache.commons.weaver.model.ScanResult;
+
/**
* An implementation of a 'Weaver' takes care about
* certain weaving jobs and will perform the byte code
* enhancement in the classes.
- *
- * TODO: we might enhance this SPI to gather upfront information about what needs to get scanned at all!
*/
public interface Weaver
{
@@ -44,35 +43,14 @@ public interface Weaver
void configure(List<String> classPath, File target, Properties config);
/**
- * A Weaver must return a List of Annotations he is interested in.
- */
- List<Class<? extends Annotation>> getInterest();
-
- /**
- * This will get invoked before any weaver did run
- */
- void preWeave();
-
- /**
- * Perform weaving on the given class for any class which has one of the required annotations.
- * If there is nothing to do, then just go on.
- *
- * @return <code>true</code> if some bytecode has been changed
- */
- boolean weave(Class classToWeave, Class<? extends Annotation> processingAnnotation);
-
- /**
- * Perform weaving on the given class for any class which has one of the required annotations.
- * If there is nothing to do, then just go on.
- *
- * @return <code>true</code> if some bytecode has been changed
+ * Get the scan request of this {@link Weaver}.
*/
- boolean weave(Method methodToWeave, Class<? extends Annotation> processingAnnotation);
+ ScanRequest getScanRequest();
/**
- * 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.
+ * Process the scanning results.
+ * @param scanResult
+ * @return whether any work was done.
*/
- void postWeave();
+ boolean process(ScanResult scanResult);
}
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaveProcessorTest.java Thu Feb 28 07:08:48 2013
@@ -31,8 +31,7 @@ import org.junit.Test;
/**
* Test the {@link WeaveProcessor}
*/
-public class WeaveProcessorTest extends WeaverTestBase
-{
+public class WeaveProcessorTest extends WeaverTestBase {
@Test
public void testWeaveVisiting() throws Exception {
@@ -44,20 +43,13 @@ public class WeaveProcessorTest extends
Properties config = new Properties();
config.put("configKey", "configValue");
- getTargetFolder();
-
wp.configure(getClassPathEntries(), getTargetFolder(), config);
-
- TestWeaver.postWeaveExecuted = false;
- TestWeaver.preWeaveExecuted = false;
TestWeaver.wovenClasses.clear();
TestWeaver.wovenMethods.clear();
wp.weave();
- Assert.assertTrue(TestWeaver.preWeaveExecuted);
- Assert.assertTrue(TestWeaver.postWeaveExecuted);
Assert.assertEquals(1, TestWeaver.wovenClasses.size());
Assert.assertEquals(TestBeanWithClassAnnotation.class, TestWeaver.wovenClasses.get(0));
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/WeaverTestBase.java Thu Feb 28 07:08:48 2013
@@ -48,17 +48,18 @@ public abstract class WeaverTestBase {
}
/**
- * Add a class to the temporary folder.
+ * Add a class (and its inner classes) to the temporary folder.
* @param clazz
*/
- protected void addClassForScanning(Class clazz) throws IOException{
+ protected void addClassForScanning(Class<?> clazz) throws IOException {
String clazzDirName = clazz.getPackage().getName().replace(".", "/");
File targetDirFile = new File(getTargetFolder(), clazzDirName);
targetDirFile.mkdirs();
- String clazzFileName = clazzDirName + "/" + clazz.getSimpleName() + ".class";
+ String fileName = baseName(clazz) + ".class";
+ String clazzFileName = clazzDirName + "/" + fileName;
URL clazzUrl = getClass().getClassLoader().getResource(clazzFileName);
- File targetClazzFile = new File(targetDirFile, clazz.getSimpleName() + ".class");
+ File targetClazzFile = new File(targetDirFile, fileName);
byte[] buffer = new byte[0xFFFF];
@@ -71,6 +72,26 @@ public abstract class WeaverTestBase {
}
fos.flush();
fos.close();
+
+ for (Class<?> inner : clazz.getClasses()) {
+ addClassForScanning(inner);
+ }
+ }
+
+ private String baseName(Class<?> clazz) {
+ if (clazz.getDeclaringClass() == null) {
+ return clazz.getSimpleName();
+ }
+ final StringBuilder result = new StringBuilder();
+ Class<?> current = clazz;
+ while (current != null) {
+ if (result.length() > 0) {
+ result.insert(0, '$');
+ }
+ result.insert(0, current.getSimpleName());
+ current = current.getDeclaringClass();
+ }
+ return result.toString();
}
/**
Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java?rev=1451121&r1=1451120&r2=1451121&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java (original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestWeaver.java Thu Feb 28 07:08:48 2013
@@ -19,31 +19,29 @@
package org.apache.commons.weaver.test.weaver;
import java.io.File;
-import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
-import java.util.logging.Logger;
+import org.apache.commons.weaver.model.ScanRequest;
+import org.apache.commons.weaver.model.ScanResult;
+import org.apache.commons.weaver.model.WeavableClass;
+import org.apache.commons.weaver.model.WeavableMethod;
+import org.apache.commons.weaver.model.WeaveInterest;
+import org.apache.commons.weaver.spi.Weaver;
import org.apache.commons.weaver.test.beans.TestAnnotation;
import org.junit.Assert;
-import org.apache.commons.weaver.spi.Weaver;
-
/**
*/
-public class TestWeaver implements Weaver
-{
- public static boolean preWeaveExecuted = false;
- public static boolean postWeaveExecuted = false;
+public class TestWeaver implements Weaver {
public static List<Method> wovenMethods = new ArrayList<Method>();
- public static List<Class> wovenClasses = new ArrayList<Class>();
+ public static List<Class<?>> wovenClasses = new ArrayList<Class<?>>();
@Override
- public void configure(List<String> classPath, File target, Properties config)
- {
+ public void configure(List<String> classPath, File target, Properties config) {
Assert.assertNotNull(config);
Assert.assertEquals(1, config.size());
@@ -52,34 +50,25 @@ public class TestWeaver implements Weave
}
@Override
- public List<Class<? extends Annotation>> getInterest()
- {
- List<Class<? extends Annotation>> interests = new ArrayList<Class<? extends Annotation>>();
- interests.add(TestAnnotation.class);
- return interests;
- }
-
- @Override
- public void preWeave()
- {
- preWeaveExecuted = true;
+ public ScanRequest getScanRequest() {
+ return new ScanRequest().add(WeaveInterest.of(TestAnnotation.class, ElementType.TYPE)).add(
+ WeaveInterest.of(TestAnnotation.class, ElementType.METHOD));
}
@Override
- public boolean weave(Class classToWeave, Class<? extends Annotation> processingAnnotation)
- {
- return wovenClasses.add(classToWeave);
+ public boolean process(ScanResult scanResult) {
+ boolean result = false;
+ for (WeavableClass<?> weavableClass : scanResult.getClasses().with(TestAnnotation.class)) {
+ if (wovenClasses.add(weavableClass.getTarget())) {
+ result = true;
+ }
+ }
+ for (WeavableMethod<?> weavableMethod : scanResult.getMethods().with(TestAnnotation.class)) {
+ if (wovenMethods.add(weavableMethod.getTarget())) {
+ result = true;
+ }
+ }
+ return result;
}
- @Override
- public boolean weave(Method methodToWeave, Class<? extends Annotation> processingAnnotation)
- {
- return wovenMethods.add(methodToWeave);
- }
-
- @Override
- public void postWeave()
- {
- postWeaveExecuted = true;
- }
}