commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r896272 - in /commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow: ant/AntRewriteTask.java bytecode/transformation/bcel/BcelClassTransformer.java
Date Tue, 05 Jan 2010 23:37:53 GMT
Author: tcurdt
Date: Tue Jan  5 23:37:41 2010
New Revision: 896272

URL: http://svn.apache.org/viewvc?rev=896272&view=rev
Log:
applied https://issues.apache.org/jira/browse/SANDBOX-290 (by Michael Binz)


Modified:
    commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
    commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java

Modified: commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java?rev=896272&r1=896271&r2=896272&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
(original)
+++ commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/ant/AntRewriteTask.java
Tue Jan  5 23:37:41 2010
@@ -49,7 +49,7 @@
     /**
      * Directory to which the transformed files will be written.
      * This can be the same as the source directory.
-     */    
+     */
     public void setDestdir(final File pFile) {
         dstDir = pFile;
     }
@@ -77,13 +77,13 @@
      */
     public void setMode(String name) {
         name = name.toLowerCase();
-        if(name.equals("bcel"))
-            transformer = new BcelClassTransformer();
-        else
-        if(name.equals("asm"))
+        if(name.equals("bcel")) {
+            transformer = new BcelClassTransformer(srcDir);
+        } else if(name.equals("asm")) {
             transformer = new AsmClassTransformer();
-        else
+        } else {
             throw new BuildException("Unrecognized mode: "+name);
+        }
     }
     
     /**
@@ -115,9 +115,10 @@
         final String[] fileNames = ds.getIncludedFiles();
 
         // default to BCEL, since the BCEL version is more stable
-        if(transformer==null)
-            transformer = new BcelClassTransformer();
-        
+        if(transformer == null) {
+            transformer = new BcelClassTransformer(srcDir);
+        }
+
         try {
             for (int i = 0; i < fileNames.length; i++) {
                 final String fileName = fileNames[i];

Modified: commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java?rev=896272&r1=896271&r2=896272&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
(original)
+++ commons/sandbox/javaflow/trunk/src/main/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
Tue Jan  5 23:37:41 2010
@@ -51,6 +51,8 @@
 import org.apache.bcel.generic.TABLESWITCH;
 import org.apache.bcel.generic.TargetLostException;
 import org.apache.bcel.generic.Type;
+import org.apache.bcel.util.ClassPath;
+import org.apache.bcel.util.SyntheticRepository;
 import org.apache.bcel.verifier.exc.AssertionViolatedException;
 import org.apache.commons.javaflow.bytecode.Continuable;
 import org.apache.commons.javaflow.bytecode.StackRecorder;
@@ -68,12 +70,12 @@
 import org.apache.commons.logging.LogFactory;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Vector;
 
-
 /**
  * {@link ResourceTransformer} that uses BCEL.
  *
@@ -126,6 +128,17 @@
     public BcelClassTransformer() {
     }
 
+    /**
+     * Creates an instance that uses the passed classpath for the resolution
+     * of referenced classes.
+     *
+     * @param classPathFile The classpath to use for class file resolution.
+     */
+    public BcelClassTransformer(File classPathFile) {
+        ClassPath classPath = new ClassPath( classPathFile.getAbsolutePath() );
+        this.repository = SyntheticRepository.getInstance( classPath );
+    }
+
     public BcelClassTransformer(org.apache.bcel.util.Repository repository) {
         this.repository = repository;
     }
@@ -163,7 +176,7 @@
 				is.close();
 			} catch (IOException e) {
 				e.printStackTrace();
-			}
+        }
         }
         
         if (javaClazz == null) {
@@ -229,7 +242,7 @@
         if(debug) {
             dump(newClass, ".rewritten");
         }
-        
+
         return changed;
     }
 
@@ -260,7 +273,7 @@
                 log.error(e1.getMessage(), e1);
             } finally {
                 out = null;
-            }        	
+            }
         }
 
         try {
@@ -281,7 +294,7 @@
                 log.error(e1.getMessage(), e1);
             } finally {
                 out = null;
-            }        	
+            }
         }
     }
 



Mime
View raw message