source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCLock.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 10.5 KB
Line 
1/*
2 * Copyright 2003-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/**
27 * TODO:
28 * comment field doesn't include all options yet
29 */
30
31
32
33/**
34 * Performs a ClearCase Lock command.
35 *
36 * <p>
37 * The following attributes are interpreted:
38 * <table border="1">
39 * <tr>
40 * <th>Attribute</th>
41 * <th>Values</th>
42 * <th>Required</th>
43 * </tr>
44 * <tr>
45 * <td>replace</td>
46 * <td>Specifies replacing an existing lock</td>
47 * <td>No</td>
48 * <tr>
49 * <tr>
50 * <td>nusers</td>
51 * <td>Specifies user(s) who can still modify the object/pname</td>
52 * <td>No</td>
53 * <tr>
54 * <tr>
55 * <td>obsolete</td>
56 * <td>Specifies that the object/pname should be marked obsolete</td>
57 * <td>No</td>
58 * <tr>
59 * <tr>
60 * <td>comment</td>
61 * <td>Specifies how to populate comments fields</td>
62 * <td>No</td>
63 * <tr>
64 * <tr>
65 * <td>pname</td>
66 * <td>Specifies the pathname to be locked.</td>
67 * <td>No</td>
68 * <tr>
69 * <td>objselect</td>
70 * <td>This variable is obsolete. Should use <i>objsel</i> instead.</td>
71 * <td>No</td>
72 * <tr>
73 * <tr>
74 * <td>objsel</td>
75 * <td>Specifies the object(s) to be unlocked.</td>
76 * <td>No</td>
77 * <tr>
78 * <tr>
79 * <td>failonerr</td>
80 * <td>Throw an exception if the command fails. Default is true</td>
81 * <td>No</td>
82 * <tr>
83 * </table>
84 *
85 */
86public class CCLock extends ClearCase {
87 private boolean mReplace = false;
88 private boolean mObsolete = false;
89 private String mComment = null;
90 private String mNusers = null;
91 private String mPname = null;
92 private String mObjselect = null;
93
94 /**
95 * Executes the task.
96 * <p>
97 * Builds a command line to execute cleartool and then calls Exec's run method
98 * to execute the command line.
99 * @throws BuildException if the command fails and failonerr is set to true
100 */
101 public void execute() throws BuildException {
102 Commandline commandLine = new Commandline();
103 Project aProj = getProject();
104 int result = 0;
105
106 // Default the viewpath to basedir if it is not specified
107 if (getViewPath() == null) {
108 setViewPath(aProj.getBaseDir().getPath());
109 }
110
111 // build the command line from what we got the format is
112 // cleartool lock [options...]
113 // as specified in the CLEARTOOL.EXE help
114 commandLine.setExecutable(getClearToolCommand());
115 commandLine.createArgument().setValue(COMMAND_LOCK);
116
117 // Check the command line options
118 checkOptions(commandLine);
119
120 // For debugging
121 // System.out.println(commandLine.toString());
122
123 if (!getFailOnErr()) {
124 getProject().log("Ignoring any errors that occur for: "
125 + getOpType(), Project.MSG_VERBOSE);
126 }
127 result = run(commandLine);
128 if (Execute.isFailure(result) && getFailOnErr()) {
129 String msg = "Failed executing: " + commandLine.toString();
130 throw new BuildException(msg, getLocation());
131 }
132 }
133
134 /**
135 * Check the command line options.
136 */
137private void checkOptions(Commandline cmd) {
138 // ClearCase items
139 if (getReplace()) {
140 // -replace
141 cmd.createArgument().setValue(FLAG_REPLACE);
142 }
143 if (getObsolete()) {
144 // -obsolete
145 cmd.createArgument().setValue(FLAG_OBSOLETE);
146 } else {
147 getNusersCommand(cmd);
148 }
149 getCommentCommand(cmd);
150
151 if (getObjselect() == null && getPname() == null) {
152 throw new BuildException("Should select either an element "
153 + "(pname) or an object (objselect)");
154 }
155 getPnameCommand(cmd);
156 // object selector
157 if (getObjselect() != null) {
158 cmd.createArgument().setValue(getObjselect());
159 }
160}
161
162 /**
163 * If true, replace an existing lock.
164 *
165 * @param replace the status to set the flag to
166 */
167 public void setReplace(boolean replace) {
168 mReplace = replace;
169 }
170
171 /**
172 * Get replace flag status
173 *
174 * @return boolean containing status of replace flag
175 */
176 public boolean getReplace() {
177 return mReplace;
178 }
179
180 /**
181 * If true, mark object as obsolete.
182 *
183 * @param obsolete the status to set the flag to
184 */
185 public void setObsolete(boolean obsolete) {
186 mObsolete = obsolete;
187 }
188
189 /**
190 * Get obsolete flag status
191 *
192 * @return boolean containing status of obsolete flag
193 */
194 public boolean getObsolete() {
195 return mObsolete;
196 }
197
198 /**
199 * Sets the users who may continue to
200 * edit the object while it is locked.
201 *
202 * @param nusers users excluded from lock
203 */
204 public void setNusers(String nusers) {
205 mNusers = nusers;
206 }
207
208 /**
209 * Get nusers list
210 *
211 * @return String containing the list of users excluded from lock
212 */
213 public String getNusers() {
214 return mNusers;
215 }
216
217 /**
218 * Sets how comments should be written
219 * for the event record(s)
220 *
221 * @param comment comment method to use
222 */
223 public void setComment(String comment) {
224 mComment = comment;
225 }
226
227 /**
228 * Get comment method
229 *
230 * @return String containing the desired comment method
231 */
232 public String getComment() {
233 return mComment;
234 }
235
236 /**
237 * Sets the pathname to be locked
238 *
239 * @param pname pathname to be locked
240 */
241 public void setPname(String pname) {
242 mPname = pname;
243 }
244
245 /**
246 * Get the pathname to be locked
247 *
248 * @return String containing the pathname to be locked
249 */
250 public String getPname() {
251 return mPname;
252 }
253
254 /**
255 * Sets the object(s) to be locked
256 *
257 * @param objsel objects to be locked
258 * @since ant 1.6.1
259 */
260 public void setObjSel(String objsel) {
261 mObjselect = objsel;
262 }
263
264 /**
265 * Sets the object(s) to be locked
266 *
267 * @param objselect objects to be locked
268 */
269 public void setObjselect(String objselect) {
270 mObjselect = objselect;
271 }
272
273 /**
274 * Get list of objects to be locked
275 *
276 * @return String containing the objects to be locked
277 */
278 public String getObjselect() {
279 return mObjselect;
280 }
281
282 /**
283 * Get the 'nusers' command
284 *
285 * @param cmd containing the command line string with or
286 * without the nusers flag and value appended
287 */
288 private void getNusersCommand(Commandline cmd) {
289 if (getNusers() == null) {
290 return;
291 } else {
292 /* Had to make two separate commands here because if a space is
293 inserted between the flag and the value, it is treated as a
294 Windows filename with a space and it is enclosed in double
295 quotes ("). This breaks clearcase.
296 */
297 cmd.createArgument().setValue(FLAG_NUSERS);
298 cmd.createArgument().setValue(getNusers());
299 }
300 }
301
302 /**
303 * Get the 'comment' command
304 *
305 * @param cmd containing the command line string with or without the
306 * comment flag and value appended
307 */
308 private void getCommentCommand(Commandline cmd) {
309 if (getComment() == null) {
310 return;
311 } else {
312 /* Had to make two separate commands here because if a space is
313 inserted between the flag and the value, it is treated as a
314 Windows filename with a space and it is enclosed in double
315 quotes ("). This breaks clearcase.
316 */
317 cmd.createArgument().setValue(FLAG_COMMENT);
318 cmd.createArgument().setValue(getComment());
319 }
320 }
321
322 /**
323 * Get the 'pname' command
324 *
325 * @param cmd containing the command line string with or
326 * without the pname flag and value appended
327 */
328 private void getPnameCommand(Commandline cmd) {
329 if (getPname() == null) {
330 return;
331 } else {
332 /* Had to make two separate commands here because if a space is
333 inserted between the flag and the value, it is treated as a
334 Windows filename with a space and it is enclosed in double
335 quotes ("). This breaks clearcase.
336 */
337 cmd.createArgument().setValue(FLAG_PNAME);
338 cmd.createArgument().setValue(getPname());
339 }
340 }
341
342 /**
343 * Return which object/pname is being operated on
344 *
345 * @return String containing the object/pname being worked on
346 */
347 private String getOpType() {
348
349 if (getPname() != null) {
350 return getPname();
351 } else {
352 return getObjselect();
353 }
354 }
355
356 /**
357 * -replace flag -- replace existing lock on object(s)
358 */
359 public static final String FLAG_REPLACE = "-replace";
360 /**
361 * -nusers flag -- list of users to exclude from lock
362 */
363 public static final String FLAG_NUSERS = "-nusers";
364 /**
365 * -obsolete flag -- mark locked object as obsolete
366 */
367 public static final String FLAG_OBSOLETE = "-obsolete";
368 /**
369 * -comment flag -- method to use for commenting events
370 */
371 public static final String FLAG_COMMENT = "-comment";
372 /**
373 * -pname flag -- pathname to lock
374 */
375 public static final String FLAG_PNAME = "-pname";
376}
377
Note: See TracBrowser for help on using the repository browser.