001package io.ebean.enhance.ant; 002 003import io.ebean.enhance.Transformer; 004import io.ebean.enhance.common.EnhanceContext; 005 006/** 007 * A utility object to run transformation from a main method. 008 */ 009public class MainTransform { 010 011 public static void main(String[] args) { 012 013 if (isHelp(args)) { 014 printHelp(); 015 return; 016 } 017 018 String transformArgs = "debug=1"; 019 String inDir = "./target/test-classes"; 020 String pkg = "test"; 021 022 if (args.length > 0) { 023 inDir = args[0]; 024 } 025 if (args.length > 1) { 026 pkg = args[1]; 027 } 028 029 if (args.length > 2) { 030 transformArgs = args[2]; 031 } 032 033 ClassLoader cl = ClassLoader.getSystemClassLoader(); 034 035 Transformer t = new Transformer(cl, transformArgs); 036 037 OfflineFileTransform ft = new OfflineFileTransform(t, cl, inDir); 038 final EnhanceContext enhanceContext = t.getEnhanceContext(); 039 if (enhanceContext.getLogLevel() > 0) { 040 System.out.println(enhanceContext.getPackagesSummary()); 041 } 042 043 ft.process(pkg); 044 } 045 046 private static void printHelp() { 047 System.out.println("Usage: [inputDirectory] [packages] [transformArguments]"); 048 } 049 050 private static boolean isHelp(String[] args) { 051 for (String arg : args) { 052 if (arg.equalsIgnoreCase("help")) { 053 return true; 054 } 055 if (arg.equalsIgnoreCase("-h")) { 056 return true; 057 } 058 } 059 return false; 060 } 061}