1 package org.objectweb.proactive.ext.util; 2 3 import java.io.File ; 4 import java.io.FileOutputStream ; 5 6 import org.objectweb.proactive.core.mop.ASMBytecodeStubBuilder; 7 import org.objectweb.proactive.core.mop.BytecodeStubBuilder; 8 import org.objectweb.proactive.core.mop.MOPClassLoader; 9 10 public class StubGenerator { 11 public static void main(String [] args) { 12 String fileName = null; 14 15 if (args.length <= 0) { 17 printUsageAndExit(); 18 } 19 20 String className = args[0]; 22 String stubClassName; 23 24 try { 25 27 byte[] data; 29 if (MOPClassLoader.BYTE_CODE_MANIPULATOR.equals("ASM")) { 30 ASMBytecodeStubBuilder bsb = new ASMBytecodeStubBuilder(className); 31 data = bsb.create(); 32 stubClassName = bsb.getStubClassFullName(); 33 } else if (MOPClassLoader.BYTE_CODE_MANIPULATOR.equals("BCEL")) { 34 BytecodeStubBuilder bsb = new BytecodeStubBuilder(className); 35 data = bsb.create(); 36 stubClassName = bsb.getStubClassFullName(); 37 } else { 38 System.err.println( 40 "byteCodeManipulator argument is optionnal. If specified, it can only be set to BCEL."); 41 System.err.println( 42 "Any other setting will result in the use of ASM, the default bytecode manipulator framework"); 43 stubClassName = null; 44 data = null; 45 } 46 String directoryName; 48 if (args.length == 2) { 49 directoryName = args[1]; 50 } else { 51 directoryName = "."; 52 } 53 if (!directoryName.endsWith(System.getProperty("file.separator"))) { 55 directoryName = directoryName + System.getProperty("file.separator"); 56 } 57 char sep = System.getProperty("file.separator").toCharArray()[0]; 58 fileName = directoryName + stubClassName.replace('.', sep) + ".class"; 59 60 new File (fileName.substring(0, fileName.lastIndexOf(sep))).mkdirs(); 62 File f = new File (fileName); 64 FileOutputStream fos = new FileOutputStream (f); 65 fos.write(data); 66 fos.flush(); 67 fos.close(); 68 System.out.println("Wrote file " + fileName); 69 } catch (ClassNotFoundException e) { 70 System.err.println("Cannot find class " + className); 71 } catch (Exception e) { 72 System.err.println("Cannot write file " + fileName); 73 System.err.println("Reason is " + e); 74 } 75 } 76 77 public static void printUsageAndExit() { 78 System.out.println( 79 "usage: pac <fully-qualified name of the class> [directory where to output stub .class file]"); 80 System.exit(0); 81 } 82 83 } 84 | Popular Tags |