source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCMklabel.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 10.9 KB
Line 
1/*
2 * Copyright 2003-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
18package org.apache.tools.ant.taskdefs.optional.clearcase;
19
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.Project;
22import org.apache.tools.ant.taskdefs.Execute;
23import org.apache.tools.ant.types.Commandline;
24
25/**
26 * Task to perform mklabel command to ClearCase.
27 * <p>
28 * The following attributes are interpreted:
29 * <table border="1">
30 * <tr>
31 * <th>Attribute</th>
32 * <th>Values</th>
33 * <th>Required</th>
34 * </tr>
35 * <tr>
36 * <td>viewpath</td>
37 * <td>Path to the ClearCase view file or directory that the command will operate on</td>
38 * <td>No</td>
39 * <tr>
40 * <tr>
41 * <td>replace</td>
42 * <td>Replace a label of the same type on the same branch</td>
43 * <td>No</td>
44 * <tr>
45 * <tr>
46 * <td>recurse</td>
47 * <td>Process each subdirectory under viewpath</td>
48 * <td>No</td>
49 * <tr>
50 * <tr>
51 * <td>version</td>
52 * <td>Identify a specific version to attach the label to</td>
53 * <td>No</td>
54 * <tr>
55 * <tr>
56 * <td>typename</td>
57 * <td>Name of the label type</td>
58 * <td>Yes</td>
59 * <tr>
60 * <tr>
61 * <td>vob</td>
62 * <td>Name of the VOB</td>
63 * <td>No</td>
64 * <tr>
65 * <tr>
66 * <td>comment</td>
67 * <td>Specify a comment. Only one of comment or cfile may be used.</td>
68 * <td>No</td>
69 * <tr>
70 * <tr>
71 * <td>commentfile</td>
72 * <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
73 * <td>No</td>
74 * <tr>
75 * <tr>
76 * <td>failonerr</td>
77 * <td>Throw an exception if the command fails. Default is true</td>
78 * <td>No</td>
79 * <tr>
80 * </table>
81 *
82 */
83public class CCMklabel extends ClearCase {
84 private boolean mReplace = false;
85 private boolean mRecurse = false;
86 private String mVersion = null;
87 private String mTypeName = null;
88 private String mVOB = null;
89 private String mComment = null;
90 private String mCfile = null;
91
92 /**
93 * Executes the task.
94 * <p>
95 * Builds a command line to execute cleartool and then calls Exec's run method
96 * to execute the command line.
97 * @throws BuildException if the command fails and failonerr is set to true
98 */
99 public void execute() throws BuildException {
100 Commandline commandLine = new Commandline();
101 Project aProj = getProject();
102 int result = 0;
103
104 // Check for required attributes
105 if (getTypeName() == null) {
106 throw new BuildException("Required attribute TypeName not specified");
107 }
108
109 // Default the viewpath to basedir if it is not specified
110 if (getViewPath() == null) {
111 setViewPath(aProj.getBaseDir().getPath());
112 }
113
114 // build the command line from what we got. the format is
115 // cleartool mklabel [options...] [viewpath ...]
116 // as specified in the CLEARTOOL help
117 commandLine.setExecutable(getClearToolCommand());
118 commandLine.createArgument().setValue(COMMAND_MKLABEL);
119
120 checkOptions(commandLine);
121
122 if (!getFailOnErr()) {
123 getProject().log("Ignoring any errors that occur for: "
124 + getViewPathBasename(), Project.MSG_VERBOSE);
125 }
126 result = run(commandLine);
127 if (Execute.isFailure(result) && getFailOnErr()) {
128 String msg = "Failed executing: " + commandLine.toString();
129 throw new BuildException(msg, getLocation());
130 }
131 }
132
133
134 /**
135 * Check the command line options.
136 */
137 private void checkOptions(Commandline cmd) {
138 if (getReplace()) {
139 // -replace
140 cmd.createArgument().setValue(FLAG_REPLACE);
141 }
142
143 if (getRecurse()) {
144 // -recurse
145 cmd.createArgument().setValue(FLAG_RECURSE);
146 }
147
148 if (getVersion() != null) {
149 // -version
150 getVersionCommand(cmd);
151 }
152
153 if (getComment() != null) {
154 // -c
155 getCommentCommand(cmd);
156 } else {
157 if (getCommentFile() != null) {
158 // -cfile
159 getCommentFileCommand(cmd);
160 } else {
161 cmd.createArgument().setValue(FLAG_NOCOMMENT);
162 }
163 }
164
165 if (getTypeName() != null) {
166 // type
167 getTypeCommand(cmd);
168 }
169
170 // viewpath
171 cmd.createArgument().setValue(getViewPath());
172 }
173
174
175 /**
176 * Set the replace flag
177 *
178 * @param replace the status to set the flag to
179 */
180 public void setReplace(boolean replace) {
181 mReplace = replace;
182 }
183
184 /**
185 * Get replace flag status
186 *
187 * @return boolean containing status of replace flag
188 */
189 public boolean getReplace() {
190 return mReplace;
191 }
192
193 /**
194 * Set recurse flag
195 *
196 * @param recurse the status to set the flag to
197 */
198 public void setRecurse(boolean recurse) {
199 mRecurse = recurse;
200 }
201
202 /**
203 * Get recurse flag status
204 *
205 * @return boolean containing status of recurse flag
206 */
207 public boolean getRecurse() {
208 return mRecurse;
209 }
210
211 /**
212 * Set the version flag
213 *
214 * @param version the status to set the flag to
215 */
216 public void setVersion(String version) {
217 mVersion = version;
218 }
219
220 /**
221 * Get version flag status
222 *
223 * @return boolean containing status of version flag
224 */
225 public String getVersion() {
226 return mVersion;
227 }
228
229 /**
230 * Set comment string
231 *
232 * @param comment the comment string
233 */
234 public void setComment(String comment) {
235 mComment = comment;
236 }
237
238 /**
239 * Get comment string
240 *
241 * @return String containing the comment
242 */
243 public String getComment() {
244 return mComment;
245 }
246
247 /**
248 * Set comment file
249 *
250 * @param cfile the path to the comment file
251 */
252 public void setCommentFile(String cfile) {
253 mCfile = cfile;
254 }
255
256 /**
257 * Get comment file
258 *
259 * @return String containing the path to the comment file
260 */
261 public String getCommentFile() {
262 return mCfile;
263 }
264
265 /**
266 * Set the type-name
267 *
268 * @param tn the type name
269 */
270 public void setTypeName(String tn) {
271 mTypeName = tn;
272 }
273
274 /**
275 * Get type-name
276 *
277 * @return String containing type name
278 */
279 public String getTypeName() {
280 return mTypeName;
281 }
282
283 /**
284 * Set the VOB name
285 *
286 * @param vob the VOB name
287 */
288 public void setVOB(String vob) {
289 mVOB = vob;
290 }
291
292 /**
293 * Get VOB name
294 *
295 * @return String containing VOB name
296 */
297 public String getVOB() {
298 return mVOB;
299 }
300
301
302 /**
303 * Get the 'version' command
304 *
305 * @param cmd CommandLine containing the command line string with or
306 * without the version flag and string appended
307 */
308 private void getVersionCommand(Commandline cmd) {
309 if (getVersion() != null) {
310 /* Had to make two separate commands here because if a space is
311 inserted between the flag and the value, it is treated as a
312 Windows filename with a space and it is enclosed in double
313 quotes ("). This breaks clearcase.
314 */
315 cmd.createArgument().setValue(FLAG_VERSION);
316 cmd.createArgument().setValue(getVersion());
317 }
318 }
319
320 /**
321 * Get the 'comment' command
322 *
323 * @param cmd containing the command line string with or
324 * without the comment flag and string appended
325 */
326 private void getCommentCommand(Commandline cmd) {
327 if (getComment() != null) {
328 /* Had to make two separate commands here because if a space is
329 inserted between the flag and the value, it is treated as a
330 Windows filename with a space and it is enclosed in double
331 quotes ("). This breaks clearcase.
332 */
333 cmd.createArgument().setValue(FLAG_COMMENT);
334 cmd.createArgument().setValue(getComment());
335 }
336 }
337
338 /**
339 * Get the 'commentfile' command
340 *
341 * @param cmd containing the command line string with or
342 * without the commentfile flag and file appended
343 */
344 private void getCommentFileCommand(Commandline cmd) {
345 if (getCommentFile() != null) {
346 /* Had to make two separate commands here because if a space is
347 inserted between the flag and the value, it is treated as a
348 Windows filename with a space and it is enclosed in double
349 quotes ("). This breaks clearcase.
350 */
351 cmd.createArgument().setValue(FLAG_COMMENTFILE);
352 cmd.createArgument().setValue(getCommentFile());
353 }
354 }
355
356 /**
357 * Get the type-name
358 *
359 * @param cmd containing the command line string with or
360 * without the type-name
361 */
362 private void getTypeCommand(Commandline cmd) {
363 String typenm = null;
364
365 if (getTypeName() != null) {
366 typenm = getTypeName();
367 if (getVOB() != null) {
368 typenm += "@" + getVOB();
369 }
370 cmd.createArgument().setValue(typenm);
371 }
372 }
373
374
375 /**
376 * -replace flag -- replace another label of the same type
377 */
378 public static final String FLAG_REPLACE = "-replace";
379 /**
380 * -recurse flag -- process all subdirectories
381 */
382 public static final String FLAG_RECURSE = "-recurse";
383 /**
384 * -version flag -- attach label to specified version
385 */
386 public static final String FLAG_VERSION = "-version";
387 /**
388 * -c flag -- comment to attach to the file
389 */
390 public static final String FLAG_COMMENT = "-c";
391 /**
392 * -cfile flag -- file containing a comment to attach to the file
393 */
394 public static final String FLAG_COMMENTFILE = "-cfile";
395 /**
396 * -nc flag -- no comment is specified
397 */
398 public static final String FLAG_NOCOMMENT = "-nc";
399
400}
401
Note: See TracBrowser for help on using the repository browser.