1 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 ; 24 import java.text.SimpleDateFormat ; 25 import java.util.Date ; 26 import org.apache.tools.ant.BuildException; 27 28 46 public class StarTeamLabel extends StarTeamTask { 47 48 51 private String labelName; 52 53 56 private String description; 57 58 63 private boolean buildlabel = false; 64 65 69 private boolean revisionlabel = false; 70 71 75 private OLEDate lastBuild = null; 76 77 private static final SimpleDateFormat DATE_FORMAT = 78 new SimpleDateFormat ("yyyyMMddHHmmss"); 79 80 81 85 public void setLabel(String label) { 86 this.labelName = label; 87 } 88 89 93 public void setDescription(String description) { 94 this.description = description; 95 } 96 97 104 public void setBuildLabel(boolean buildlabel) { 105 this.buildlabel = buildlabel; 106 } 107 108 115 public void setRevisionLabel(boolean revisionlabel) { 116 this.revisionlabel = revisionlabel; 117 } 118 119 120 121 127 public void setLastBuild(String lastbuild) throws BuildException { 128 try { 129 Date lastBuildTime = DATE_FORMAT.parse(lastbuild); 130 this.lastBuild = new OLEDate(lastBuildTime); 131 } catch (ParseException e) { 132 throw new BuildException("Unable to parse the date '" 133 + lastbuild + "'", e); 134 } 135 } 136 137 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 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 e) { 170 throw new BuildException(e); 171 } finally { 172 disconnectFromServer(); 173 } 174 175 } 176 177 185 protected View createSnapshotView(View raw) { 186 192 return raw; 193 } 194 195 } 196 197 | Popular Tags |