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: * Portions of this software are based upon public domain software
020: * originally written at the National Center for Supercomputing Applications,
021: * University of Illinois, Urbana-Champaign.
022: */
023:
024: package org.apache.tools.ant.taskdefs.optional.perforce;
025:
026: import org.apache.tools.ant.BuildException;
027:
028: /**
029: * Integrate file(s).
030: * P4Change should be used to obtain a new changelist for P4Integrate,
031: * although P4Integrate can open files to the default change,
032: * P4Submit cannot yet submit to it.
033: * Example Usage:<br>
034: * <p4integrate change="${p4.change}"
035: * fromfile="//depot/project/dev/foo.txt" tofile="//depot/project/main/foo.txt" />
036: *
037: *
038: * @ant.task category="scm"
039: */
040:
041: public class P4Integrate extends P4Base {
042:
043: private String change = null;
044: private String fromfile = null;
045: private String tofile = null;
046: private String branch = null;
047: private boolean restoredeletedrevisions = false;
048: private boolean forceintegrate = false;
049: private boolean leavetargetrevision = false;
050: private boolean enablebaselessmerges = false;
051: private boolean simulationmode = false;
052: private boolean reversebranchmappings = false;
053: private boolean propagatesourcefiletype = false;
054: private boolean nocopynewtargetfiles = false;
055:
056: /**
057: * get the changelist number
058: *
059: * @return the changelist number set for this task
060: */
061: public String getChange() {
062: return change;
063: }
064:
065: /**
066: * set the changelist number for the operation
067: *
068: * @param change An existing changelist number to assign files to; optional
069: * but strongly recommended.
070: */
071: public void setChange(String change) {
072: this .change = change;
073: }
074:
075: /**
076: * get the from file specification
077: *
078: * @return the from file specification
079: */
080: public String getFromfile() {
081: return fromfile;
082: }
083:
084: /**
085: * sets the from file specification
086: *
087: * @param fromf the from file specification
088: */
089: public void setFromfile(String fromf) {
090: this .fromfile = fromf;
091: }
092:
093: /**
094: * get the to file specification
095: *
096: * @return the to file specification
097: */
098: public String getTofile() {
099: return tofile;
100: }
101:
102: /**
103: * sets the to file specification
104: *
105: * @param tof the to file specification
106: */
107: public void setTofile(String tof) {
108: this .tofile = tof;
109: }
110:
111: /**
112: * get the branch
113: *
114: * @return the name of the branch
115: */
116: public String getBranch() {
117: return branch;
118: }
119:
120: /**
121: * sets the branch
122: *
123: * @param br the name of the branch to use
124: */
125: public void setBranch(String br) {
126: this .branch = br;
127: }
128:
129: /**
130: * gets the restoredeletedrevisions flag
131: *
132: * @return restore deleted revisions
133: */
134: public boolean isRestoreDeletedRevisions() {
135: return restoredeletedrevisions;
136: }
137:
138: /**
139: * sets the restoredeletedrevisions flag
140: *
141: * @param setrest value chosen for restoredeletedrevisions
142: */
143: public void setRestoreDeletedRevisions(boolean setrest) {
144: this .restoredeletedrevisions = setrest;
145: }
146:
147: /**
148: * gets the forceintegrate flag
149: *
150: * @return restore deleted revisions
151: */
152: public boolean isForceIntegrate() {
153: return forceintegrate;
154: }
155:
156: /**
157: * sets the forceintegrate flag
158: *
159: * @param setrest value chosen for forceintegrate
160: */
161: public void setForceIntegrate(boolean setrest) {
162: this .forceintegrate = setrest;
163: }
164:
165: /**
166: * gets the leavetargetrevision flag
167: *
168: * @return flag indicating if the target revision should be preserved
169: */
170: public boolean isLeaveTargetRevision() {
171: return leavetargetrevision;
172: }
173:
174: /**
175: * sets the leavetargetrevision flag
176: *
177: * @param setrest value chosen for leavetargetrevision
178: */
179: public void setLeaveTargetRevision(boolean setrest) {
180: this .leavetargetrevision = setrest;
181: }
182:
183: /**
184: * gets the enablebaselessmerges flag
185: *
186: * @return boolean indicating if baseless merges are desired
187: */
188: public boolean isEnableBaselessMerges() {
189: return enablebaselessmerges;
190: }
191:
192: /**
193: * sets the enablebaselessmerges flag
194: *
195: * @param setrest value chosen for enablebaselessmerges
196: */
197: public void setEnableBaselessMerges(boolean setrest) {
198: this .enablebaselessmerges = setrest;
199: }
200:
201: /**
202: * gets the simulationmode flag
203: *
204: * @return simulation mode flag
205: */
206: public boolean isSimulationMode() {
207: return simulationmode;
208: }
209:
210: /**
211: * sets the simulationmode flag
212: *
213: * @param setrest value chosen for simulationmode
214: */
215: public void setSimulationMode(boolean setrest) {
216: this .simulationmode = setrest;
217: }
218:
219: /**
220: * returns the flag indicating if reverse branch mappings are sought
221: *
222: * @return reversebranchmappings flag
223: */
224: public boolean isReversebranchmappings() {
225: return reversebranchmappings;
226: }
227:
228: /**
229: * sets the reversebranchmappings flag
230: *
231: * @param reversebranchmappings flag indicating if reverse branch mappings are sought
232: */
233: public void setReversebranchmappings(boolean reversebranchmappings) {
234: this .reversebranchmappings = reversebranchmappings;
235: }
236:
237: /**
238: * returns flag indicating if propagation of source file type is sought
239: *
240: * @return flag set to true if you want to propagate source file type for existing target files
241: */
242: public boolean isPropagatesourcefiletype() {
243: return propagatesourcefiletype;
244: }
245:
246: /**
247: * sets flag indicating if one wants to propagate the source file type
248: *
249: * @param propagatesourcefiletype
250: * set it to true if you want to change the type of existing target files
251: * according to type of source file.
252: */
253: public void setPropagatesourcefiletype(
254: boolean propagatesourcefiletype) {
255: this .propagatesourcefiletype = propagatesourcefiletype;
256: }
257:
258: /**
259: * indicates intention to suppress the copying on the local hard disk of new target files.
260: *
261: * @return indicates intention to suppress the copying
262: * on the local hard disk of new target files.
263: */
264: public boolean isNocopynewtargetfiles() {
265: return nocopynewtargetfiles;
266: }
267:
268: /**
269: * sets nocopynewtargetfiles flag
270: *
271: * @param nocopynewtargetfiles set it to true to gain speed in integration by not copying on
272: * the local Perforce client new target files
273: */
274: public void setNocopynewtargetfiles(boolean nocopynewtargetfiles) {
275: this .nocopynewtargetfiles = nocopynewtargetfiles;
276: }
277:
278: /**
279: * execute the p4 integrate
280: * @throws BuildException if there are missing parameters
281: */
282: public void execute() throws BuildException {
283: if (change != null) {
284: P4CmdOpts = "-c " + change;
285: }
286: if (this .forceintegrate) {
287: P4CmdOpts = P4CmdOpts + " -f";
288: }
289: if (this .restoredeletedrevisions) {
290: P4CmdOpts = P4CmdOpts + " -d";
291: }
292: if (this .leavetargetrevision) {
293: P4CmdOpts = P4CmdOpts + " -h";
294: }
295: if (this .enablebaselessmerges) {
296: P4CmdOpts = P4CmdOpts + " -i";
297: }
298: if (this .simulationmode) {
299: P4CmdOpts = P4CmdOpts + " -n";
300: }
301: if (this .reversebranchmappings) {
302: P4CmdOpts = P4CmdOpts + " -r";
303: }
304: if (this .propagatesourcefiletype) {
305: P4CmdOpts = P4CmdOpts + " -t";
306: }
307: if (this .nocopynewtargetfiles) {
308: P4CmdOpts = P4CmdOpts + "-v";
309: }
310: String command;
311: if (branch == null && fromfile != null && tofile != null) {
312: command = P4CmdOpts + " " + fromfile + " " + tofile;
313: } else if (branch != null && fromfile == null && tofile != null) {
314: command = P4CmdOpts + " -b " + branch + " " + tofile;
315: } else if (branch != null && fromfile != null) {
316: command = P4CmdOpts + " -b " + branch + " -s " + fromfile
317: + " " + tofile;
318: } else {
319: throw new BuildException(
320: "you need to specify fromfile and tofile, "
321: + "or branch and tofile, or branch and fromfile, or branch and fromfile and tofile ");
322: }
323: execP4Command("-s integrate " + command,
324: new SimpleP4OutputHandler(this));
325: }
326: }
|