KickJava   Java API By Example, From Geeks To Geeks.

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


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 a ClearCase Update command.
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>graphical</td>
44  * <td>Displays a graphical dialog during the update</td>
45  * <td>No</td>
46  * <tr>
47  * <tr>
48  * <td>log</td>
49  * <td>Specifies a log file for ClearCase to write to</td>
50  * <td>No</td>
51  * <tr>
52  * <tr>
53  * <td>overwrite</td>
54  * <td>Specifies whether to overwrite hijacked files or not</td>
55  * <td>No</td>
56  * <tr>
57  * <tr>
58  * <td>rename</td>
59  * <td>Specifies that hijacked files should be renamed with a .keep extension</td>
60  * <td>No</td>
61  * <tr>
62  * <tr>
63  * <td>currenttime</td>
64  * <td>Specifies that modification time should be written as the current
65  * time. Either currenttime or preservetime can be specified.</td>
66  * <td>No</td>
67  * <tr>
68  * <tr>
69  * <td>preservetime</td>
70  * <td>Specifies that modification time should preserved from the VOB
71  * time. Either currenttime or preservetime can be specified.</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 CCUpdate extends ClearCase {
83     private boolean mGraphical = false;
84     private boolean mOverwrite = false;
85     private boolean mRename = false;
86     private boolean mCtime = false;
87     private boolean mPtime = false;
88     private String JavaDoc mLog = null;
89
90     /**
91      * Executes the task.
92      * <p>
93      * Builds a command line to execute cleartool and then calls Exec's run method
94      * to execute the command line.
95      * @throws BuildException if the command fails and failonerr is set to true
96      */

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

133     private void checkOptions(Commandline cmd) {
134         // ClearCase items
135
if (getGraphical()) {
136             // -graphical
137
cmd.createArgument().setValue(FLAG_GRAPHICAL);
138         } else {
139             if (getOverwrite()) {
140                 // -overwrite
141
cmd.createArgument().setValue(FLAG_OVERWRITE);
142             } else {
143                 if (getRename()) {
144                     // -rename
145
cmd.createArgument().setValue(FLAG_RENAME);
146                 } else {
147                     // -noverwrite
148
cmd.createArgument().setValue(FLAG_NOVERWRITE);
149                 }
150             }
151
152             if (getCurrentTime()) {
153                 // -ctime
154
cmd.createArgument().setValue(FLAG_CURRENTTIME);
155             } else {
156                 if (getPreserveTime()) {
157                     // -ptime
158
cmd.createArgument().setValue(FLAG_PRESERVETIME);
159                 }
160             }
161
162             // -log logname
163
getLogCommand(cmd);
164         }
165
166         // viewpath
167
cmd.createArgument().setValue(getViewPath());
168     }
169
170     /**
171      * If true, displays a graphical dialog during the update.
172      *
173      * @param graphical the status to set the flag to
174      */

175     public void setGraphical(boolean graphical) {
176         mGraphical = graphical;
177     }
178
179     /**
180      * Get graphical flag status
181      *
182      * @return boolean containing status of graphical flag
183      */

184     public boolean getGraphical() {
185         return mGraphical;
186     }
187
188     /**
189      * If true, overwrite hijacked files.
190      *
191      * @param ow the status to set the flag to
192      */

193     public void setOverwrite(boolean ow) {
194         mOverwrite = ow;
195     }
196
197     /**
198      * Get overwrite hijacked files status
199      *
200      * @return boolean containing status of overwrite flag
201      */

202     public boolean getOverwrite() {
203         return mOverwrite;
204     }
205
206     /**
207      * If true, hijacked files are renamed with a .keep extension.
208      *
209      * @param ren the status to set the flag to
210      */

211     public void setRename(boolean ren) {
212         mRename = ren;
213     }
214
215     /**
216      * Get rename hijacked files status
217      *
218      * @return boolean containing status of rename flag
219      */

220     public boolean getRename() {
221         return mRename;
222     }
223
224     /**
225      * If true, modification time should be written as the current time.
226      * Either currenttime or preservetime can be specified.
227      *
228      * @param ct the status to set the flag to
229      */

230     public void setCurrentTime(boolean ct) {
231         mCtime = ct;
232     }
233
234     /**
235      * Get current time status
236      *
237      * @return boolean containing status of current time flag
238      */

239     public boolean getCurrentTime() {
240         return mCtime;
241     }
242
243     /**
244      * If true, modification time should be preserved from the VOB time.
245      * Either currenttime or preservetime can be specified.
246      *
247      * @param pt the status to set the flag to
248      */

249     public void setPreserveTime(boolean pt) {
250         mPtime = pt;
251     }
252
253     /**
254      * Get preserve time status
255      *
256      * @return boolean containing status of preserve time flag
257      */

258     public boolean getPreserveTime() {
259         return mPtime;
260     }
261
262     /**
263      * Sets the log file where cleartool records
264      * the status of the command.
265      *
266      * @param log the path to the log file
267      */

268     public void setLog(String JavaDoc log) {
269         mLog = log;
270     }
271
272     /**
273      * Get log file
274      *
275      * @return String containing the path to the log file
276      */

277     public String JavaDoc getLog() {
278         return mLog;
279     }
280
281
282     /**
283      * Get the 'log' command
284      *
285      * @param cmd containing the command line string with or without the log flag and path appended
286      */

287     private void getLogCommand(Commandline cmd) {
288         if (getLog() == null) {
289             return;
290         } else {
291             /* Had to make two separate commands here because if a space is
292                inserted between the flag and the value, it is treated as a
293                Windows filename with a space and it is enclosed in double
294                quotes ("). This breaks clearcase.
295             */

296             cmd.createArgument().setValue(FLAG_LOG);
297             cmd.createArgument().setValue(getLog());
298         }
299     }
300
301     /**
302      * -graphical flag -- display graphical dialog during update operation
303      */

304     public static final String JavaDoc FLAG_GRAPHICAL = "-graphical";
305     /**
306      * -log flag -- file to log status to
307      */

308     public static final String JavaDoc FLAG_LOG = "-log";
309     /**
310      * -overwrite flag -- overwrite hijacked files
311      */

312     public static final String JavaDoc FLAG_OVERWRITE = "-overwrite";
313     /**
314      * -noverwrite flag -- do not overwrite hijacked files
315      */

316     public static final String JavaDoc FLAG_NOVERWRITE = "-noverwrite";
317     /**
318      * -rename flag -- rename hijacked files with .keep extension
319      */

320     public static final String JavaDoc FLAG_RENAME = "-rename";
321     /**
322      * -ctime flag -- modified time is written as the current time
323      */

324     public static final String JavaDoc FLAG_CURRENTTIME = "-ctime";
325     /**
326      * -ptime flag -- modified time is written as the VOB time
327      */

328     public static final String JavaDoc FLAG_PRESERVETIME = "-ptime";
329
330 }
331
332
Popular Tags