1. /*
  2. * Copyright 2000-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. /*
  18. * Portions of this software are based upon public domain software
  19. * originally written at the National Center for Supercomputing Applications,
  20. * University of Illinois, Urbana-Champaign.
  21. */
  22. package org.apache.tools.ant.taskdefs.optional.perforce;
  23. import org.apache.tools.ant.BuildException;
  24. /**
  25. * @ant.task category="scm"
  26. */
  27. public class P4Resolve extends P4Base {
  28. private String resolvemode = null;
  29. private boolean redoall; /* -f */
  30. private boolean simulationmode; /* -n */
  31. private boolean forcetextmode; /* -t */
  32. private boolean markersforall; /* -v */
  33. private static final String AUTOMATIC = "automatic";
  34. private static final String FORCE = "force";
  35. private static final String SAFE = "safe";
  36. private static final String THEIRS = "theirs";
  37. private static final String YOURS = "yours";
  38. private static final String[] RESOLVE_MODES = {
  39. AUTOMATIC,
  40. FORCE,
  41. SAFE,
  42. THEIRS,
  43. YOURS
  44. };
  45. /**
  46. * returns the resolve mode
  47. * @return returns the resolve mode
  48. */
  49. public String getResolvemode() {
  50. return resolvemode;
  51. }
  52. /**
  53. * values for resolvemode
  54. * <ul>
  55. * <li> automatic -am</li>
  56. * <li> force -af </li>
  57. * <li> safe -as </li>
  58. * <li> theirs -at </li>
  59. * <li> yours -ay </li>
  60. * </ul>
  61. * @param resolvemode one of automatic, force, safe, theirs, yours
  62. */
  63. public void setResolvemode(String resolvemode) {
  64. boolean found = false;
  65. for (int counter = 0; counter < RESOLVE_MODES.length; counter++) {
  66. if (resolvemode.equals(RESOLVE_MODES[counter])) {
  67. found = true;
  68. break;
  69. }
  70. }
  71. if (found == false) {
  72. throw new BuildException("Unacceptable value for resolve mode");
  73. }
  74. this.resolvemode = resolvemode;
  75. }
  76. /**
  77. * allows previously resolved files to be resolved again
  78. * @return flag indicating whether one wants to
  79. * allow previously resolved files to be resolved again
  80. */
  81. public boolean isRedoall() {
  82. return redoall;
  83. }
  84. /**
  85. * set the redoall flag
  86. * @param redoall flag indicating whether one want to
  87. * allow previously resolved files to be resolved again
  88. */
  89. public void setRedoall(boolean redoall) {
  90. this.redoall = redoall;
  91. }
  92. /**
  93. * read the simulation mode flag
  94. * @return flag indicating whether one wants just to simulate
  95. * the p4 resolve operation whithout actually doing it
  96. */
  97. public boolean isSimulationmode() {
  98. return simulationmode;
  99. }
  100. /**
  101. * sets a flag
  102. * @param simulationmode set to true, lists the integrations which would be performed,
  103. * without actually doing them.
  104. */
  105. public void setSimulationmode(boolean simulationmode) {
  106. this.simulationmode = simulationmode;
  107. }
  108. /**
  109. * If set to true, attempts a textual merge, even for binary files
  110. * @return flag value
  111. */
  112. public boolean isForcetextmode() {
  113. return forcetextmode;
  114. }
  115. /**
  116. * If set to true, attempts a textual merge, even for binary files
  117. * @param forcetextmode set the flag value
  118. */
  119. public void setForcetextmode(boolean forcetextmode) {
  120. this.forcetextmode = forcetextmode;
  121. }
  122. /**
  123. * If set to true, puts in markers for all changes, conflicting or not
  124. * @return flag markersforall value
  125. */
  126. public boolean isMarkersforall() {
  127. return markersforall;
  128. }
  129. /**
  130. * If set to true, puts in markers for all changes, conflicting or not
  131. * @param markersforall flag true or false
  132. */
  133. public void setMarkersforall(boolean markersforall) {
  134. this.markersforall = markersforall;
  135. }
  136. /**
  137. * execute the p4 resolve
  138. * @throws BuildException if there is a wrong resolve mode specified
  139. * or no view specified
  140. */
  141. public void execute() throws BuildException {
  142. if (this.resolvemode.equals(AUTOMATIC)) {
  143. P4CmdOpts = P4CmdOpts + " -am";
  144. } else if (this.resolvemode.equals(FORCE)) {
  145. P4CmdOpts = P4CmdOpts + " -af";
  146. } else if (this.resolvemode.equals(SAFE)) {
  147. P4CmdOpts = P4CmdOpts + " -as";
  148. } else if (this.resolvemode.equals(THEIRS)) {
  149. P4CmdOpts = P4CmdOpts + " -at";
  150. } else if (this.resolvemode.equals(YOURS)) {
  151. P4CmdOpts = P4CmdOpts + " -ay";
  152. } else {
  153. throw new BuildException("unsupported or absent resolve mode");
  154. }
  155. if (P4View == null) {
  156. throw new BuildException("please specify a view");
  157. }
  158. if (this.isRedoall()) {
  159. P4CmdOpts = P4CmdOpts + " -f";
  160. }
  161. if (this.isSimulationmode()) {
  162. P4CmdOpts = P4CmdOpts + " -n";
  163. }
  164. if (this.isForcetextmode()) {
  165. P4CmdOpts = P4CmdOpts + " -t";
  166. }
  167. if (this.isMarkersforall()) {
  168. P4CmdOpts = P4CmdOpts + " -v";
  169. }
  170. execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
  171. }
  172. }