KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.tools.ant.Project;
28 import org.apache.tools.ant.util.StringUtils;
29
30 /**
31  * This method syncs an existing Perforce label against the Perforce client
32  * or against a set of files/revisions.
33  *
34  *
35  * Example Usage:
36  * <pre>
37  * &lt;p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}"
38  * view="//depot/...#head;//depot2/file1#25" /&gt;
39  * </pre>
40  *
41  * @ant.task category="scm"
42  */

43 public class P4Labelsync extends P4Base {
44
45     // CheckStyle:VisibilityModifier OFF - bc
46
protected String JavaDoc name;
47     private boolean add; /* -a */
48     private boolean delete; /* -n */
49     private boolean simulationmode; /* -n */
50     // CheckStyle:VisibilityModifier ON
51
/**
52      * -a flag of p4 labelsync - preserve files which exist in the label,
53      * but not in the current view
54      * @return add attribute
55      * if set to true the task will not remove any files from the label
56      * only add files which were not there previously or update these where the revision has changed
57      * the add attribute is the -a flag of p4 labelsync
58      */

59     public boolean isAdd() {
60         return add;
61     }
62     /**
63      * -a flag of p4 labelsync - preserve files which exist in the label,
64      * but not in the current view
65      * @param add if set to true the task will not remove any files from the label
66      * only add files which were not there previously or update these where the revision has changed
67      * the add attribute is the -a flag of p4 labelsync
68      */

69     public void setAdd(boolean add) {
70         this.add = add;
71     }
72     /**
73      * -d flag of p4 labelsync; indicates an intention of deleting from the label
74      * the files specified in the view
75      * @return delete attribute
76      */

77     public boolean isDelete() {
78         return delete;
79     }
80
81     /**
82      * -d flag of p4 labelsync; indicates an intention of deleting from the label
83      * the files specified in the view
84      * @param delete indicates intention of deleting from the label
85      * the files specified in the view
86      */

87     public void setDelete(boolean delete) {
88         this.delete = delete;
89     }
90
91
92     /**
93      * The name of the label; optional, default "AntLabel"
94      * @param name of the label
95      */

96     public void setName(String JavaDoc name) {
97         this.name = name;
98     }
99     /**
100      * -n flag of p4 labelsync - display changes without actually doing them
101      * @return -n flag of p4 labelsync
102      */

103     public boolean isSimulationmode() {
104         return simulationmode;
105     }
106     /**
107      * -n flag of p4 labelsync - display changes without actually doing them
108      * @param simulationmode display changes without actually doing them
109      */

110     public void setSimulationmode(boolean simulationmode) {
111         this.simulationmode = simulationmode;
112     }
113
114
115     /**
116      * do the work
117      * @throws BuildException if the label name is not supplied
118      */

119     public void execute() throws BuildException {
120         log("P4Labelsync exec:", Project.MSG_INFO);
121
122         if (P4View != null && P4View.length() >= 1) {
123             P4View = StringUtils.replace(P4View, ":", "\n\t");
124             P4View = StringUtils.replace(P4View, ";", "\n\t");
125         }
126         if (P4View == null) {
127             P4View = "";
128         }
129
130         if (name == null || name.length() < 1) {
131             throw new BuildException("name attribute is compulsory for labelsync");
132         }
133
134         if (this.isSimulationmode()) {
135             P4CmdOpts = P4CmdOpts + " -n";
136         }
137         if (this.isDelete()) {
138             P4CmdOpts = P4CmdOpts + " -d";
139         }
140         if (this.isAdd()) {
141             P4CmdOpts = P4CmdOpts + " -a";
142         }
143
144         execP4Command("-s labelsync -l " + name + " " + P4CmdOpts + " " + P4View,
145             new SimpleP4OutputHandler(this));
146
147
148     }
149 }
150
151
Popular Tags