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: * @ant.task category="scm"
030: */
031: public class P4Resolve extends P4Base {
032: private String resolvemode = null;
033:
034: private boolean redoall; /* -f */
035: private boolean simulationmode; /* -n */
036: private boolean forcetextmode; /* -t */
037: private boolean markersforall; /* -v */
038: private static final String AUTOMATIC = "automatic";
039: private static final String FORCE = "force";
040: private static final String SAFE = "safe";
041: private static final String THEIRS = "theirs";
042: private static final String YOURS = "yours";
043: private static final String[] RESOLVE_MODES = { AUTOMATIC, FORCE,
044: SAFE, THEIRS, YOURS };
045:
046: /**
047: * returns the resolve mode
048: * @return returns the resolve mode
049: */
050: public String getResolvemode() {
051: return resolvemode;
052: }
053:
054: /**
055: * values for resolvemode
056: * <ul>
057: * <li> automatic -am</li>
058: * <li> force -af </li>
059: * <li> safe -as </li>
060: * <li> theirs -at </li>
061: * <li> yours -ay </li>
062: * </ul>
063: * @param resolvemode one of automatic, force, safe, theirs, yours
064: */
065: public void setResolvemode(String resolvemode) {
066: boolean found = false;
067: for (int counter = 0; counter < RESOLVE_MODES.length; counter++) {
068: if (resolvemode.equals(RESOLVE_MODES[counter])) {
069: found = true;
070: break;
071: }
072: }
073: if (!found) {
074: throw new BuildException(
075: "Unacceptable value for resolve mode");
076: }
077: this .resolvemode = resolvemode;
078: }
079:
080: /**
081: * allows previously resolved files to be resolved again
082: * @return flag indicating whether one wants to
083: * allow previously resolved files to be resolved again
084: */
085: public boolean isRedoall() {
086: return redoall;
087: }
088:
089: /**
090: * set the redoall flag
091: * @param redoall flag indicating whether one want to
092: * allow previously resolved files to be resolved again
093: */
094: public void setRedoall(boolean redoall) {
095: this .redoall = redoall;
096: }
097:
098: /**
099: * read the simulation mode flag
100: * @return flag indicating whether one wants just to simulate
101: * the p4 resolve operation whithout actually doing it
102: */
103: public boolean isSimulationmode() {
104: return simulationmode;
105: }
106:
107: /**
108: * sets a flag
109: * @param simulationmode set to true, lists the integrations which would be performed,
110: * without actually doing them.
111: */
112: public void setSimulationmode(boolean simulationmode) {
113: this .simulationmode = simulationmode;
114: }
115:
116: /**
117: * If set to true, attempts a textual merge, even for binary files
118: * @return flag value
119: */
120: public boolean isForcetextmode() {
121: return forcetextmode;
122: }
123:
124: /**
125: * If set to true, attempts a textual merge, even for binary files
126: * @param forcetextmode set the flag value
127: */
128: public void setForcetextmode(boolean forcetextmode) {
129: this .forcetextmode = forcetextmode;
130: }
131:
132: /**
133: * If set to true, puts in markers for all changes, conflicting or not
134: * @return flag markersforall value
135: */
136: public boolean isMarkersforall() {
137: return markersforall;
138: }
139:
140: /**
141: * If set to true, puts in markers for all changes, conflicting or not
142: * @param markersforall flag true or false
143: */
144: public void setMarkersforall(boolean markersforall) {
145: this .markersforall = markersforall;
146: }
147:
148: /**
149: * execute the p4 resolve
150: * @throws BuildException if there is a wrong resolve mode specified
151: * or no view specified
152: */
153: public void execute() throws BuildException {
154: if (this .resolvemode.equals(AUTOMATIC)) {
155: P4CmdOpts = P4CmdOpts + " -am";
156: } else if (this .resolvemode.equals(FORCE)) {
157: P4CmdOpts = P4CmdOpts + " -af";
158: } else if (this .resolvemode.equals(SAFE)) {
159: P4CmdOpts = P4CmdOpts + " -as";
160: } else if (this .resolvemode.equals(THEIRS)) {
161: P4CmdOpts = P4CmdOpts + " -at";
162: } else if (this .resolvemode.equals(YOURS)) {
163: P4CmdOpts = P4CmdOpts + " -ay";
164: } else {
165: throw new BuildException(
166: "unsupported or absent resolve mode");
167: }
168: if (P4View == null) {
169: throw new BuildException("please specify a view");
170: }
171: if (this .isRedoall()) {
172: P4CmdOpts = P4CmdOpts + " -f";
173: }
174: if (this .isSimulationmode()) {
175: P4CmdOpts = P4CmdOpts + " -n";
176: }
177: if (this .isForcetextmode()) {
178: P4CmdOpts = P4CmdOpts + " -t";
179: }
180: if (this .isMarkersforall()) {
181: P4CmdOpts = P4CmdOpts + " -v";
182: }
183: execP4Command("-s resolve " + P4CmdOpts + " " + P4View,
184: new SimpleP4OutputHandler(this));
185: }
186: }
|