KickJava   Java API By Example, From Geeks To Geeks.

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


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 ClearCase mkdir.
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 directory that the command will operate on</td>
40  * <td>Yes</td>
41  * <tr>
42  * <tr>
43  * <td>comment</td>
44  * <td>Specify a comment. Only one of comment or cfile may be used.</td>
45  * <td>No</td>
46  * <tr>
47  * <tr>
48  * <td>commentfile</td>
49  * <td>Specify a file containing a comment. Only one of comment or cfile may be used.</td>
50  * <td>No</td>
51  * <tr>
52  * <tr>
53  * <td>nocheckout</td>
54  * <td>Do not checkout after element creation</td>
55  * <td>No</td>
56  * <tr>
57  * <tr>
58  * <td>failonerr</td>
59  * <td>Throw an exception if the command fails. Default is true</td>
60  * <td>No</td>
61  * <tr>
62  * </table>
63  *
64  */

65 public class CCMkdir extends ClearCase {
66     private String JavaDoc mComment = null;
67     private String JavaDoc mCfile = null;
68     private boolean mNoco = false;
69
70     /**
71      * Executes the task.
72      * <p>
73      * Builds a command line to execute cleartool and then calls Exec's run method
74      * to execute the command line.
75      * @throws BuildException if the command fails and failonerr is set to true
76      */

77     public void execute() throws BuildException {
78         Commandline commandLine = new Commandline();
79         Project aProj = getProject();
80         int result = 0;
81
82         // Default the viewpath to basedir if it is not specified
83
if (getViewPath() == null) {
84             setViewPath(aProj.getBaseDir().getPath());
85         }
86
87         // build the command line from what we got. the format is
88
// cleartool mkelem [options...] [viewpath ...]
89
// as specified in the CLEARTOOL.EXE help
90
commandLine.setExecutable(getClearToolCommand());
91         commandLine.createArgument().setValue(COMMAND_MKDIR);
92
93         checkOptions(commandLine);
94
95         if (!getFailOnErr()) {
96             getProject().log("Ignoring any errors that occur for: "
97                     + getViewPathBasename(), Project.MSG_VERBOSE);
98         }
99         result = run(commandLine);
100         if (Execute.isFailure(result) && getFailOnErr()) {
101             String JavaDoc msg = "Failed executing: " + commandLine.toString();
102             throw new BuildException(msg, getLocation());
103         }
104     }
105
106     /**
107      * Check the command line options.
108      */

109     private void checkOptions(Commandline cmd) {
110         if (getComment() != null) {
111             // -c
112
getCommentCommand(cmd);
113         } else {
114             if (getCommentFile() != null) {
115                 // -cfile
116
getCommentFileCommand(cmd);
117             } else {
118                 cmd.createArgument().setValue(FLAG_NOCOMMENT);
119             }
120         }
121         if (getNoCheckout()) {
122             // -nco
123
cmd.createArgument().setValue(FLAG_NOCHECKOUT);
124         }
125         // viewpath
126
cmd.createArgument().setValue(getViewPath());
127     }
128
129     /**
130      * Sets the comment string.
131      *
132      * @param comment the comment string
133      */

134     public void setComment(String JavaDoc comment) {
135         mComment = comment;
136     }
137
138     /**
139      * Get comment string
140      *
141      * @return String containing the comment
142      */

143     public String JavaDoc getComment() {
144         return mComment;
145     }
146
147     /**
148      * Specifies a file containing a comment.
149      *
150      * @param cfile the path to the comment file
151      */

152     public void setCommentFile(String JavaDoc cfile) {
153         mCfile = cfile;
154     }
155
156     /**
157      * Get comment file
158      *
159      * @return String containing the path to the comment file
160      */

161     public String JavaDoc getCommentFile() {
162         return mCfile;
163     }
164
165     /**
166      * If true, do not checkout element after creation.
167      *
168      * @param co the status to set the flag to
169      */

170     public void setNoCheckout(boolean co) {
171         mNoco = co;
172     }
173
174     /**
175      * Get no checkout flag status
176      *
177      * @return boolean containing status of noco flag
178      */

179     public boolean getNoCheckout() {
180         return mNoco;
181     }
182
183
184     /**
185      * Get the 'comment' command
186      *
187      * @param cmd containing the command line string with or
188      * without the comment flag and string appended
189      */

190     private void getCommentCommand(Commandline cmd) {
191         if (getComment() != null) {
192             /* Had to make two separate commands here because if a space is
193                inserted between the flag and the value, it is treated as a
194                Windows filename with a space and it is enclosed in double
195                quotes ("). This breaks clearcase.
196             */

197             cmd.createArgument().setValue(FLAG_COMMENT);
198             cmd.createArgument().setValue(getComment());
199         }
200     }
201
202     /**
203      * Get the 'commentfile' command
204      *
205      * @param cmd containing the command line string with or
206      * without the commentfile flag and file appended
207      */

208     private void getCommentFileCommand(Commandline cmd) {
209         if (getCommentFile() != null) {
210             /* Had to make two separate commands here because if a space is
211                inserted between the flag and the value, it is treated as a
212                Windows filename with a space and it is enclosed in double
213                quotes ("). This breaks clearcase.
214             */

215             cmd.createArgument().setValue(FLAG_COMMENTFILE);
216             cmd.createArgument().setValue(getCommentFile());
217         }
218     }
219
220     /**
221      * -c flag -- comment to attach to the directory
222      */

223     public static final String JavaDoc FLAG_COMMENT = "-c";
224     /**
225      * -cfile flag -- file containing a comment to attach to the directory
226      */

227     public static final String JavaDoc FLAG_COMMENTFILE = "-cfile";
228     /**
229      * -nc flag -- no comment is specified
230      */

231     public static final String JavaDoc FLAG_NOCOMMENT = "-nc";
232     /**
233      * -nco flag -- do not checkout element after creation
234      */

235     public static final String JavaDoc FLAG_NOCHECKOUT = "-nco";
236 }
237
238
Popular Tags