KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > clearcase > CCRmtype


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.clearcase;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.taskdefs.Execute;
24 import org.apache.tools.ant.types.Commandline;
25
26 /**
27  * Task to perform rmtype command to ClearCase.
28  * <p>
29  * The following attributes are interpreted:
30  * <table border="1">
31  * <tr>
32  * <th>Attribute</th>
33  * <th>Values</th>
34  * <th>Required</th>
35  * </tr>
36  * <tr>
37  * <td>typekind</td>
38  * <td>The kind of type to create. Valid types are:<br>
39  * attype attribute type<br>
40  * brtype branch type<br>
41  * eltype element type<br>
42  * hltype hyperlink type<br>
43  * lbtype label type<br>
44  * trtype trigger type<br>
45  * </td>
46  * <td>Yes</td>
47  * <tr>
48  * <tr>
49  * <td>typename</td>
50  * <td>The name of the type to remove</td>
51  * <td>Yes</td>
52  * <tr>
53  * <tr>
54  * <td>vob</td>
55  * <td>Name of the VOB</td>
56  * <td>No</td>
57  * <tr>
58  * <tr>
59  * <td>ignore</td>
60  * <td>Used with trigger types only. Forces removal of trigger type
61  * even if a pre-operation trigger would prevent its removal</td>
62  * <td>No</td>
63  * <tr>
64  * <tr>
65  * <td>rmall</td>
66  * <td>Removes all instances of a type and the type object itself</td>
67  * <td>No</td>
68  * <tr>
69  * <tr>
70  * <td>comment</td>
71  * <td>Specify a comment. Only one of comment or cfile may be used.</td>
72  * <td>No</td>
73  * <tr>
74  * <tr>
75  * <td>commentfile</td>
76  * <td>Specify a file containing a comment. Only one of comment or cfile
77  * may be used.</td>
78  * <td>No</td>
79  * <tr>
80  * <tr>
81  * <td>failonerr</td>
82  * <td>Throw an exception if the command fails. Default is true</td>
83  * <td>No</td>
84  * <tr>
85  * </table>
86  *
87  */

88 public class CCRmtype extends ClearCase {
89     private String JavaDoc mTypeKind = null;
90     private String JavaDoc mTypeName = null;
91     private String JavaDoc mVOB = null;
92     private String JavaDoc mComment = null;
93     private String JavaDoc mCfile = null;
94     private boolean mRmall = false;
95     private boolean mIgnore = false;
96
97     /**
98      * Executes the task.
99      * <p>
100      * Builds a command line to execute cleartool and then calls Exec's run method
101      * to execute the command line.
102      * @throws BuildException if the command fails and failonerr is set to true
103      */

104     public void execute() throws BuildException {
105         Commandline commandLine = new Commandline();
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 JavaDoc 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 JavaDoc comment) {
207         mComment = comment;
208     }
209
210     /**
211      * Get comment string
212      *
213      * @return String containing the comment
214      */

215     public String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc tk) {
243         mTypeKind = tk;
244     }
245
246     /**
247      * Get type-kind string
248      *
249      * @return String containing the type-kind
250      */

251     public String JavaDoc 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 JavaDoc tn) {
261         mTypeName = tn;
262     }
263
264     /**
265      * Get type-name string
266      *
267      * @return String containing the type-name
268      */

269     public String JavaDoc 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 JavaDoc vob) {
279         mVOB = vob;
280     }
281
282     /**
283      * Get VOB name
284      *
285      * @return String containing VOB name
286      */

287     public String JavaDoc 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 JavaDoc getTypeSpecifier() {
298         String JavaDoc tkind = getTypeKind();
299         String JavaDoc tname = getTypeName();
300         String JavaDoc 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 JavaDoc FLAG_IGNORE = "-ignore";
351     /**
352      * -rmall flag -- removes all instances of a type and the type object itself
353      */

354     public static final String JavaDoc FLAG_RMALL = "-rmall";
355     /**
356      * -force flag -- suppresses confirmation prompts
357      */

358     public static final String JavaDoc FLAG_FORCE = "-force";
359     /**
360      * -c flag -- comment to attach to the file
361      */

362     public static final String JavaDoc FLAG_COMMENT = "-c";
363     /**
364      * -cfile flag -- file containing a comment to attach to the file
365      */

366     public static final String JavaDoc FLAG_COMMENTFILE = "-cfile";
367     /**
368      * -nc flag -- no comment is specified
369      */

370     public static final String JavaDoc FLAG_NOCOMMENT = "-nc";
371
372 }
373
374
Popular Tags