1. /*
  2. * Copyright 2001-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. package org.apache.tools.ant.taskdefs.optional.ccm;
  18. import org.apache.tools.ant.BuildException;
  19. import org.apache.tools.ant.Project;
  20. import org.apache.tools.ant.Task;
  21. import org.apache.tools.ant.taskdefs.Execute;
  22. import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
  23. import org.apache.tools.ant.taskdefs.LogStreamHandler;
  24. import org.apache.tools.ant.types.Commandline;
  25. /**
  26. * A base class for creating tasks for executing commands on Continuus 5.1.
  27. * <p>
  28. * The class extends the task as it operates by executing the ccm.exe program
  29. * supplied with Continuus/Synergy. By default the task expects the ccm executable to be
  30. * in the path,
  31. * you can override this be specifying the ccmdir attribute.
  32. * </p>
  33. *
  34. */
  35. public abstract class Continuus extends Task {
  36. private String ccmDir = "";
  37. private String ccmAction = "";
  38. /**
  39. * Get the value of ccmAction.
  40. * @return value of ccmAction.
  41. */
  42. public String getCcmAction() {
  43. return ccmAction;
  44. }
  45. /**
  46. * Set the value of ccmAction.
  47. * @param v Value to assign to ccmAction.
  48. * @ant.attribute ignore="true"
  49. */
  50. public void setCcmAction(String v) {
  51. this.ccmAction = v;
  52. }
  53. /**
  54. * Set the directory where the ccm executable is located.
  55. *
  56. * @param dir the directory containing the ccm executable
  57. */
  58. public final void setCcmDir(String dir) {
  59. ccmDir = Project.translatePath(dir);
  60. }
  61. /**
  62. * Builds and returns the command string to execute ccm
  63. * @return String containing path to the executable
  64. */
  65. protected final String getCcmCommand() {
  66. String toReturn = ccmDir;
  67. if (!toReturn.equals("") && !toReturn.endsWith("/")) {
  68. toReturn += "/";
  69. }
  70. toReturn += CCM_EXE;
  71. return toReturn;
  72. }
  73. protected int run(Commandline cmd, ExecuteStreamHandler handler) {
  74. try {
  75. Execute exe = new Execute(handler);
  76. exe.setAntRun(getProject());
  77. exe.setWorkingDirectory(getProject().getBaseDir());
  78. exe.setCommandline(cmd.getCommandline());
  79. return exe.execute();
  80. } catch (java.io.IOException e) {
  81. throw new BuildException(e, getLocation());
  82. }
  83. }
  84. protected int run(Commandline cmd) {
  85. return run(cmd, new LogStreamHandler(this, Project.MSG_VERBOSE, Project.MSG_WARN));
  86. }
  87. /**
  88. * Constant for the thing to execute
  89. */
  90. private static final String CCM_EXE = "ccm";
  91. /**
  92. * The 'CreateTask' command
  93. */
  94. public static final String COMMAND_CREATE_TASK = "create_task";
  95. /**
  96. * The 'Checkout' command
  97. */
  98. public static final String COMMAND_CHECKOUT = "co";
  99. /**
  100. * The 'Checkin' command
  101. */
  102. public static final String COMMAND_CHECKIN = "ci";
  103. /**
  104. * The 'Reconfigure' command
  105. */
  106. public static final String COMMAND_RECONFIGURE = "reconfigure";
  107. /**
  108. * The 'Reconfigure' command
  109. */
  110. public static final String COMMAND_DEFAULT_TASK = "default_task";
  111. }