KickJava   Java API By Example, From Geeks To Geeks.

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


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 CreateBaseline 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>comment</td>
38  * <td>Specify a comment. Only one of comment or cfile may be
39 used.</td>
40  * <td>No</td>
41  * </tr>
42  * <tr>
43  * <td>commentfile</td>
44  * <td>Specify a file containing a comment. Only one of comment or
45 cfile may be used.</td>
46  * <td>No</td>
47  * </tr>
48  * <tr>
49  * <td>baselinerootname</td>
50  * <td>Specify the name to be associated with the baseline.</td>
51  * <td>Yes</td>
52  * </tr>
53  * <tr>
54  * <td>nowarn</td>
55  * <td>Suppress warning messages</td>
56  * <td>No</td>
57  * <tr>
58  * <tr>
59  * <td>identical</td>
60  * <td>Allows the baseline to be created even if it is identical to the
61 previous baseline.</td>
62  * <td>No</td>
63  * </tr>
64  * <tr>
65  * <td>full</td>
66  * <td>Creates a full baseline.</td>
67  * <td>No</td>
68  * </tr>
69  * <tr>
70  * <td>nlabel</td>
71  * <td>Allows the baseline to be created without a label.</td>
72  * <td>No</td>
73  * </tr>
74  * <tr>
75  * <td>failonerr</td>
76  * <td>Throw an exception if the command fails. Default is true</td>
77  * <td>No</td>
78  * <tr>
79  * </table>
80  *
81  */

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

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

132     private void checkOptions(Commandline cmd) {
133         if (getComment() != null) {
134             // -c
135
getCommentCommand(cmd);
136         } else {
137             if (getCommentFile() != null) {
138                 // -cfile
139
getCommentFileCommand(cmd);
140             } else {
141                 cmd.createArgument().setValue(FLAG_NOCOMMENT);
142             }
143         }
144
145         if (getIdentical()) {
146             // -identical
147
cmd.createArgument().setValue(FLAG_IDENTICAL);
148         }
149
150        if (getFull()) {
151            // -full
152
cmd.createArgument().setValue(FLAG_FULL);
153        } else {
154            // -incremental
155
cmd.createArgument().setValue(FLAG_INCREMENTAL);
156        }
157
158        if (getNlabel()) {
159            // -nlabel
160
cmd.createArgument().setValue(FLAG_NLABEL);
161        }
162
163        // baseline_root_name
164
cmd.createArgument().setValue(getBaselineRootName());
165
166     }
167
168
169     /**
170      * Set comment string
171      *
172      * @param comment the comment string
173      */

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

183     public String JavaDoc getComment() {
184         return mComment;
185     }
186
187     /**
188      * Set comment file
189      *
190      * @param cfile the path to the comment file
191      */

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

201     public String JavaDoc getCommentFile() {
202         return mCfile;
203     }
204
205     /**
206      * Set baseline_root_name
207      *
208      * @param baselineRootName the name of the baseline
209      */

210     public void setBaselineRootName(String JavaDoc baselineRootName) {
211         mBaselineRootName = baselineRootName;
212     }
213
214     /**
215      * Get baseline_root_name
216      *
217      * @return String containing the name of the baseline
218      */

219     public String JavaDoc getBaselineRootName() {
220         return mBaselineRootName;
221     }
222
223     /**
224
225     /**
226      * Set the nowarn flag
227      *
228      * @param nwarn the status to set the flag to
229      */

230     public void setNoWarn(boolean nwarn) {
231         mNwarn = nwarn;
232     }
233
234     /**
235      * Get nowarn flag status
236      *
237      * @return boolean containing status of nwarn flag
238      */

239     public boolean getNoWarn() {
240         return mNwarn;
241     }
242
243     /**
244      * Set the identical flag
245      *
246      * @param identical the status to set the flag to
247      */

248     public void setIdentical(boolean identical) {
249         mIdentical = identical;
250     }
251
252     /**
253      * Get identical flag status
254      *
255      * @return boolean containing status of identical flag
256      */

257     public boolean getIdentical() {
258         return mIdentical;
259     }
260
261     /**
262      * Set the full flag
263      *
264      * @param full the status to set the flag to
265      */

266     public void setFull(boolean full) {
267         mFull = full;
268     }
269
270     /**
271      * Get full flag status
272      *
273      * @return boolean containing status of full flag
274      */

275     public boolean getFull() {
276         return mFull;
277     }
278
279     /**
280      * Set the nlabel flag
281      *
282      * @param nlabel the status to set the flag to
283      */

284     public void setNlabel(boolean nlabel) {
285         mNlabel = nlabel;
286     }
287
288     /**
289      * Get nlabel status
290      *
291      * @return boolean containing status of nlabel flag
292      */

293     public boolean getNlabel() {
294         return mNlabel;
295     }
296
297
298     /**
299      * Get the 'comment' command
300      *
301      * @param cmd containing the command line string with or
302      * without the comment flag and string appended
303      */

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

311             cmd.createArgument().setValue(FLAG_COMMENT);
312             cmd.createArgument().setValue(getComment());
313         }
314     }
315
316     /**
317      * Get the 'commentfile' command
318      *
319      * @param cmd CommandLine containing the command line string with or
320      * without the commentfile flag and file appended
321      */

322     private void getCommentFileCommand(Commandline cmd) {
323         if (getCommentFile() != null) {
324             /* Had to make two separate commands here because if a space is
325                inserted between the flag and the value, it is treated as a
326                Windows filename with a space and it is enclosed in double
327                quotes ("). This breaks clearcase.
328             */

329             cmd.createArgument().setValue(FLAG_COMMENTFILE);
330             cmd.createArgument().setValue(getCommentFile());
331         }
332     }
333
334
335         /**
336      * -c flag -- comment to attach to the file
337      */

338     public static final String JavaDoc FLAG_COMMENT = "-c";
339         /**
340      * -cfile flag -- file containing a comment to attach to the file
341      */

342     public static final String JavaDoc FLAG_COMMENTFILE = "-cfile";
343         /**
344      * -nc flag -- no comment is specified
345      */

346     public static final String JavaDoc FLAG_NOCOMMENT = "-nc";
347         /**
348      * -identical flag -- allows the file to be checked in even if it is identical to the original
349      */

350     public static final String JavaDoc FLAG_IDENTICAL = "-identical";
351        /**
352      * -incremental flag -- baseline to be created is incremental
353      */

354     public static final String JavaDoc FLAG_INCREMENTAL = "-incremental";
355        /**
356      * -full flag -- baseline to be created is full
357      */

358     public static final String JavaDoc FLAG_FULL = "-full";
359        /**
360      * -nlabel -- baseline to be created without a label
361      */

362     public static final String JavaDoc FLAG_NLABEL = "-nlabel";
363
364
365 }
366
Popular Tags