KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > ccm > CCMCreateTask


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

18
19 package org.apache.tools.ant.taskdefs.optional.ccm;
20
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.io.OutputStream JavaDoc;
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.Project;
29 import org.apache.tools.ant.taskdefs.Execute;
30 import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
31 import org.apache.tools.ant.types.Commandline;
32
33
34 /**
35  * Creates new Continuus ccm task and sets it as the default.
36  *
37  * @ant.task name="ccmcreatetask" category="scm"
38  */

39 public class CCMCreateTask extends Continuus implements ExecuteStreamHandler {
40
41     private String JavaDoc comment = null;
42     private String JavaDoc platform = null;
43     private String JavaDoc resolver = null;
44     private String JavaDoc release = null;
45     private String JavaDoc subSystem = null;
46     private String JavaDoc task = null;
47
48     /**
49      * Constructor for CCMCreateTask.
50      */

51     public CCMCreateTask() {
52         super();
53         setCcmAction(COMMAND_CREATE_TASK);
54     }
55
56
57     /**
58      * Executes the task.
59      * <p>
60      * Builds a command line to execute ccm and then calls Exec's run method
61      * to execute the command line.
62      * </p>
63      * @throws BuildException on error
64      */

65     public void execute() throws BuildException {
66         Commandline commandLine = new Commandline();
67         int result = 0;
68
69         // build the command line from what we got the format
70
// as specified in the CCM.EXE help
71
commandLine.setExecutable(getCcmCommand());
72         commandLine.createArgument().setValue(getCcmAction());
73
74         checkOptions(commandLine);
75
76         result = run(commandLine, this);
77         if (Execute.isFailure(result)) {
78             String JavaDoc msg = "Failed executing: " + commandLine.toString();
79             throw new BuildException(msg, getLocation());
80         }
81
82         //create task ok, set this task as the default one
83
Commandline commandLine2 = new Commandline();
84         commandLine2.setExecutable(getCcmCommand());
85         commandLine2.createArgument().setValue(COMMAND_DEFAULT_TASK);
86         commandLine2.createArgument().setValue(getTask());
87
88         log(commandLine.describeCommand(), Project.MSG_DEBUG);
89
90         result = run(commandLine2);
91         if (result != 0) {
92             String JavaDoc msg = "Failed executing: " + commandLine2.toString();
93             throw new BuildException(msg, getLocation());
94         }
95
96     }
97
98
99     /**
100      * Check the command line options.
101      */

102     private void checkOptions(Commandline cmd) {
103         if (getComment() != null) {
104             cmd.createArgument().setValue(FLAG_COMMENT);
105             cmd.createArgument().setValue("\"" + getComment() + "\"");
106         }
107
108         if (getPlatform() != null) {
109             cmd.createArgument().setValue(FLAG_PLATFORM);
110             cmd.createArgument().setValue(getPlatform());
111         } // end of if ()
112

113         if (getResolver() != null) {
114             cmd.createArgument().setValue(FLAG_RESOLVER);
115             cmd.createArgument().setValue(getResolver());
116         } // end of if ()
117

118         if (getSubSystem() != null) {
119             cmd.createArgument().setValue(FLAG_SUBSYSTEM);
120             cmd.createArgument().setValue("\"" + getSubSystem() + "\"");
121         } // end of if ()
122

123         if (getRelease() != null) {
124             cmd.createArgument().setValue(FLAG_RELEASE);
125             cmd.createArgument().setValue(getRelease());
126         } // end of if ()
127
}
128
129
130     /**
131      * Get the value of comment.
132      * @return value of comment.
133      */

134     public String JavaDoc getComment() {
135         return comment;
136     }
137
138     /**
139      * Specifies a comment.
140      *
141      * @param v Value to assign to comment.
142      */

143     public void setComment(String JavaDoc v) {
144         this.comment = v;
145     }
146
147
148     /**
149      * Get the value of platform.
150      * @return value of platform.
151      */

152     public String JavaDoc getPlatform() {
153         return platform;
154     }
155
156     /**
157      * Specifies the target platform.
158      *
159      * @param v Value to assign to platform.
160      */

161     public void setPlatform(String JavaDoc v) {
162         this.platform = v;
163     }
164
165
166     /**
167      * Get the value of resolver.
168      * @return value of resolver.
169      */

170     public String JavaDoc getResolver() {
171         return resolver;
172     }
173
174     /**
175      * Specifies the resolver.
176      *
177      * @param v Value to assign to resolver.
178      */

179     public void setResolver(String JavaDoc v) {
180         this.resolver = v;
181     }
182
183
184     /**
185      * Get the value of release.
186      * @return value of release.
187      */

188     public String JavaDoc getRelease() {
189         return release;
190     }
191
192     /**
193      * Specify the CCM release.
194      *
195      * @param v Value to assign to release.
196      */

197     public void setRelease(String JavaDoc v) {
198         this.release = v;
199     }
200
201     /**
202      * Get the value of subSystem.
203      * @return value of subSystem.
204      */

205     public String JavaDoc getSubSystem() {
206         return subSystem;
207     }
208
209     /**
210      * Specifies the subsystem.
211      *
212      * @param v Value to assign to subSystem.
213      */

214     public void setSubSystem(String JavaDoc v) {
215         this.subSystem = v;
216     }
217
218
219     /**
220      * Get the value of task.
221      * @return value of task.
222      */

223     public String JavaDoc getTask() {
224         return task;
225     }
226
227     /**
228      * Specifies the task number used to checkin
229      * the file (may use 'default').
230      *
231      * @param v Value to assign to task.
232      */

233     public void setTask(String JavaDoc v) {
234         this.task = v;
235     }
236
237     /**
238      * /comment -- comments associated to the task
239      */

240     public static final String JavaDoc FLAG_COMMENT = "/synopsis";
241
242     /**
243      * /platform flag -- target platform
244      */

245     public static final String JavaDoc FLAG_PLATFORM = "/plat";
246
247     /**
248      * /resolver flag
249      */

250     public static final String JavaDoc FLAG_RESOLVER = "/resolver";
251
252     /**
253      * /release flag
254      */

255     public static final String JavaDoc FLAG_RELEASE = "/release";
256
257     /**
258      * /release flag
259      */

260     public static final String JavaDoc FLAG_SUBSYSTEM = "/subsystem";
261
262     /**
263      * -task flag -- associate checkout task with task
264      */

265     public static final String JavaDoc FLAG_TASK = "/task";
266
267
268     // implementation of org.apache.tools.ant.taskdefs.ExecuteStreamHandler interface
269

270     /**
271      *
272      * @throws IOException on error
273      */

274     public void start() throws IOException JavaDoc {
275     }
276
277     /**
278      *
279      */

280     public void stop() {
281     }
282
283     /**
284      *
285      * @param param1 the output stream
286      * @exception java.io.IOException on error
287      */

288     public void setProcessInputStream(OutputStream JavaDoc param1) throws IOException JavaDoc {
289     }
290
291     /**
292      *
293      * @param is the input stream
294      * @exception java.io.IOException on error
295      */

296     public void setProcessErrorStream(InputStream JavaDoc is) throws IOException JavaDoc {
297         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is));
298         String JavaDoc s = reader.readLine();
299         if (s != null) {
300             log("err " + s, Project.MSG_DEBUG);
301         } // end of if ()
302
}
303
304     /**
305      * read the output stream to retrieve the new task number.
306      * @param is InputStream
307      * @throws IOException on error
308      */

309     public void setProcessOutputStream(InputStream JavaDoc is) throws IOException JavaDoc {
310
311         String JavaDoc buffer = "";
312         try {
313             BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is));
314             buffer = reader.readLine();
315             if (buffer != null) {
316                 log("buffer:" + buffer, Project.MSG_DEBUG);
317                 String JavaDoc taskstring = buffer.substring(buffer.indexOf(' ')).trim();
318                 taskstring = taskstring.substring(0, taskstring.lastIndexOf(' ')).trim();
319                 setTask(taskstring);
320                 log("task is " + getTask(), Project.MSG_DEBUG);
321             } // end of if ()
322
} catch (NullPointerException JavaDoc npe) {
323             log("error procession stream , null pointer exception", Project.MSG_ERR);
324             npe.printStackTrace();
325             throw new BuildException(npe.getClass().getName());
326         } catch (Exception JavaDoc e) {
327             log("error procession stream " + e.getMessage(), Project.MSG_ERR);
328             throw new BuildException(e.getMessage());
329         } // end of try-catch
330

331     }
332
333 }
334
335
Popular Tags