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

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

initial import of LiRK3

File size: 9.9 KB
RevLine 
[14982]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 CreateBaseline 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>comment</td>
37 * <td>Specify a comment. Only one of comment or cfile may be
38used.</td>
39 * <td>No</td>
40 * </tr>
41 * <tr>
42 * <td>commentfile</td>
43 * <td>Specify a file containing a comment. Only one of comment or
44cfile may be used.</td>
45 * <td>No</td>
46 * </tr>
47 * <tr>
48 * <td>baselinerootname</td>
49 * <td>Specify the name to be associated with the baseline.</td>
50 * <td>Yes</td>
51 * </tr>
52 * <tr>
53 * <td>nowarn</td>
54 * <td>Suppress warning messages</td>
55 * <td>No</td>
56 * <tr>
57 * <tr>
58 * <td>identical</td>
59 * <td>Allows the baseline to be created even if it is identical to the
60previous baseline.</td>
61 * <td>No</td>
62 * </tr>
63 * <tr>
64 * <td>full</td>
65 * <td>Creates a full baseline.</td>
66 * <td>No</td>
67 * </tr>
68 * <tr>
69 * <td>nlabel</td>
70 * <td>Allows the baseline to be created without a label.</td>
71 * <td>No</td>
72 * </tr>
73 * <tr>
74 * <td>failonerr</td>
75 * <td>Throw an exception if the command fails. Default is true</td>
76 * <td>No</td>
77 * <tr>
78 * </table>
79 *
80 */
81public class CCMkbl extends ClearCase {
82 private String mComment = null;
83 private String mCfile = null;
84 private String mBaselineRootName = null;
85 private boolean mNwarn = false;
86 private boolean mIdentical = true;
87 private boolean mFull = false;
88 private boolean mNlabel = false;
89
90
91 /**
92 * Executes the task.
93 * <p>
94 * Builds a command line to execute cleartool and then calls Exec's run method
95 * to execute the command line.
96 * @throws BuildException if the command fails and failonerr is set to true
97 */
98 public void execute() throws BuildException {
99 Commandline commandLine = new Commandline();
100 Project aProj = getProject();
101 int result = 0;
102
103 // Default the viewpath to basedir if it is not specified
104 if (getViewPath() == null) {
105 setViewPath(aProj.getBaseDir().getPath());
106 }
107
108 // build the command line from what we got. the format is
109 // cleartool checkin [options...] [viewpath ...]
110 // as specified in the CLEARTOOL.EXE help
111 commandLine.setExecutable(getClearToolCommand());
112 commandLine.createArgument().setValue(COMMAND_MKBL);
113
114 checkOptions(commandLine);
115
116 if (!getFailOnErr()) {
117 getProject().log("Ignoring any errors that occur for: "
118 + getBaselineRootName(), Project.MSG_VERBOSE);
119 }
120 result = run(commandLine);
121 if (Execute.isFailure(result) && getFailOnErr()) {
122 String msg = "Failed executing: " + commandLine.toString();
123 throw new BuildException(msg, getLocation());
124 }
125 }
126
127
128 /**
129 * Check the command line options.
130 */
131 private void checkOptions(Commandline cmd) {
132 if (getComment() != null) {
133 // -c
134 getCommentCommand(cmd);
135 } else {
136 if (getCommentFile() != null) {
137 // -cfile
138 getCommentFileCommand(cmd);
139 } else {
140 cmd.createArgument().setValue(FLAG_NOCOMMENT);
141 }
142 }
143
144 if (getIdentical()) {
145 // -identical
146 cmd.createArgument().setValue(FLAG_IDENTICAL);
147 }
148
149 if (getFull()) {
150 // -full
151 cmd.createArgument().setValue(FLAG_FULL);
152 } else {
153 // -incremental
154 cmd.createArgument().setValue(FLAG_INCREMENTAL);
155 }
156
157 if (getNlabel()) {
158 // -nlabel
159 cmd.createArgument().setValue(FLAG_NLABEL);
160 }
161
162 // baseline_root_name
163 cmd.createArgument().setValue(getBaselineRootName());
164
165 }
166
167
168 /**
169 * Set comment string
170 *
171 * @param comment the comment string
172 */
173 public void setComment(String comment) {
174 mComment = comment;
175 }
176
177 /**
178 * Get comment string
179 *
180 * @return String containing the comment
181 */
182 public String getComment() {
183 return mComment;
184 }
185
186 /**
187 * Set comment file
188 *
189 * @param cfile the path to the comment file
190 */
191 public void setCommentFile(String cfile) {
192 mCfile = cfile;
193 }
194
195 /**
196 * Get comment file
197 *
198 * @return String containing the path to the comment file
199 */
200 public String getCommentFile() {
201 return mCfile;
202 }
203
204 /**
205 * Set baseline_root_name
206 *
207 * @param baselineRootName the name of the baseline
208 */
209 public void setBaselineRootName(String baselineRootName) {
210 mBaselineRootName = baselineRootName;
211 }
212
213 /**
214 * Get baseline_root_name
215 *
216 * @return String containing the name of the baseline
217 */
218 public String getBaselineRootName() {
219 return mBaselineRootName;
220 }
221
222 /**
223
224 /**
225 * Set the nowarn flag
226 *
227 * @param nwarn the status to set the flag to
228 */
229 public void setNoWarn(boolean nwarn) {
230 mNwarn = nwarn;
231 }
232
233 /**
234 * Get nowarn flag status
235 *
236 * @return boolean containing status of nwarn flag
237 */
238 public boolean getNoWarn() {
239 return mNwarn;
240 }
241
242 /**
243 * Set the identical flag
244 *
245 * @param identical the status to set the flag to
246 */
247 public void setIdentical(boolean identical) {
248 mIdentical = identical;
249 }
250
251 /**
252 * Get identical flag status
253 *
254 * @return boolean containing status of identical flag
255 */
256 public boolean getIdentical() {
257 return mIdentical;
258 }
259
260 /**
261 * Set the full flag
262 *
263 * @param full the status to set the flag to
264 */
265 public void setFull(boolean full) {
266 mFull = full;
267 }
268
269 /**
270 * Get full flag status
271 *
272 * @return boolean containing status of full flag
273 */
274 public boolean getFull() {
275 return mFull;
276 }
277
278 /**
279 * Set the nlabel flag
280 *
281 * @param nlabel the status to set the flag to
282 */
283 public void setNlabel(boolean nlabel) {
284 mNlabel = nlabel;
285 }
286
287 /**
288 * Get nlabel status
289 *
290 * @return boolean containing status of nlabel flag
291 */
292 public boolean getNlabel() {
293 return mNlabel;
294 }
295
296
297 /**
298 * Get the 'comment' command
299 *
300 * @param cmd containing the command line string with or
301 * without the comment flag and string appended
302 */
303 private void getCommentCommand(Commandline cmd) {
304 if (getComment() != null) {
305 /* Had to make two separate commands here because if a space is
306 inserted between the flag and the value, it is treated as a
307 Windows filename with a space and it is enclosed in double
308 quotes ("). This breaks clearcase.
309 */
310 cmd.createArgument().setValue(FLAG_COMMENT);
311 cmd.createArgument().setValue(getComment());
312 }
313 }
314
315 /**
316 * Get the 'commentfile' command
317 *
318 * @param cmd CommandLine containing the command line string with or
319 * without the commentfile flag and file appended
320 */
321 private void getCommentFileCommand(Commandline cmd) {
322 if (getCommentFile() != null) {
323 /* Had to make two separate commands here because if a space is
324 inserted between the flag and the value, it is treated as a
325 Windows filename with a space and it is enclosed in double
326 quotes ("). This breaks clearcase.
327 */
328 cmd.createArgument().setValue(FLAG_COMMENTFILE);
329 cmd.createArgument().setValue(getCommentFile());
330 }
331 }
332
333
334 /**
335 * -c flag -- comment to attach to the file
336 */
337 public static final String FLAG_COMMENT = "-c";
338 /**
339 * -cfile flag -- file containing a comment to attach to the file
340 */
341 public static final String FLAG_COMMENTFILE = "-cfile";
342 /**
343 * -nc flag -- no comment is specified
344 */
345 public static final String FLAG_NOCOMMENT = "-nc";
346 /**
347 * -identical flag -- allows the file to be checked in even if it is identical to the original
348 */
349 public static final String FLAG_IDENTICAL = "-identical";
350 /**
351 * -incremental flag -- baseline to be created is incremental
352 */
353 public static final String FLAG_INCREMENTAL = "-incremental";
354 /**
355 * -full flag -- baseline to be created is full
356 */
357 public static final String FLAG_FULL = "-full";
358 /**
359 * -nlabel -- baseline to be created without a label
360 */
361 public static final String FLAG_NLABEL = "-nlabel";
362
363
364}
Note: See TracBrowser for help on using the repository browser.