KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > ccm > CCMReconfigure


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.ccm;
20
21
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.taskdefs.Execute;
24 import org.apache.tools.ant.types.Commandline;
25
26
27 /**
28  * Task allows to reconfigure a project, recursively or not
29  */

30 public class CCMReconfigure extends Continuus {
31
32     private String JavaDoc ccmProject = null;
33     private boolean recurse = false;
34     private boolean verbose = false;
35
36     /** Constructor for CCMReconfigure. */
37     public CCMReconfigure() {
38         super();
39         setCcmAction(COMMAND_RECONFIGURE);
40     }
41
42
43     /**
44      * Executes the task.
45      * <p>
46      * Builds a command line to execute ccm and then calls Exec's run method
47      * to execute the command line.
48      * </p>
49      * @throws BuildException on error
50      */

51     public void execute() throws BuildException {
52         Commandline commandLine = new Commandline();
53         int result = 0;
54
55         // build the command line from what we got the format
56
// as specified in the CCM.EXE help
57
commandLine.setExecutable(getCcmCommand());
58         commandLine.createArgument().setValue(getCcmAction());
59
60         checkOptions(commandLine);
61
62         result = run(commandLine);
63         if (Execute.isFailure(result)) {
64             String JavaDoc msg = "Failed executing: " + commandLine.toString();
65             throw new BuildException(msg, getLocation());
66         }
67     }
68
69
70     /**
71      * Check the command line options.
72      */

73     private void checkOptions(Commandline cmd) {
74
75         if (isRecurse()) {
76             cmd.createArgument().setValue(FLAG_RECURSE);
77         } // end of if ()
78

79         if (isVerbose()) {
80             cmd.createArgument().setValue(FLAG_VERBOSE);
81         } // end of if ()
82

83         if (getCcmProject() != null) {
84             cmd.createArgument().setValue(FLAG_PROJECT);
85             cmd.createArgument().setValue(getCcmProject());
86         }
87
88     }
89
90     /**
91      * Get the value of project.
92      * @return value of project.
93      */

94     public String JavaDoc getCcmProject() {
95         return ccmProject;
96     }
97
98     /**
99      * Sets the ccm project on which the operation is applied.
100      * @param v Value to assign to project.
101      */

102     public void setCcmProject(String JavaDoc v) {
103         this.ccmProject = v;
104     }
105
106
107     /**
108      * Get the value of recurse.
109      * @return value of recurse.
110      */

111     public boolean isRecurse() {
112         return recurse;
113     }
114
115     /**
116      * If true, recurse on subproject (default false).
117      *
118      * @param v Value to assign to recurse.
119      */

120     public void setRecurse(boolean v) {
121         this.recurse = v;
122     }
123
124
125     /**
126      * Get the value of verbose.
127      * @return value of verbose.
128      */

129     public boolean isVerbose() {
130         return verbose;
131     }
132
133     /**
134      * If true, do a verbose reconfigure operation (default false).
135      * @param v Value to assign to verbose.
136      */

137     public void setVerbose(boolean v) {
138         this.verbose = v;
139     }
140
141
142     /**
143      * /recurse --
144      */

145     public static final String JavaDoc FLAG_RECURSE = "/recurse";
146
147     /**
148      * /recurse --
149      */

150     public static final String JavaDoc FLAG_VERBOSE = "/verbose";
151
152
153     /**
154      * /project flag -- target project
155      */

156     public static final String JavaDoc FLAG_PROJECT = "/project";
157
158 }
159
160
Popular Tags