KickJava   Java API By Example, From Geeks To Geeks.

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


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 CGeneratorTask extends Task {
34     
35     int version = 2;
36     File JavaDoc source = new File JavaDoc(".");
37     File JavaDoc target = new File JavaDoc(".");
38     
39     public static void main(String JavaDoc[] args) {
40         
41         Project project = new Project();
42         project.init();
43         CGeneratorTask generator = new CGeneratorTask();
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 JavaDoc(args[1]);
52         }
53         
54         if( args.length > 2 ) {
55             generator.target = new File JavaDoc(args[2]);
56         }
57         
58         generator.execute();
59     }
60     
61     public void execute() throws BuildException {
62         try {
63             
64             String JavaDoc 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 JavaDoc[] dirs = new File JavaDoc[]{new File JavaDoc(sourceDir)};
71             params.includeSourcePattern(dirs, "**/*.java");
72             JamService jam = jamServiceFactory.createService(params);
73
74             {
75                 CHeadersGenerator script = new CHeadersGenerator();
76                 script.setJam(jam);
77                 script.setTargetDir(target+"/src/libopenwire");
78                 script.setOpenwireVersion(version);
79                 script.run();
80             }
81             {
82                 CSourcesGenerator script = new CSourcesGenerator();
83                 script.setJam(jam);
84                 script.setTargetDir(target+"/src/libopenwire");
85                 script.setOpenwireVersion(version);
86                 script.run();
87             }
88             
89             
90             
91         } catch (Exception JavaDoc e) {
92             throw new BuildException(e);
93         }
94     }
95
96     public int getVersion() {
97         return version;
98     }
99
100     public void setVersion(int version) {
101         this.version = version;
102     }
103
104     public File JavaDoc getSource() {
105         return source;
106     }
107
108     public void setSource(File JavaDoc basedir) {
109         this.source = basedir;
110     }
111
112     public File JavaDoc getTarget() {
113         return target;
114     }
115
116     public void setTarget(File JavaDoc target) {
117         this.target = target;
118     }
119
120 }
121
Popular Tags