source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/clearcase/CCUnCheckout.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: 4.1 KB
Line 
1/*
2 * Copyright 2000-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 UnCheckout command.
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 file or directory that the command will operate on</td>
39 * <td>No</td>
40 * <tr>
41 * <tr>
42 * <td>keepcopy</td>
43 * <td>Specifies whether to keep a copy of the file with a .keep extension or not</td>
44 * <td>No</td>
45 * <tr>
46 * <tr>
47 * <td>failonerr</td>
48 * <td>Throw an exception if the command fails. Default is true</td>
49 * <td>No</td>
50 * <tr>
51 * </table>
52 *
53 */
54public class CCUnCheckout extends ClearCase {
55 private boolean mKeep = false;
56
57 /**
58 * Executes the task.
59 * <p>
60 * Builds a command line to execute cleartool and then calls Exec's run method
61 * to execute the command line.
62 * @throws BuildException if the command fails and failonerr is set to true
63 */
64 public void execute() throws BuildException {
65 Commandline commandLine = new Commandline();
66 Project aProj = getProject();
67 int result = 0;
68
69 // Default the viewpath to basedir if it is not specified
70 if (getViewPath() == null) {
71 setViewPath(aProj.getBaseDir().getPath());
72 }
73
74 // build the command line from what we got the format is
75 // cleartool uncheckout [options...] [viewpath ...]
76 // as specified in the CLEARTOOL.EXE help
77 commandLine.setExecutable(getClearToolCommand());
78 commandLine.createArgument().setValue(COMMAND_UNCHECKOUT);
79
80 checkOptions(commandLine);
81
82 if (!getFailOnErr()) {
83 getProject().log("Ignoring any errors that occur for: "
84 + getViewPathBasename(), Project.MSG_VERBOSE);
85 }
86 result = run(commandLine);
87 if (Execute.isFailure(result) && getFailOnErr()) {
88 String msg = "Failed executing: " + commandLine.toString();
89 throw new BuildException(msg, getLocation());
90 }
91 }
92
93
94 /**
95 * Check the command line options.
96 */
97 private void checkOptions(Commandline cmd) {
98 // ClearCase items
99 if (getKeepCopy()) {
100 // -keep
101 cmd.createArgument().setValue(FLAG_KEEPCOPY);
102 } else {
103 // -rm
104 cmd.createArgument().setValue(FLAG_RM);
105 }
106
107 // viewpath
108 cmd.createArgument().setValue(getViewPath());
109 }
110
111 /**
112 * If true, keep a copy of the file with a .keep extension.
113 *
114 * @param keep the status to set the flag to
115 */
116 public void setKeepCopy(boolean keep) {
117 mKeep = keep;
118 }
119
120 /**
121 * Get keepcopy flag status
122 *
123 * @return boolean containing status of keep flag
124 */
125 public boolean getKeepCopy() {
126 return mKeep;
127 }
128
129
130 /**
131 * -keep flag -- keep a copy of the file with .keep extension
132 */
133 public static final String FLAG_KEEPCOPY = "-keep";
134 /**
135 * -rm flag -- remove the copy of the file
136 */
137 public static final String FLAG_RM = "-rm";
138
139}
140
Note: See TracBrowser for help on using the repository browser.