1. /*
  2. * Copyright 2003-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. * Integrate file(s).
  26. * P4Change should be used to obtain a new changelist for P4Integrate,
  27. * although P4Integrate can open files to the default change,
  28. * P4Submit cannot yet submit to it.
  29. * Example Usage:<br>
  30. * <p4integrate change="${p4.change}"
  31. * fromfile="//depot/project/dev/foo.txt" tofile="//depot/project/main/foo.txt" />
  32. *
  33. *
  34. * @ant.task category="scm"
  35. */
  36. public class P4Integrate extends P4Base {
  37. private String change = null;
  38. private String fromfile = null;
  39. private String tofile = null;
  40. private String branch = null;
  41. private boolean restoredeletedrevisions = false;
  42. private boolean forceintegrate = false;
  43. private boolean leavetargetrevision = false;
  44. private boolean enablebaselessmerges = false;
  45. private boolean simulationmode = false;
  46. private boolean reversebranchmappings = false;
  47. private boolean propagatesourcefiletype = false;
  48. private boolean nocopynewtargetfiles = false;
  49. /**
  50. * get the changelist number
  51. *
  52. * @return the changelist number set for this task
  53. */
  54. public String getChange() {
  55. return change;
  56. }
  57. /**
  58. * set the changelist number for the operation
  59. *
  60. * @param change An existing changelist number to assign files to; optional
  61. * but strongly recommended.
  62. */
  63. public void setChange(String change) {
  64. this.change = change;
  65. }
  66. /**
  67. * get the from file specification
  68. *
  69. * @return the from file specification
  70. */
  71. public String getFromfile() {
  72. return fromfile;
  73. }
  74. /**
  75. * sets the from file specification
  76. *
  77. * @param fromf the from file specification
  78. */
  79. public void setFromfile(String fromf) {
  80. this.fromfile = fromf;
  81. }
  82. /**
  83. * get the to file specification
  84. *
  85. * @return the to file specification
  86. */
  87. public String getTofile() {
  88. return tofile;
  89. }
  90. /**
  91. * sets the to file specification
  92. *
  93. * @param tof the to file specification
  94. */
  95. public void setTofile(String tof) {
  96. this.tofile = tof;
  97. }
  98. /**
  99. * get the branch
  100. *
  101. * @return the name of the branch
  102. */
  103. public String getBranch() {
  104. return branch;
  105. }
  106. /**
  107. * sets the branch
  108. *
  109. * @param br the name of the branch to use
  110. */
  111. public void setBranch(String br) {
  112. this.branch = br;
  113. }
  114. /**
  115. * gets the restoredeletedrevisions flag
  116. *
  117. * @return restore deleted revisions
  118. */
  119. public boolean isRestoreDeletedRevisions() {
  120. return restoredeletedrevisions;
  121. }
  122. /**
  123. * sets the restoredeletedrevisions flag
  124. *
  125. * @param setrest value chosen for restoredeletedrevisions
  126. */
  127. public void setRestoreDeletedRevisions(boolean setrest) {
  128. this.restoredeletedrevisions = setrest;
  129. }
  130. /**
  131. * gets the forceintegrate flag
  132. *
  133. * @return restore deleted revisions
  134. */
  135. public boolean isForceIntegrate() {
  136. return forceintegrate;
  137. }
  138. /**
  139. * sets the forceintegrate flag
  140. *
  141. * @param setrest value chosen for forceintegrate
  142. */
  143. public void setForceIntegrate(boolean setrest) {
  144. this.forceintegrate = setrest;
  145. }
  146. /**
  147. * gets the leavetargetrevision flag
  148. *
  149. * @return flag indicating if the target revision should be preserved
  150. */
  151. public boolean isLeaveTargetRevision() {
  152. return leavetargetrevision;
  153. }
  154. /**
  155. * sets the leavetargetrevision flag
  156. *
  157. * @param setrest value chosen for leavetargetrevision
  158. */
  159. public void setLeaveTargetRevision(boolean setrest) {
  160. this.leavetargetrevision = setrest;
  161. }
  162. /**
  163. * gets the enablebaselessmerges flag
  164. *
  165. * @return boolean indicating if baseless merges are desired
  166. */
  167. public boolean isEnableBaselessMerges() {
  168. return enablebaselessmerges;
  169. }
  170. /**
  171. * sets the enablebaselessmerges flag
  172. *
  173. * @param setrest value chosen for enablebaselessmerges
  174. */
  175. public void setEnableBaselessMerges(boolean setrest) {
  176. this.enablebaselessmerges = setrest;
  177. }
  178. /**
  179. * gets the simulationmode flag
  180. *
  181. * @return simulation mode flag
  182. */
  183. public boolean isSimulationMode() {
  184. return simulationmode;
  185. }
  186. /**
  187. * sets the simulationmode flag
  188. *
  189. * @param setrest value chosen for simulationmode
  190. */
  191. public void setSimulationMode(boolean setrest) {
  192. this.simulationmode = setrest;
  193. }
  194. /**
  195. * returns the flag indicating if reverse branch mappings are sought
  196. *
  197. * @return reversebranchmappings flag
  198. */
  199. public boolean isReversebranchmappings() {
  200. return reversebranchmappings;
  201. }
  202. /**
  203. * sets the reversebranchmappings flag
  204. *
  205. * @param reversebranchmappings flag indicating if reverse branch mappings are sought
  206. */
  207. public void setReversebranchmappings(boolean reversebranchmappings) {
  208. this.reversebranchmappings = reversebranchmappings;
  209. }
  210. /**
  211. * returns flag indicating if propagation of source file type is sought
  212. *
  213. * @return flag set to true if you want to propagate source file type for existing target files
  214. */
  215. public boolean isPropagatesourcefiletype() {
  216. return propagatesourcefiletype;
  217. }
  218. /**
  219. * sets flag indicating if one wants to propagate the source file type
  220. *
  221. * @param propagatesourcefiletype
  222. * set it to true if you want to change the type of existing target files
  223. * according to type of source file.
  224. */
  225. public void setPropagatesourcefiletype(boolean propagatesourcefiletype) {
  226. this.propagatesourcefiletype = propagatesourcefiletype;
  227. }
  228. /**
  229. * indicates intention to suppress the copying on the local hard disk of new target files.
  230. *
  231. * @return indicates intention to suppress the copying
  232. * on the local hard disk of new target files.
  233. */
  234. public boolean isNocopynewtargetfiles() {
  235. return nocopynewtargetfiles;
  236. }
  237. /**
  238. * sets nocopynewtargetfiles flag
  239. *
  240. * @param nocopynewtargetfiles set it to true to gain speed in integration by not copying on
  241. * the local Perforce client new target files
  242. */
  243. public void setNocopynewtargetfiles(boolean nocopynewtargetfiles) {
  244. this.nocopynewtargetfiles = nocopynewtargetfiles;
  245. }
  246. /**
  247. * execute the p4 integrate
  248. * @throws BuildException if there are missing parameters
  249. */
  250. public void execute() throws BuildException {
  251. if (change != null) {
  252. P4CmdOpts = "-c " + change;
  253. }
  254. if (this.forceintegrate) {
  255. P4CmdOpts = P4CmdOpts + " -f";
  256. }
  257. if (this.restoredeletedrevisions) {
  258. P4CmdOpts = P4CmdOpts + " -d";
  259. }
  260. if (this.leavetargetrevision) {
  261. P4CmdOpts = P4CmdOpts + " -h";
  262. }
  263. if (this.enablebaselessmerges) {
  264. P4CmdOpts = P4CmdOpts + " -i";
  265. }
  266. if (this.simulationmode) {
  267. P4CmdOpts = P4CmdOpts + " -n";
  268. }
  269. if (this.reversebranchmappings) {
  270. P4CmdOpts = P4CmdOpts + " -r";
  271. }
  272. if (this.propagatesourcefiletype) {
  273. P4CmdOpts = P4CmdOpts + " -t";
  274. }
  275. if (this.nocopynewtargetfiles) {
  276. P4CmdOpts = P4CmdOpts + "-v";
  277. }
  278. String command;
  279. if (branch == null && fromfile != null && tofile != null) {
  280. command = P4CmdOpts + " " + fromfile + " " + tofile;
  281. } else if (branch != null && fromfile == null && tofile != null) {
  282. command = P4CmdOpts + " -b " + branch + " " + tofile;
  283. } else if (branch != null && fromfile != null) {
  284. command = P4CmdOpts + " -b " + branch + " -s " + fromfile + " " + tofile;
  285. } else {
  286. throw new BuildException("you need to specify fromfile and tofile, "
  287. + "or branch and tofile, or branch and fromfile, or branch and fromfile and tofile ");
  288. }
  289. execP4Command("-s integrate " + command, new SimpleP4OutputHandler(this));
  290. }
  291. }