KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > openwire > tool > JavaGeneratorTask


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.openwire.tool;
19
20 import java.io.File JavaDoc;
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 /**
30  *
31  * @version $Revision: 384826 $
32  */

33 public class JavaGeneratorTask extends Task {
34     
35     int version = 2;
36     File JavaDoc basedir = new File JavaDoc(".");
37     
38     public static void main(String JavaDoc[] args) {
39         
40         Project project = new Project();
41         project.init();
42         JavaGeneratorTask generator = new JavaGeneratorTask();
43         generator.setProject(project);
44         
45         if( args.length > 0 ) {
46             generator.version = Integer.parseInt(args[0]);
47         }
48
49         if( args.length > 1 ) {
50             generator.basedir = new File JavaDoc(args[1]);
51         }
52         
53         generator.execute();
54     }
55     
56     public void execute() throws BuildException {
57         try {
58             
59             String JavaDoc sourceDir = basedir+"/src/main/java";
60             
61             System.out.println("Parsing source files in: " + sourceDir);
62
63             JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
64             JamServiceParams params = jamServiceFactory.createServiceParams();
65             File JavaDoc[] dirs = new File JavaDoc[]{new File JavaDoc(sourceDir)};
66             params.includeSourcePattern(dirs, "**/*.java");
67             JamService jam = jamServiceFactory.createService(params);
68
69             {
70                 JavaMarshallingGenerator script = new JavaMarshallingGenerator();
71                 script.setJam(jam);
72                 script.setTargetDir(basedir+"/src/main/java");
73                 script.setOpenwireVersion(version);
74                 script.run();
75             }
76             {
77                 JavaTestsGenerator script = new JavaTestsGenerator();
78                 script.setJam(jam);
79                 script.setTargetDir(basedir+"/src/test/java");
80                 script.setOpenwireVersion(version);
81                 script.run();
82             }
83             
84         } catch (Exception JavaDoc e) {
85             throw new BuildException(e);
86         }
87     }
88
89     public int getVersion() {
90         return version;
91     }
92
93     public void setVersion(int version) {
94         this.version = version;
95     }
96
97     public File JavaDoc getBasedir() {
98         return basedir;
99     }
100
101     public void setBasedir(File JavaDoc basedir) {
102         this.basedir = basedir;
103     }
104
105 }
106
Popular Tags