1 18 package org.apache.tools.ant.taskdefs.optional.starteam; 19 20 import com.starbase.starteam.Folder; 21 import com.starbase.starteam.Item; 22 import com.starbase.starteam.Status; 23 import com.starbase.starteam.View; 24 import com.starbase.starteam.ViewConfiguration; 25 import java.io.IOException ; 26 import java.util.Enumeration ; 27 import org.apache.tools.ant.BuildException; 28 29 39 public class StarTeamCheckin extends TreeBasedTask { 40 41 44 public StarTeamCheckin() { 45 setRecursive(false); 47 } 48 49 private boolean createFolders = true; 50 51 54 private String comment = null; 55 56 60 private boolean addUncontrolled = false; 61 62 67 public void setCreateFolders(boolean argCreateFolders) { 68 this.createFolders = argCreateFolders; 69 } 70 71 72 76 public String getComment() { 77 return this.comment; 78 } 79 80 84 public void setComment(String comment) { 85 this.comment = comment; 86 } 87 88 92 public boolean isAddUncontrolled() { 93 return this.addUncontrolled; 94 } 95 96 101 public void setAddUncontrolled(boolean addUncontrolled) { 102 this.addUncontrolled = addUncontrolled; 103 } 104 105 111 private int lockStatus = Item.LockType.UNCHANGED; 112 113 120 public void setUnlocked(boolean v) { 121 if (v) { 122 this.lockStatus = Item.LockType.UNLOCKED; 123 } else { 124 this.lockStatus = Item.LockType.UNCHANGED; 125 } 126 } 127 128 136 protected View createSnapshotView(View raw) { 137 return new View(raw, ViewConfiguration.createTip()); 138 } 139 140 147 protected void testPreconditions() throws BuildException { 148 } 149 159 protected void logOperationDescription( 160 Folder starteamrootFolder, java.io.File targetrootFolder) { 161 log((this.isRecursive() ? "Recursive" : "Non-recursive") 162 + " Checkin from" 163 + (null == getRootLocalFolder() ? " (default): " : ": ") 164 + targetrootFolder.getAbsolutePath()); 165 166 log("Checking in to: " + starteamrootFolder.getFolderHierarchy()); 167 logIncludes(); 168 logExcludes(); 169 170 if (this.lockStatus == Item.LockType.UNLOCKED) { 171 log(" Items will be checked in unlocked."); 172 } else { 173 log(" Items will be checked in with no change in lock status."); 174 } 175 176 if (this.isForced()) { 177 log(" Items will be checked in in accordance with repository " 178 + "status and regardless of lock status."); 179 } else { 180 log(" Items will be checked in regardless of repository status " 181 + "only if locked."); 182 } 183 184 185 } 186 187 196 protected void visit(Folder starteamFolder, java.io.File targetFolder) 197 throws BuildException { 198 try { 199 if (null != getRootLocalFolder()) { 200 starteamFolder.setAlternatePathFragment( 201 targetFolder.getAbsolutePath()); 202 } 203 204 Folder[] foldersList = starteamFolder.getSubFolders(); 205 Item[] stFiles = starteamFolder.getItems(getTypeNames().FILE); 206 207 212 UnmatchedFileMap ufm = 213 new CheckinMap().init( 214 targetFolder.getAbsoluteFile(), starteamFolder); 215 216 217 for (int i = 0, size = foldersList.length; i < size; i++) { 218 Folder stFolder = foldersList[i]; 219 java.io.File subfolder = 220 new java.io.File (targetFolder, stFolder.getName()); 221 222 ufm.removeControlledItem(subfolder); 223 224 if (isRecursive()) { 225 visit(stFolder, subfolder); 226 } 227 } 228 229 230 for (int i = 0, size = stFiles.length; i < size; i++) { 231 com.starbase.starteam.File stFile = 232 (com.starbase.starteam.File) stFiles[i]; 233 processFile(stFile); 234 235 ufm.removeControlledItem( 236 new java.io.File (targetFolder, stFile.getName())); 237 } 238 239 if (this.addUncontrolled) { 240 ufm.processUncontrolledItems(); 241 } 242 243 } catch (IOException e) { 244 throw new BuildException(e); 245 } 246 247 } 248 249 256 private String describeCheckin(com.starbase.starteam.File remotefile) { 257 StringBuffer sb = new StringBuffer (); 258 sb.append(remotefile.getFullName()) 259 .append(" --> ") 260 .append(getFullRepositoryPath(remotefile)); 261 return sb.toString(); 262 } 263 264 271 private void processFile(com.starbase.starteam.File eachFile) 272 throws IOException { 273 String filename = eachFile.getName(); 274 275 if (!shouldProcess(filename)) { 277 log("Excluding " + getFullRepositoryPath(eachFile)); 278 return; 279 } 280 281 boolean checkin = true; 282 int fileStatus = (eachFile.getStatus()); 283 284 287 if (fileStatus == Status.MERGE || fileStatus == Status.UNKNOWN) { 288 eachFile.updateStatus(true, true); 289 fileStatus = (eachFile.getStatus()); 290 } 291 292 if (fileStatus == Status.MODIFIED) { 293 log("Checking in: " + describeCheckin(eachFile)); 294 } else if (fileStatus == Status.MISSING) { 295 log("Local file missing: " + describeCheckin(eachFile)); 296 checkin = false; 297 } else { 298 if (isForced()) { 299 log("Forced checkin of " + describeCheckin(eachFile) 300 + " over status " + Status.name(fileStatus)); 301 } else { 302 log("Skipping: " + getFullRepositoryPath(eachFile) 303 + " - status: " + Status.name(fileStatus)); 304 checkin = false; 305 } 306 } 307 if (checkin) { 308 eachFile.checkin(this.comment, this.lockStatus, 309 this.isForced(), true, true); 310 } 311 } 312 313 316 private class CheckinMap extends UnmatchedFileMap { 317 protected boolean isActive() { 318 return StarTeamCheckin.this.addUncontrolled; 319 } 320 321 322 328 void processUncontrolledItems() throws BuildException { 329 if (this.isActive()) { 330 Enumeration e = this.keys(); 331 while (e.hasMoreElements()) { 332 java.io.File local = (java.io.File ) e.nextElement(); 333 Item remoteItem = (Item) this.get(local); 334 remoteItem.update(); 335 336 if (local.isDirectory()) { 339 Folder folder = (Folder) remoteItem; 340 log("Added uncontrolled folder " 341 + folder.getFolderHierarchy() 342 + " from " + local.getAbsoluteFile()); 343 if (isRecursive()) { 344 UnmatchedFileMap submap = 345 new CheckinMap().init(local, folder); 346 submap.processUncontrolledItems(); 347 } 348 } else { 349 com.starbase.starteam.File remoteFile = 350 (com.starbase.starteam.File) remoteItem; 351 log("Added uncontrolled file " 352 + TreeBasedTask.getFullRepositoryPath(remoteFile) 353 + " from " + local.getAbsoluteFile()); 354 355 } 356 } 357 } 358 } 359 } 360 361 } 362 | Popular Tags |