KickJava   Java API By Example, From Geeks To Geeks.

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


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 UnCheckout command.
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 file or directory that the command will operate on</td>
40  * <td>No</td>
41  * <tr>
42  * <tr>
43  * <td>keepcopy</td>
44  * <td>Specifies whether to keep a copy of the file with a .keep extension or not</td>
45  * <td>No</td>
46  * <tr>
47  * <tr>
48  * <td>failonerr</td>
49  * <td>Throw an exception if the command fails. Default is true</td>
50  * <td>No</td>
51  * <tr>
52  * </table>
53  *
54  */

55 public class CCUnCheckout extends ClearCase {
56     private boolean mKeep = false;
57
58     /**
59      * Executes the task.
60      * <p>
61      * Builds a command line to execute cleartool and then calls Exec's run method
62      * to execute the command line.
63      * @throws BuildException if the command fails and failonerr is set to true
64      */

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

98     private void checkOptions(Commandline cmd) {
99         // ClearCase items
100
if (getKeepCopy()) {
101             // -keep
102
cmd.createArgument().setValue(FLAG_KEEPCOPY);
103         } else {
104             // -rm
105
cmd.createArgument().setValue(FLAG_RM);
106         }
107
108         // viewpath
109
cmd.createArgument().setValue(getViewPath());
110     }
111
112     /**
113      * If true, keep a copy of the file with a .keep extension.
114      *
115      * @param keep the status to set the flag to
116      */

117     public void setKeepCopy(boolean keep) {
118         mKeep = keep;
119     }
120
121     /**
122      * Get keepcopy flag status
123      *
124      * @return boolean containing status of keep flag
125      */

126     public boolean getKeepCopy() {
127         return mKeep;
128     }
129
130
131     /**
132      * -keep flag -- keep a copy of the file with .keep extension
133      */

134     public static final String JavaDoc FLAG_KEEPCOPY = "-keep";
135     /**
136      * -rm flag -- remove the copy of the file
137      */

138     public static final String JavaDoc FLAG_RM = "-rm";
139
140 }
141
142
Popular Tags