1 18 package org.apache.activemq.openwire.tool; 19 20 import java.io.File ; 21 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.Task; 25 import org.codehaus.jam.JamService; 26 import org.codehaus.jam.JamServiceFactory; 27 import org.codehaus.jam.JamServiceParams; 28 29 33 public class CppGeneratorTask extends Task { 34 35 int version = 2; 36 File source = new File ("."); 37 File target = new File ("."); 38 39 public static void main(String [] args) { 40 41 Project project = new Project(); 42 project.init(); 43 CppGeneratorTask generator = new CppGeneratorTask(); 44 generator.setProject(project); 45 46 if( args.length > 0 ) { 47 generator.version = Integer.parseInt(args[0]); 48 } 49 50 if( args.length > 1 ) { 51 generator.source = new File (args[1]); 52 } 53 54 if( args.length > 2 ) { 55 generator.target = new File (args[2]); 56 } 57 58 generator.execute(); 59 } 60 61 public void execute() throws BuildException { 62 try { 63 64 String sourceDir = source+"/src/main/java"; 65 66 System.out.println("Parsing source files in: " + sourceDir); 67 68 JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance(); 69 JamServiceParams params = jamServiceFactory.createServiceParams(); 70 File [] dirs = new File []{new File (sourceDir)}; 71 params.includeSourcePattern(dirs, "**/*.java"); 72 JamService jam = jamServiceFactory.createService(params); 73 74 { 75 CppClassesGenerator script = new CppClassesGenerator(); 76 script.setJam(jam); 77 script.setTargetDir(target+"/src/main/cpp"); 78 script.setOpenwireVersion(version); 79 script.run(); 80 } 81 { 82 CppHeadersGenerator script = new CppHeadersGenerator(); 83 script.setJam(jam); 84 script.setTargetDir(target+"/src/main/cpp"); 85 script.setOpenwireVersion(version); 86 script.run(); 87 } 88 { 89 CppMarshallingHeadersGenerator script = new CppMarshallingHeadersGenerator(); 90 script.setJam(jam); 91 script.setTargetDir(target+"/src"); 92 script.setOpenwireVersion(version); 93 script.run(); 94 } 95 { 96 CppMarshallingClassesGenerator script = new CppMarshallingClassesGenerator(); 97 script.setJam(jam); 98 script.setTargetDir(target+"/src"); 99 script.setOpenwireVersion(version); 100 script.run(); 101 } 102 103 104 } catch (Exception e) { 105 throw new BuildException(e); 106 } 107 } 108 109 public int getVersion() { 110 return version; 111 } 112 113 public void setVersion(int version) { 114 this.version = version; 115 } 116 117 public File getSource() { 118 return source; 119 } 120 121 public void setSource(File basedir) { 122 this.source = basedir; 123 } 124 125 public File getTarget() { 126 return target; 127 } 128 129 public void setTarget(File target) { 130 this.target = target; 131 } 132 133 } 134 | Popular Tags |