001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.optional.ccm;
020:
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.taskdefs.Execute;
023: import org.apache.tools.ant.types.Commandline;
024:
025: /**
026: * Task allows to reconfigure a project, recursively or not
027: */
028: public class CCMReconfigure extends Continuus {
029:
030: private String ccmProject = null;
031: private boolean recurse = false;
032: private boolean verbose = false;
033:
034: /** Constructor for CCMReconfigure. */
035: public CCMReconfigure() {
036: super ();
037: setCcmAction(COMMAND_RECONFIGURE);
038: }
039:
040: /**
041: * Executes the task.
042: * <p>
043: * Builds a command line to execute ccm and then calls Exec's run method
044: * to execute the command line.
045: * </p>
046: * @throws BuildException on error
047: */
048: public void execute() throws BuildException {
049: Commandline commandLine = new Commandline();
050: int result = 0;
051:
052: // build the command line from what we got the format
053: // as specified in the CCM.EXE help
054: commandLine.setExecutable(getCcmCommand());
055: commandLine.createArgument().setValue(getCcmAction());
056:
057: checkOptions(commandLine);
058:
059: result = run(commandLine);
060: if (Execute.isFailure(result)) {
061: String msg = "Failed executing: " + commandLine.toString();
062: throw new BuildException(msg, getLocation());
063: }
064: }
065:
066: /**
067: * Check the command line options.
068: */
069: private void checkOptions(Commandline cmd) {
070:
071: if (isRecurse()) {
072: cmd.createArgument().setValue(FLAG_RECURSE);
073: } // end of if ()
074:
075: if (isVerbose()) {
076: cmd.createArgument().setValue(FLAG_VERBOSE);
077: } // end of if ()
078:
079: if (getCcmProject() != null) {
080: cmd.createArgument().setValue(FLAG_PROJECT);
081: cmd.createArgument().setValue(getCcmProject());
082: }
083:
084: }
085:
086: /**
087: * Get the value of project.
088: * @return value of project.
089: */
090: public String getCcmProject() {
091: return ccmProject;
092: }
093:
094: /**
095: * Sets the ccm project on which the operation is applied.
096: * @param v Value to assign to project.
097: */
098: public void setCcmProject(String v) {
099: this .ccmProject = v;
100: }
101:
102: /**
103: * Get the value of recurse.
104: * @return value of recurse.
105: */
106: public boolean isRecurse() {
107: return recurse;
108: }
109:
110: /**
111: * If true, recurse on subproject (default false).
112: *
113: * @param v Value to assign to recurse.
114: */
115: public void setRecurse(boolean v) {
116: this .recurse = v;
117: }
118:
119: /**
120: * Get the value of verbose.
121: * @return value of verbose.
122: */
123: public boolean isVerbose() {
124: return verbose;
125: }
126:
127: /**
128: * If true, do a verbose reconfigure operation (default false).
129: * @param v Value to assign to verbose.
130: */
131: public void setVerbose(boolean v) {
132: this .verbose = v;
133: }
134:
135: /**
136: * /recurse --
137: */
138: public static final String FLAG_RECURSE = "/recurse";
139:
140: /**
141: * /recurse --
142: */
143: public static final String FLAG_VERBOSE = "/verbose";
144:
145: /**
146: * /project flag -- target project
147: */
148: public static final String FLAG_PROJECT = "/project";
149:
150: }
|