source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCRmtype.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.3 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 rmtype 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>typekind</td>
37 * <td>The kind of type to create. Valid types are:<br>
38 * attype attribute type<br>
39 * brtype branch type<br>
40 * eltype element type<br>
41 * hltype hyperlink type<br>
42 * lbtype label type<br>
43 * trtype trigger type<br>
44 * </td>
45 * <td>Yes</td>
46 * <tr>
47 * <tr>
48 * <td>typename</td>
49 * <td>The name of the type to remove</td>
50 * <td>Yes</td>
51 * <tr>
52 * <tr>
53 * <td>vob</td>
54 * <td>Name of the VOB</td>
55 * <td>No</td>
56 * <tr>
57 * <tr>
58 * <td>ignore</td>
59 * <td>Used with trigger types only. Forces removal of trigger type
60 * even if a pre-operation trigger would prevent its removal</td>
61 * <td>No</td>
62 * <tr>
63 * <tr>
64 * <td>rmall</td>
65 * <td>Removes all instances of a type and the type object itself</td>
66 * <td>No</td>
67 * <tr>
68 * <tr>
69 * <td>comment</td>
70 * <td>Specify a comment. Only one of comment or cfile may be used.</td>
71 * <td>No</td>
72 * <tr>
73 * <tr>
74 * <td>commentfile</td>
75 * <td>Specify a file containing a comment. Only one of comment or cfile
76 * may be used.</td>
77 * <td>No</td>
78 * <tr>
79 * <tr>
80 * <td>failonerr</td>
81 * <td>Throw an exception if the command fails. Default is true</td>
82 * <td>No</td>
83 * <tr>
84 * </table>
85 *
86 */
87public class CCRmtype extends ClearCase {
88 private String mTypeKind = null;
89 private String mTypeName = null;
90 private String mVOB = null;
91 private String mComment = null;
92 private String mCfile = null;
93 private boolean mRmall = false;
94 private boolean mIgnore = false;
95
96 /**
97 * Executes the task.
98 * <p>
99 * Builds a command line to execute cleartool and then calls Exec's run method
100 * to execute the command line.
101 * @throws BuildException if the command fails and failonerr is set to true
102 */
103 public void execute() throws BuildException {
104 Commandline commandLine = new Commandline();
105 Project aProj = getProject();
106 int result = 0;
107
108 // Check for required attributes
109 if (getTypeKind() == null) {
110 throw new BuildException("Required attribute TypeKind not specified");
111 }
112 if (getTypeName() == null) {
113 throw new BuildException("Required attribute TypeName not specified");
114 }
115
116 // build the command line from what we got. the format is
117 // cleartool rmtype [options...] type-selector...
118 // as specified in the CLEARTOOL help
119 commandLine.setExecutable(getClearToolCommand());
120 commandLine.createArgument().setValue(COMMAND_RMTYPE);
121
122 checkOptions(commandLine);
123
124 if (!getFailOnErr()) {
125 getProject().log("Ignoring any errors that occur for: "
126 + getTypeSpecifier(), Project.MSG_VERBOSE);
127 }
128 result = run(commandLine);
129 if (Execute.isFailure(result) && getFailOnErr()) {
130 String msg = "Failed executing: " + commandLine.toString();
131 throw new BuildException(msg, getLocation());
132 }
133 }
134
135
136 /**
137 * Check the command line options.
138 */
139 private void checkOptions(Commandline cmd) {
140 if (getIgnore()) {
141 // -ignore
142 cmd.createArgument().setValue(FLAG_IGNORE);
143 }
144 if (getRmAll()) {
145 // -rmall -force
146 cmd.createArgument().setValue(FLAG_RMALL);
147 cmd.createArgument().setValue(FLAG_FORCE);
148 }
149 if (getComment() != null) {
150 // -c
151 getCommentCommand(cmd);
152 } else {
153 if (getCommentFile() != null) {
154 // -cfile
155 getCommentFileCommand(cmd);
156 } else {
157 cmd.createArgument().setValue(FLAG_NOCOMMENT);
158 }
159 }
160
161 // type-kind:type-name
162 cmd.createArgument().setValue(getTypeSpecifier());
163 }
164
165 /**
166 * Set the ignore flag
167 *
168 * @param ignore the status to set the flag to
169 */
170 public void setIgnore(boolean ignore) {
171 mIgnore = ignore;
172 }
173
174 /**
175 * Get ignore flag status
176 *
177 * @return boolean containing status of ignore flag
178 */
179 public boolean getIgnore() {
180 return mIgnore;
181 }
182
183 /**
184 * Set rmall flag
185 *
186 * @param rmall the status to set the flag to
187 */
188 public void setRmAll(boolean rmall) {
189 mRmall = rmall;
190 }
191
192 /**
193 * Get rmall flag status
194 *
195 * @return boolean containing status of rmall flag
196 */
197 public boolean getRmAll() {
198 return mRmall;
199 }
200
201 /**
202 * Set comment string
203 *
204 * @param comment the comment string
205 */
206 public void setComment(String comment) {
207 mComment = comment;
208 }
209
210 /**
211 * Get comment string
212 *
213 * @return String containing the comment
214 */
215 public String getComment() {
216 return mComment;
217 }
218
219 /**
220 * Set comment file
221 *
222 * @param cfile the path to the comment file
223 */
224 public void setCommentFile(String cfile) {
225 mCfile = cfile;
226 }
227
228 /**
229 * Get comment file
230 *
231 * @return String containing the path to the comment file
232 */
233 public String getCommentFile() {
234 return mCfile;
235 }
236
237 /**
238 * Set type-kind string
239 *
240 * @param tk the type-kind string
241 */
242 public void setTypeKind(String tk) {
243 mTypeKind = tk;
244 }
245
246 /**
247 * Get type-kind string
248 *
249 * @return String containing the type-kind
250 */
251 public String getTypeKind() {
252 return mTypeKind;
253 }
254
255 /**
256 * Set type-name string
257 *
258 * @param tn the type-name string
259 */
260 public void setTypeName(String tn) {
261 mTypeName = tn;
262 }
263
264 /**
265 * Get type-name string
266 *
267 * @return String containing the type-name
268 */
269 public String getTypeName() {
270 return mTypeName;
271 }
272
273 /**
274 * Set the VOB name
275 *
276 * @param vob the VOB name
277 */
278 public void setVOB(String vob) {
279 mVOB = vob;
280 }
281
282 /**
283 * Get VOB name
284 *
285 * @return String containing VOB name
286 */
287 public String getVOB() {
288 return mVOB;
289 }
290
291 /**
292 * Get the 'type-specifier' string
293 *
294 * @return the 'type-kind:type-name@vob' specifier
295 *
296 */
297 private String getTypeSpecifier() {
298 String tkind = getTypeKind();
299 String tname = getTypeName();
300 String typeSpec = null;
301
302 // Return the type-selector
303 typeSpec = tkind + ":" + tname;
304 if (getVOB() != null) {
305 typeSpec += "@" + getVOB();
306 }
307 return typeSpec;
308 }
309
310 /**
311 * Get the 'comment' command
312 *
313 * @param cmd containing the command line string with or
314 * without the comment flag and string appended
315 */
316 private void getCommentCommand(Commandline cmd) {
317 if (getComment() != null) {
318 /* Had to make two separate commands here because if a space is
319 inserted between the flag and the value, it is treated as a
320 Windows filename with a space and it is enclosed in double
321 quotes ("). This breaks clearcase.
322 */
323 cmd.createArgument().setValue(FLAG_COMMENT);
324 cmd.createArgument().setValue(getComment());
325 }
326 }
327
328 /**
329 * Get the 'commentfile' command
330 *
331 * @param cmd containing the command line string with or
332 * without the commentfile flag and file appended
333 */
334 private void getCommentFileCommand(Commandline cmd) {
335 if (getCommentFile() != null) {
336 /* Had to make two separate commands here because if a space is
337 inserted between the flag and the value, it is treated as a
338 Windows filename with a space and it is enclosed in double
339 quotes ("). This breaks clearcase.
340 */
341 cmd.createArgument().setValue(FLAG_COMMENTFILE);
342 cmd.createArgument().setValue(getCommentFile());
343 }
344 }
345
346
347 /**
348 * -ignore flag -- ignore pre-trigger operations when removing a trigger type
349 */
350 public static final String FLAG_IGNORE = "-ignore";
351 /**
352 * -rmall flag -- removes all instances of a type and the type object itself
353 */
354 public static final String FLAG_RMALL = "-rmall";
355 /**
356 * -force flag -- suppresses confirmation prompts
357 */
358 public static final String FLAG_FORCE = "-force";
359 /**
360 * -c flag -- comment to attach to the file
361 */
362 public static final String FLAG_COMMENT = "-c";
363 /**
364 * -cfile flag -- file containing a comment to attach to the file
365 */
366 public static final String FLAG_COMMENTFILE = "-cfile";
367 /**
368 * -nc flag -- no comment is specified
369 */
370 public static final String FLAG_NOCOMMENT = "-nc";
371
372}
373
Note: See TracBrowser for help on using the repository browser.