source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCMkelem.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 11.9 KB
Line 
1/*
2 * Copyright 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 * Performs ClearCase mkelem.
27 *
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>viewpath</td>
38 * <td>Path to the ClearCase view file or directory that the command will operate on</td>
39 * <td>Yes</td>
40 * <tr>
41 * <tr>
42 * <td>comment</td>
43 * <td>Specify a comment. Only one of comment or cfile may be used.</td>
44 * <td>No</td>
45 * <tr>
46 * <tr>
47 * <td>commentfile</td>
48 * <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
49 * <td>No</td>
50 * <tr>
51 * <tr>
52 * <td>nowarn</td>
53 * <td>Suppress warning messages</td>
54 * <td>No</td>
55 * <tr>
56 * <tr>
57 * <td>nocheckout</td>
58 * <td>Do not checkout after element creation</td>
59 * <td>No</td>
60 * <tr>
61 * <tr>
62 * <td>checkin</td>
63 * <td>Checkin element after creation</td>
64 * <td>No</td>
65 * <tr>
66 * <tr>
67 * <td>preservetime</td>
68 * <td>Preserve the modification time (for checkin)</td>
69 * <td>No</td>
70 * <tr>
71 * <tr>
72 * <td>master</td>
73 * <td>Assign mastership of the main branch to the current site</td>
74 * <td>No</td>
75 * <tr>
76 * <tr>
77 * <td>eltype</td>
78 * <td>Element type to use during element creation</td>
79 * <td>No</td>
80 * <tr>
81 * <tr>
82 * <td>failonerr</td>
83 * <td>Throw an exception if the command fails. Default is true</td>
84 * <td>No</td>
85 * <tr>
86 * </table>
87 *
88 */
89public class CCMkelem extends ClearCase {
90 private String mComment = null;
91 private String mCfile = null;
92 private boolean mNwarn = false;
93 private boolean mPtime = false;
94 private boolean mNoco = false;
95 private boolean mCheckin = false;
96 private boolean mMaster = false;
97 private String mEltype = null;
98
99 /**
100 * Executes the task.
101 * <p>
102 * Builds a command line to execute cleartool and then calls Exec's run method
103 * to execute the command line.
104 * @throws BuildException if the command fails and failonerr is set to true
105 */
106 public void execute() throws BuildException {
107 Commandline commandLine = new Commandline();
108 Project aProj = getProject();
109 int result = 0;
110
111 // Default the viewpath to basedir if it is not specified
112 if (getViewPath() == null) {
113 setViewPath(aProj.getBaseDir().getPath());
114 }
115
116 // build the command line from what we got. the format is
117 // cleartool mkelem [options...] [viewpath ...]
118 // as specified in the CLEARTOOL.EXE help
119 commandLine.setExecutable(getClearToolCommand());
120 commandLine.createArgument().setValue(COMMAND_MKELEM);
121
122 checkOptions(commandLine);
123
124 if (!getFailOnErr()) {
125 getProject().log("Ignoring any errors that occur for: "
126 + getViewPathBasename(), 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 (getComment() != null) {
141 // -c
142 getCommentCommand(cmd);
143 } else {
144 if (getCommentFile() != null) {
145 // -cfile
146 getCommentFileCommand(cmd);
147 } else {
148 cmd.createArgument().setValue(FLAG_NOCOMMENT);
149 }
150 }
151
152 if (getNoWarn()) {
153 // -nwarn
154 cmd.createArgument().setValue(FLAG_NOWARN);
155 }
156 /*
157 * Should choose either -ci or -nco.
158 */
159 if (getNoCheckout() && getCheckin()) {
160 throw new BuildException("Should choose either [nocheckout | checkin]");
161 }
162 if (getNoCheckout()) {
163 // -nco
164 cmd.createArgument().setValue(FLAG_NOCHECKOUT);
165 }
166 if (getCheckin()) {
167 // -ci
168 cmd.createArgument().setValue(FLAG_CHECKIN);
169 if (getPreserveTime()) {
170 // -ptime
171 cmd.createArgument().setValue(FLAG_PRESERVETIME);
172 }
173 }
174 if (getMaster()) {
175 // -master
176 cmd.createArgument().setValue(FLAG_MASTER);
177 }
178 if (getEltype() != null) {
179 // -eltype
180 getEltypeCommand(cmd);
181 }
182 // viewpath
183 cmd.createArgument().setValue(getViewPath());
184 }
185
186 /**
187 * Sets the comment string.
188 *
189 * @param comment the comment string
190 */
191 public void setComment(String comment) {
192 mComment = comment;
193 }
194
195 /**
196 * Get comment string
197 *
198 * @return String containing the comment
199 */
200 public String getComment() {
201 return mComment;
202 }
203
204 /**
205 * Specifies a file containing a comment.
206 *
207 * @param cfile the path to the comment file
208 */
209 public void setCommentFile(String cfile) {
210 mCfile = cfile;
211 }
212
213 /**
214 * Get comment file
215 *
216 * @return String containing the path to the comment file
217 */
218 public String getCommentFile() {
219 return mCfile;
220 }
221
222 /**
223 * If true, suppress warning messages.
224 *
225 * @param nwarn the status to set the flag to
226 */
227 public void setNoWarn(boolean nwarn) {
228 mNwarn = nwarn;
229 }
230
231 /**
232 * Get nowarn flag status
233 *
234 * @return boolean containing status of nwarn flag
235 */
236 public boolean getNoWarn() {
237 return mNwarn;
238 }
239
240 /**
241 * If true, preserve the modification time.
242 *
243 * @param ptime the status to set the flag to
244 */
245 public void setPreserveTime(boolean ptime) {
246 mPtime = ptime;
247 }
248
249 /**
250 * Get preservetime flag status
251 *
252 * @return boolean containing status of preservetime flag
253 */
254 public boolean getPreserveTime() {
255 return mPtime;
256 }
257
258 /**
259 * If true, do not checkout element after creation.
260 *
261 * @param co the status to set the flag to
262 */
263 public void setNoCheckout(boolean co) {
264 mNoco = co;
265 }
266
267 /**
268 * Get no checkout flag status
269 *
270 * @return boolean containing status of noco flag
271 */
272 public boolean getNoCheckout() {
273 return mNoco;
274 }
275
276 /**
277 * If true, checkin the element after creation
278 *
279 * @param ci the status to set the flag to
280 */
281 public void setCheckin(boolean ci) {
282 mCheckin = ci;
283 }
284
285 /**
286 * Get ci flag status
287 *
288 * @return boolean containing status of ci flag
289 */
290 public boolean getCheckin() {
291 return mCheckin;
292 }
293
294 /**
295 * If true, changes mastership of the main branch
296 * to the current site
297 *
298 * @param master the status to set the flag to
299 */
300 public void setMaster(boolean master) {
301 mMaster = master;
302 }
303
304 /**
305 * Get master flag status
306 *
307 * @return boolean containing status of master flag
308 */
309 public boolean getMaster() {
310 return mMaster;
311 }
312
313 /**
314 * Specifies the element type to use.
315 *
316 * @param eltype to create element
317 */
318 public void setEltype(String eltype) {
319 mEltype = eltype;
320 }
321
322 /**
323 * Get element type
324 *
325 * @return String containing the element type
326 */
327 public String getEltype() {
328 return mEltype;
329 }
330
331
332 /**
333 * Get the 'comment' command
334 *
335 * @param cmd containing the command line string with or
336 * without the comment flag and string appended
337 */
338 private void getCommentCommand(Commandline cmd) {
339 if (getComment() != null) {
340 /* Had to make two separate commands here because if a space is
341 inserted between the flag and the value, it is treated as a
342 Windows filename with a space and it is enclosed in double
343 quotes ("). This breaks clearcase.
344 */
345 cmd.createArgument().setValue(FLAG_COMMENT);
346 cmd.createArgument().setValue(getComment());
347 }
348 }
349
350 /**
351 * Get the 'commentfile' command
352 *
353 * @param cmd containing the command line string with or
354 * without the commentfile flag and file appended
355 */
356 private void getCommentFileCommand(Commandline cmd) {
357 if (getCommentFile() != null) {
358 /* Had to make two separate commands here because if a space is
359 inserted between the flag and the value, it is treated as a
360 Windows filename with a space and it is enclosed in double
361 quotes ("). This breaks clearcase.
362 */
363 cmd.createArgument().setValue(FLAG_COMMENTFILE);
364 cmd.createArgument().setValue(getCommentFile());
365 }
366 }
367
368 /**
369 * Get the 'element type' command
370 *
371 * @param cmd containing the command line string with or
372 * without the comment flag and string appended
373 */
374 private void getEltypeCommand(Commandline cmd) {
375 if (getEltype() != null) {
376 /* Had to make two separate commands here because if a space is
377 inserted between the flag and the value, it is treated as a
378 Windows filename with a space and it is enclosed in double
379 quotes ("). This breaks clearcase.
380 */
381 cmd.createArgument().setValue(FLAG_ELTYPE);
382 cmd.createArgument().setValue(getEltype());
383 }
384 }
385
386 /**
387 * -c flag -- comment to attach to the file
388 */
389 public static final String FLAG_COMMENT = "-c";
390 /**
391 * -cfile flag -- file containing a comment to attach to the file
392 */
393 public static final String FLAG_COMMENTFILE = "-cfile";
394 /**
395 * -nc flag -- no comment is specified
396 */
397 public static final String FLAG_NOCOMMENT = "-nc";
398 /**
399 * -nwarn flag -- suppresses warning messages
400 */
401 public static final String FLAG_NOWARN = "-nwarn";
402 /**
403 * -ptime flag -- preserves the modification time on checkin
404 */
405 public static final String FLAG_PRESERVETIME = "-ptime";
406 /**
407 * -nco flag -- do not checkout element after creation
408 */
409 public static final String FLAG_NOCHECKOUT = "-nco";
410 /**
411 * -ci flag -- checkin element after creation
412 */
413 public static final String FLAG_CHECKIN = "-ci";
414 /**
415 * -master flag -- change mastership of main branch to current site
416 */
417 public static final String FLAG_MASTER = "-master";
418 /**
419 * -eltype flag -- element type to use during creation
420 */
421 public static final String FLAG_ELTYPE = "-eltype";
422}
423
Note: See TracBrowser for help on using the repository browser.