001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.openwire.tool; 018 019import java.io.File; 020 021import org.apache.tools.ant.BuildException; 022import org.apache.tools.ant.Project; 023import org.apache.tools.ant.Task; 024import org.codehaus.jam.JamService; 025import org.codehaus.jam.JamServiceFactory; 026import org.codehaus.jam.JamServiceParams; 027 028/** 029 * 030 */ 031public class CppGeneratorTask extends Task { 032 033 int version = 2; 034 File source = new File("."); 035 File target = new File("."); 036 037 public static void main(String[] args) { 038 039 Project project = new Project(); 040 project.init(); 041 CppGeneratorTask generator = new CppGeneratorTask(); 042 generator.setProject(project); 043 044 if (args.length > 0) { 045 generator.version = Integer.parseInt(args[0]); 046 } 047 048 if (args.length > 1) { 049 generator.source = new File(args[1]); 050 } 051 052 if (args.length > 2) { 053 generator.target = new File(args[2]); 054 } 055 056 generator.execute(); 057 } 058 059 public void execute() throws BuildException { 060 try { 061 062 String sourceDir = source + "/src/main/java"; 063 064 System.out.println("Parsing source files in: " + sourceDir); 065 066 JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance(); 067 JamServiceParams params = jamServiceFactory.createServiceParams(); 068 File[] dirs = new File[] { 069 new File(sourceDir) 070 }; 071 params.includeSourcePattern(dirs, "**/*.java"); 072 JamService jam = jamServiceFactory.createService(params); 073 074 { 075 CppClassesGenerator script = new CppClassesGenerator(); 076 script.setJam(jam); 077 script.setTargetDir(target + "/src/main/cpp"); 078 script.setOpenwireVersion(version); 079 script.run(); 080 } 081 { 082 CppHeadersGenerator script = new CppHeadersGenerator(); 083 script.setJam(jam); 084 script.setTargetDir(target + "/src/main/cpp"); 085 script.setOpenwireVersion(version); 086 script.run(); 087 } 088 { 089 CppMarshallingHeadersGenerator script = new CppMarshallingHeadersGenerator(); 090 script.setJam(jam); 091 script.setTargetDir(target + "/src"); 092 script.setOpenwireVersion(version); 093 script.run(); 094 } 095 { 096 CppMarshallingClassesGenerator script = new CppMarshallingClassesGenerator(); 097 script.setJam(jam); 098 script.setTargetDir(target + "/src"); 099 script.setOpenwireVersion(version); 100 script.run(); 101 } 102 103 } catch (Exception e) { 104 throw new BuildException(e); 105 } 106 } 107 108 public int getVersion() { 109 return version; 110 } 111 112 public void setVersion(int version) { 113 this.version = version; 114 } 115 116 public File getSource() { 117 return source; 118 } 119 120 public void setSource(File basedir) { 121 this.source = basedir; 122 } 123 124 public File getTarget() { 125 return target; 126 } 127 128 public void setTarget(File target) { 129 this.target = target; 130 } 131 132}