1 | /*
|
---|
2 | * Copyright 2000-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 |
|
---|
23 | package org.apache.tools.ant.taskdefs.optional.perforce;
|
---|
24 |
|
---|
25 | import org.apache.tools.ant.BuildException;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * @ant.task category="scm"
|
---|
29 | */
|
---|
30 | public class P4Resolve extends P4Base {
|
---|
31 | private String resolvemode = null;
|
---|
32 |
|
---|
33 |
|
---|
34 | private boolean redoall; /* -f */
|
---|
35 | private boolean simulationmode; /* -n */
|
---|
36 | private boolean forcetextmode; /* -t */
|
---|
37 | private boolean markersforall; /* -v */
|
---|
38 | private static final String AUTOMATIC = "automatic";
|
---|
39 | private static final String FORCE = "force";
|
---|
40 | private static final String SAFE = "safe";
|
---|
41 | private static final String THEIRS = "theirs";
|
---|
42 | private static final String YOURS = "yours";
|
---|
43 | private static final String[] RESOLVE_MODES = {
|
---|
44 | AUTOMATIC,
|
---|
45 | FORCE,
|
---|
46 | SAFE,
|
---|
47 | THEIRS,
|
---|
48 | YOURS
|
---|
49 | };
|
---|
50 | /**
|
---|
51 | * returns the resolve mode
|
---|
52 | * @return returns the resolve mode
|
---|
53 | */
|
---|
54 | public String getResolvemode() {
|
---|
55 | return resolvemode;
|
---|
56 | }
|
---|
57 | /**
|
---|
58 | * values for resolvemode
|
---|
59 | * <ul>
|
---|
60 | * <li> automatic -am</li>
|
---|
61 | * <li> force -af </li>
|
---|
62 | * <li> safe -as </li>
|
---|
63 | * <li> theirs -at </li>
|
---|
64 | * <li> yours -ay </li>
|
---|
65 | * </ul>
|
---|
66 | * @param resolvemode one of automatic, force, safe, theirs, yours
|
---|
67 | */
|
---|
68 | public void setResolvemode(String resolvemode) {
|
---|
69 | boolean found = false;
|
---|
70 | for (int counter = 0; counter < RESOLVE_MODES.length; counter++) {
|
---|
71 | if (resolvemode.equals(RESOLVE_MODES[counter])) {
|
---|
72 | found = true;
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | if (!found) {
|
---|
77 | throw new BuildException("Unacceptable value for resolve mode");
|
---|
78 | }
|
---|
79 | this.resolvemode = resolvemode;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * allows previously resolved files to be resolved again
|
---|
84 | * @return flag indicating whether one wants to
|
---|
85 | * allow previously resolved files to be resolved again
|
---|
86 | */
|
---|
87 | public boolean isRedoall() {
|
---|
88 | return redoall;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * set the redoall flag
|
---|
93 | * @param redoall flag indicating whether one want to
|
---|
94 | * allow previously resolved files to be resolved again
|
---|
95 | */
|
---|
96 | public void setRedoall(boolean redoall) {
|
---|
97 | this.redoall = redoall;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * read the simulation mode flag
|
---|
102 | * @return flag indicating whether one wants just to simulate
|
---|
103 | * the p4 resolve operation whithout actually doing it
|
---|
104 | */
|
---|
105 | public boolean isSimulationmode() {
|
---|
106 | return simulationmode;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * sets a flag
|
---|
111 | * @param simulationmode set to true, lists the integrations which would be performed,
|
---|
112 | * without actually doing them.
|
---|
113 | */
|
---|
114 | public void setSimulationmode(boolean simulationmode) {
|
---|
115 | this.simulationmode = simulationmode;
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * If set to true, attempts a textual merge, even for binary files
|
---|
120 | * @return flag value
|
---|
121 | */
|
---|
122 | public boolean isForcetextmode() {
|
---|
123 | return forcetextmode;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * If set to true, attempts a textual merge, even for binary files
|
---|
128 | * @param forcetextmode set the flag value
|
---|
129 | */
|
---|
130 | public void setForcetextmode(boolean forcetextmode) {
|
---|
131 | this.forcetextmode = forcetextmode;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * If set to true, puts in markers for all changes, conflicting or not
|
---|
136 | * @return flag markersforall value
|
---|
137 | */
|
---|
138 | public boolean isMarkersforall() {
|
---|
139 | return markersforall;
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * If set to true, puts in markers for all changes, conflicting or not
|
---|
144 | * @param markersforall flag true or false
|
---|
145 | */
|
---|
146 | public void setMarkersforall(boolean markersforall) {
|
---|
147 | this.markersforall = markersforall;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * execute the p4 resolve
|
---|
152 | * @throws BuildException if there is a wrong resolve mode specified
|
---|
153 | * or no view specified
|
---|
154 | */
|
---|
155 | public void execute() throws BuildException {
|
---|
156 | if (this.resolvemode.equals(AUTOMATIC)) {
|
---|
157 | P4CmdOpts = P4CmdOpts + " -am";
|
---|
158 | } else if (this.resolvemode.equals(FORCE)) {
|
---|
159 | P4CmdOpts = P4CmdOpts + " -af";
|
---|
160 | } else if (this.resolvemode.equals(SAFE)) {
|
---|
161 | P4CmdOpts = P4CmdOpts + " -as";
|
---|
162 | } else if (this.resolvemode.equals(THEIRS)) {
|
---|
163 | P4CmdOpts = P4CmdOpts + " -at";
|
---|
164 | } else if (this.resolvemode.equals(YOURS)) {
|
---|
165 | P4CmdOpts = P4CmdOpts + " -ay";
|
---|
166 | } else {
|
---|
167 | throw new BuildException("unsupported or absent resolve mode");
|
---|
168 | }
|
---|
169 | if (P4View == null) {
|
---|
170 | throw new BuildException("please specify a view");
|
---|
171 | }
|
---|
172 | if (this.isRedoall()) {
|
---|
173 | P4CmdOpts = P4CmdOpts + " -f";
|
---|
174 | }
|
---|
175 | if (this.isSimulationmode()) {
|
---|
176 | P4CmdOpts = P4CmdOpts + " -n";
|
---|
177 | }
|
---|
178 | if (this.isForcetextmode()) {
|
---|
179 | P4CmdOpts = P4CmdOpts + " -t";
|
---|
180 | }
|
---|
181 | if (this.isMarkersforall()) {
|
---|
182 | P4CmdOpts = P4CmdOpts + " -v";
|
---|
183 | }
|
---|
184 | execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this));
|
---|
185 | }
|
---|
186 | }
|
---|