1 18 package org.apache.tools.ant.taskdefs.optional.starteam; 19 20 import com.starbase.starteam.File; 21 import com.starbase.starteam.Folder; 22 import com.starbase.starteam.Item; 23 import com.starbase.starteam.Status; 24 import com.starbase.starteam.View; 25 import com.starbase.starteam.ViewConfiguration; 26 import java.io.IOException ; 27 import java.text.SimpleDateFormat ; 28 import java.util.Enumeration ; 29 import org.apache.tools.ant.BuildException; 30 import org.apache.tools.ant.Project; 31 32 42 43 public class StarTeamList extends TreeBasedTask { 44 private boolean listUncontrolled = true; 45 52 public void setLabel(String label) { 53 _setLabel(label); 54 } 55 56 63 public void setAsOfDate(String asOfDateParam) { 64 _setAsOfDate(asOfDateParam); 65 } 66 67 76 public void setAsOfDateFormat(String asOfDateFormat) { 77 _setAsOfDateFormat(asOfDateFormat); 78 } 79 80 81 89 protected View createSnapshotView(View raw) { 90 91 int labelID = getLabelID(raw); 92 93 if (labelID >= 0) { 96 return new View(raw, ViewConfiguration.createFromLabel(labelID)); 97 } 98 View view = getViewConfiguredByDate(raw); 100 if (view != null) { 101 return view; 102 } else { 104 return new View(raw, ViewConfiguration.createTip()); 105 } 106 } 107 108 114 protected void testPreconditions() throws BuildException { 115 if (null != getLabel() && null != getAsOfDate()) { 116 throw new BuildException( 117 "Both label and asOfDate specified. " 118 + "Unable to process request."); 119 } 120 } 121 122 131 protected void logOperationDescription(Folder starteamrootFolder, 132 java.io.File targetrootFolder) { 133 log((this.isRecursive() ? "Recursive" : "Non-recursive") 134 + " Listing of: " + starteamrootFolder.getFolderHierarchy()); 135 136 log("Listing against local folder" 137 + (null == getRootLocalFolder() ? " (default): " : ": ") 138 + targetrootFolder.getAbsolutePath(), 139 Project.MSG_INFO); 140 logLabel(); 141 logAsOfDate(); 142 logIncludes(); 143 logExcludes(); 144 145 146 } 147 156 protected void visit(Folder starteamFolder, java.io.File targetFolder) 157 throws BuildException { 158 try { 159 if (null != getRootLocalFolder()) { 160 starteamFolder.setAlternatePathFragment( 161 targetFolder.getAbsolutePath()); 162 163 } 164 Folder[] subFolders = starteamFolder.getSubFolders(); 165 Item[] files = starteamFolder.getItems(getTypeNames().FILE); 166 167 UnmatchedFileMap ufm = 168 new UnmatchedListingMap().init( 169 targetFolder.getAbsoluteFile(), starteamFolder); 170 171 log(""); 172 log("Listing StarTeam folder " 173 + starteamFolder.getFolderHierarchy()); 174 log(" against local folder " + targetFolder.getAbsolutePath()); 175 176 177 180 for (int i = 0; i < files.length; i++) { 181 File eachFile = (File) files[i]; 182 String filename = eachFile.getName(); 183 java.io.File localFile = 184 new java.io.File (targetFolder, filename); 185 186 ufm.removeControlledItem(localFile); 187 188 if (!shouldProcess(filename)) { 190 continue; 191 } 192 193 list(eachFile, localFile); 194 } 195 196 197 for (int i = 0; i < subFolders.length; i++) { 200 java.io.File targetSubfolder = 201 new java.io.File (targetFolder, subFolders[i].getName()); 202 ufm.removeControlledItem(targetSubfolder); 203 if (isRecursive()) { 204 visit(subFolders[i], targetSubfolder); 205 } 206 } 207 if (this.listUncontrolled) { 208 ufm.processUncontrolledItems(); 209 } 210 211 } catch (IOException e) { 212 throw new BuildException(e); 213 } 214 } 215 216 private static final SimpleDateFormat SDF = 217 new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss zzz"); 218 219 225 protected void list(File reposFile, java.io.File localFile) 226 throws IOException { 227 StringBuffer b = new StringBuffer (); 228 int status = reposFile.getStatus(); 229 java.util.Date displayDate = null; 230 if (status == Status.NEW) { 231 displayDate = new java.util.Date (localFile.lastModified()); 232 } else { 233 displayDate = reposFile.getModifiedTime().createDate(); 234 } 235 b.append(pad(Status.name(status), 12)).append(' '); 236 b.append(pad(getUserName(reposFile.getLocker()), 20)) 237 .append(' ') 238 .append(SDF.format(displayDate)) 239 .append(rpad(String.valueOf(reposFile.getSize()), 9)) 240 .append(' ') 241 .append(reposFile.getName()); 242 243 log(b.toString()); 244 } 245 246 private static final String BLANK_STRING = blanks(30); 247 248 private static String blanks(int len) { 249 StringBuffer b = new StringBuffer (); 250 for (int i = 0; i < len; i++) { 251 b.append(' '); 252 } 253 return b.toString(); 254 } 255 256 262 protected static String pad(String s, int padlen) { 263 return (s + BLANK_STRING).substring(0, padlen); 264 } 265 266 272 protected static String rpad(String s, int padlen) { 273 s = BLANK_STRING + s; 274 return s.substring(s.length() - padlen); 275 } 276 277 280 private class UnmatchedListingMap extends UnmatchedFileMap { 281 282 protected boolean isActive() { 283 return StarTeamList.this.listUncontrolled; 284 } 285 286 292 void processUncontrolledItems() throws BuildException { 293 if (this.isActive()) { 294 Enumeration e = this.keys(); 295 296 while (e.hasMoreElements()) { 298 java.io.File local = (java.io.File ) e.nextElement(); 299 Item remoteItem = (Item) this.get(local); 300 301 if (local.isFile()) { 304 com.starbase.starteam.File remoteFile = 305 (com.starbase.starteam.File) remoteItem; 306 try { 307 list(remoteFile, local); 308 } catch (IOException ie) { 309 throw new BuildException("IOError in stlist", ie); 310 } 311 } 312 } 313 e = this.keys(); 315 while (e.hasMoreElements()) { 316 java.io.File local = (java.io.File ) e.nextElement(); 317 Item remoteItem = (Item) this.get(local); 318 319 if (local.isDirectory()) { 322 Folder folder = (Folder) remoteItem; 323 if (isRecursive()) { 324 log("Listing uncontrolled folder " 325 + folder.getFolderHierarchy() 326 + " from " + local.getAbsoluteFile()); 327 UnmatchedFileMap submap = 328 new UnmatchedListingMap().init(local, folder); 329 submap.processUncontrolledItems(); 330 } 331 } 332 } 333 } 334 } 335 } 336 } 337 338 339 | Popular Tags |