Commits

Don Brown committed 7a4e0fb

Make autoinit configurable

  • Participants
  • Parent commits 7a5a26c

Comments (0)

Files changed (4)

levee-instrumentor/src/main/java/com/atlassian/levee/instrumentor/Instrumentor.java

             is = new FileInputStream(file);
             out = new FileOutputStream(new File(args[1]));
             byte[] bytes = IOUtils.toByteArray(is);
-            IOUtils.write(instrument(bytes), out);
+            IOUtils.write(instrument(bytes, true), out);
 
         }
         catch (Exception e)
         }
     }
 
-    public static byte[] instrument(byte[] classfileBuffer)
+    public static byte[] instrument(byte[] classfileBuffer, boolean autoInit)
     {
         ClassReader cr = new ClassReader(classfileBuffer);
         ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
-        LeveeClassAdapter lca = new LeveeClassAdapter(cw);
+        LeveeClassAdapter lca = new LeveeClassAdapter(cw, autoInit);
         cr.accept(lca, 0);
         return cw.toByteArray();
     }

levee-instrumentor/src/main/java/com/atlassian/levee/instrumentor/LeveeClassAdapter.java

 
 public class LeveeClassAdapter extends ClassAdapter
 {
+    private final boolean autoInit;
+
     /**
      * Constructs a new {@link org.objectweb.asm.ClassAdapter} object.
      *
      * @param cv the class visitor to which this adapter must delegate calls.
      */
-    public LeveeClassAdapter(ClassVisitor cv)
+    public LeveeClassAdapter(ClassVisitor cv, boolean autoInit)
     {
         super(cv);
+        this.autoInit = autoInit;
     }
 
     @Override
     public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
         MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
         if (mv != null) {
-            mv = new LeveeMethodAdapter(mv, name);
+            mv = new LeveeMethodAdapter(mv, name, autoInit);
         }
         return mv;
     }

levee-instrumentor/src/main/java/com/atlassian/levee/instrumentor/LeveeMethodAdapter.java

     boolean isEntryPoint = true;
     String name;
 
-    public LeveeMethodAdapter(MethodVisitor methodVisitor, String name)
+    public LeveeMethodAdapter(MethodVisitor methodVisitor, String name, boolean autoInit)
     {
         super(methodVisitor);
         this.name = name;
         // TODO : abstract this instead of hardcoding everything to be an entry point
-        this.isEntryPoint = !name.equals("<init>");
+        this.isEntryPoint = autoInit && !name.equals("<init>");
     }
 
     public void visitCode() {

levee-instrumentor/src/test/java/com/atlassian/levee/test/SandboxedRunner.java

         final String newName = oldName + "$junitInst";
         final byte[] instrumentedClass = renameClass(oldName.replace('.','/'),
                                                      newName.replace('.','/'),
-                                                     instrument(bytesForClass(clazz)));
+                                                     instrument(bytesForClass(clazz), true));
 
         Class<?> instrumented = loadClass(newName, instrumentedClass);
         this.runner = new BlockJUnit4ClassRunner(instrumented);