⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 starteamcheckout.java

📁 java ant的源码!非常值得看的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        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"             : "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."             : " only where needed to check out files."));    }    /**     * Implements base-class abstract function to perform the checkout     * operation on the files in each folder of the tree.     *     * @param starteamFolder the StarTeam folder from which files to be     *                       checked out     * @param targetFolder the local mapping of rootStarteamFolder     * @exception BuildException if any error occurs     */    protected void visit(Folder starteamFolder, java.io.File targetFolder)            throws BuildException {        try {            if (null != getRootLocalFolder()) {                starteamFolder.setAlternatePathFragment(                    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            // folders and files (unattached to repository) and we            // don't want to include those in our traversal.            UnmatchedFileMap ufm =                new CheckoutMap().                    init(targetFolder.getAbsoluteFile(), starteamFolder);            for (int i = 0; i < foldersList.length; 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; i < filesList.length; i++) {                com.starbase.starteam.File stFile =                    (com.starbase.starteam.File) filesList[i];                processFile(stFile, targetFolder);                ufm.removeControlledItem(                    new java.io.File(targetFolder, stFile.getName()));            }            if (this.deleteUncontrolled) {                ufm.processUncontrolledItems();            }        } catch (IOException e) {            throw new BuildException(e);        }    }    /**     * 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) {        StringBuffer sb = new StringBuffer();        sb.append(getFullRepositoryPath(remotefile))          .append(" --> ");        if (null == localFile) {            sb.append(remotefile.getFullName());        } else {            sb.append(localFile);        }        return sb.toString();    }    private String describeCheckout(com.starbase.starteam.File remotefile) {        return describeCheckout(remotefile, null);    }    /**     * Processes (checks out) <code>stFiles</code>files 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     */    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),                Project.MSG_INFO);                return;        }        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(),                this.lockStatus,                !this.useRepositoryTimeStamp,                true,                false);            if (success) {                log("Checked out " + describeCheckout(eachFile, localFile));            }        } else {            boolean checkout = true;            // Just a note: StarTeam has a status for NEW which implies            // that there is an item  on your local machine that is not            // in the repository.  These are the items that show up as            // NOT IN VIEW in the Starteam GUI.            // One would think that we would want to perhaps checkin the            // NEW items (not in all cases! - Steve Cohen 15 Dec 2001)            // Unfortunately, the sdk doesn't really work, and we can't            // actually see  anything with a status of NEW. That is why            // we can just check out  everything here without worrying            // about losing anything.            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());            }            log(eachFile.toString() + " has status of "                + Status.name(fileStatus), Project.MSG_DEBUG);            switch (fileStatus) {            case Status.OUTOFDATE:            case Status.MISSING:                log("Checking out: " + describeCheckout(eachFile));                break;            default:                if (isForced() && fileStatus != Status.CURRENT) {                    log("Forced checkout of "                        + describeCheckout(eachFile)                        + " over status " + Status.name(fileStatus));                } else {                    log("Skipping: " + getFullRepositoryPath(eachFile)                        + " - status: " + Status.name(fileStatus));                    checkout = false;                }            }            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, this.convertEOL, false);            }        }    }    /**     * handles the deletion of uncontrolled items     */    private class CheckoutMap extends UnmatchedFileMap {        protected boolean isActive() {            return StarTeamCheckout.this.deleteUncontrolled;        }        /**         * 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         *        not used in this implementation         */        UnmatchedFileMap init(java.io.File localFolder, Folder remoteFolder) {            if (!localFolder.exists()) {                return this;            }            String[] localFiles = localFolder.list();            // PR 31965 says that it can return null            if (localFiles == null) {                return this;            }            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 {                    this.put(localFile, "");                }            }            return this;        }        /**         * deletes uncontrolled items from the local tree.  It is assumed         * that this method will not be called until all the items in the         * corresponding folder have been processed, and that the internal map         * will contain only uncontrolled items.         */        void processUncontrolledItems() throws BuildException {            if (this.isActive()) {                Enumeration e = this.keys();                while (e.hasMoreElements()) {                    java.io.File local = (java.io.File) e.nextElement();                    delete(local);                }            }        }        /**         * 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,            // anything below it can be deleted.            if (local.isDirectory() && isRecursive()) {                String[] contents = local.list();                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());        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -