KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > starteam > StarTeamLabel


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 package org.apache.tools.ant.taskdefs.optional.starteam;
19
20 import com.starbase.starteam.Label;
21 import com.starbase.starteam.View;
22 import com.starbase.util.OLEDate;
23 import java.text.ParseException JavaDoc;
24 import java.text.SimpleDateFormat JavaDoc;
25 import java.util.Date JavaDoc;
26 import org.apache.tools.ant.BuildException;
27
28 /**
29  * Creates a view label in StarTeam at the specified view.
30  *
31  * Ant Usage:
32  * <pre>
33  * &lt;taskdef name="stlabel"
34  * classname="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamLabel"/&lt;
35  * &lt;stlabel
36  * label="1.0" lastbuild="20011514100000" description="Successful Build"
37  * username="BuildMaster" password="ant"
38  * starteamurl="server:port/project/view"/&gt;
39  * </pre>
40  *
41   * @see <a HREF="http://www.borland.com/us/products/starteam/index.html"
42   * >borland StarTeam Web Site</a>
43  *
44  * @ant.task name="stlabel" category="scm"
45  */

46 public class StarTeamLabel extends StarTeamTask {
47
48     /**
49      * The name of the label to be set in Starteam.
50      */

51     private String JavaDoc labelName;
52
53     /**
54      * The label description to be set in Starteam.
55      */

56     private String JavaDoc description;
57
58     /**
59      * If true, this will be a build label. If false, it will be a non-build
60      * label. The default is false. Has no effect if revision label is
61      * true.
62      */

63     private boolean buildlabel = false;
64
65     /**
66      * If true, this will be a revision label. If false, it will be a build
67      * label. The default is false.
68      */

69     private boolean revisionlabel = false;
70
71     /**
72      * The time of the last successful. The new label will be a snapshot of the
73      * repository at this time. String should be formatted as "yyyyMMddHHmmss"
74      */

75     private OLEDate lastBuild = null;
76
77     private static final SimpleDateFormat JavaDoc DATE_FORMAT =
78             new SimpleDateFormat JavaDoc("yyyyMMddHHmmss");
79
80
81     /**
82      * The name to be given to the label; required.
83      * @param label the name to be used
84      */

85     public void setLabel(String JavaDoc label) {
86         this.labelName = label;
87     }
88
89     /**
90      * Description of the label to be stored in the StarTeam project.
91      * @param description the description to be used
92      */

93     public void setDescription(String JavaDoc description) {
94         this.description = description;
95     }
96
97     /**
98      * set the type of label based on the supplied value - if true, this
99      * label will be a revision label, if false, a build label.
100      *
101      * @param buildlabel If true this will be a revision label; if false,
102      * a build label
103      */

104     public void setBuildLabel(boolean buildlabel) {
105         this.buildlabel = buildlabel;
106     }
107
108     /**
109      * set the type of label based on the supplied value - if true, this
110      * label will be a revision label, if false, a build label.
111      *
112      * @param revisionlabel If true this will be a revision label; if false,
113      * a build label
114      */

115     public void setRevisionLabel(boolean revisionlabel) {
116         this.revisionlabel = revisionlabel;
117     }
118
119
120
121     /**
122      * The timestamp of the build that will be stored with the label; required.
123      * Must be formatted <code>yyyyMMddHHmmss</code>
124      * @param lastbuild the timestamp of the last build
125      * @throws BuildException on error
126      */

127     public void setLastBuild(String JavaDoc lastbuild) throws BuildException {
128         try {
129             Date lastBuildTime = DATE_FORMAT.parse(lastbuild);
130             this.lastBuild = new OLEDate(lastBuildTime);
131         } catch (ParseException JavaDoc e) {
132             throw new BuildException("Unable to parse the date '"
133                 + lastbuild + "'", e);
134         }
135     }
136
137     /**
138      * This method does the work of creating the new view and checking it into
139      * Starteam.
140      * @throws BuildException on error
141      */

142     public void execute() throws BuildException {
143
144         if (this.revisionlabel && this.buildlabel) {
145             throw new BuildException("'revisionlabel' and 'buildlabel' "
146                 + "both specified. A revision label cannot be a build label.");
147         }
148
149         try {
150             View snapshot = openView();
151
152             // Create the new label and update the repository
153

154             if (this.revisionlabel) {
155                 new Label(snapshot, this.labelName, this.description).update();
156                 log("Created Revision Label " + this.labelName);
157             } else if (null != lastBuild) {
158                 new Label(snapshot, this.labelName, this.description, this.lastBuild,
159                           this.buildlabel).update();
160                 log("Created View Label ("
161                     + (this.buildlabel ? "" : "non-") + "build) " + this.labelName
162                     + " as of " + this.lastBuild.toString());
163             } else {
164                 new Label(snapshot, this.labelName, this.description,
165                           this.buildlabel).update();
166                 log("Created View Label ("
167                     + (this.buildlabel ? "" : "non-") + "build) " + this.labelName);
168             }
169         } catch (Exception JavaDoc e) {
170             throw new BuildException(e);
171         } finally {
172             disconnectFromServer();
173         }
174
175     }
176
177     /**
178      * Override of base-class abstract function creates an
179      * appropriately configured view. For labels this a view
180      * configured as of this.lastBuild.
181      *
182      * @param raw the unconfigured <code>View</code>
183      * @return the snapshot <code>View</code> appropriately configured.
184      */

185     protected View createSnapshotView(View raw) {
186         /*
187         if (this.revisionlabel) {
188             return raw;
189         }
190         return new View(raw, ViewConfiguration.createFromTime(this.lastBuild));
191         */

192         return raw;
193     }
194
195 }
196
197
Popular Tags