KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @ant.task category="scm"
30  */

31 public class P4Resolve extends P4Base {
32     private String JavaDoc resolvemode = null;
33
34
35     private boolean redoall; /* -f */
36     private boolean simulationmode; /* -n */
37     private boolean forcetextmode; /* -t */
38     private boolean markersforall; /* -v */
39     private static final String JavaDoc AUTOMATIC = "automatic";
40     private static final String JavaDoc FORCE = "force";
41     private static final String JavaDoc SAFE = "safe";
42     private static final String JavaDoc THEIRS = "theirs";
43     private static final String JavaDoc YOURS = "yours";
44     private static final String JavaDoc[] RESOLVE_MODES = {
45         AUTOMATIC,
46         FORCE,
47         SAFE,
48         THEIRS,
49         YOURS
50     };
51    /**
52     * returns the resolve mode
53     * @return returns the resolve mode
54     */

55     public String JavaDoc getResolvemode() {
56         return resolvemode;
57     }
58     /**
59      * values for resolvemode
60      * <ul>
61      * <li> automatic -am</li>
62      * <li> force -af </li>
63      * <li> safe -as </li>
64      * <li> theirs -at </li>
65      * <li> yours -ay </li>
66      * </ul>
67      * @param resolvemode one of automatic, force, safe, theirs, yours
68      */

69     public void setResolvemode(String JavaDoc resolvemode) {
70         boolean found = false;
71         for (int counter = 0; counter < RESOLVE_MODES.length; counter++) {
72             if (resolvemode.equals(RESOLVE_MODES[counter])) {
73                 found = true;
74                 break;
75             }
76         }
77         if (!found) {
78             throw new BuildException("Unacceptable value for resolve mode");
79         }
80         this.resolvemode = resolvemode;
81     }
82
83     /**
84      * allows previously resolved files to be resolved again
85      * @return flag indicating whether one wants to
86      * allow previously resolved files to be resolved again
87      */

88     public boolean isRedoall() {
89         return redoall;
90     }
91
92     /**
93      * set the redoall flag
94      * @param redoall flag indicating whether one want to
95      * allow previously resolved files to be resolved again
96      */

97     public void setRedoall(boolean redoall) {
98         this.redoall = redoall;
99     }
100
101     /**
102      * read the simulation mode flag
103      * @return flag indicating whether one wants just to simulate
104      * the p4 resolve operation whithout actually doing it
105      */

106     public boolean isSimulationmode() {
107         return simulationmode;
108     }
109
110     /**
111      * sets a flag
112      * @param simulationmode set to true, lists the integrations which would be performed,
113      * without actually doing them.
114      */

115     public void setSimulationmode(boolean simulationmode) {
116         this.simulationmode = simulationmode;
117     }
118
119     /**
120      * If set to true, attempts a textual merge, even for binary files
121      * @return flag value
122      */

123     public boolean isForcetextmode() {
124         return forcetextmode;
125     }
126
127     /**
128      * If set to true, attempts a textual merge, even for binary files
129      * @param forcetextmode set the flag value
130      */

131     public void setForcetextmode(boolean forcetextmode) {
132         this.forcetextmode = forcetextmode;
133     }
134
135     /**
136      * If set to true, puts in markers for all changes, conflicting or not
137      * @return flag markersforall value
138      */

139     public boolean isMarkersforall() {
140         return markersforall;
141     }
142
143     /**
144       * If set to true, puts in markers for all changes, conflicting or not
145      * @param markersforall flag true or false
146      */

147     public void setMarkersforall(boolean markersforall) {
148         this.markersforall = markersforall;
149     }
150
151     /**
152      * execute the p4 resolve
153      * @throws BuildException if there is a wrong resolve mode specified
154      * or no view specified
155      */

156     public void execute() throws BuildException {
157         if (this.resolvemode.equals(AUTOMATIC)) {
158             P4CmdOpts = P4CmdOpts + " -am";
159         } else if (this.resolvemode.equals(FORCE)) {
160             P4CmdOpts = P4CmdOpts + " -af";
161         } else if (this.resolvemode.equals(SAFE)) {
162             P4CmdOpts = P4CmdOpts + " -as";
163         } else if (this.resolvemode.equals(THEIRS)) {
164             P4CmdOpts = P4CmdOpts + " -at";
165         } else if (this.resolvemode.equals(YOURS)) {
166             P4CmdOpts = P4CmdOpts + " -ay";
167         } else {
168             throw new BuildException("unsupported or absent resolve mode");
169         }
170         if (P4View == null) {
171             throw new BuildException("please specify a view");
172         }
173         if (this.isRedoall()) {
174             P4CmdOpts = P4CmdOpts + " -f";
175         }
176         if (this.isSimulationmode()) {
177             P4CmdOpts = P4CmdOpts + " -n";
178         }
179         if (this.isForcetextmode()) {
180             P4CmdOpts = P4CmdOpts + " -t";
181         }
182         if (this.isMarkersforall()) {
183             P4CmdOpts = P4CmdOpts + " -v";
184         }
185         execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
186     }
187 }
188
Popular Tags