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 */
017 package org.apache.activemq.openwire.tool;
018
019 import java.io.File;
020
021 import org.apache.tools.ant.BuildException;
022 import org.apache.tools.ant.Project;
023 import org.apache.tools.ant.Task;
024 import org.codehaus.jam.JamService;
025 import org.codehaus.jam.JamServiceFactory;
026 import org.codehaus.jam.JamServiceParams;
027
028 /**
029 * @version $Revision: 384826 $
030 */
031 public class CGeneratorTask 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 CGeneratorTask generator = new CGeneratorTask();
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 CHeadersGenerator script = new CHeadersGenerator();
076 script.setJam(jam);
077 script.setTargetDir(target + "/src/libopenwire");
078 script.setOpenwireVersion(version);
079 script.run();
080 }
081 {
082 CSourcesGenerator script = new CSourcesGenerator();
083 script.setJam(jam);
084 script.setTargetDir(target + "/src/libopenwire");
085 script.setOpenwireVersion(version);
086 script.run();
087 }
088
089 } catch (Exception e) {
090 throw new BuildException(e);
091 }
092 }
093
094 public int getVersion() {
095 return version;
096 }
097
098 public void setVersion(int version) {
099 this.version = version;
100 }
101
102 public File getSource() {
103 return source;
104 }
105
106 public void setSource(File basedir) {
107 this.source = basedir;
108 }
109
110 public File getTarget() {
111 return target;
112 }
113
114 public void setTarget(File target) {
115 this.target = target;
116 }
117
118 }