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

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

initial import of LiRK3

File size: 7.0 KB
Line 
1/*
2 * Copyright 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 * Performs ClearCase mkdir.
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 directory that the command will operate on</td>
39 * <td>Yes</td>
40 * <tr>
41 * <tr>
42 * <td>comment</td>
43 * <td>Specify a comment. Only one of comment or cfile may be used.</td>
44 * <td>No</td>
45 * <tr>
46 * <tr>
47 * <td>commentfile</td>
48 * <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
49 * <td>No</td>
50 * <tr>
51 * <tr>
52 * <td>nocheckout</td>
53 * <td>Do not checkout after element creation</td>
54 * <td>No</td>
55 * <tr>
56 * <tr>
57 * <td>failonerr</td>
58 * <td>Throw an exception if the command fails. Default is true</td>
59 * <td>No</td>
60 * <tr>
61 * </table>
62 *
63 */
64public class CCMkdir extends ClearCase {
65 private String mComment = null;
66 private String mCfile = null;
67 private boolean mNoco = false;
68
69 /**
70 * Executes the task.
71 * <p>
72 * Builds a command line to execute cleartool and then calls Exec's run method
73 * to execute the command line.
74 * @throws BuildException if the command fails and failonerr is set to true
75 */
76 public void execute() throws BuildException {
77 Commandline commandLine = new Commandline();
78 Project aProj = getProject();
79 int result = 0;
80
81 // Default the viewpath to basedir if it is not specified
82 if (getViewPath() == null) {
83 setViewPath(aProj.getBaseDir().getPath());
84 }
85
86 // build the command line from what we got. the format is
87 // cleartool mkelem [options...] [viewpath ...]
88 // as specified in the CLEARTOOL.EXE help
89 commandLine.setExecutable(getClearToolCommand());
90 commandLine.createArgument().setValue(COMMAND_MKDIR);
91
92 checkOptions(commandLine);
93
94 if (!getFailOnErr()) {
95 getProject().log("Ignoring any errors that occur for: "
96 + getViewPathBasename(), Project.MSG_VERBOSE);
97 }
98 result = run(commandLine);
99 if (Execute.isFailure(result) && getFailOnErr()) {
100 String msg = "Failed executing: " + commandLine.toString();
101 throw new BuildException(msg, getLocation());
102 }
103 }
104
105 /**
106 * Check the command line options.
107 */
108 private void checkOptions(Commandline cmd) {
109 if (getComment() != null) {
110 // -c
111 getCommentCommand(cmd);
112 } else {
113 if (getCommentFile() != null) {
114 // -cfile
115 getCommentFileCommand(cmd);
116 } else {
117 cmd.createArgument().setValue(FLAG_NOCOMMENT);
118 }
119 }
120 if (getNoCheckout()) {
121 // -nco
122 cmd.createArgument().setValue(FLAG_NOCHECKOUT);
123 }
124 // viewpath
125 cmd.createArgument().setValue(getViewPath());
126 }
127
128 /**
129 * Sets the comment string.
130 *
131 * @param comment the comment string
132 */
133 public void setComment(String comment) {
134 mComment = comment;
135 }
136
137 /**
138 * Get comment string
139 *
140 * @return String containing the comment
141 */
142 public String getComment() {
143 return mComment;
144 }
145
146 /**
147 * Specifies a file containing a comment.
148 *
149 * @param cfile the path to the comment file
150 */
151 public void setCommentFile(String cfile) {
152 mCfile = cfile;
153 }
154
155 /**
156 * Get comment file
157 *
158 * @return String containing the path to the comment file
159 */
160 public String getCommentFile() {
161 return mCfile;
162 }
163
164 /**
165 * If true, do not checkout element after creation.
166 *
167 * @param co the status to set the flag to
168 */
169 public void setNoCheckout(boolean co) {
170 mNoco = co;
171 }
172
173 /**
174 * Get no checkout flag status
175 *
176 * @return boolean containing status of noco flag
177 */
178 public boolean getNoCheckout() {
179 return mNoco;
180 }
181
182
183 /**
184 * Get the 'comment' command
185 *
186 * @param cmd containing the command line string with or
187 * without the comment flag and string appended
188 */
189 private void getCommentCommand(Commandline cmd) {
190 if (getComment() != null) {
191 /* Had to make two separate commands here because if a space is
192 inserted between the flag and the value, it is treated as a
193 Windows filename with a space and it is enclosed in double
194 quotes ("). This breaks clearcase.
195 */
196 cmd.createArgument().setValue(FLAG_COMMENT);
197 cmd.createArgument().setValue(getComment());
198 }
199 }
200
201 /**
202 * Get the 'commentfile' command
203 *
204 * @param cmd containing the command line string with or
205 * without the commentfile flag and file appended
206 */
207 private void getCommentFileCommand(Commandline cmd) {
208 if (getCommentFile() != null) {
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_COMMENTFILE);
215 cmd.createArgument().setValue(getCommentFile());
216 }
217 }
218
219 /**
220 * -c flag -- comment to attach to the directory
221 */
222 public static final String FLAG_COMMENT = "-c";
223 /**
224 * -cfile flag -- file containing a comment to attach to the directory
225 */
226 public static final String FLAG_COMMENTFILE = "-cfile";
227 /**
228 * -nc flag -- no comment is specified
229 */
230 public static final String FLAG_NOCOMMENT = "-nc";
231 /**
232 * -nco flag -- do not checkout element after creation
233 */
234 public static final String FLAG_NOCHECKOUT = "-nco";
235}
236
Note: See TracBrowser for help on using the repository browser.