source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCCheckin.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.6 KB
Line 
1/*
2 * Copyright 2000,2002-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 checkin.
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>No</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>preservetime</td>
58 * <td>Preserve the modification time</td>
59 * <td>No</td>
60 * <tr>
61 * <tr>
62 * <td>keepcopy</td>
63 * <td>Keeps a copy of the file with a .keep extension</td>
64 * <td>No</td>
65 * <tr>
66 * <tr>
67 * <td>identical</td>
68 * <td>Allows the file to be checked in even if it is identical to the original</td>
69 * <td>No</td>
70 * <tr>
71 * <tr>
72 * <td>failonerr</td>
73 * <td>Throw an exception if the command fails. Default is true</td>
74 * <td>No</td>
75 * <tr>
76 * </table>
77 *
78 */
79public class CCCheckin extends ClearCase {
80 private String mComment = null;
81 private String mCfile = null;
82 private boolean mNwarn = false;
83 private boolean mPtime = false;
84 private boolean mKeep = false;
85 private boolean mIdentical = true;
86
87 /**
88 * Executes the task.
89 * <p>
90 * Builds a command line to execute cleartool and then calls Exec's run method
91 * to execute the command line.
92 * @throws BuildException if the command fails and failonerr is set to true
93 */
94 public void execute() throws BuildException {
95 Commandline commandLine = new Commandline();
96 Project aProj = getProject();
97 int result = 0;
98
99 // Default the viewpath to basedir if it is not specified
100 if (getViewPath() == null) {
101 setViewPath(aProj.getBaseDir().getPath());
102 }
103
104 // build the command line from what we got. the format is
105 // cleartool checkin [options...] [viewpath ...]
106 // as specified in the CLEARTOOL.EXE help
107 commandLine.setExecutable(getClearToolCommand());
108 commandLine.createArgument().setValue(COMMAND_CHECKIN);
109
110 checkOptions(commandLine);
111
112 if (!getFailOnErr()) {
113 getProject().log("Ignoring any errors that occur for: "
114 + getViewPathBasename(), Project.MSG_VERBOSE);
115 }
116 result = run(commandLine);
117 if (Execute.isFailure(result) && getFailOnErr()) {
118 String msg = "Failed executing: " + commandLine.toString();
119 throw new BuildException(msg, getLocation());
120 }
121 }
122
123
124 /**
125 * Check the command line options.
126 */
127 private void checkOptions(Commandline cmd) {
128 if (getComment() != null) {
129 // -c
130 getCommentCommand(cmd);
131 } else {
132 if (getCommentFile() != null) {
133 // -cfile
134 getCommentFileCommand(cmd);
135 } else {
136 cmd.createArgument().setValue(FLAG_NOCOMMENT);
137 }
138 }
139
140 if (getNoWarn()) {
141 // -nwarn
142 cmd.createArgument().setValue(FLAG_NOWARN);
143 }
144
145 if (getPreserveTime()) {
146 // -ptime
147 cmd.createArgument().setValue(FLAG_PRESERVETIME);
148 }
149
150 if (getKeepCopy()) {
151 // -keep
152 cmd.createArgument().setValue(FLAG_KEEPCOPY);
153 }
154
155 if (getIdentical()) {
156 // -identical
157 cmd.createArgument().setValue(FLAG_IDENTICAL);
158 }
159
160 // viewpath
161 cmd.createArgument().setValue(getViewPath());
162 }
163
164
165 /**
166 * Sets the comment string.
167 *
168 * @param comment the comment string
169 */
170 public void setComment(String comment) {
171 mComment = comment;
172 }
173
174 /**
175 * Get comment string
176 *
177 * @return String containing the comment
178 */
179 public String getComment() {
180 return mComment;
181 }
182
183 /**
184 * Specifies a file containing a comment.
185 *
186 * @param cfile the path to the comment file
187 */
188 public void setCommentFile(String cfile) {
189 mCfile = cfile;
190 }
191
192 /**
193 * Get comment file
194 *
195 * @return String containing the path to the comment file
196 */
197 public String getCommentFile() {
198 return mCfile;
199 }
200
201 /**
202 * If true, suppress warning messages.
203 *
204 * @param nwarn the status to set the flag to
205 */
206 public void setNoWarn(boolean nwarn) {
207 mNwarn = nwarn;
208 }
209
210 /**
211 * Get nowarn flag status
212 *
213 * @return boolean containing status of nwarn flag
214 */
215 public boolean getNoWarn() {
216 return mNwarn;
217 }
218
219 /**
220 * If true, preserve the modification time.
221 *
222 * @param ptime the status to set the flag to
223 */
224 public void setPreserveTime(boolean ptime) {
225 mPtime = ptime;
226 }
227
228 /**
229 * Get preservetime flag status
230 *
231 * @return boolean containing status of preservetime flag
232 */
233 public boolean getPreserveTime() {
234 return mPtime;
235 }
236
237 /**
238 * If true, keeps a copy of the file with a .keep extension.
239 *
240 * @param keep the status to set the flag to
241 */
242 public void setKeepCopy(boolean keep) {
243 mKeep = keep;
244 }
245
246 /**
247 * Get keepcopy flag status
248 *
249 * @return boolean containing status of keepcopy flag
250 */
251 public boolean getKeepCopy() {
252 return mKeep;
253 }
254
255 /**
256 * If true, allows the file to be checked in even
257 * if it is identical to the original.
258 *
259 * @param identical the status to set the flag to
260 */
261 public void setIdentical(boolean identical) {
262 mIdentical = identical;
263 }
264
265 /**
266 * Get identical flag status
267 *
268 * @return boolean containing status of identical flag
269 */
270 public boolean getIdentical() {
271 return mIdentical;
272 }
273
274
275 /**
276 * Get the 'comment' command
277 *
278 * @param cmd containing the command line string with or
279 * without the comment flag and string appended
280 */
281 private void getCommentCommand(Commandline cmd) {
282 if (getComment() != null) {
283 /* Had to make two separate commands here because if a space is
284 inserted between the flag and the value, it is treated as a
285 Windows filename with a space and it is enclosed in double
286 quotes ("). This breaks clearcase.
287 */
288 cmd.createArgument().setValue(FLAG_COMMENT);
289 cmd.createArgument().setValue(getComment());
290 }
291 }
292
293 /**
294 * Get the 'commentfile' command
295 *
296 * @param cmd containing the command line string with or
297 * without the commentfile flag and file appended
298 */
299 private void getCommentFileCommand(Commandline cmd) {
300 if (getCommentFile() != null) {
301 /* Had to make two separate commands here because if a space is
302 inserted between the flag and the value, it is treated as a
303 Windows filename with a space and it is enclosed in double
304 quotes ("). This breaks clearcase.
305 */
306 cmd.createArgument().setValue(FLAG_COMMENTFILE);
307 cmd.createArgument().setValue(getCommentFile());
308 }
309 }
310
311
312 /**
313 * -c flag -- comment to attach to the file
314 */
315 public static final String FLAG_COMMENT = "-c";
316 /**
317 * -cfile flag -- file containing a comment to attach to the file
318 */
319 public static final String FLAG_COMMENTFILE = "-cfile";
320 /**
321 * -nc flag -- no comment is specified
322 */
323 public static final String FLAG_NOCOMMENT = "-nc";
324 /**
325 * -nwarn flag -- suppresses warning messages
326 */
327 public static final String FLAG_NOWARN = "-nwarn";
328 /**
329 * -ptime flag -- preserves the modification time
330 */
331 public static final String FLAG_PRESERVETIME = "-ptime";
332 /**
333 * -keep flag -- keeps a copy of the file with a .keep extension
334 */
335 public static final String FLAG_KEEPCOPY = "-keep";
336 /**
337 * -identical flag -- allows the file to be checked in even if it is identical to the original
338 */
339 public static final String FLAG_IDENTICAL = "-identical";
340
341}
342
Note: See TracBrowser for help on using the repository browser.