commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1513000 - in /commons/sandbox/weaver/trunk: modules/normalizer/weaver/src/main/java/org/apache/commons/weaver/normalizer/ modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ processor/src/main/java/org/apache/comm...
Date Sun, 11 Aug 2013 20:34:54 GMT
Author: mbenson
Date: Sun Aug 11 20:34:53 2013
New Revision: 1513000

URL: http://svn.apache.org/r1513000
Log:
define an API for working with classfile and potentially other resources in the WeaveEnvironment,
which is now an abstract class, and depend on it everywhere.  This should insulate weaver
implementations from the environment in which they are invoked

Added:
    commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java
  (with props)
Modified:
    commons/sandbox/weaver/trunk/modules/normalizer/weaver/src/main/java/org/apache/commons/weaver/normalizer/Normalizer.java
    commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.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/PrivilizerCleaner.java
    commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/CleanProcessor.java
    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/model/WeaveEnvironment.java
    commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestCleaner.java

Modified: commons/sandbox/weaver/trunk/modules/normalizer/weaver/src/main/java/org/apache/commons/weaver/normalizer/Normalizer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/normalizer/weaver/src/main/java/org/apache/commons/weaver/normalizer/Normalizer.java?rev=1513000&r1=1512999&r2=1513000&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/normalizer/weaver/src/main/java/org/apache/commons/weaver/normalizer/Normalizer.java
(original)
+++ commons/sandbox/weaver/trunk/modules/normalizer/weaver/src/main/java/org/apache/commons/weaver/normalizer/Normalizer.java
Sun Aug 11 20:34:53 2013
@@ -16,9 +16,9 @@
  */
 package org.apache.commons.weaver.normalizer;
 
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Target;
 import java.nio.charset.Charset;
@@ -30,7 +30,8 @@ import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.io.FileUtils;
+import javax.activation.DataSource;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.CharEncoding;
@@ -43,7 +44,6 @@ import org.apache.commons.weaver.model.S
 import org.apache.commons.weaver.model.Scanner;
 import org.apache.commons.weaver.model.WeavableClass;
 import org.apache.commons.weaver.model.WeaveEnvironment;
-import org.apache.xbean.finder.archive.FileArchive;
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
@@ -96,12 +96,16 @@ public class Normalizer {
             super.visitEnd();
             final byte[] bytecode = ((ClassWriter) cv).toByteArray();
 
-            final File f = new File(fileArchive.getDir(), className.replace('.', File.separatorChar)
+ ".class");
-            env.debug("Writing class %s to %s", className, f);
+            final DataSource classfile = env.getClassfile(className);
+            env.debug("Writing class %s to %s", className, classfile.getName());
+            OutputStream outputStream = null;
             try {
-                FileUtils.writeByteArrayToFile(f, bytecode);
+                outputStream = classfile.getOutputStream();
+                IOUtils.write(bytecode, outputStream);
             } catch (IOException e) {
                 throw new RuntimeException(e);
+            } finally {
+                IOUtils.closeQuietly(outputStream);
             }
         }
     }
@@ -126,14 +130,12 @@ public class Normalizer {
     private static final Charset UTF8 = Charset.forName(CharEncoding.UTF_8);
 
     private final WeaveEnvironment env;
-    private final FileArchive fileArchive;
 
     private final Set<Class<?>> normalizeTypes;
     private final String targetPackage;
 
     public Normalizer(WeaveEnvironment env) {
         this.env = env;
-        fileArchive = new FileArchive(env.classLoader, env.target);
 
         this.targetPackage =
             Utils.validatePackageName(Validate.notBlank(env.config.getProperty(CONFIG_TARGET_PACKAGE),
@@ -189,8 +191,9 @@ public class Normalizer {
             }
             final Remapper remapper = new SimpleRemapper(classMap);
 
-            final InputStream enclosingBytecode = fileArchive.getBytecode(outer);
+            InputStream enclosingBytecode = null;
             try {
+                enclosingBytecode = env.getClassfile(outer).getInputStream();
                 final ClassReader reader = new ClassReader(enclosingBytecode);
 
                 final ClassVisitor cv = new RemappingClassAdapter(new WriteClass(reader),
remapper) {
@@ -229,14 +232,10 @@ public class Normalizer {
                 IOUtils.closeQuietly(enclosingBytecode);
             }
             for (String merged : e.getValue().keySet()) {
-                final File classfile = new File(env.target, merged + ".class");
-                if (!classfile.exists()) {
-                    env.error("Cannot find classfile for type %s; expected at %s", merged,
classfile);
-                }
-                if (classfile.delete()) {
-                    env.debug("Deleted classfile %s", classfile);
+                if (env.deleteClassfile(merged)) {
+                    env.debug("Deleted class %s", merged);
                 } else {
-                    env.warn("Unable to delete classfile %s", classfile);
+                    env.warn("Unable to delete class %s", merged);
                 }
             }
         }
@@ -307,9 +306,10 @@ public class Normalizer {
             final MutablePair<String, String> key = new MutablePair<String, String>();
             final MutableBoolean valid = new MutableBoolean(true);
             final MutableBoolean mustRewriteConstructor = new MutableBoolean();
-            final InputStream bytecode = fileArchive.getBytecode(subtype.getName());
+            InputStream bytecode = null;
 
             try {
+                bytecode = env.getClassfile(subtype).getInputStream();
                 new ClassReader(bytecode).accept(new ClassVisitor(Opcodes.ASM4) {
                     String superName;
 
@@ -406,12 +406,12 @@ public class Normalizer {
 
         final String result = new StringBuilder(targetPackage).append("/$normalized").append(digest).toString();
 
-        final String className = classWrapper.wrapped.getName();
-        env.debug("Copying class %s to %s", className, result);
+        env.debug("Copying class %s to %s", classWrapper.wrapped.getName(), result);
 
-        final InputStream bytecode = fileArchive.getBytecode(className);
+        InputStream bytecode = null;
 
         try {
+            bytecode = env.getClassfile(classWrapper.wrapped).getInputStream();
             final ClassReader reader = new ClassReader(bytecode);
 
             final ClassVisitor w = new WriteClass();

Modified: commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java?rev=1513000&r1=1512999&r2=1513000&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java
(original)
+++ commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java
Sun Aug 11 20:34:53 2013
@@ -111,7 +111,7 @@ class BlueprintingVisitor extends Privil
         final ClassNode result = new ClassNode(Opcodes.ASM4);
         InputStream bytecode = null;
         try {
-            bytecode = privilizer().fileArchive.getBytecode(className);
+            bytecode = privilizer().env.getClassfile(className).getInputStream();
             new ClassReader(bytecode).accept(result, ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES);
         } catch (Exception e) {
             throw new RuntimeException(e);
@@ -204,7 +204,7 @@ class BlueprintingVisitor extends Privil
                     stk.push(next.getValue());
                     InputStream bytecode = null;
                     try {
-                        bytecode = privilizer().fileArchive.getBytecode(next.getValue().getInternalName());
+                        bytecode = privilizer().env.getClassfile(next.getValue().getInternalName()).getInputStream();
                         new ClassReader(bytecode).accept(privilizer().new PrivilizerClassVisitor()
{
                             @Override
                             public void visit(int version, int access, String name, String
signature, String superName,

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=1513000&r1=1512999&r2=1513000&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
Sun Aug 11 20:34:53 2013
@@ -21,18 +21,19 @@ package org.apache.commons.weaver.privil
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.commons.io.FileUtils;
+import javax.activation.DataSource;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.Validate;
 import org.apache.commons.weaver.model.WeaveEnvironment;
-import org.apache.xbean.finder.archive.FileArchive;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
@@ -80,12 +81,17 @@ public class Privilizer {
                 verify(className, bytecode);
             }
 
-            final File f = new File(fileArchive.getDir(), className.replace('.', File.separatorChar)
+ ".class");
-            env.debug("Writing class %s to %s", className, f);
+            final String resourceName = className.replace('.', File.separatorChar) + ".class";
+            final DataSource classfile = env.getResource(resourceName);
+            env.debug("Writing class %s to resource %s", className, resourceName);
+            OutputStream outputStream = null;
             try {
-                FileUtils.writeByteArrayToFile(f, bytecode);
+                outputStream = classfile.getOutputStream();
+                IOUtils.write(bytecode, outputStream);
             } catch (IOException e) {
                 throw new RuntimeException(e);
+            } finally {
+                IOUtils.closeQuietly(outputStream);
             }
         }
     }
@@ -104,7 +110,6 @@ public class Privilizer {
 
     final WeaveEnvironment env;
     final AccessLevel accessLevel;
-    final FileArchive fileArchive;
     final Policy policy;
     final boolean verify;
 
@@ -113,7 +118,6 @@ public class Privilizer {
         this.env = env;
         this.policy = Policy.parse(env.config.getProperty(CONFIG_POLICY));
         this.accessLevel = AccessLevel.parse(env.config.getProperty(CONFIG_ACCESS_LEVEL));
-        fileArchive = new FileArchive(env.classLoader, env.target);
         verify = BooleanUtils.toBoolean(env.config.getProperty(CONFIG_VERIFY));
     }
 
@@ -151,7 +155,7 @@ public class Privilizer {
         env.debug("blueprinting class %s %s", args);
         InputStream bytecode = null;
         try {
-            bytecode = fileArchive.getBytecode(type.getName());
+            bytecode = env.getClassfile(type).getInputStream();
             final ClassReader classReader = new ClassReader(bytecode);
 
             ClassVisitor cv;
@@ -172,7 +176,7 @@ public class Privilizer {
         env.debug("privilizing class %s", args);
         InputStream bytecode = null;
         try {
-            bytecode = fileArchive.getBytecode(type.getName());
+            bytecode = env.getClassfile(type).getInputStream();
             final ClassReader classReader = new ClassReader(bytecode);
             ClassVisitor cv;
             cv = new WriteClass(new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES |
ClassWriter.COMPUTE_MAXS));

Modified: commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerCleaner.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerCleaner.java?rev=1513000&r1=1512999&r2=1513000&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerCleaner.java
(original)
+++ commons/sandbox/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/PrivilizerCleaner.java
Sun Aug 11 20:34:53 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.commons.weaver.privilizer;
 
-import java.io.File;
 import java.io.InputStream;
 import java.lang.annotation.ElementType;
 import java.util.ArrayList;
@@ -59,7 +58,7 @@ public class PrivilizerCleaner implement
 
             InputStream bytecode = null;
             try {
-                bytecode = privilizer.fileArchive.getBytecode(className);
+                bytecode = privilizer.env.getClassfile(className).getInputStream();
                 final ClassReader classReader = new ClassReader(bytecode);
                 classReader.accept(new ClassVisitor(Opcodes.ASM4) {
                     @Override
@@ -83,9 +82,9 @@ public class PrivilizerCleaner implement
         }
         boolean result = false;
         for (String className : toDelete) {
-            final File classfile = new File(environment.target, toResourcePath(className));
-            final boolean success = classfile.delete();
-            environment.debug("Deletion of %s was %ssuccessful.", classfile, success ? ""
: "un");
+            final String resourcePath = toResourcePath(className);
+            final boolean success = environment.deleteResource(resourcePath);
+            environment.debug("Deletion of resource %s was %ssuccessful.", resourcePath,
success ? "" : "un");
             result |= success;
         }
         return result;

Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/CleanProcessor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/CleanProcessor.java?rev=1513000&r1=1512999&r2=1513000&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/CleanProcessor.java
(original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/CleanProcessor.java
Sun Aug 11 20:34:53 2013
@@ -74,6 +74,7 @@ public class CleanProcessor {
         super();
         this.classpath = Validate.notNull(classpath, "classpath");
         this.target = Validate.notNull(target, "target");
+        Validate.isTrue(target.isDirectory(), "%s is not a directory", target);
         this.configuration = Validate.notNull(configuration, "configuration");
     }
 
@@ -85,7 +86,7 @@ public class CleanProcessor {
         final Finder finder = new Finder(new FileArchive(classLoader, target));
         for (Cleaner cleaner : CLEANERS) {
             final WeaveEnvironment env =
-                new WeaveEnvironment(target, classLoader, configuration, Logger.getLogger(cleaner.getClass().getName()));
+                new LocalWeaveEnvironment(target, classLoader, configuration, Logger.getLogger(cleaner.getClass().getName()));
             cleaner.clean(env, finder);
         }
     }

Added: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java?rev=1513000&view=auto
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java
(added)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java
Sun Aug 11 20:34:53 2013
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Properties;
+import java.util.logging.Logger;
+
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.weaver.model.WeaveEnvironment;
+
+class LocalWeaveEnvironment extends WeaveEnvironment {
+
+    private final File target;
+
+    protected LocalWeaveEnvironment(File target, ClassLoader classLoader, Properties config,
Logger log) {
+        super(classLoader, config, log);
+        Validate.notNull(target, "target");
+        this.target = target;
+    }
+
+    @Override
+    public boolean deleteResource(String name) {
+        return new File(target, name).delete();
+    }
+
+    @Override
+    protected OutputStream getOutputStream(String resourceName) throws IOException {
+        final File file = new File(target, resourceName);
+        final File parent = file.getParentFile();
+        if (!parent.exists()) {
+            Validate.validState(parent.mkdirs(), "Unable to create output directory %s",
parent);
+        } else {
+            Validate.validState(parent.isDirectory(), "Cannot write %s to non-directory parent",
file);
+        }
+        return new FileOutputStream(file);
+    }
+}

Propchange: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/LocalWeaveEnvironment.java
------------------------------------------------------------------------------
    svn:executable = *

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=1513000&r1=1512999&r2=1513000&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
Sun Aug 11 20:34:53 2013
@@ -75,6 +75,7 @@ public class WeaveProcessor {
         super();
         this.classpath = Validate.notNull(classpath, "classpath");
         this.target = Validate.notNull(target, "target");
+        Validate.isTrue(target.isDirectory(), "%s is not a directory", target);
         this.configuration = Validate.notNull(configuration, "configuration");
     }
 
@@ -86,7 +87,7 @@ public class WeaveProcessor {
         final Finder finder = new Finder(new FileArchive(classLoader, target));
         for (Weaver weaver : WEAVERS) {
             final WeaveEnvironment env =
-                new WeaveEnvironment(target, classLoader, configuration, Logger.getLogger(weaver.getClass().getName()));
+                new LocalWeaveEnvironment(target, classLoader, configuration, Logger.getLogger(weaver.getClass().getName()));
             weaver.process(env, finder);
         }
     }

Modified: commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/WeaveEnvironment.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/WeaveEnvironment.java?rev=1513000&r1=1512999&r2=1513000&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/WeaveEnvironment.java
(original)
+++ commons/sandbox/weaver/trunk/processor/src/main/java/org/apache/commons/weaver/model/WeaveEnvironment.java
Sun Aug 11 20:34:53 2013
@@ -18,10 +18,14 @@
  */
 package org.apache.commons.weaver.model;
 
-import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Properties;
 import java.util.logging.Logger;
 
+import javax.activation.DataSource;
+
 import org.apache.commons.lang3.Validate;
 import org.apache.commons.weaver.spi.Cleaner;
 import org.apache.commons.weaver.spi.Weaver;
@@ -29,13 +33,38 @@ import org.apache.commons.weaver.spi.Wea
 /**
  * Encapsulates the environment in which a {@link Weaver} or {@link Cleaner} must operate.
  */
-public class WeaveEnvironment {
+public abstract class WeaveEnvironment {
+    private static final String CONTENT_TYPE = "application/octet-stream";
+
+    private class Resource implements DataSource {
+        private final String name;
+
+        Resource(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public String getContentType() {
+            return CONTENT_TYPE;
+        }
+
+        @Override
+        public InputStream getInputStream() throws IOException {
+            return classLoader.getResourceAsStream(name);
+        }
+
+        @Override
+        public String getName() {
+            return name;
+        }
+
+        @Override
+        public OutputStream getOutputStream() throws IOException {
+            return WeaveEnvironment.this.getOutputStream(name);
+        }
+
+    }
 
-    /**
-     * Target where weavable classes reside.
-     */
-    public final File target;
-    
     /**
      * ClassLoader containing scannable and weavable classes.
      */
@@ -46,19 +75,18 @@ public class WeaveEnvironment {
      * "privilizer".
      */
     public final Properties config;
-    
+
     private final Logger log;
 
     /**
      * Create a new {@link WeaveEnvironment}.
-     * @param target
+     * 
      * @param classLoader
      * @param config
      * @param log
      */
-    public WeaveEnvironment(File target, ClassLoader classLoader, Properties config, Logger
log) {
+    protected WeaveEnvironment(ClassLoader classLoader, Properties config, Logger log) {
         super();
-        this.target = Validate.notNull(target, "target");
         this.classLoader = classLoader;
         this.config = (Properties) Validate.notNull(config, "config").clone();
         this.log = log;
@@ -84,4 +112,31 @@ public class WeaveEnvironment {
         log.severe(String.format(message, args));
     }
 
+    public final DataSource getClassfile(Class<?> cls) {
+        return getClassfile(cls.getName());
+    }
+
+    public final DataSource getClassfile(String classname) {
+        return getResource(getResourceName(classname));
+    }
+
+    public final DataSource getResource(String name) {
+        return new Resource(name);
+    }
+
+    public final boolean deleteClassfile(Class<?> cls) {
+        return deleteClassfile(cls.getName());
+    }
+
+    public final boolean deleteClassfile(String classname) {
+        return deleteResource(getResourceName(classname));
+    }
+
+    public abstract boolean deleteResource(String name);
+
+    protected abstract OutputStream getOutputStream(String resourceName) throws IOException;
+
+    protected static String getResourceName(String classname) {
+        return classname.replace('.', '/') + ".class";
+    }
 }

Modified: commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestCleaner.java
URL: http://svn.apache.org/viewvc/commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestCleaner.java?rev=1513000&r1=1512999&r2=1513000&view=diff
==============================================================================
--- commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestCleaner.java
(original)
+++ commons/sandbox/weaver/trunk/processor/src/test/java/org/apache/commons/weaver/test/weaver/TestCleaner.java
Sun Aug 11 20:34:53 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.commons.weaver.test.weaver;
 
-import java.io.File;
 import java.lang.annotation.ElementType;
 
 import org.apache.commons.weaver.model.ScanRequest;
@@ -29,8 +28,6 @@ import org.apache.commons.weaver.model.W
 import org.apache.commons.weaver.spi.Cleaner;
 import org.apache.commons.weaver.test.beans.TestAnnotation;
 
-/**
- */
 public class TestCleaner implements Cleaner {
 
     @Override
@@ -42,11 +39,7 @@ public class TestCleaner implements Clea
                 WeaveInterest.of(TestAnnotation.class, ElementType.METHOD));
 
         for (WeavableClass<?> weavableClass : scanner.scan(scanRequest).getClasses())
{
-
-            final File classFile =
-                new File(environment.target, weavableClass.getTarget().getName().replace('.',
File.separatorChar)
-                    + ".class");
-            if (classFile.delete()) {
+            if (environment.deleteClassfile(weavableClass.getTarget())) {
                 result = true;
             } else {
                 break;



Mime
View raw message