conor 2003/02/11 03:43:11
Modified: src/main/org/apache/tools/ant/taskdefs/optional/starteam StarTeamCheckout.java TreeBasedTask.java Log: iStarteam - when checking out to a revision label, directories are never created unless needed. PR: 14295 Submitted By: Steve Cohen Revision Changes Path 1.15 +61 -12 ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamCheckout.java Index: StarTeamCheckout.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamCheckout.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -w -u -r1.14 -r1.15 --- StarTeamCheckout.java 10 Feb 2003 14:14:27 -0000 1.14 +++ StarTeamCheckout.java 11 Feb 2003 11:43:10 -0000 1.15 @@ -241,7 +241,12 @@ * and viewRootLocalFolder are defined */ protected void testPreconditions() throws BuildException { - //intentionally do nothing + if (this.isUsingRevisionLabel() && this.createDirs) { + log("Ignoring createworkingdirs while using a revision label." + + " Folders will be created only as needed.", + Project.MSG_WARN); + this.createDirs=false; + } } /** @@ -288,9 +293,9 @@ if (this.deleteUncontrolled) { log(" Local items not found in the repository will be deleted."); } - log(" Working directories will "+ - (this.createDirs ? "be created as needed." - : "not be created.")); + log(" Directories will be created"+ + (this.createDirs ? " wherever they exist in the repository, even if empty." + : " only where needed to check out files.")); } /** @@ -313,10 +318,46 @@ targetFolder.getAbsolutePath()); } + if (!targetFolder.exists()) { + if (!this.isUsingRevisionLabel()) { + if (this.createDirs) { + if (targetFolder.mkdirs()) { + log("Creating folder: " + targetFolder); + } else { + throw new BuildException( + "Failed to create local folder " + targetFolder); + } + } + } + } + Folder[] foldersList = starteamFolder.getSubFolders(); Item[] filesList = starteamFolder.getItems(getTypeNames().FILE); + if (this.isUsingRevisionLabel()) { + + // prune away any files not belonging to the revision label + // this is one ugly API from Starteam SDK + + Hashtable labelItems = new Hashtable(filesList.length); + int s = filesList.length; + int[] ids = new int[s]; + for (int i=0; i < s; i++) { + ids[i]=filesList[i].getItemID(); + labelItems.put(new Integer(ids[i]), new Integer(i)); + } + int[] foundIds = getLabelInUse().getLabeledItemIDs(ids); + s = foundIds.length; + Item[] labeledFiles = new Item[s]; + for (int i=0; i < s; i++) { + Integer ID = new Integer(foundIds[i]); + labeledFiles[i] = + filesList[((Integer) labelItems.get(ID)).intValue()]; + } + filesList = labeledFiles; + } + // note, it's important to scan the items BEFORE we make the // Unmatched file map because that creates a bunch of NEW @@ -338,17 +379,9 @@ ufm.removeControlledItem(subfolder); if (isRecursive()) { - if (!subfolder.exists()) { - if (this.createDirs) { - log("Creating folder: " + subfolder); - subfolder.mkdirs(); - } - } - if (subfolder.exists()) { visit(stFolder, subfolder); } } - } for (int i = 0; i < filesList.length; i++) { com.starbase.starteam.File stFile = @@ -413,6 +446,14 @@ } if (this.isUsingRevisionLabel()) { + if (!targetFolder.exists()) { + if (targetFolder.mkdirs()) { + log("Creating folder: " + targetFolder); + } else { + throw new BuildException( + "Failed to create local folder " + targetFolder); + } + } boolean success = eachFile.checkoutByLabelID( localFile, getIDofLabelInUse(), @@ -472,6 +513,14 @@ } if (checkout) { + if (!targetFolder.exists()) { + if (targetFolder.mkdirs()) { + log("Creating folder: " + targetFolder); + } else { + throw new BuildException( + "Failed to create local folder " + targetFolder); + } + } eachFile.checkout(this.lockStatus, !this.useRepositoryTimeStamp, true, true); } 1.14 +11 -1 ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java Index: TreeBasedTask.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -u -r1.13 -r1.14 --- TreeBasedTask.java 10 Feb 2003 14:14:27 -0000 1.13 +++ TreeBasedTask.java 11 Feb 2003 11:43:10 -0000 1.14 @@ -381,6 +381,15 @@ } /** + * returns the label being used + * + * @return + */ + protected Label getLabelInUse() { + return this.labelInUse; + } + + /** * show the label in the log and its type. */ protected void logLabel() { @@ -532,7 +541,6 @@ public final void execute() throws BuildException { try { - testPreconditions(); Folder starteamrootfolder = configureRootStarteamFolder(); @@ -540,6 +548,8 @@ java.io.File localrootfolder = getLocalRootMapping(starteamrootfolder); + testPreconditions(); + // Tell user what he is doing logOperationDescription(starteamrootfolder, localrootfolder);