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 JavaGeneratorTask extends Task {
032    
033        int version = 2;
034        File basedir = new File(".");
035    
036        public static void main(String[] args) {
037    
038            Project project = new Project();
039            project.init();
040            JavaGeneratorTask generator = new JavaGeneratorTask();
041            generator.setProject(project);
042    
043            if (args.length > 0) {
044                generator.version = Integer.parseInt(args[0]);
045            }
046    
047            if (args.length > 1) {
048                generator.basedir = new File(args[1]);
049            }
050    
051            generator.execute();
052        }
053    
054        public void execute() throws BuildException {
055            try {
056    
057                String sourceDir = basedir + "/src/main/java";
058    
059                System.out.println("Parsing source files in: " + sourceDir);
060    
061                JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
062                JamServiceParams params = jamServiceFactory.createServiceParams();
063                File[] dirs = new File[] {
064                    new File(sourceDir)
065                };
066                params.includeSourcePattern(dirs, "**/*.java");
067                JamService jam = jamServiceFactory.createService(params);
068    
069                {
070                    JavaMarshallingGenerator script = new JavaMarshallingGenerator();
071                    script.setJam(jam);
072                    script.setTargetDir(basedir + "/src/main/java");
073                    script.setOpenwireVersion(version);
074                    script.run();
075                }
076                {
077                    JavaTestsGenerator script = new JavaTestsGenerator();
078                    script.setJam(jam);
079                    script.setTargetDir(basedir + "/src/test/java");
080                    script.setOpenwireVersion(version);
081                    script.run();
082                }
083    
084            } catch (Exception e) {
085                throw new BuildException(e);
086            }
087        }
088    
089        public int getVersion() {
090            return version;
091        }
092    
093        public void setVersion(int version) {
094            this.version = version;
095        }
096    
097        public File getBasedir() {
098            return basedir;
099        }
100    
101        public void setBasedir(File basedir) {
102            this.basedir = basedir;
103        }
104    
105    }