FileDocCategorySizeDatePackage
StarTeamCheckin.javaAPI DocApache Ant 1.7012572Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.starteam

StarTeamCheckin

public class StarTeamCheckin extends TreeBasedTask
Checks files into a StarTeam project. Optionally adds files and in the local tree that are not managed by the repository to its control. Created: Sat Dec 15 20:26:07 2001
version
1.0
ant.task
name="stcheckin" category="scm" product="Starteam"

Fields Summary
private boolean
createFolders
private String
comment
The comment which will be stored with the checkin.
private boolean
addUncontrolled
holder for the add Uncontrolled attribute. If true, all local files not in StarTeam will be added to the repository.
private int
lockStatus
This attribute tells whether unlocked files on checkin (so that other users may access them) checkout or to leave the checkout status alone (default).
Constructors Summary
public StarTeamCheckin()
Constructor for StarTeamCheckin.

        // we want this to have a false default, unlike for Checkin.
        setRecursive(false);
    
Methods Summary
protected com.starbase.starteam.ViewcreateSnapshotView(com.starbase.starteam.View raw)
Override of base-class abstract function creates an appropriately configured view. For checkins this is always the current or "tip" view.

param
raw the unconfigured View
return
the snapshot View appropriately configured.

        return new View(raw, ViewConfiguration.createTip());
    
private java.lang.StringdescribeCheckin(com.starbase.starteam.File remotefile)
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

        StringBuffer sb = new StringBuffer();
        sb.append(remotefile.getFullName())
          .append(" --> ")
          .append(getFullRepositoryPath(remotefile));
        return sb.toString();
    
public java.lang.StringgetComment()
Get the comment attribute for this operation

return
value of comment.

        return this.comment;
    
public booleanisAddUncontrolled()
Get the value of addUncontrolled.

return
value of addUncontrolled.

        return this.addUncontrolled;
    
protected voidlogOperationDescription(com.starbase.starteam.Folder starteamrootFolder, java.io.File targetrootFolder)
Implements base-class abstract function to 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 by the user or not).

        log((this.isRecursive() ? "Recursive" : "Non-recursive")
            + " Checkin from"
            + (null == getRootLocalFolder() ? " (default): " : ": ")
            + targetrootFolder.getAbsolutePath());

        log("Checking in to: " + starteamrootFolder.getFolderHierarchy());
        logIncludes();
        logExcludes();

        if (this.lockStatus == Item.LockType.UNLOCKED) {
            log("  Items will be checked in unlocked.");
        } else {
            log("  Items will be checked in with no change in lock status.");
        }

        if (this.isForced()) {
            log("  Items will be checked in in accordance with repository "
                + "status and regardless of lock status.");
        } else {
            log("  Items will be checked in regardless of repository status "
                + "only if locked.");
        }


    
private voidprocessFile(com.starbase.starteam.File eachFile)
Processes (checks-out) stFilesfiles from StarTeam folder.

param
eachFile repository file to process
param
targetFolder a java.io.File (Folder) to work
throws
IOException when StarTeam API fails to work with files

        String filename = eachFile.getName();

        // If the file doesn't pass the include/exclude tests, skip it.
        if (!shouldProcess(filename)) {
            log("Excluding " + getFullRepositoryPath(eachFile));
                return;
        }

        boolean checkin = true;
        int fileStatus = (eachFile.getStatus());

        // We try to update the status once to give StarTeam
        // another chance.

        if (fileStatus == Status.MERGE || fileStatus == Status.UNKNOWN) {
            eachFile.updateStatus(true, true);
            fileStatus = (eachFile.getStatus());
        }

        if (fileStatus == Status.MODIFIED) {
            log("Checking in: " + describeCheckin(eachFile));
        } else if (fileStatus == Status.MISSING) {
            log("Local file missing: " + describeCheckin(eachFile));
            checkin = false;
        } else {
            if (isForced()) {
                log("Forced checkin of " + describeCheckin(eachFile)
                    + " over status " + Status.name(fileStatus));
            } else {
                log("Skipping: " + getFullRepositoryPath(eachFile)
                    + " - status: " + Status.name(fileStatus));
                checkin = false;
            }
        }
        if (checkin) {
            eachFile.checkin(this.comment, this.lockStatus,
                             this.isForced(), true, true);
        }
    
public voidsetAddUncontrolled(boolean addUncontrolled)
if true, any files or folders NOT in StarTeam will be added to the repository. Defaults to "false".

param
addUncontrolled Value to assign to addUncontrolled.

        this.addUncontrolled = addUncontrolled;
    
public voidsetComment(java.lang.String comment)
Optional checkin comment to be saved with the file.

param
comment Value to assign to comment.

        this.comment = comment;
    
public voidsetCreateFolders(boolean argCreateFolders)
Sets the value of createFolders

param
argCreateFolders Value to assign to this.createFolders


                     
        
        this.createFolders = argCreateFolders;
    
public voidsetUnlocked(boolean v)
Set to do an unlocked checkout; optional, default is false; If true, file will be unlocked so that other users may change it. If false, lock status will not change.

param
v true means do an unlocked checkout false means leave status alone.


                                                                
        
        if (v) {
            this.lockStatus = Item.LockType.UNLOCKED;
        } else {
            this.lockStatus = Item.LockType.UNCHANGED;
        }
    
protected voidtestPreconditions()
Implements base-class abstract function to define tests for any preconditons required by the task.

exception
BuildException thrown if both rootLocalFolder and viewRootLocalFolder are defined

    
protected voidvisit(com.starbase.starteam.Folder starteamFolder, java.io.File targetFolder)
Implements base-class abstract function to perform the checkout operation on the files in each folder of the tree.

param
starteamFolder the StarTeam folder to which files will be checked in
param
targetFolder local folder from which files will be checked in
exception
BuildException if any error occurs

        try {
            if (null != getRootLocalFolder()) {
                starteamFolder.setAlternatePathFragment(
                    targetFolder.getAbsolutePath());
            }

            Folder[] foldersList = starteamFolder.getSubFolders();
            Item[] stFiles = starteamFolder.getItems(getTypeNames().FILE);

            // note, it's important to scan the items BEFORE we make the
            // UnmatchedFileMap 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 =
                new CheckinMap().init(
                    targetFolder.getAbsoluteFile(), starteamFolder);


            for (int i = 0, size = foldersList.length; i < size; i++) {
                Folder stFolder = foldersList[i];
                java.io.File subfolder =
                    new java.io.File(targetFolder, stFolder.getName());

                ufm.removeControlledItem(subfolder);

                if (isRecursive()) {
                    visit(stFolder, subfolder);
                }
            }


            for (int i = 0, size = stFiles.length; i < size; i++) {
                com.starbase.starteam.File stFile =
                    (com.starbase.starteam.File) stFiles[i];
                processFile(stFile);

                ufm.removeControlledItem(
                    new java.io.File(targetFolder, stFile.getName()));
            }

            if (this.addUncontrolled) {
                ufm.processUncontrolledItems();
            }

        } catch (IOException e) {
            throw new BuildException(e);
        }