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 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.clearcase;
|
---|
19 |
|
---|
20 | import org.apache.tools.ant.BuildException;
|
---|
21 | import org.apache.tools.ant.Project;
|
---|
22 | import org.apache.tools.ant.taskdefs.Execute;
|
---|
23 | import org.apache.tools.ant.types.Commandline;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Performs a ClearCase Update command.
|
---|
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>graphical</td>
|
---|
43 | * <td>Displays a graphical dialog during the update</td>
|
---|
44 | * <td>No</td>
|
---|
45 | * <tr>
|
---|
46 | * <tr>
|
---|
47 | * <td>log</td>
|
---|
48 | * <td>Specifies a log file for ClearCase to write to</td>
|
---|
49 | * <td>No</td>
|
---|
50 | * <tr>
|
---|
51 | * <tr>
|
---|
52 | * <td>overwrite</td>
|
---|
53 | * <td>Specifies whether to overwrite hijacked files or not</td>
|
---|
54 | * <td>No</td>
|
---|
55 | * <tr>
|
---|
56 | * <tr>
|
---|
57 | * <td>rename</td>
|
---|
58 | * <td>Specifies that hijacked files should be renamed with a .keep extension</td>
|
---|
59 | * <td>No</td>
|
---|
60 | * <tr>
|
---|
61 | * <tr>
|
---|
62 | * <td>currenttime</td>
|
---|
63 | * <td>Specifies that modification time should be written as the current
|
---|
64 | * time. Either currenttime or preservetime can be specified.</td>
|
---|
65 | * <td>No</td>
|
---|
66 | * <tr>
|
---|
67 | * <tr>
|
---|
68 | * <td>preservetime</td>
|
---|
69 | * <td>Specifies that modification time should preserved from the VOB
|
---|
70 | * time. Either currenttime or preservetime can be specified.</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 | */
|
---|
81 | public class CCUpdate extends ClearCase {
|
---|
82 | private boolean mGraphical = false;
|
---|
83 | private boolean mOverwrite = false;
|
---|
84 | private boolean mRename = false;
|
---|
85 | private boolean mCtime = false;
|
---|
86 | private boolean mPtime = false;
|
---|
87 | private String mLog = null;
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Executes the task.
|
---|
91 | * <p>
|
---|
92 | * Builds a command line to execute cleartool and then calls Exec's run method
|
---|
93 | * to execute the command line.
|
---|
94 | * @throws BuildException if the command fails and failonerr is set to true
|
---|
95 | */
|
---|
96 | public void execute() throws BuildException {
|
---|
97 | Commandline commandLine = new Commandline();
|
---|
98 | Project aProj = getProject();
|
---|
99 | int result = 0;
|
---|
100 |
|
---|
101 | // Default the viewpath to basedir if it is not specified
|
---|
102 | if (getViewPath() == null) {
|
---|
103 | setViewPath(aProj.getBaseDir().getPath());
|
---|
104 | }
|
---|
105 |
|
---|
106 | // build the command line from what we got the format is
|
---|
107 | // cleartool update [options...] [viewpath ...]
|
---|
108 | // as specified in the CLEARTOOL.EXE help
|
---|
109 | commandLine.setExecutable(getClearToolCommand());
|
---|
110 | commandLine.createArgument().setValue(COMMAND_UPDATE);
|
---|
111 |
|
---|
112 | // Check the command line options
|
---|
113 | checkOptions(commandLine);
|
---|
114 |
|
---|
115 | // For debugging
|
---|
116 | getProject().log(commandLine.toString(), Project.MSG_DEBUG);
|
---|
117 |
|
---|
118 | if (!getFailOnErr()) {
|
---|
119 | getProject().log("Ignoring any errors that occur for: "
|
---|
120 | + getViewPathBasename(), Project.MSG_VERBOSE);
|
---|
121 | }
|
---|
122 | result = run(commandLine);
|
---|
123 | if (Execute.isFailure(result) && getFailOnErr()) {
|
---|
124 | String msg = "Failed executing: " + commandLine.toString();
|
---|
125 | throw new BuildException(msg, getLocation());
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Check the command line options.
|
---|
131 | */
|
---|
132 | private void checkOptions(Commandline cmd) {
|
---|
133 | // ClearCase items
|
---|
134 | if (getGraphical()) {
|
---|
135 | // -graphical
|
---|
136 | cmd.createArgument().setValue(FLAG_GRAPHICAL);
|
---|
137 | } else {
|
---|
138 | if (getOverwrite()) {
|
---|
139 | // -overwrite
|
---|
140 | cmd.createArgument().setValue(FLAG_OVERWRITE);
|
---|
141 | } else {
|
---|
142 | if (getRename()) {
|
---|
143 | // -rename
|
---|
144 | cmd.createArgument().setValue(FLAG_RENAME);
|
---|
145 | } else {
|
---|
146 | // -noverwrite
|
---|
147 | cmd.createArgument().setValue(FLAG_NOVERWRITE);
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (getCurrentTime()) {
|
---|
152 | // -ctime
|
---|
153 | cmd.createArgument().setValue(FLAG_CURRENTTIME);
|
---|
154 | } else {
|
---|
155 | if (getPreserveTime()) {
|
---|
156 | // -ptime
|
---|
157 | cmd.createArgument().setValue(FLAG_PRESERVETIME);
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | // -log logname
|
---|
162 | getLogCommand(cmd);
|
---|
163 | }
|
---|
164 |
|
---|
165 | // viewpath
|
---|
166 | cmd.createArgument().setValue(getViewPath());
|
---|
167 | }
|
---|
168 |
|
---|
169 | /**
|
---|
170 | * If true, displays a graphical dialog during the update.
|
---|
171 | *
|
---|
172 | * @param graphical the status to set the flag to
|
---|
173 | */
|
---|
174 | public void setGraphical(boolean graphical) {
|
---|
175 | mGraphical = graphical;
|
---|
176 | }
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Get graphical flag status
|
---|
180 | *
|
---|
181 | * @return boolean containing status of graphical flag
|
---|
182 | */
|
---|
183 | public boolean getGraphical() {
|
---|
184 | return mGraphical;
|
---|
185 | }
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * If true, overwrite hijacked files.
|
---|
189 | *
|
---|
190 | * @param ow the status to set the flag to
|
---|
191 | */
|
---|
192 | public void setOverwrite(boolean ow) {
|
---|
193 | mOverwrite = ow;
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Get overwrite hijacked files status
|
---|
198 | *
|
---|
199 | * @return boolean containing status of overwrite flag
|
---|
200 | */
|
---|
201 | public boolean getOverwrite() {
|
---|
202 | return mOverwrite;
|
---|
203 | }
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * If true, hijacked files are renamed with a .keep extension.
|
---|
207 | *
|
---|
208 | * @param ren the status to set the flag to
|
---|
209 | */
|
---|
210 | public void setRename(boolean ren) {
|
---|
211 | mRename = ren;
|
---|
212 | }
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Get rename hijacked files status
|
---|
216 | *
|
---|
217 | * @return boolean containing status of rename flag
|
---|
218 | */
|
---|
219 | public boolean getRename() {
|
---|
220 | return mRename;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * If true, modification time should be written as the current time.
|
---|
225 | * Either currenttime or preservetime can be specified.
|
---|
226 | *
|
---|
227 | * @param ct the status to set the flag to
|
---|
228 | */
|
---|
229 | public void setCurrentTime(boolean ct) {
|
---|
230 | mCtime = ct;
|
---|
231 | }
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Get current time status
|
---|
235 | *
|
---|
236 | * @return boolean containing status of current time flag
|
---|
237 | */
|
---|
238 | public boolean getCurrentTime() {
|
---|
239 | return mCtime;
|
---|
240 | }
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * If true, modification time should be preserved from the VOB time.
|
---|
244 | * Either currenttime or preservetime can be specified.
|
---|
245 | *
|
---|
246 | * @param pt the status to set the flag to
|
---|
247 | */
|
---|
248 | public void setPreserveTime(boolean pt) {
|
---|
249 | mPtime = pt;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Get preserve time status
|
---|
254 | *
|
---|
255 | * @return boolean containing status of preserve time flag
|
---|
256 | */
|
---|
257 | public boolean getPreserveTime() {
|
---|
258 | return mPtime;
|
---|
259 | }
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Sets the log file where cleartool records
|
---|
263 | * the status of the command.
|
---|
264 | *
|
---|
265 | * @param log the path to the log file
|
---|
266 | */
|
---|
267 | public void setLog(String log) {
|
---|
268 | mLog = log;
|
---|
269 | }
|
---|
270 |
|
---|
271 | /**
|
---|
272 | * Get log file
|
---|
273 | *
|
---|
274 | * @return String containing the path to the log file
|
---|
275 | */
|
---|
276 | public String getLog() {
|
---|
277 | return mLog;
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * Get the 'log' command
|
---|
283 | *
|
---|
284 | * @param cmd containing the command line string with or without the log flag and path appended
|
---|
285 | */
|
---|
286 | private void getLogCommand(Commandline cmd) {
|
---|
287 | if (getLog() == null) {
|
---|
288 | return;
|
---|
289 | } else {
|
---|
290 | /* Had to make two separate commands here because if a space is
|
---|
291 | inserted between the flag and the value, it is treated as a
|
---|
292 | Windows filename with a space and it is enclosed in double
|
---|
293 | quotes ("). This breaks clearcase.
|
---|
294 | */
|
---|
295 | cmd.createArgument().setValue(FLAG_LOG);
|
---|
296 | cmd.createArgument().setValue(getLog());
|
---|
297 | }
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * -graphical flag -- display graphical dialog during update operation
|
---|
302 | */
|
---|
303 | public static final String FLAG_GRAPHICAL = "-graphical";
|
---|
304 | /**
|
---|
305 | * -log flag -- file to log status to
|
---|
306 | */
|
---|
307 | public static final String FLAG_LOG = "-log";
|
---|
308 | /**
|
---|
309 | * -overwrite flag -- overwrite hijacked files
|
---|
310 | */
|
---|
311 | public static final String FLAG_OVERWRITE = "-overwrite";
|
---|
312 | /**
|
---|
313 | * -noverwrite flag -- do not overwrite hijacked files
|
---|
314 | */
|
---|
315 | public static final String FLAG_NOVERWRITE = "-noverwrite";
|
---|
316 | /**
|
---|
317 | * -rename flag -- rename hijacked files with .keep extension
|
---|
318 | */
|
---|
319 | public static final String FLAG_RENAME = "-rename";
|
---|
320 | /**
|
---|
321 | * -ctime flag -- modified time is written as the current time
|
---|
322 | */
|
---|
323 | public static final String FLAG_CURRENTTIME = "-ctime";
|
---|
324 | /**
|
---|
325 | * -ptime flag -- modified time is written as the VOB time
|
---|
326 | */
|
---|
327 | public static final String FLAG_PRESERVETIME = "-ptime";
|
---|
328 |
|
---|
329 | }
|
---|
330 |
|
---|