1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.ccm;
|
---|
19 |
|
---|
20 |
|
---|
21 | import java.io.BufferedReader;
|
---|
22 | import java.io.IOException;
|
---|
23 | import java.io.InputStream;
|
---|
24 | import java.io.InputStreamReader;
|
---|
25 | import java.io.OutputStream;
|
---|
26 | import org.apache.tools.ant.BuildException;
|
---|
27 | import org.apache.tools.ant.Project;
|
---|
28 | import org.apache.tools.ant.taskdefs.Execute;
|
---|
29 | import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
|
---|
30 | import org.apache.tools.ant.types.Commandline;
|
---|
31 |
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Creates new Continuus ccm task and sets it as the default.
|
---|
35 | *
|
---|
36 | *
|
---|
37 | * @ant.task name="ccmcreatetask" category="scm"
|
---|
38 | */
|
---|
39 | public class CCMCreateTask extends Continuus implements ExecuteStreamHandler {
|
---|
40 |
|
---|
41 | private String comment = null;
|
---|
42 | private String platform = null;
|
---|
43 | private String resolver = null;
|
---|
44 | private String release = null;
|
---|
45 | private String subSystem = null;
|
---|
46 | private String task = null;
|
---|
47 |
|
---|
48 | public CCMCreateTask() {
|
---|
49 | super();
|
---|
50 | setCcmAction(COMMAND_CREATE_TASK);
|
---|
51 | }
|
---|
52 |
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Executes the task.
|
---|
56 | * <p>
|
---|
57 | * Builds a command line to execute ccm and then calls Exec's run method
|
---|
58 | * to execute the command line.
|
---|
59 | * </p>
|
---|
60 | */
|
---|
61 | public void execute() throws BuildException {
|
---|
62 | Commandline commandLine = new Commandline();
|
---|
63 | int result = 0;
|
---|
64 |
|
---|
65 | // build the command line from what we got the format
|
---|
66 | // as specified in the CCM.EXE help
|
---|
67 | commandLine.setExecutable(getCcmCommand());
|
---|
68 | commandLine.createArgument().setValue(getCcmAction());
|
---|
69 |
|
---|
70 | checkOptions(commandLine);
|
---|
71 |
|
---|
72 | result = run(commandLine, this);
|
---|
73 | if (Execute.isFailure(result)) {
|
---|
74 | String msg = "Failed executing: " + commandLine.toString();
|
---|
75 | throw new BuildException(msg, getLocation());
|
---|
76 | }
|
---|
77 |
|
---|
78 | //create task ok, set this task as the default one
|
---|
79 | Commandline commandLine2 = new Commandline();
|
---|
80 | commandLine2.setExecutable(getCcmCommand());
|
---|
81 | commandLine2.createArgument().setValue(COMMAND_DEFAULT_TASK);
|
---|
82 | commandLine2.createArgument().setValue(getTask());
|
---|
83 |
|
---|
84 | log(commandLine.describeCommand(), Project.MSG_DEBUG);
|
---|
85 |
|
---|
86 | result = run(commandLine2);
|
---|
87 | if (result != 0) {
|
---|
88 | String msg = "Failed executing: " + commandLine2.toString();
|
---|
89 | throw new BuildException(msg, getLocation());
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Check the command line options.
|
---|
97 | */
|
---|
98 | private void checkOptions(Commandline cmd) {
|
---|
99 | if (getComment() != null) {
|
---|
100 | cmd.createArgument().setValue(FLAG_COMMENT);
|
---|
101 | cmd.createArgument().setValue("\"" + getComment() + "\"");
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (getPlatform() != null) {
|
---|
105 | cmd.createArgument().setValue(FLAG_PLATFORM);
|
---|
106 | cmd.createArgument().setValue(getPlatform());
|
---|
107 | } // end of if ()
|
---|
108 |
|
---|
109 | if (getResolver() != null) {
|
---|
110 | cmd.createArgument().setValue(FLAG_RESOLVER);
|
---|
111 | cmd.createArgument().setValue(getResolver());
|
---|
112 | } // end of if ()
|
---|
113 |
|
---|
114 | if (getSubSystem() != null) {
|
---|
115 | cmd.createArgument().setValue(FLAG_SUBSYSTEM);
|
---|
116 | cmd.createArgument().setValue("\"" + getSubSystem() + "\"");
|
---|
117 | } // end of if ()
|
---|
118 |
|
---|
119 | if (getRelease() != null) {
|
---|
120 | cmd.createArgument().setValue(FLAG_RELEASE);
|
---|
121 | cmd.createArgument().setValue(getRelease());
|
---|
122 | } // end of if ()
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Get the value of comment.
|
---|
128 | * @return value of comment.
|
---|
129 | */
|
---|
130 | public String getComment() {
|
---|
131 | return comment;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Specifies a comment.
|
---|
136 | *
|
---|
137 | * @param v Value to assign to comment.
|
---|
138 | */
|
---|
139 | public void setComment(String v) {
|
---|
140 | this.comment = v;
|
---|
141 | }
|
---|
142 |
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Get the value of platform.
|
---|
146 | * @return value of platform.
|
---|
147 | */
|
---|
148 | public String getPlatform() {
|
---|
149 | return platform;
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Specifies the target platform.
|
---|
154 | *
|
---|
155 | * @param v Value to assign to platform.
|
---|
156 | */
|
---|
157 | public void setPlatform(String v) {
|
---|
158 | this.platform = v;
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Get the value of resolver.
|
---|
164 | * @return value of resolver.
|
---|
165 | */
|
---|
166 | public String getResolver() {
|
---|
167 | return resolver;
|
---|
168 | }
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Specifies the resolver.
|
---|
172 | *
|
---|
173 | * @param v Value to assign to resolver.
|
---|
174 | */
|
---|
175 | public void setResolver(String v) {
|
---|
176 | this.resolver = v;
|
---|
177 | }
|
---|
178 |
|
---|
179 |
|
---|
180 | /**
|
---|
181 | * Get the value of release.
|
---|
182 | * @return value of release.
|
---|
183 | */
|
---|
184 | public String getRelease() {
|
---|
185 | return release;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Specify the CCM release.
|
---|
190 | *
|
---|
191 | * @param v Value to assign to release.
|
---|
192 | */
|
---|
193 | public void setRelease(String v) {
|
---|
194 | this.release = v;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Get the value of subSystem.
|
---|
199 | * @return value of subSystem.
|
---|
200 | */
|
---|
201 | public String getSubSystem() {
|
---|
202 | return subSystem;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Specifies the subsystem.
|
---|
207 | *
|
---|
208 | * @param v Value to assign to subSystem.
|
---|
209 | */
|
---|
210 | public void setSubSystem(String v) {
|
---|
211 | this.subSystem = v;
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Get the value of task.
|
---|
217 | * @return value of task.
|
---|
218 | */
|
---|
219 | public String getTask() {
|
---|
220 | return task;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * Specifies the task number used to checkin
|
---|
225 | * the file (may use 'default').
|
---|
226 | *
|
---|
227 | * @param v Value to assign to task.
|
---|
228 | */
|
---|
229 | public void setTask(String v) {
|
---|
230 | this.task = v;
|
---|
231 | }
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * /comment -- comments associated to the task
|
---|
235 | */
|
---|
236 | public static final String FLAG_COMMENT = "/synopsis";
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * /platform flag -- target platform
|
---|
240 | */
|
---|
241 | public static final String FLAG_PLATFORM = "/plat";
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * /resolver flag
|
---|
245 | */
|
---|
246 | public static final String FLAG_RESOLVER = "/resolver";
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * /release flag
|
---|
250 | */
|
---|
251 | public static final String FLAG_RELEASE = "/release";
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * /release flag
|
---|
255 | */
|
---|
256 | public static final String FLAG_SUBSYSTEM = "/subsystem";
|
---|
257 |
|
---|
258 | /**
|
---|
259 | * -task flag -- associate checkout task with task
|
---|
260 | */
|
---|
261 | public static final String FLAG_TASK = "/task";
|
---|
262 |
|
---|
263 |
|
---|
264 | // implementation of org.apache.tools.ant.taskdefs.ExecuteStreamHandler interface
|
---|
265 |
|
---|
266 | /**
|
---|
267 | *
|
---|
268 | * @exception java.io.IOException
|
---|
269 | */
|
---|
270 | public void start() throws IOException {
|
---|
271 | }
|
---|
272 |
|
---|
273 | /**
|
---|
274 | *
|
---|
275 | */
|
---|
276 | public void stop() {
|
---|
277 | }
|
---|
278 |
|
---|
279 | /**
|
---|
280 | *
|
---|
281 | * @param param1
|
---|
282 | * @exception java.io.IOException
|
---|
283 | */
|
---|
284 | public void setProcessInputStream(OutputStream param1) throws IOException {
|
---|
285 | }
|
---|
286 |
|
---|
287 | /**
|
---|
288 | *
|
---|
289 | * @param is
|
---|
290 | * @exception java.io.IOException
|
---|
291 | */
|
---|
292 | public void setProcessErrorStream(InputStream is) throws IOException {
|
---|
293 | BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
---|
294 | String s = reader.readLine();
|
---|
295 | if (s != null) {
|
---|
296 | log("err " + s, Project.MSG_DEBUG);
|
---|
297 | } // end of if ()
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * read the output stream to retrieve the new task number.
|
---|
302 | * @param is InputStream
|
---|
303 | * @exception java.io.IOException
|
---|
304 | */
|
---|
305 | public void setProcessOutputStream(InputStream is) throws IOException {
|
---|
306 |
|
---|
307 | String buffer = "";
|
---|
308 | try {
|
---|
309 | BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
---|
310 | buffer = reader.readLine();
|
---|
311 | if (buffer != null) {
|
---|
312 | log("buffer:" + buffer, Project.MSG_DEBUG);
|
---|
313 | String taskstring = buffer.substring(buffer.indexOf(' ')).trim();
|
---|
314 | taskstring = taskstring.substring(0, taskstring.lastIndexOf(' ')).trim();
|
---|
315 | setTask(taskstring);
|
---|
316 | log("task is " + getTask(), Project.MSG_DEBUG);
|
---|
317 | } // end of if ()
|
---|
318 | } catch (NullPointerException npe) {
|
---|
319 | log("error procession stream , null pointer exception", Project.MSG_ERR);
|
---|
320 | npe.printStackTrace();
|
---|
321 | throw new BuildException(npe.getClass().getName());
|
---|
322 | } catch (Exception e) {
|
---|
323 | log("error procession stream " + e.getMessage(), Project.MSG_ERR);
|
---|
324 | throw new BuildException(e.getMessage());
|
---|
325 | } // end of try-catch
|
---|
326 |
|
---|
327 | }
|
---|
328 |
|
---|
329 | }
|
---|
330 |
|
---|