Author: mbenson Date: Thu Apr 25 15:10:40 2013 New Revision: 1475818 URL: http://svn.apache.org/r1475818 Log: more ordering, refactor modifiedClassWriter
Modified: 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 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=1475818&r1=1475817&r2=1475818&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 Apr 25 15:10:40 2013 @@ -50,28 +50,23 @@ public class FilesystemPrivilizer extend return target; } - private final File target; - - private final ModifiedClassWriter modifiedClassWriter = new ModifiedClassWriter() { - @Override - public void write(CtClass type) throws CannotCompileException, IOException { - type.writeFile(target.getAbsolutePath()); - } - }; - - public FilesystemPrivilizer(ClassLoader classpath, File target) { - super(createClassPool(classpath, target)); - this.target = target; - } - - public FilesystemPrivilizer(Policy policy, ClassLoader classpath, File target) { - super(policy, createClassPool(classpath, target)); - this.target = target; + public FilesystemPrivilizer(final ClassLoader classpath, final File target) { + super(createClassPool(classpath, target), new ModifiedClassWriter() { + + @Override + public void write(CtClass type) throws CannotCompileException, IOException { + type.writeFile(target.getAbsolutePath()); + } + }); } - @Override - protected ModifiedClassWriter getModifiedClassWriter() { - return modifiedClassWriter; + public FilesystemPrivilizer(final Policy policy, final ClassLoader classpath, final File target) { + super(createClassPool(classpath, target), new ModifiedClassWriter() { + @Override + public void write(CtClass type) throws CannotCompileException, IOException { + type.writeFile(target.getAbsolutePath()); + } + }, policy); } } 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=1475818&r1=1475817&r2=1475818&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 Apr 25 15:10:40 2013 @@ -159,21 +159,32 @@ public abstract class Privilizer { return result; } - protected final Policy policy; - - protected final ClassPool classPool; + private static String importedMethodName(CtMethod blueprint) { + return new StringBuilder(blueprint.getDeclaringClass().getName().replace('.', '_')).append('$') + .append(blueprint.getName()).toString(); + } - private boolean settingsReported; + private static CodeConverter redirect(CtMethod origMethod, CtMethod substMethod) throws CannotCompileException { + final CodeConverter result = new CodeConverter(); + result.redirectMethodCall(origMethod, substMethod); + return result; + } + private final Policy policy; + private final ClassPool classPool; + private final ModifiedClassWriter modifiedClassWriter; private final Assistant assistant; - public Privilizer(ClassPool classPool) { - this(Policy.DYNAMIC, classPool); + private boolean settingsReported; + + public Privilizer(ClassPool classPool, ModifiedClassWriter modifiedClassWriter) { + this(classPool, modifiedClassWriter, Policy.DYNAMIC); } - public Privilizer(Policy policy, ClassPool classPool) { + public Privilizer(ClassPool classPool, ModifiedClassWriter modifiedClassWriter, Policy policy) { this.policy = Validate.notNull(policy, "policy"); this.classPool = Validate.notNull(classPool, "classPool"); + this.modifiedClassWriter = Validate.notNull(modifiedClassWriter, "modifiedClassWriter"); this.assistant = new Assistant(classPool, "__privilizer_"); } @@ -239,7 +250,7 @@ public abstract class Privilizer { } if (result) { type.setAttribute(policyName, policy.name().getBytes(Charset.forName("UTF-8"))); - getModifiedClassWriter().write(type); + modifiedClassWriter.write(type); } } log.info(String.format(result ? "Wove class %s" : "Nothing to do for class %s", type.getName())); @@ -325,11 +336,6 @@ public abstract class Privilizer { return result.booleanValue(); } - private static String importedMethodName(CtMethod blueprint) { - return new StringBuilder(blueprint.getDeclaringClass().getName().replace('.', '_')).append('$') - .append(blueprint.getName()).toString(); - } - /* * This design is almost certainly suboptimal. Basically, we have: * @@ -451,12 +457,6 @@ public abstract class Privilizer { return result; } - private static CodeConverter redirect(CtMethod origMethod, CtMethod substMethod) throws CannotCompileException { - final CodeConverter result = new CodeConverter(); - result.redirectMethodCall(origMethod, substMethod); - return result; - } - private void handleReferencedFields(final CtClass target, final CtMethod method, final CtMethod source, final List<CtField> referencedFields) throws CannotCompileException, NotFoundException { @@ -556,8 +556,6 @@ public abstract class Privilizer { log.warning(String.format(message, args)); } - protected abstract ModifiedClassWriter getModifiedClassWriter(); - protected void info(String message, Object... args) { log.info(String.format(message, args)); } @@ -644,7 +642,7 @@ public abstract class Privilizer { result.addMethod(CtNewMethod.make(run.append(body.complete()).toString(), result)); } - getModifiedClassWriter().write(result); + modifiedClassWriter.write(result); debug("Returning action type %s", result); return result; }