source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Labelsync.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.7 KB
Line 
1/*
2 * Copyright 2003-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
23package org.apache.tools.ant.taskdefs.optional.perforce;
24
25import org.apache.tools.ant.BuildException;
26import org.apache.tools.ant.Project;
27import org.apache.tools.ant.util.StringUtils;
28
29/**
30 * This method syncs an existing Perforce label against the Perforce client
31 * or against a set of files/revisions.
32 *
33 *
34 * Example Usage:
35 * <pre>
36 * &lt;p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}"
37 * view="//depot/...#head;//depot2/file1#25" /&gt;
38 * </pre>
39 *
40 *
41 * @ant.task category="scm"
42 */
43public class P4Labelsync extends P4Base {
44
45 protected String name;
46 private boolean add; /* -a */
47 private boolean delete; /* -n */
48 private boolean simulationmode; /* -n */
49 /**
50 * -a flag of p4 labelsync - preserve files which exist in the label,
51 * but not in the current view
52 * @return add attribute
53 * if set to true the task will not remove any files from the label
54 * only add files which were not there previously or update these where the revision has changed
55 * the add attribute is the -a flag of p4 labelsync
56 */
57 public boolean isAdd() {
58 return add;
59 }
60 /**
61 * -a flag of p4 labelsync - preserve files which exist in the label,
62 * but not in the current view
63 * @param add if set to true the task will not remove any files from the label
64 * only add files which were not there previously or update these where the revision has changed
65 * the add attribute is the -a flag of p4 labelsync
66 */
67 public void setAdd(boolean add) {
68 this.add = add;
69 }
70 /**
71 * -d flag of p4 labelsync; indicates an intention of deleting from the label
72 * the files specified in the view
73 * @return delete attribute
74 */
75 public boolean isDelete() {
76 return delete;
77 }
78
79 /**
80 * -d flag of p4 labelsync; indicates an intention of deleting from the label
81 * the files specified in the view
82 * @param delete indicates intention of deleting from the label
83 * the files specified in the view
84 */
85 public void setDelete(boolean delete) {
86 this.delete = delete;
87 }
88
89
90 /**
91 * The name of the label; optional, default "AntLabel"
92 * @param name of the label
93 */
94 public void setName(String name) {
95 this.name = name;
96 }
97 /**
98 * -n flag of p4 labelsync - display changes without actually doing them
99 * @return -n flag of p4 labelsync
100 */
101 public boolean isSimulationmode() {
102 return simulationmode;
103 }
104 /**
105 * -n flag of p4 labelsync - display changes without actually doing them
106 * @param simulationmode display changes without actually doing them
107 */
108 public void setSimulationmode(boolean simulationmode) {
109 this.simulationmode = simulationmode;
110 }
111
112
113 /**
114 * do the work
115 * @throws BuildException if the label name is not supplied
116 */
117 public void execute() throws BuildException {
118 log("P4Labelsync exec:", Project.MSG_INFO);
119
120 if (P4View != null && P4View.length() >= 1) {
121 P4View = StringUtils.replace(P4View, ":", "\n\t");
122 P4View = StringUtils.replace(P4View, ";", "\n\t");
123 }
124 if (P4View == null) {
125 P4View = "";
126 }
127
128 if (name == null || name.length() < 1) {
129 throw new BuildException("name attribute is compulsory for labelsync");
130 }
131
132 if (this.isSimulationmode()) {
133 P4CmdOpts = P4CmdOpts + " -n";
134 }
135 if (this.isDelete()) {
136 P4CmdOpts = P4CmdOpts + " -d";
137 }
138 if (this.isAdd()) {
139 P4CmdOpts = P4CmdOpts + " -a";
140 }
141
142 execP4Command("-s labelsync -l " + name + " " + P4CmdOpts + " " + P4View,
143 new SimpleP4OutputHandler(this));
144
145
146 }
147}
148
Note: See TracBrowser for help on using the repository browser.