@@ -59,6 +59,7 @@ import com.starbase.starteam.Status;
import com.starbase.starteam.View;
import com.starbase.starteam.ViewConfiguration;
import java.io.IOException;
import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.tools.ant.BuildException;
@@ -100,7 +101,7 @@ public class StarTeamCheckout extends TreeBasedTask {
/**
* holder for the deleteUncontrolled attribute. If true,
* (default) local non-binary files will be checked out using the local
* (default) local non-binary files will be checked out using the local
* platform's EOL convention. If false, checkouts will preserve the
* server's EOL convention.
*/
@@ -134,10 +135,10 @@ public class StarTeamCheckout extends TreeBasedTask {
public void setConvertEOL(boolean value) {
this.convertEOL = value;
}
/**
* Sets the label StarTeam is to use for checkout; defaults to the most recent file.
* The label must exist in starteam or an exception will be thrown.
* The label must exist in starteam or an exception will be thrown.
* @param label the label to be used
*/
public void setLabel(String label) {
@@ -156,7 +157,7 @@ public class StarTeamCheckout extends TreeBasedTask {
private int lockStatus = Item.LockType.UNCHANGED;
/**
* Set to do a locked checkout; optional default is false.
* Set to do a locked checkout; optional default is false.
* @param v True to do a locked checkout, false to checkout without
* changing status/.
* @exception BuildException if both locked and unlocked are set true
@@ -190,27 +191,26 @@ public class StarTeamCheckout extends TreeBasedTask {
/**
* should checked out files get the timestamp from the repository
* or the time they are checked out. True means use the repository
* or the time they are checked out. True means use the repository
* timestamp.
*/
private boolean useRepositoryTimeStamp = false;
/**
* sets the useRepositoryTimestmp member.
*
*
* @param useRepositoryTimeStamp
* true means checked out files will get the repository timestamp.
* false means the checked out files will be timestamped at the time
* of checkout.
*/
public void setUseRepositoryTimeStamp(boolean useRepositoryTimeStamp)
{
public void setUseRepositoryTimeStamp(boolean useRepositoryTimeStamp) {
this.useRepositoryTimeStamp = useRepositoryTimeStamp;
}
/**
* returns the value of the useRepositoryTimestamp member
*
*
* @return the value of the useRepositoryTimestamp member
*/
public boolean getUseRepositoryTimeStamp() {
@@ -221,24 +221,22 @@ public class StarTeamCheckout extends TreeBasedTask {
* appropriately configured view for checkouts - either
* the current view or a view from this.label or the raw
* view itself in the case of a revision label.
*
*
* @param raw the unconfigured <code>View</code>
*
*
* @return the snapshot <code>View</code> appropriately configured.
* @exception BuildException
*/
protected View createSnapshotView(View raw)
throws BuildException
{
protected View createSnapshotView(View raw) throws BuildException {
int labelID = getLabelID(raw);
// if a label has been supplied and it is a view label, use it
// if a label has been supplied and it is a view label, use it
// to configure the view
if (this.isUsingViewLabel()) {
return new View(raw, ViewConfiguration.createFromLabel(labelID));
}
// if a label has been supplied and it is a revision label, use the raw
}
// if a label has been supplied and it is a revision label, use the raw
// the view as the snapshot
else if (this.isUsingRevisionLabel()) {
return raw;
@@ -253,37 +251,36 @@ public class StarTeamCheckout extends TreeBasedTask {
* Implements base-class abstract function to define tests for
* any preconditons required by the task.
*
* @exception BuildException thrown if both rootLocalFolder
* @exception BuildException thrown if both rootLocalFolder
* and viewRootLocalFolder are defined
*/
protected void testPreconditions() throws BuildException {
if (this.isUsingRevisionLabel() && this.createDirs) {
log("Ignoring createworkingdirs while using a revision label." +
" Folders will be created only as needed.",
log("Ignoring createworkingdirs while using a revision label."
+ " Folders will be created only as needed.",
Project.MSG_WARN);
this.createDirs=false;
this.createDirs = false;
}
}
/**
* extenders should emit to the log an entry describing the parameters
* that will be used by this operation.
*
*
* @param starteamrootFolder
* root folder in StarTeam for the operation
* @param targetrootFolder
* root local folder for the operation (whether specified
* root local folder for the operation (whether specified
* by the user or not.
*/
protected void logOperationDescription(
Folder starteamrootFolder, java.io.File targetrootFolder)
{
log((this.isRecursive() ? "Recursive" : "Non-recursive") +
" Checkout from: " + starteamrootFolder.getFolderHierarchy());
Folder starteamrootFolder, java.io.File targetrootFolder) {
log((this.isRecursive() ? "Recursive" : "Non-recursive")
+ " Checkout from: " + starteamrootFolder.getFolderHierarchy());
log(" Checking out to"
+ (null == getRootLocalFolder() ? "(default): " : ": ")
log(" Checking out to"
+ (null == getRootLocalFolder() ? "(default): " : ": ")
+ targetrootFolder.getAbsolutePath());
@@ -293,32 +290,28 @@ public class StarTeamCheckout extends TreeBasedTask {
if (this.lockStatus == Item.LockType.EXCLUSIVE) {
log(" Items will be checked out with Exclusive locks.");
}
else if (this.lockStatus == Item.LockType.UNLOCKED) {
} else if (this.lockStatus == Item.LockType.UNLOCKED) {
log(" Items will be checked out unlocked "
+"(even if presently locked).");
}
else {
+ "(even if presently locked).");
} else {
log(" Items will be checked out with no change in lock status.");
}
log(" Items will be checked out with " +
(this.useRepositoryTimeStamp ? "repository timestamps."
log(" Items will be checked out with "
+ (this.useRepositoryTimeStamp ? "repository timestamps."
: "the current timestamp."));
log(" Items will be checked out " +
(this.isForced() ? "regardless of" : "in accordance with") +
log(" Items will be checked out "
+ (this.isForced() ? "regardless of" : "in accordance with") +
" repository status.");
if (this.deleteUncontrolled) {
log(" Local items not found in the repository will be deleted.");
}
log(" Items will be checked out " +
(this.convertEOL
? "using the local machine's EOL convention"
log(" Items will be checked out "
+ (this.convertEOL ? "using the local machine's EOL convention"
: "without changing the EOL convention used on the server"));
log(" Directories will be created"+
(this.createDirs
? " wherever they exist in the repository, even if empty."
log(" Directories will be created"
+ (this.createDirs ? " wherever they exist in the repository, even if empty."
: " only where needed to check out files."));
}
/**
* Implements base-class abstract function to perform the checkout
@@ -330,8 +323,7 @@ public class StarTeamCheckout extends TreeBasedTask {
* @exception BuildException if any error occurs
*/
protected void visit(Folder starteamFolder, java.io.File targetFolder)
throws BuildException
{
throws BuildException {
try {
@@ -339,7 +331,7 @@ public class StarTeamCheckout extends TreeBasedTask {
starteamFolder.setAlternatePathFragment(
targetFolder.getAbsolutePath());
}
if (!targetFolder.exists()) {
if (!this.isUsingRevisionLabel()) {
if (this.createDirs) {
@@ -352,8 +344,8 @@ public class StarTeamCheckout extends TreeBasedTask {
}
}
}
Folder[] foldersList = starteamFolder.getSubFolders();
Item[] filesList = starteamFolder.getItems(getTypeNames().FILE);
@@ -361,32 +353,32 @@ public class StarTeamCheckout extends TreeBasedTask {
// 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();
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()];
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
// folders and files (unattached to repository) and we
// don't want to include those in our traversal.
UnmatchedFileMap ufm =
UnmatchedFileMap ufm =
new CheckoutMap().
init(targetFolder.getAbsoluteFile(), starteamFolder);
@@ -395,7 +387,7 @@ public class StarTeamCheckout extends TreeBasedTask {
for (int i = 0; i < foldersList.length; i++) {
Folder stFolder = foldersList[i];
java.io.File subfolder =
java.io.File subfolder =
new java.io.File(targetFolder, stFolder.getName());
ufm.removeControlledItem(subfolder);
@@ -406,10 +398,10 @@ public class StarTeamCheckout extends TreeBasedTask {
}
for (int i = 0; i < filesList.length; i++) {
com.starbase.starteam.File stFile =
com.starbase.starteam.File stFile =
(com.starbase.starteam.File) filesList[i];
processFile( stFile, targetFolder);
processFile(stFile, targetFolder);
ufm.removeControlledItem(
new java.io.File(targetFolder, stFile.getName()));
}
@@ -424,14 +416,13 @@ public class StarTeamCheckout extends TreeBasedTask {
/**
* provides a string showing from and to full paths for logging
*
*
* @param remotefile the Star Team file being processed.
*
*
* @return a string showing from and to full paths
*/
private String describeCheckout(com.starbase.starteam.File remotefile,
java.io.File localFile)
{
java.io.File localFile) {
StringBuffer sb = new StringBuffer();
sb.append(getFullRepositoryPath(remotefile))
.append(" --> ");
@@ -443,7 +434,7 @@ public class StarTeamCheckout extends TreeBasedTask {
return sb.toString();
}
private String describeCheckout(com.starbase.starteam.File remotefile) {
return describeCheckout(remotefile,null);
return describeCheckout(remotefile, null);
}
/**
* Processes (checks out) <code>stFiles</code>files from StarTeam folder.
@@ -452,17 +443,16 @@ public class StarTeamCheckout extends TreeBasedTask {
* @param targetFolder a java.io.File (Folder) to work
* @throws IOException when StarTeam API fails to work with files
*/
private void processFile(com.starbase.starteam.File eachFile,
java.io.File targetFolder )
throws IOException
{
private void processFile(com.starbase.starteam.File eachFile,
File targetFolder)
throws IOException {
String filename = eachFile.getName();
java.io.File localFile = new java.io.File(targetFolder, filename);
// If the file doesn't pass the include/exclude tests, skip it.
if (!shouldProcess(filename)) {
log("Excluding " + getFullRepositoryPath(eachFile),
log("Excluding " + getFullRepositoryPath(eachFile),
Project.MSG_INFO);
return;
}
@@ -486,8 +476,7 @@ public class StarTeamCheckout extends TreeBasedTask {
if (success) {
log("Checked out " + describeCheckout(eachFile, localFile));
}
}
else {
} else {
boolean checkout = true;
// Just a note: StarTeam has a status for NEW which implies
@@ -506,15 +495,14 @@ public class StarTeamCheckout extends TreeBasedTask {
// We try to update the status once to give StarTeam
// another chance.
if (fileStatus == Status.MERGE ||
fileStatus == Status.UNKNOWN)
{
if (fileStatus == Status.MERGE
|| fileStatus == Status.UNKNOWN) {
eachFile.updateStatus(true, true);
fileStatus = (eachFile.getStatus());
}
log(eachFile.toString() + " has status of " +
Status.name(fileStatus), Project.MSG_DEBUG);
log(eachFile.toString() + " has status of "
+ Status.name(fileStatus), Project.MSG_DEBUG);
switch (fileStatus) {
@@ -524,12 +512,12 @@ public class StarTeamCheckout extends TreeBasedTask {
break;
default:
if (isForced()) {
log("Forced checkout of "
+ describeCheckout(eachFile)
log("Forced checkout of "
+ describeCheckout(eachFile)
+ " over status " + Status.name(fileStatus));
} else {
log("Skipping: " + getFullRepositoryPath(eachFile) +
" - status: " + Status.name(fileStatus));
log("Skipping: " + getFullRepositoryPath(eachFile)
+ " - status: " + Status.name(fileStatus));
checkout = false;
}
}
@@ -543,7 +531,7 @@ public class StarTeamCheckout extends TreeBasedTask {
"Failed to create local folder " + targetFolder);
}
}
eachFile.checkout(this.lockStatus,
eachFile.checkout(this.lockStatus,
!this.useRepositoryTimeStamp, this.convertEOL, true);
}
}
@@ -560,7 +548,7 @@ public class StarTeamCheckout extends TreeBasedTask {
* override of the base class init. It can be much simpler, since
* the action to be taken is simply to delete the local files. No
* further interaction with the repository is necessary.
*
*
* @param localFolder
* the local folder from which the mappings will be made.
* @param remoteFolder
@@ -572,18 +560,17 @@ public class StarTeamCheckout extends TreeBasedTask {
}
String[] localFiles = localFolder.list();
for (int i=0; i < localFiles.length; i++) {
java.io.File localFile =
for (int i = 0; i < localFiles.length; i++) {
java.io.File localFile =
new java.io.File(localFolder, localFiles[i]).getAbsoluteFile();
log("adding " + localFile + " to UnmatchedFileMap",
Project.MSG_DEBUG);
if (localFile.isDirectory()) {
this.put(localFile, "");
}
else {
} else {
this.put(localFile, "");
}
}
@@ -591,7 +578,7 @@ public class StarTeamCheckout extends TreeBasedTask {
}
/**
* deletes uncontrolled items from the local tree. It is assumed
* that this method will not be called until all the items in the
@@ -607,23 +594,23 @@ public class StarTeamCheckout extends TreeBasedTask {
}
}
}
/**
* deletes all files and if the file is a folder recursively deletes
* everything in it.
*
*
* @param local The local file or folder to be deleted.
*/
void delete(java.io.File local) {
// once we find a folder that isn't in the repository,
// once we find a folder that isn't in the repository,
// anything below it can be deleted.
if (local.isDirectory() && isRecursive()) {
String[] contents = local.list();
for (int i=0; i< contents.length; i++) {
for (int i = 0; i < contents.length; i++) {
java.io.File file = new java.io.File(local, contents[i]);
delete(file);
}
}
}
local.delete();
log("Deleted uncontrolled item " + local.getAbsolutePath());
}