KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > perforce > P4Integrate


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 /*
19  * Portions of this software are based upon public domain software
20  * originally written at the National Center for Supercomputing Applications,
21  * University of Illinois, Urbana-Champaign.
22  */

23
24 package org.apache.tools.ant.taskdefs.optional.perforce;
25
26 import org.apache.tools.ant.BuildException;
27
28 /**
29  * Integrate file(s).
30  * P4Change should be used to obtain a new changelist for P4Integrate,
31  * although P4Integrate can open files to the default change,
32  * P4Submit cannot yet submit to it.
33  * Example Usage:<br>
34  * &lt;p4integrate change="${p4.change}"
35  * fromfile="//depot/project/dev/foo.txt" tofile="//depot/project/main/foo.txt" /&gt;
36  *
37  *
38  * @ant.task category="scm"
39  */

40
41 public class P4Integrate extends P4Base {
42
43     private String JavaDoc change = null;
44     private String JavaDoc fromfile = null;
45     private String JavaDoc tofile = null;
46     private String JavaDoc branch = null;
47     private boolean restoredeletedrevisions = false;
48     private boolean forceintegrate = false;
49     private boolean leavetargetrevision = false;
50     private boolean enablebaselessmerges = false;
51     private boolean simulationmode = false;
52     private boolean reversebranchmappings = false;
53     private boolean propagatesourcefiletype = false;
54     private boolean nocopynewtargetfiles = false;
55
56     /**
57      * get the changelist number
58      *
59      * @return the changelist number set for this task
60      */

61     public String JavaDoc getChange() {
62         return change;
63     }
64
65     /**
66      * set the changelist number for the operation
67      *
68      * @param change An existing changelist number to assign files to; optional
69      * but strongly recommended.
70      */

71     public void setChange(String JavaDoc change) {
72         this.change = change;
73     }
74
75     /**
76      * get the from file specification
77      *
78      * @return the from file specification
79      */

80     public String JavaDoc getFromfile() {
81         return fromfile;
82     }
83
84     /**
85      * sets the from file specification
86      *
87      * @param fromf the from file specification
88      */

89     public void setFromfile(String JavaDoc fromf) {
90         this.fromfile = fromf;
91     }
92
93     /**
94      * get the to file specification
95      *
96      * @return the to file specification
97      */

98     public String JavaDoc getTofile() {
99         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 JavaDoc tof) {
108         this.tofile = tof;
109     }
110
111     /**
112      * get the branch
113      *
114      * @return the name of the branch
115      */

116     public String JavaDoc 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 JavaDoc 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      * returns the flag indicating if reverse branch mappings are sought
220      *
221      * @return reversebranchmappings flag
222      */

223     public boolean isReversebranchmappings() {
224         return reversebranchmappings;
225     }
226
227     /**
228      * sets the reversebranchmappings flag
229      *
230      * @param reversebranchmappings flag indicating if reverse branch mappings are sought
231      */

232     public void setReversebranchmappings(boolean reversebranchmappings) {
233         this.reversebranchmappings = reversebranchmappings;
234     }
235     /**
236      * returns flag indicating if propagation of source file type is sought
237      *
238      * @return flag set to true if you want to propagate source file type for existing target files
239      */

240     public boolean isPropagatesourcefiletype() {
241         return propagatesourcefiletype;
242     }
243     /**
244      * sets flag indicating if one wants to propagate the source file type
245      *
246      * @param propagatesourcefiletype
247      * set it to true if you want to change the type of existing target files
248      * according to type of source file.
249      */

250     public void setPropagatesourcefiletype(boolean propagatesourcefiletype) {
251         this.propagatesourcefiletype = propagatesourcefiletype;
252     }
253     /**
254      * indicates intention to suppress the copying on the local hard disk of new target files.
255      *
256      * @return indicates intention to suppress the copying
257      * on the local hard disk of new target files.
258      */

259     public boolean isNocopynewtargetfiles() {
260         return nocopynewtargetfiles;
261     }
262
263     /**
264      * sets nocopynewtargetfiles flag
265      *
266      * @param nocopynewtargetfiles set it to true to gain speed in integration by not copying on
267      * the local Perforce client new target files
268      */

269     public void setNocopynewtargetfiles(boolean nocopynewtargetfiles) {
270         this.nocopynewtargetfiles = nocopynewtargetfiles;
271     }
272
273     /**
274      * execute the p4 integrate
275      * @throws BuildException if there are missing parameters
276      */

277     public void execute() throws BuildException {
278         if (change != null) {
279             P4CmdOpts = "-c " + change;
280         }
281         if (this.forceintegrate) {
282             P4CmdOpts = P4CmdOpts + " -f";
283         }
284         if (this.restoredeletedrevisions) {
285                 P4CmdOpts = P4CmdOpts + " -d";
286             }
287         if (this.leavetargetrevision) {
288             P4CmdOpts = P4CmdOpts + " -h";
289         }
290         if (this.enablebaselessmerges) {
291             P4CmdOpts = P4CmdOpts + " -i";
292         }
293         if (this.simulationmode) {
294             P4CmdOpts = P4CmdOpts + " -n";
295         }
296         if (this.reversebranchmappings) {
297             P4CmdOpts = P4CmdOpts + " -r";
298         }
299         if (this.propagatesourcefiletype) {
300             P4CmdOpts = P4CmdOpts + " -t";
301         }
302         if (this.nocopynewtargetfiles) {
303             P4CmdOpts = P4CmdOpts + "-v";
304         }
305         String JavaDoc command;
306         if (branch == null && fromfile != null && tofile != null) {
307            command = P4CmdOpts + " " + fromfile + " " + tofile;
308         } else if (branch != null && fromfile == null && tofile != null) {
309             command = P4CmdOpts + " -b " + branch + " " + tofile;
310         } else if (branch != null && fromfile != null) {
311             command = P4CmdOpts + " -b " + branch + " -s " + fromfile + " " + tofile;
312         } else {
313             throw new BuildException("you need to specify fromfile and tofile, "
314             + "or branch and tofile, or branch and fromfile, or branch and fromfile and tofile ");
315         }
316         execP4Command("-s integrate " + command, new SimpleP4OutputHandler(this));
317     }
318 }
319
Popular Tags