1 | /*
|
---|
2 | * Copyright 2001-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 | package org.apache.tools.ant.taskdefs.optional.starteam;
|
---|
18 |
|
---|
19 | import com.starbase.starteam.Label;
|
---|
20 | import com.starbase.starteam.View;
|
---|
21 | import com.starbase.util.OLEDate;
|
---|
22 | import java.text.ParseException;
|
---|
23 | import java.text.SimpleDateFormat;
|
---|
24 | import java.util.Date;
|
---|
25 | import org.apache.tools.ant.BuildException;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Creates a view label in StarTeam at the specified view.
|
---|
29 | *
|
---|
30 | * Ant Usage:
|
---|
31 | * <pre>
|
---|
32 | * <taskdef name="stlabel"
|
---|
33 | * classname="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamLabel"/<
|
---|
34 | * <stlabel
|
---|
35 | * label="1.0" lastbuild="20011514100000" description="Successful Build"
|
---|
36 | * username="BuildMaster" password="ant"
|
---|
37 | * starteamurl="server:port/project/view"/>
|
---|
38 | * </pre>
|
---|
39 | *
|
---|
40 | * @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
|
---|
41 | *
|
---|
42 | * @ant.task name="stlabel" category="scm"
|
---|
43 | */
|
---|
44 | public class StarTeamLabel extends StarTeamTask {
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * The name of the label to be set in Starteam.
|
---|
48 | */
|
---|
49 | private String labelName;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * The label description to be set in Starteam.
|
---|
53 | */
|
---|
54 | private String description;
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * If true, this will be a build label. If false, it will be a non-build
|
---|
58 | * label. The default is false. Has no effect if revision label is
|
---|
59 | * true.
|
---|
60 | */
|
---|
61 | private boolean buildlabel = false;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * If true, this will be a revision label. If false, it will be a build
|
---|
65 | * label. The default is false.
|
---|
66 | */
|
---|
67 | private boolean revisionlabel = false;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * The time of the last successful. The new label will be a snapshot of the
|
---|
71 | * repository at this time. String should be formatted as "yyyyMMddHHmmss"
|
---|
72 | */
|
---|
73 | private OLEDate lastBuild = null;
|
---|
74 |
|
---|
75 | private static final SimpleDateFormat DATE_FORMAT =
|
---|
76 | new SimpleDateFormat("yyyyMMddHHmmss");
|
---|
77 |
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * The name to be given to the label; required.
|
---|
81 | */
|
---|
82 | public void setLabel(String label) {
|
---|
83 | this.labelName = label;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Description of the label to be stored in the StarTeam project.
|
---|
88 | */
|
---|
89 | public void setDescription(String description) {
|
---|
90 | this.description = description;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * set the type of label based on the supplied value - if true, this
|
---|
95 | * label will be a revision label, if false, a build label.
|
---|
96 | *
|
---|
97 | * @param buildlabel If true this will be a revision label; if false,
|
---|
98 | * a build label
|
---|
99 | */
|
---|
100 | public void setBuildLabel(boolean buildlabel) {
|
---|
101 | this.buildlabel = buildlabel;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * set the type of label based on the supplied value - if true, this
|
---|
106 | * label will be a revision label, if false, a build label.
|
---|
107 | *
|
---|
108 | * @param revisionlabel If true this will be a revision label; if false,
|
---|
109 | * a build label
|
---|
110 | */
|
---|
111 | public void setRevisionLabel(boolean revisionlabel) {
|
---|
112 | this.revisionlabel = revisionlabel;
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * The timestamp of the build that will be stored with the label; required.
|
---|
119 | * Must be formatted <code>yyyyMMddHHmmss</code>
|
---|
120 | */
|
---|
121 | public void setLastBuild(String lastbuild) throws BuildException {
|
---|
122 | try {
|
---|
123 | Date lastBuildTime = DATE_FORMAT.parse(lastbuild);
|
---|
124 | this.lastBuild = new OLEDate(lastBuildTime);
|
---|
125 | } catch (ParseException e) {
|
---|
126 | throw new BuildException("Unable to parse the date '"
|
---|
127 | + lastbuild + "'", e);
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * This method does the work of creating the new view and checking it into
|
---|
133 | * Starteam.
|
---|
134 | *
|
---|
135 | */
|
---|
136 | public void execute() throws BuildException {
|
---|
137 |
|
---|
138 | if (this.revisionlabel && this.buildlabel) {
|
---|
139 | throw new BuildException("'revisionlabel' and 'buildlabel' "
|
---|
140 | + "both specified. A revision label cannot be a build label.");
|
---|
141 | }
|
---|
142 |
|
---|
143 | try {
|
---|
144 | View snapshot = openView();
|
---|
145 |
|
---|
146 | // Create the new label and update the repository
|
---|
147 |
|
---|
148 | if (this.revisionlabel) {
|
---|
149 | new Label(snapshot, this.labelName, this.description).update();
|
---|
150 | log("Created Revision Label " + this.labelName);
|
---|
151 | } else if (null != lastBuild) {
|
---|
152 | new Label(snapshot, this.labelName, this.description, this.lastBuild,
|
---|
153 | this.buildlabel).update();
|
---|
154 | log("Created View Label ("
|
---|
155 | + (this.buildlabel ? "" : "non-") + "build) " + this.labelName
|
---|
156 | + " as of " + this.lastBuild.toString());
|
---|
157 | } else {
|
---|
158 | new Label(snapshot, this.labelName, this.description,
|
---|
159 | this.buildlabel).update();
|
---|
160 | log("Created View Label ("
|
---|
161 | + (this.buildlabel ? "" : "non-") + "build) " + this.labelName);
|
---|
162 | }
|
---|
163 | } catch (Exception e) {
|
---|
164 | throw new BuildException(e);
|
---|
165 | } finally {
|
---|
166 | disconnectFromServer();
|
---|
167 | }
|
---|
168 |
|
---|
169 | }
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Override of base-class abstract function creates an
|
---|
173 | * appropriately configured view. For labels this a view
|
---|
174 | * configured as of this.lastBuild.
|
---|
175 | *
|
---|
176 | * @param raw the unconfigured <code>View</code>
|
---|
177 | * @return the snapshot <code>View</code> appropriately configured.
|
---|
178 | */
|
---|
179 | protected View createSnapshotView(View raw) {
|
---|
180 | /*
|
---|
181 | if (this.revisionlabel) {
|
---|
182 | return raw;
|
---|
183 | }
|
---|
184 | return new View(raw, ViewConfiguration.createFromTime(this.lastBuild));
|
---|
185 | */
|
---|
186 | return raw;
|
---|
187 | }
|
---|
188 |
|
---|
189 | }
|
---|
190 |
|
---|