source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCUnlock.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 7.3 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 * TODO:
27 * comment field doesn't include all options yet
28 */
29
30
31/**
32 * Performs a ClearCase Unlock command.
33 *
34 * <p>
35 * The following attributes are interpreted:
36 * <table border="1">
37 * <tr>
38 * <th>Attribute</th>
39 * <th>Values</th>
40 * <th>Required</th>
41 * </tr>
42 * <tr>
43 * <td>comment</td>
44 * <td>Specifies how to populate comments fields</td>
45 * <td>No</td>
46 * <tr>
47 * <tr>
48 * <td>pname</td>
49 * <td>Specifies the object pathname to be unlocked.</td>
50 * <td>No</td>
51 * <tr>
52 * <td>objselect</td>
53 * <td>This variable is obsolete. Should use <i>objsel</i> instead.</td>
54 * <td>no</td>
55 * <tr>
56 * <tr>
57 * <td>objsel</td>
58 * <td>Specifies the object(s) to be unlocked.</td>
59 * <td>No</td>
60 * <tr>
61 * <tr>
62 * <td>failonerr</td>
63 * <td>Throw an exception if the command fails. Default is true</td>
64 * <td>No</td>
65 * <tr>
66 *
67 * </table>
68 *
69 */
70public class CCUnlock extends ClearCase {
71 private String mComment = null;
72 private String mPname = null;
73 private String mObjselect = null;
74
75 /**
76 * Executes the task.
77 * <p>
78 * Builds a command line to execute cleartool and then calls Exec's run method
79 * to execute the command line.
80 * @throws BuildException if the command fails and failonerr is set to true
81 */
82 public void execute() throws BuildException {
83 Commandline commandLine = new Commandline();
84 Project aProj = getProject();
85 int result = 0;
86
87 // Default the viewpath to basedir if it is not specified
88 if (getViewPath() == null) {
89 setViewPath(aProj.getBaseDir().getPath());
90 }
91
92 // build the command line from what we got the format is
93 // cleartool lock [options...]
94 // as specified in the CLEARTOOL.EXE help
95 commandLine.setExecutable(getClearToolCommand());
96 commandLine.createArgument().setValue(COMMAND_UNLOCK);
97
98 // Check the command line options
99 checkOptions(commandLine);
100
101 // For debugging
102 // System.out.println(commandLine.toString());
103
104 if (!getFailOnErr()) {
105 getProject().log("Ignoring any errors that occur for: "
106 + getOpType(), Project.MSG_VERBOSE);
107 }
108 result = run(commandLine);
109 if (Execute.isFailure(result) && getFailOnErr()) {
110 String msg = "Failed executing: " + commandLine.toString();
111 throw new BuildException(msg, getLocation());
112 }
113 }
114
115 /**
116 * Check the command line options.
117 */
118private void checkOptions(Commandline cmd) {
119 // ClearCase items
120 getCommentCommand(cmd);
121
122 if (getObjselect() == null && getPname() == null) {
123 throw new BuildException("Should select either an element "
124 + "(pname) or an object (objselect)");
125 }
126 getPnameCommand(cmd);
127 // object selector
128 if (getObjselect() != null) {
129 cmd.createArgument().setValue(getObjselect());
130 }
131}
132
133 /**
134 * Sets how comments should be written
135 * for the event record(s)
136 *
137 * @param comment comment method to use
138 */
139 public void setComment(String comment) {
140 mComment = comment;
141 }
142
143 /**
144 * Get comment method
145 *
146 * @return String containing the desired comment method
147 */
148 public String getComment() {
149 return mComment;
150 }
151
152 /**
153 * Sets the pathname to be locked
154 *
155 * @param pname pathname to be locked
156 */
157 public void setPname(String pname) {
158 mPname = pname;
159 }
160
161 /**
162 * Get the pathname to be locked
163 *
164 * @return String containing the pathname to be locked
165 */
166 public String getPname() {
167 return mPname;
168 }
169
170 /**
171 * Sets the object(s) to be locked
172 *
173 * @param objselect objects to be locked
174 */
175 public void setObjselect(String objselect) {
176 mObjselect = objselect;
177 }
178
179 /**
180 * Sets the object(s) to be locked
181 *
182 * @param objsel objects to be locked
183 * @since ant 1.6.1
184 */
185 public void setObjSel(String objsel) {
186 mObjselect = objsel;
187 }
188
189 /**
190 * Get list of objects to be locked
191 *
192 * @return String containing the objects to be locked
193 */
194 public String getObjselect() {
195 return mObjselect;
196 }
197
198
199 /**
200 * Get the 'comment' command
201 *
202 * @param cmd containing the command line string with or without the
203 * comment flag and value appended
204 */
205 private void getCommentCommand(Commandline cmd) {
206 if (getComment() == null) {
207 return;
208 } else {
209 /* Had to make two separate commands here because if a space is
210 inserted between the flag and the value, it is treated as a
211 Windows filename with a space and it is enclosed in double
212 quotes ("). This breaks clearcase.
213 */
214 cmd.createArgument().setValue(FLAG_COMMENT);
215 cmd.createArgument().setValue(getComment());
216 }
217 }
218
219 /**
220 * Get the 'pname' command
221 *
222 * @param cmd containing the command line string with or without the
223 * pname flag and value appended
224 */
225 private void getPnameCommand(Commandline cmd) {
226 if (getPname() == null) {
227 return;
228 } else {
229 /* Had to make two separate commands here because if a space is
230 inserted between the flag and the value, it is treated as a
231 Windows filename with a space and it is enclosed in double
232 quotes ("). This breaks clearcase.
233 */
234 cmd.createArgument().setValue(FLAG_PNAME);
235 cmd.createArgument().setValue(getPname());
236 }
237 }
238
239 /**
240 * Return which object/pname is being operated on
241 *
242 * @return String containing the object/pname being worked on
243 */
244 private String getOpType() {
245
246 if (getPname() != null) {
247 return getPname();
248 } else {
249 return getObjselect();
250 }
251 }
252
253 /**
254 * -comment flag -- method to use for commenting events
255 */
256 public static final String FLAG_COMMENT = "-comment";
257 /**
258 * -pname flag -- pathname to lock
259 */
260 public static final String FLAG_PNAME = "-pname";
261}
262
Note: See TracBrowser for help on using the repository browser.