source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCMklbtype.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: 11.8 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 mklbtype 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>typename</td>
37 * <td>Name of the label type to create</td>
38 * <td>Yes</td>
39 * <tr>
40 * <tr>
41 * <td>vob</td>
42 * <td>Name of the VOB</td>
43 * <td>No</td>
44 * <tr>
45 * <tr>
46 * <td>replace</td>
47 * <td>Replace an existing label definition of the same type</td>
48 * <td>No</td>
49 * <tr>
50 * <tr>
51 * <td>global</td>
52 * <td>Either global or ordinary can be specified, not both.
53 * Creates a label type that is global to the VOB or to
54 * VOBs that use this VOB</td>
55 * <td>No</td>
56 * <tr>
57 * <tr>
58 * <td>ordinary</td>
59 * <td>Either global or ordinary can be specified, not both.
60 * Creates a label type that can be used only in the current
61 * VOB. <B>Default</B></td>
62 * <td>No</td>
63 * <tr>
64 * <tr>
65 * <td>pbranch</td>
66 * <td>Allows the label type to be used once per branch in a given
67 * element's version tree</td>
68 * <td>No</td>
69 * <tr>
70 * <tr>
71 * <td>shared</td>
72 * <td>Sets the way mastership is checked by ClearCase. See ClearCase
73 * documentation for details</td>
74 * <td>No</td>
75 * <tr>
76 * <tr>
77 * <td>comment</td>
78 * <td>Specify a comment. Only one of comment or cfile may be used.</td>
79 * <td>No</td>
80 * <tr>
81 * <tr>
82 * <td>commentfile</td>
83 * <td>Specify a file containing a comment. Only one of comment or
84 * cfile may be used.</td>
85 * <td>No</td>
86 * <tr>
87 * <tr>
88 * <td>failonerr</td>
89 * <td>Throw an exception if the command fails. Default is true</td>
90 * <td>No</td>
91 * <tr>
92 * </table>
93 *
94 */
95public class CCMklbtype extends ClearCase {
96 private String mTypeName = null;
97 private String mVOB = null;
98 private String mComment = null;
99 private String mCfile = null;
100 private boolean mReplace = false;
101 private boolean mGlobal = false;
102 private boolean mOrdinary = true;
103 private boolean mPbranch = false;
104 private boolean mShared = false;
105
106 /**
107 * Executes the task.
108 * <p>
109 * Builds a command line to execute cleartool and then calls Exec's run method
110 * to execute the command line.
111 * @throws BuildException if the command fails and failonerr is set to true
112 */
113 public void execute() throws BuildException {
114 Commandline commandLine = new Commandline();
115 Project aProj = getProject();
116 int result = 0;
117
118 // Check for required attributes
119 if (getTypeName() == null) {
120 throw new BuildException("Required attribute TypeName not specified");
121 }
122
123 // build the command line from what we got. the format is
124 // cleartool mklbtype [options...] type-selector...
125 // as specified in the CLEARTOOL help
126 commandLine.setExecutable(getClearToolCommand());
127 commandLine.createArgument().setValue(COMMAND_MKLBTYPE);
128
129 checkOptions(commandLine);
130
131 if (!getFailOnErr()) {
132 getProject().log("Ignoring any errors that occur for: "
133 + getTypeSpecifier(), Project.MSG_VERBOSE);
134 }
135 result = run(commandLine);
136 if (Execute.isFailure(result) && getFailOnErr()) {
137 String msg = "Failed executing: " + commandLine.toString();
138 throw new BuildException(msg, getLocation());
139 }
140 }
141
142
143 /**
144 * Check the command line options.
145 */
146 private void checkOptions(Commandline cmd) {
147 if (getReplace()) {
148 // -replace
149 cmd.createArgument().setValue(FLAG_REPLACE);
150 }
151
152 if (getOrdinary()) {
153 // -ordinary
154 cmd.createArgument().setValue(FLAG_ORDINARY);
155 } else {
156 if (getGlobal()) {
157 // -global
158 cmd.createArgument().setValue(FLAG_GLOBAL);
159 }
160 }
161
162 if (getPbranch()) {
163 // -pbranch
164 cmd.createArgument().setValue(FLAG_PBRANCH);
165 }
166
167 if (getShared()) {
168 // -shared
169 cmd.createArgument().setValue(FLAG_SHARED);
170 }
171
172 if (getComment() != null) {
173 // -c
174 getCommentCommand(cmd);
175 } else {
176 if (getCommentFile() != null) {
177 // -cfile
178 getCommentFileCommand(cmd);
179 } else {
180 cmd.createArgument().setValue(FLAG_NOCOMMENT);
181 }
182 }
183
184 // type-name@vob
185 cmd.createArgument().setValue(getTypeSpecifier());
186 }
187
188
189 /**
190 * Set type-name string
191 *
192 * @param tn the type-name string
193 */
194 public void setTypeName(String tn) {
195 mTypeName = tn;
196 }
197
198 /**
199 * Get type-name string
200 *
201 * @return String containing the type-name
202 */
203 public String getTypeName() {
204 return mTypeName;
205 }
206
207 /**
208 * Set the VOB name
209 *
210 * @param vob the VOB name
211 */
212 public void setVOB(String vob) {
213 mVOB = vob;
214 }
215
216 /**
217 * Get VOB name
218 *
219 * @return String containing VOB name
220 */
221 public String getVOB() {
222 return mVOB;
223 }
224
225 /**
226 * Set the replace flag
227 *
228 * @param repl the status to set the flag to
229 */
230 public void setReplace(boolean repl) {
231 mReplace = repl;
232 }
233
234 /**
235 * Get replace flag status
236 *
237 * @return boolean containing status of replace flag
238 */
239 public boolean getReplace() {
240 return mReplace;
241 }
242
243 /**
244 * Set the global flag
245 *
246 * @param glob the status to set the flag to
247 */
248 public void setGlobal(boolean glob) {
249 mGlobal = glob;
250 }
251
252 /**
253 * Get global flag status
254 *
255 * @return boolean containing status of global flag
256 */
257 public boolean getGlobal() {
258 return mGlobal;
259 }
260
261 /**
262 * Set the ordinary flag
263 *
264 * @param ordinary the status to set the flag to
265 */
266 public void setOrdinary(boolean ordinary) {
267 mOrdinary = ordinary;
268 }
269
270 /**
271 * Get ordinary flag status
272 *
273 * @return boolean containing status of ordinary flag
274 */
275 public boolean getOrdinary() {
276 return mOrdinary;
277 }
278
279 /**
280 * Set the pbranch flag
281 *
282 * @param pbranch the status to set the flag to
283 */
284 public void setPbranch(boolean pbranch) {
285 mPbranch = pbranch;
286 }
287
288 /**
289 * Get pbranch flag status
290 *
291 * @return boolean containing status of pbranch flag
292 */
293 public boolean getPbranch() {
294 return mPbranch;
295 }
296
297 /**
298 * Set the shared flag
299 *
300 * @param shared the status to set the flag to
301 */
302 public void setShared(boolean shared) {
303 mShared = shared;
304 }
305
306 /**
307 * Get shared flag status
308 *
309 * @return boolean containing status of shared flag
310 */
311 public boolean getShared() {
312 return mShared;
313 }
314
315 /**
316 * Set comment string
317 *
318 * @param comment the comment string
319 */
320 public void setComment(String comment) {
321 mComment = comment;
322 }
323
324 /**
325 * Get comment string
326 *
327 * @return String containing the comment
328 */
329 public String getComment() {
330 return mComment;
331 }
332
333 /**
334 * Set comment file
335 *
336 * @param cfile the path to the comment file
337 */
338 public void setCommentFile(String cfile) {
339 mCfile = cfile;
340 }
341
342 /**
343 * Get comment file
344 *
345 * @return String containing the path to the comment file
346 */
347 public String getCommentFile() {
348 return mCfile;
349 }
350
351
352 /**
353 * Get the 'comment' command
354 *
355 * @param cmd containing the command line string with or
356 * without the comment flag and string appended
357 */
358 private void getCommentCommand(Commandline cmd) {
359 if (getComment() != null) {
360 /* Had to make two separate commands here because if a space is
361 inserted between the flag and the value, it is treated as a
362 Windows filename with a space and it is enclosed in double
363 quotes ("). This breaks clearcase.
364 */
365 cmd.createArgument().setValue(FLAG_COMMENT);
366 cmd.createArgument().setValue(getComment());
367 }
368 }
369
370 /**
371 * Get the 'commentfile' command
372 *
373 * @param cmd containing the command line string with or
374 * without the commentfile flag and file appended
375 */
376 private void getCommentFileCommand(Commandline cmd) {
377 if (getCommentFile() != null) {
378 /* Had to make two separate commands here because if a space is
379 inserted between the flag and the value, it is treated as a
380 Windows filename with a space and it is enclosed in double
381 quotes ("). This breaks clearcase.
382 */
383 cmd.createArgument().setValue(FLAG_COMMENTFILE);
384 cmd.createArgument().setValue(getCommentFile());
385 }
386 }
387
388 /**
389 * Get the type-name specifier
390 *
391 * @return the 'type-name-specifier' command if the attribute was
392 * specified, otherwise an empty string
393 */
394 private String getTypeSpecifier() {
395 String typenm = null;
396
397 typenm = getTypeName();
398 if (getVOB() != null) {
399 typenm += "@" + getVOB();
400 }
401
402 return typenm;
403 }
404
405
406 /**
407 * -replace flag -- replace existing label definition of the same type
408 */
409 public static final String FLAG_REPLACE = "-replace";
410 /**
411 * -global flag -- creates a label type that is global to the VOB or to VOBs that use this VOB
412 */
413 public static final String FLAG_GLOBAL = "-global";
414 /**
415 * -ordinary flag -- creates a label type that can be used only in the current VOB
416 */
417 public static final String FLAG_ORDINARY = "-ordinary";
418 /**
419 * -pbranch flag -- allows label type to be used once per branch
420 */
421 public static final String FLAG_PBRANCH = "-pbranch";
422 /**
423 * -shared flag -- sets the way mastership is checked by ClearCase
424 */
425 public static final String FLAG_SHARED = "-shared";
426 /**
427 * -c flag -- comment to attach to the file
428 */
429 public static final String FLAG_COMMENT = "-c";
430 /**
431 * -cfile flag -- file containing a comment to attach to the file
432 */
433 public static final String FLAG_COMMENTFILE = "-cfile";
434 /**
435 * -nc flag -- no comment is specified
436 */
437 public static final String FLAG_NOCOMMENT = "-nc";
438
439}
440
Note: See TracBrowser for help on using the repository browser.