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.Project;
023: import org.apache.tools.ant.Task;
024: import org.apache.tools.ant.taskdefs.Execute;
025: import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
026: import org.apache.tools.ant.taskdefs.LogStreamHandler;
027: import org.apache.tools.ant.types.Commandline;
028: import org.apache.tools.ant.util.FileUtils;
029:
030: /**
031: * A base class for creating tasks for executing commands on Continuus 5.1.
032: * <p>
033: * The class extends the task as it operates by executing the ccm.exe program
034: * supplied with Continuus/Synergy. By default the task expects the ccm executable to be
035: * in the path,
036: * you can override this be specifying the ccmdir attribute.
037: * </p>
038: *
039: */
040: public abstract class Continuus extends Task {
041:
042: private String ccmDir = "";
043: private String ccmAction = "";
044:
045: /**
046: * Get the value of ccmAction.
047: * @return value of ccmAction.
048: */
049: public String getCcmAction() {
050: return ccmAction;
051: }
052:
053: /**
054: * Set the value of ccmAction.
055: * @param v Value to assign to ccmAction.
056: * @ant.attribute ignore="true"
057: */
058: public void setCcmAction(String v) {
059: this .ccmAction = v;
060: }
061:
062: /**
063: * Set the directory where the ccm executable is located.
064: *
065: * @param dir the directory containing the ccm executable
066: */
067: public final void setCcmDir(String dir) {
068: ccmDir = FileUtils.translatePath(dir);
069: }
070:
071: /**
072: * Builds and returns the command string to execute ccm
073: * @return String containing path to the executable
074: */
075: protected final String getCcmCommand() {
076: String toReturn = ccmDir;
077: if (!toReturn.equals("") && !toReturn.endsWith("/")) {
078: toReturn += "/";
079: }
080:
081: toReturn += CCM_EXE;
082:
083: return toReturn;
084: }
085:
086: /**
087: * Run the command.
088: * @param cmd the command line
089: * @param handler an execute stream handler
090: * @return the exit status of the command
091: */
092: protected int run(Commandline cmd, ExecuteStreamHandler handler) {
093: try {
094: Execute exe = new Execute(handler);
095: exe.setAntRun(getProject());
096: exe.setWorkingDirectory(getProject().getBaseDir());
097: exe.setCommandline(cmd.getCommandline());
098: return exe.execute();
099: } catch (java.io.IOException e) {
100: throw new BuildException(e, getLocation());
101: }
102: }
103:
104: /**
105: * Run the command.
106: * @param cmd the command line
107: * @return the exit status of the command
108: */
109: protected int run(Commandline cmd) {
110: return run(cmd, new LogStreamHandler(this , Project.MSG_VERBOSE,
111: Project.MSG_WARN));
112: }
113:
114: /**
115: * Constant for the thing to execute
116: */
117: private static final String CCM_EXE = "ccm";
118:
119: /**
120: * The 'CreateTask' command
121: */
122: public static final String COMMAND_CREATE_TASK = "create_task";
123: /**
124: * The 'Checkout' command
125: */
126: public static final String COMMAND_CHECKOUT = "co";
127: /**
128: * The 'Checkin' command
129: */
130: public static final String COMMAND_CHECKIN = "ci";
131: /**
132: * The 'Reconfigure' command
133: */
134: public static final String COMMAND_RECONFIGURE = "reconfigure";
135:
136: /**
137: * The 'Reconfigure' command
138: */
139: public static final String COMMAND_DEFAULT_TASK = "default_task";
140:
141: }
|