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.taskdefs.Execute;
  20. import org.apache.tools.ant.types.Commandline;
  21. /**
  22. * Task allows to reconfigure a project, recursively or not
  23. */
  24. public class CCMReconfigure extends Continuus {
  25. private String project = null;
  26. private boolean recurse = false;
  27. private boolean verbose = false;
  28. public CCMReconfigure() {
  29. super();
  30. setCcmAction(COMMAND_RECONFIGURE);
  31. }
  32. /**
  33. * Executes the task.
  34. * <p>
  35. * Builds a command line to execute ccm and then calls Exec's run method
  36. * to execute the command line.
  37. * </p>
  38. */
  39. public void execute() throws BuildException {
  40. Commandline commandLine = new Commandline();
  41. int result = 0;
  42. // build the command line from what we got the format
  43. // as specified in the CCM.EXE help
  44. commandLine.setExecutable(getCcmCommand());
  45. commandLine.createArgument().setValue(getCcmAction());
  46. checkOptions(commandLine);
  47. result = run(commandLine);
  48. if (Execute.isFailure(result)) {
  49. String msg = "Failed executing: " + commandLine.toString();
  50. throw new BuildException(msg, getLocation());
  51. }
  52. }
  53. /**
  54. * Check the command line options.
  55. */
  56. private void checkOptions(Commandline cmd) {
  57. if (isRecurse() == true) {
  58. cmd.createArgument().setValue(FLAG_RECURSE);
  59. } // end of if ()
  60. if (isVerbose() == true) {
  61. cmd.createArgument().setValue(FLAG_VERBOSE);
  62. } // end of if ()
  63. if (getCcmProject() != null) {
  64. cmd.createArgument().setValue(FLAG_PROJECT);
  65. cmd.createArgument().setValue(getCcmProject());
  66. }
  67. }
  68. /**
  69. * Get the value of project.
  70. * @return value of project.
  71. */
  72. public String getCcmProject() {
  73. return project;
  74. }
  75. /**
  76. * Sets the ccm project on which the operation is applied.
  77. * @param v Value to assign to project.
  78. */
  79. public void setCcmProject(String v) {
  80. this.project = v;
  81. }
  82. /**
  83. * Get the value of recurse.
  84. * @return value of recurse.
  85. */
  86. public boolean isRecurse() {
  87. return recurse;
  88. }
  89. /**
  90. * If true, recurse on subproject (default false).
  91. *
  92. * @param v Value to assign to recurse.
  93. */
  94. public void setRecurse(boolean v) {
  95. this.recurse = v;
  96. }
  97. /**
  98. * Get the value of verbose.
  99. * @return value of verbose.
  100. */
  101. public boolean isVerbose() {
  102. return verbose;
  103. }
  104. /**
  105. * If true, do a verbose reconfigure operation (default false).
  106. * @param v Value to assign to verbose.
  107. */
  108. public void setVerbose(boolean v) {
  109. this.verbose = v;
  110. }
  111. /**
  112. * /recurse --
  113. */
  114. public static final String FLAG_RECURSE = "/recurse";
  115. /**
  116. * /recurse --
  117. */
  118. public static final String FLAG_VERBOSE = "/verbose";
  119. /**
  120. * /project flag -- target project
  121. */
  122. public static final String FLAG_PROJECT = "/project";
  123. }