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 | import org.apache.tools.ant.Project;
|
---|
27 | import java.util.Vector;
|
---|
28 |
|
---|
29 | /** Submits a numbered changelist to Perforce.
|
---|
30 | *
|
---|
31 | * <B>Note:</B> P4Submit cannot (yet) submit the default changelist.
|
---|
32 | * This shouldn't be a problem with the ANT task as the usual flow is
|
---|
33 | * P4Change to create a new numbered change followed by P4Edit then P4Submit.
|
---|
34 | *
|
---|
35 | * Example Usage:-<br>
|
---|
36 | * <p4submit change="${p4.change}" />
|
---|
37 | *
|
---|
38 | *
|
---|
39 | * @ant.task category="scm"
|
---|
40 | */
|
---|
41 | public class P4Submit extends P4Base {
|
---|
42 |
|
---|
43 | //ToDo: If dealing with default cl need to parse out <enter description here>
|
---|
44 | /**
|
---|
45 | * change list number
|
---|
46 | */
|
---|
47 | public String change;
|
---|
48 | /**
|
---|
49 | * change property
|
---|
50 | */
|
---|
51 | private String changeProperty;
|
---|
52 | /**
|
---|
53 | * needsresolveproperty
|
---|
54 | */
|
---|
55 | private String needsResolveProperty;
|
---|
56 | /**
|
---|
57 | * set the change list number to submit
|
---|
58 | * @param change The changelist number to submit; required.
|
---|
59 | */
|
---|
60 | public void setChange(String change) {
|
---|
61 | this.change = change;
|
---|
62 | }
|
---|
63 | /**
|
---|
64 | * property defining the change number if the change number gets renumbered
|
---|
65 | * @param changeProperty name of a new property to which the change number
|
---|
66 | * will be assigned if it changes
|
---|
67 | * @since ant 1.6.1
|
---|
68 | */
|
---|
69 | public void setChangeProperty(String changeProperty) {
|
---|
70 | this.changeProperty = changeProperty;
|
---|
71 | }
|
---|
72 | /**
|
---|
73 | * property defining the need to resolve the change list
|
---|
74 | * @param needsResolveProperty a property which will be set if the change needs resolve
|
---|
75 | * @since ant 1.6.1
|
---|
76 | */
|
---|
77 | public void setNeedsResolveProperty(String needsResolveProperty) {
|
---|
78 | this.needsResolveProperty = needsResolveProperty;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * do the work
|
---|
83 | * @throws BuildException if no change list specified
|
---|
84 | */
|
---|
85 | public void execute() throws BuildException {
|
---|
86 | if (change != null) {
|
---|
87 | execP4Command("submit -c " + change, (P4HandlerAdapter) new P4SubmitAdapter(this));
|
---|
88 | } else {
|
---|
89 | //here we'd parse the output from change -o into submit -i
|
---|
90 | //in order to support default change.
|
---|
91 | throw new BuildException("No change specified (no support for default change yet....");
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * internal class used to process the output of p4 submit
|
---|
97 | */
|
---|
98 | public class P4SubmitAdapter extends SimpleP4OutputHandler {
|
---|
99 | public P4SubmitAdapter(P4Base parent) {
|
---|
100 | super(parent);
|
---|
101 | }
|
---|
102 | /**
|
---|
103 | * process a line of stdout/stderr coming from Perforce
|
---|
104 | * @param line line of stdout or stderr coming from Perforce
|
---|
105 | */
|
---|
106 | public void process(String line) {
|
---|
107 | super.process(line);
|
---|
108 | getProject().setProperty("p4.needsresolve", "0");
|
---|
109 | // this type of output might happen
|
---|
110 | // Change 18 renamed change 20 and submitted.
|
---|
111 | if (util.match("/renamed/", line)) {
|
---|
112 | try {
|
---|
113 | Vector myarray = new Vector();
|
---|
114 | util.split(myarray, line);
|
---|
115 | boolean found = false;
|
---|
116 | for (int counter = 0; counter < myarray.size(); counter++) {
|
---|
117 | if (found == true) {
|
---|
118 | String chnum = (String) myarray.elementAt(counter + 1);
|
---|
119 | int changenumber = Integer.parseInt(chnum);
|
---|
120 | log("Perforce change renamed " + changenumber, Project.MSG_INFO);
|
---|
121 | getProject().setProperty("p4.change", "" + changenumber);
|
---|
122 | if (changeProperty != null) {
|
---|
123 | getProject().setNewProperty(changeProperty, chnum);
|
---|
124 | }
|
---|
125 | found = false;
|
---|
126 | }
|
---|
127 | if (((myarray.elementAt(counter))).equals("renamed")) {
|
---|
128 | found = true;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | // NumberFormatException or ArrayOutOfBondsException could happen here
|
---|
132 | } catch (Exception e) {
|
---|
133 | String msg = "Failed to parse " + line + "\n"
|
---|
134 | + " due to " + e.getMessage();
|
---|
135 | throw new BuildException(msg, e, getLocation());
|
---|
136 | }
|
---|
137 | }
|
---|
138 | if (util.match("/p4 submit -c/", line)) {
|
---|
139 | getProject().setProperty("p4.needsresolve", "1");
|
---|
140 | if (needsResolveProperty != null) {
|
---|
141 | getProject().setNewProperty(needsResolveProperty, "true");
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | }
|
---|