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

📄 antstarteamcheckout.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one or more *  contributor license agreements.  See the NOTICE file distributed with *  this work for additional information regarding copyright ownership. *  The ASF licenses this file to You under the Apache License, Version 2.0 *  (the "License"); you may not use this file except in compliance with *  the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, software *  distributed under the License is distributed on an "AS IS" BASIS, *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  See the License for the specific language governing permissions and *  limitations under the License. * */package org.apache.tools.ant.taskdefs.optional.scm;import com.starbase.starteam.Folder;import com.starbase.starteam.Item;import com.starbase.starteam.Property;import com.starbase.starteam.Server;import com.starbase.starteam.StarTeamFinder;import com.starbase.starteam.Type;import com.starbase.starteam.View;import com.starbase.util.Platform;import java.util.StringTokenizer;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.Project;/** * Checks out files from a specific StarTeam server, project, view, and * folder. * <BR><BR> * This program logs in to a StarTeam server and opens up the specified * project and view.  Then, it searches through that view for the given * folder (or, if you prefer, it uses the root folder).  Beginning with * that folder and optionally continuing recursivesly, AntStarTeamCheckOut * compares each file with your include and exclude filters and checks it * out only if appropriate. * <BR><BR> * Checked out files go to a directory you specify under the subfolder * named for the default StarTeam path to the view.  That is, if you * entered /home/cpovirk/work as the target folder, your project was named * "OurProject," the given view was named "TestView," and that view is * stored by default at "C:\projects\Test," your files would be checked * out to /home/cpovirk/work/Test."  I avoided using the project name in * the path because you may want to keep several versions of the same * project on your computer, and I didn't want to use the view name, as * there may be many "Test" or "Version 1.0" views, for example.  This * system's success, of course, depends on what you set the default path * to in StarTeam. * <BR><BR> * You can set AntStarTeamCheckOut to verbose or quiet mode.  Also, it has * a safeguard against overwriting the files on your computer:  If the * target directory you specify already exists, the program will throw a * BuildException.  To override the exception, set <CODE>force</CODE> to * true. * <BR><BR> * <B>This program makes use of functions from the StarTeam API.  As a result * AntStarTeamCheckOut is available only to licensed users of StarTeam and * requires the StarTeam SDK to function.  You must have * <CODE>starteam-sdk.jar</CODE> in your classpath to run this program. * For more information about the StarTeam API and how to license it, see * the link below.</B> * * @version 1.0 * @see <A HREF="http://www.starbase.com/">StarBase Web Site</A> * * @ant.task name="starteam" category="scm" ignore="true" */public class AntStarTeamCheckOut extends org.apache.tools.ant.Task {    /**     * This constant sets the filter to include all files. This default has     * the same result as <CODE>setIncludes("*")</CODE>.     *     * @see #getIncludes()     * @see #setIncludes(String includes)     */    public static final String DEFAULT_INCLUDESETTING = "*";    /**     * This disables the exclude filter by default. In other words, no files     * are excluded. This setting is equivalent to <CODE>setExcludes(null)</CODE>     * .     *     * @see #getExcludes()     * @see #setExcludes(String excludes)     */    public static final String DEFAULT_EXCLUDESETTING = null;    /**     * The default folder to search; the root folder. Since     * AntStarTeamCheckOut searches subfolders, by default it processes an     * entire view.     *     * @see #getFolderName()     * @see #setFolderName(String folderName)     */    public static final String DEFAULT_FOLDERSETTING = null;    /**     * This is used when formatting the output. The directory name is     * displayed only when it changes.     */    private Folder prevFolder = null;    /** This field keeps count of the number of files checked out.  */    private int checkedOut = 0;    // Change these through their GET and SET methods.    /** The name of the server you wish to connect to.  */    private String serverName = null;    /** The port on the server used for StarTeam.  */    private int serverPort = -1;    /** The name of your project.  */    private String projectName = null;    /**     * The name of the folder you want to check out files from. All subfolders     * will be searched, as well.     */    private String folderName = DEFAULT_FOLDERSETTING;    /** The view that the files you want are in.  */    private String viewName = null;    /** Your username on the StarTeam server.  */    private String username = null;    /** Your StarTeam password.  */    private String password = null;    /**     * The path to the root folder you want to check out to. This is a local     * directory.     */    private String targetFolder = null;    /**     * If force set to true, AntStarTeamCheckOut will overwrite files in the     * target directory.     */    private boolean force = false;    /**     * When verbose is true, the program will display all files and     * directories as they are checked out.     */    private boolean verbose = false;    /**     * Set recursion to false to check out files in only the given folder and     * not in its subfolders.     */    private boolean recursion = true;    // These fields deal with includes and excludes    /** All files that fit this pattern are checked out.  */    private String includes = DEFAULT_INCLUDESETTING;    /** All files fitting this pattern are ignored.  */    private String excludes = DEFAULT_EXCLUDESETTING;    /** The file delimitor on the user's system.  */    private String delim = Platform.getFilePathDelim();    /**     * whether to use the Starteam "default folder" when calculating the     * target paths to which files are checked out (false) or if targetFolder     * represents an absolute mapping to folderName.     */    private boolean targetFolderAbsolute = false;    /** convenient method to check for conditions */    private static void assertTrue(boolean value, String msg) throws BuildException {        if (!value) {            throw new BuildException(msg);        }    }    /**     * Check if the attributes/elements are correct.     * @throws BuildException if there was a problem.     */    protected void checkParameters() throws BuildException {        // Check all of the properties that are required.        assertTrue(getServerName() != null, "ServerName must be set.");        assertTrue(getServerPort() != -1, "ServerPort must be set.");        assertTrue(getProjectName() != null, "ProjectName must be set.");        assertTrue(getViewName() != null, "ViewName must be set.");        assertTrue(getUsername() != null, "Username must be set.");        assertTrue(getPassword() != null, "Password must be set.");        assertTrue(getTargetFolder() != null, "TargetFolder must be set.");        // Because of the way I create the full target path, there        // must be NO slash at the end of targetFolder and folderName        // However, if the slash or backslash is the only character, leave it alone        if ((getTargetFolder().endsWith("/")                || getTargetFolder().endsWith("\\"))             && getTargetFolder().length() > 1) {            setTargetFolder(getTargetFolder().substring(0, getTargetFolder().length() - 1));        }        // Check to see if the target directory exists.        java.io.File dirExist = new java.io.File(getTargetFolder());        if (dirExist.isDirectory() && !getForce()) {            throw new BuildException("Target directory exists. Set \"force\" "                 + "to \"true\" to continue anyway.");        }    }    /**     * Do the execution.     *     * @throws BuildException if there was a problem.     */    public void execute() throws BuildException {        log("DEPRECATED - The starteam task is deprecated.  Use stcheckout instead.",            Project.MSG_WARN);        // Connect to the StarTeam server, and log on.        Server s = getServer();        try {            // Search the items on this server.            runServer(s);        } finally {            // Disconnect from the server.            s.disconnect();        }        // after you are all of the properties are ok, do your thing        // with StarTeam.  If there are any kind of exceptions then        // send the message to the project log.        // Tell how many files were checked out.        log(checkedOut + " files checked out.");    }    /**     * Creates and logs in to a StarTeam server.     *     * @return A StarTeam server.     */    protected Server getServer() {        // Simplest constructor, uses default encryption algorithm and compression level.        Server s = new Server(getServerName(), getServerPort());        // Optional; logOn() connects if necessary.        s.connect();        // Logon using specified user name and password.        s.logOn(getUsername(), getPassword());        return s;    }    /**     * Searches for the specified project on the server.     *     * @param s A StarTeam server.     */    protected void runServer(Server s) {        com.starbase.starteam.Project[] projects = s.getProjects();        for (int i = 0; i < projects.length; i++) {            com.starbase.starteam.Project p = projects[i];            if (p.getName().equals(getProjectName())) {                if (getVerbose()) {                    log("Found " + getProjectName() + delim);                }                runProject(s, p);                break;            }        }    }    /**     * Searches for the given view in the project.     *     * @param s A StarTeam server.     * @param p A valid project on the given server.     */    protected void runProject(Server s, com.starbase.starteam.Project p) {        View[] views = p.getViews();        for (int i = 0; i < views.length; i++) {            View v = views[i];            if (v.getName().equals(getViewName())) {                if (getVerbose()) {                    log("Found " + getProjectName() + delim + getViewName() + delim);                }                runType(s, p, v, s.typeForName(s.getTypeNames().FILE));                break;            }        }    }    /**     * Searches for folders in the given view.     *     * @param s A StarTeam server.     * @param p A valid project on the server.     * @param v A view name from the specified project.     * @param t An item type which is currently always "file".     */    protected void runType(Server s, com.starbase.starteam.Project p, View v, Type t) {        // This is ugly; checking for the root folder.        Folder f = v.getRootFolder();        if (getFolderName() != null) {            if (getFolderName().equals("\\") || getFolderName().equals("/")) {                setFolderName(null);            } else {                f = StarTeamFinder.findFolder(v.getRootFolder(), getFolderName());                assertTrue(null != f, "ERROR: " + getProjectName() + delim                    + getViewName() + delim + v.getRootFolder() + delim                    + getFolderName() + delim                    + " does not exist.");            }        }        if (getVerbose() && getFolderName() != null) {            log("Found " + getProjectName() + delim + getViewName()                + delim + getFolderName() + delim + "\n");        }        // For performance reasons, it is important to pre-fetch all the        // properties we'll need for all the items we'll be searching.        // We always display the ItemID (OBJECT_ID) and primary descriptor.        int nProperties = 2;        // We'll need this item type's primary descriptor.        Property p1 = getPrimaryDescriptor(t);        // Does this item type have a secondary descriptor?        // If so, we'll need it.        Property p2 = getSecondaryDescriptor(t);        if (p2 != null) {            nProperties++;        }        // Now, build an array of the property names.

⌨️ 快捷键说明

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