KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Performs ClearCase checkin.
28  *
29  * <p>
30  * The following attributes are interpreted:
31  * <table border="1">
32  * <tr>
33  * <th>Attribute</th>
34  * <th>Values</th>
35  * <th>Required</th>
36  * </tr>
37  * <tr>
38  * <td>viewpath</td>
39  * <td>Path to the ClearCase view file or directory that the command will operate on</td>
40  * <td>No</td>
41  * <tr>
42  * <tr>
43  * <td>comment</td>
44  * <td>Specify a comment. Only one of comment or cfile may be used.</td>
45  * <td>No</td>
46  * <tr>
47  * <tr>
48  * <td>commentfile</td>
49  * <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
50  * <td>No</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>preservetime</td>
59  * <td>Preserve the modification time</td>
60  * <td>No</td>
61  * <tr>
62  * <tr>
63  * <td>keepcopy</td>
64  * <td>Keeps a copy of the file with a .keep extension</td>
65  * <td>No</td>
66  * <tr>
67  * <tr>
68  * <td>identical</td>
69  * <td>Allows the file to be checked in even if it is identical to the original</td>
70  * <td>No</td>
71  * <tr>
72  * <tr>
73  * <td>failonerr</td>
74  * <td>Throw an exception if the command fails. Default is true</td>
75  * <td>No</td>
76  * <tr>
77  * </table>
78  *
79  */

80 public class CCCheckin extends ClearCase {
81     private String JavaDoc mComment = null;
82     private String JavaDoc mCfile = null;
83     private boolean mNwarn = false;
84     private boolean mPtime = false;
85     private boolean mKeep = false;
86     private boolean mIdentical = true;
87
88     /**
89      * Executes the task.
90      * <p>
91      * Builds a command line to execute cleartool and then calls Exec's run method
92      * to execute the command line.
93      * @throws BuildException if the command fails and failonerr is set to true
94      */

95     public void execute() throws BuildException {
96         Commandline commandLine = new Commandline();
97         Project aProj = getProject();
98         int result = 0;
99
100         // Default the viewpath to basedir if it is not specified
101
if (getViewPath() == null) {
102             setViewPath(aProj.getBaseDir().getPath());
103         }
104
105         // build the command line from what we got. the format is
106
// cleartool checkin [options...] [viewpath ...]
107
// as specified in the CLEARTOOL.EXE help
108
commandLine.setExecutable(getClearToolCommand());
109         commandLine.createArgument().setValue(COMMAND_CHECKIN);
110
111         checkOptions(commandLine);
112
113         if (!getFailOnErr()) {
114             getProject().log("Ignoring any errors that occur for: "
115                     + getViewPathBasename(), Project.MSG_VERBOSE);
116         }
117         result = run(commandLine);
118         if (Execute.isFailure(result) && getFailOnErr()) {
119             String JavaDoc msg = "Failed executing: " + commandLine.toString();
120             throw new BuildException(msg, getLocation());
121         }
122     }
123
124
125     /**
126      * Check the command line options.
127      */

128     private void checkOptions(Commandline cmd) {
129         if (getComment() != null) {
130             // -c
131
getCommentCommand(cmd);
132         } else {
133             if (getCommentFile() != null) {
134                 // -cfile
135
getCommentFileCommand(cmd);
136             } else {
137                 cmd.createArgument().setValue(FLAG_NOCOMMENT);
138             }
139         }
140
141         if (getNoWarn()) {
142             // -nwarn
143
cmd.createArgument().setValue(FLAG_NOWARN);
144         }
145
146         if (getPreserveTime()) {
147             // -ptime
148
cmd.createArgument().setValue(FLAG_PRESERVETIME);
149         }
150
151         if (getKeepCopy()) {
152             // -keep
153
cmd.createArgument().setValue(FLAG_KEEPCOPY);
154         }
155
156         if (getIdentical()) {
157             // -identical
158
cmd.createArgument().setValue(FLAG_IDENTICAL);
159         }
160
161         // viewpath
162
cmd.createArgument().setValue(getViewPath());
163     }
164
165
166     /**
167      * Sets the comment string.
168      *
169      * @param comment the comment string
170      */

171     public void setComment(String JavaDoc comment) {
172         mComment = comment;
173     }
174
175     /**
176      * Get comment string
177      *
178      * @return String containing the comment
179      */

180     public String JavaDoc getComment() {
181         return mComment;
182     }
183
184     /**
185      * Specifies a file containing a comment.
186      *
187      * @param cfile the path to the comment file
188      */

189     public void setCommentFile(String JavaDoc cfile) {
190         mCfile = cfile;
191     }
192
193     /**
194      * Get comment file
195      *
196      * @return String containing the path to the comment file
197      */

198     public String JavaDoc getCommentFile() {
199         return mCfile;
200     }
201
202     /**
203      * If true, suppress warning messages.
204      *
205      * @param nwarn the status to set the flag to
206      */

207     public void setNoWarn(boolean nwarn) {
208         mNwarn = nwarn;
209     }
210
211     /**
212      * Get nowarn flag status
213      *
214      * @return boolean containing status of nwarn flag
215      */

216     public boolean getNoWarn() {
217         return mNwarn;
218     }
219
220     /**
221      * If true, preserve the modification time.
222      *
223      * @param ptime the status to set the flag to
224      */

225     public void setPreserveTime(boolean ptime) {
226         mPtime = ptime;
227     }
228
229     /**
230      * Get preservetime flag status
231      *
232      * @return boolean containing status of preservetime flag
233      */

234     public boolean getPreserveTime() {
235         return mPtime;
236     }
237
238     /**
239      * If true, keeps a copy of the file with a .keep extension.
240      *
241      * @param keep the status to set the flag to
242      */

243     public void setKeepCopy(boolean keep) {
244         mKeep = keep;
245     }
246
247     /**
248      * Get keepcopy flag status
249      *
250      * @return boolean containing status of keepcopy flag
251      */

252     public boolean getKeepCopy() {
253         return mKeep;
254     }
255
256     /**
257      * If true, allows the file to be checked in even
258      * if it is identical to the original.
259      *
260      * @param identical the status to set the flag to
261      */

262     public void setIdentical(boolean identical) {
263         mIdentical = identical;
264     }
265
266     /**
267      * Get identical flag status
268      *
269      * @return boolean containing status of identical flag
270      */

271     public boolean getIdentical() {
272         return mIdentical;
273     }
274
275
276     /**
277      * Get the 'comment' command
278      *
279      * @param cmd containing the command line string with or
280      * without the comment flag and string appended
281      */

282     private void getCommentCommand(Commandline cmd) {
283         if (getComment() != null) {
284             /* Had to make two separate commands here because if a space is
285                inserted between the flag and the value, it is treated as a
286                Windows filename with a space and it is enclosed in double
287                quotes ("). This breaks clearcase.
288             */

289             cmd.createArgument().setValue(FLAG_COMMENT);
290             cmd.createArgument().setValue(getComment());
291         }
292     }
293
294     /**
295      * Get the 'commentfile' command
296      *
297      * @param cmd containing the command line string with or
298      * without the commentfile flag and file appended
299      */

300     private void getCommentFileCommand(Commandline cmd) {
301         if (getCommentFile() != null) {
302             /* Had to make two separate commands here because if a space is
303                inserted between the flag and the value, it is treated as a
304                Windows filename with a space and it is enclosed in double
305                quotes ("). This breaks clearcase.
306             */

307             cmd.createArgument().setValue(FLAG_COMMENTFILE);
308             cmd.createArgument().setValue(getCommentFile());
309         }
310     }
311
312
313         /**
314      * -c flag -- comment to attach to the file
315      */

316     public static final String JavaDoc FLAG_COMMENT = "-c";
317         /**
318      * -cfile flag -- file containing a comment to attach to the file
319      */

320     public static final String JavaDoc FLAG_COMMENTFILE = "-cfile";
321         /**
322      * -nc flag -- no comment is specified
323      */

324     public static final String JavaDoc FLAG_NOCOMMENT = "-nc";
325         /**
326      * -nwarn flag -- suppresses warning messages
327      */

328     public static final String JavaDoc FLAG_NOWARN = "-nwarn";
329         /**
330      * -ptime flag -- preserves the modification time
331      */

332     public static final String JavaDoc FLAG_PRESERVETIME = "-ptime";
333         /**
334      * -keep flag -- keeps a copy of the file with a .keep extension
335      */

336     public static final String JavaDoc FLAG_KEEPCOPY = "-keep";
337         /**
338      * -identical flag -- allows the file to be checked in even if it is identical to the original
339      */

340     public static final String JavaDoc FLAG_IDENTICAL = "-identical";
341
342 }
343
344
Popular Tags