diff --git a/docs/manual/OptionalTasks/starteam.html b/docs/manual/OptionalTasks/starteam.html
index 17d4cbe10..2d7bcdc8a 100644
--- a/docs/manual/OptionalTasks/starteam.html
+++ b/docs/manual/OptionalTasks/starteam.html
@@ -4,8 +4,25 @@
Apache Ant User Manual
+StarTeam Support
+
-Starteam
+
+These tasks make use of functions from the StarTeam API. As a result
+they are only available to licensed users of StarTeam. You must have
+starteam-sdk.jar
in your classpath to run these tasks.
+For more information about the StarTeam API and how to license it, see
+the StarBase web site.
+
+
+
+
+STCheckout
Description
@@ -13,43 +30,273 @@ Checks out files from a StarTeam project.
The includes and excludes attributes function differently from
-other tasks in Ant. Multiple patterns must be separated by spaces, not
-commas. See the examples for more information.
-
-
-This program makes use of functions from the StarTeam API. As a result
-this task is only available to licensed users of StarTeam. You must have
-starteam-sdk.jar
in your classpath to run this task.
-For more information about the StarTeam API and how to license it, see
-the StarBase web site.
+other tasks in Ant. Inclusion/exclusion by folder is NOT supported.
+
Parameters
- Attribute |
- Description |
- Required |
+ username |
+ The username of the account used to log in to the StarTeam server. |
+ yes |
+
+
+ password |
+ The password of the account used to log in to the StarTeam server. |
+ yes |
+
+ URL |
+ A string of the form "servername:portnum/project/view
+which enables user to set all of these elements in one string. |
+ yes* |
+
servername |
The name of the StarTeam server. |
- yes |
+ yes* |
serverport |
The port number of the StarTeam server. |
- yes |
+ yes* |
projectname |
The name of the StarTeam project. |
+ yes* |
+
+
+ viewname |
+ The name of the view in the StarTeam project. |
+ yes* |
+
+
+
+ rootstarteamfolder |
+ The root of the subtree in the StarTeam repository from which to
+ check out files. Defaults to the root folder of the view ('/'). |
+ no |
+
+
+ rootlocalfolder |
+ The local folder which will be the root of the tree to which files are checked out. If this is not supplied, then the StarTeam "default folder" associated with rootstarteamfolder is used. |
+ no |
+
+
+
+ createworkingdirs |
+ creates local folders even when the corresponding StarTeam folder is empty. Defaults to "true". |
+ no |
+
+
+ deleteuncontrolled |
+ if true, any files NOT in StarTeam will be deleted. Defaults to "true". |
+ no |
+
+
+ includes |
+ Only check out files that match at least one of the patterns in this list. Patterns must be separated by commas. Patterns in excludes take precedence over patterns in includes. |
+ no |
+
+
+ excludes |
+ Do not check out files that match at least one of the patterns in this list. Patterns must be separated by commas. Patterns in excludes take precedence over patterns in includes. |
+ no |
+
+
+
+* Either the URL attribute or all four of the servername, serverport, projectname and viewname attributes must be defined.
+
+Examples
+
+
+ <stcheckout servername="STARTEAM"
+ serverport="49201"
+ projectname="AProject"
+ viewname="AView"
+ username="auser"
+ password="secret"
+ rootlocalfolder="C:\dev\buildtest\co"
+ />
+
+
+The minimum necessary to check out files out from a StarTeam server. This will
+check out all files in the AView view of the AProject project to
+C:\dev\buildtest\co
. Empty folders in StarTeam will have local folders
+created for them and any non-StarTeam files found in the tree will be deleted.
+
+Or more simply:
+
+ <stcheckout URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ rootlocalfolder="C:\dev\buildtest\co"
+ />
+
+
+
+ <stcheckout URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ rootlocalfolder="C:\dev\buildtest\co"
+ rootstarteamfolder="\Dev"
+ excludes="*.bak *.old"
+ />
+
+
+This will checkout all files from the Dev folder and below that do not
+end in .bak or .old.
+
+
+ <stcheckout URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ rootlocalfolder="C:\dev\buildtest\co"
+ includes="*.htm,*.html"
+ excludes="index.*"
+ />
+
+
+
+
+This is an example of overlapping includes and excludes attributes. Because
+excludes takes precedence over includes, files named index.html
will
+not be checked out by this command.
+
+
+
+ <stcheckout URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ rootstarteamfolder="src/java"
+ rootlocalfolder="C:\dev\buildtest\co"
+ />
+
+
+
+ <stcheckout URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ rootstarteamfolder="src/java"
+ />
+
+
+
+ <stcheckout URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ rootstarteamfolder="src/java"
+ rootlocalfolder="C:\dev\buildtest\co\src\java"
+ />
+
+
+In the preceding three examples, assuming that the AProject project has a default folder of
+"AProject", the first example will check the files located in starteam under src/java out to a tree rooted at C:\dev\buildtest\co,
+the second to a tree rooted at C:\dev\buildtest\co\AProject\src\java and the third to a tree rooted at C:\dev\buildtest\co\src\java.
+
+
+STLabel
+
+Description
+
+Creates a view label in StarTeam at the specified view. The label will be classified by StarTeam as a "build label". This task will fail if there already exexists in viewname a label with the same name as the label parameter.
+
+Parameters
+
+
+ username |
+ The username of the account used to log in to the StarTeam server. |
yes |
+
+ password |
+ The password of the account used to log in to the StarTeam server. |
+ yes |
+
+
+
+ URL |
+ A string of the form "servername:portnum/project/view"
+which enables user to set all of these elements in one string. |
+ yes* |
+
+ servername |
+ The name of the StarTeam server. |
+ yes* |
+
+
+ serverport |
+ The port number of the StarTeam server. |
+ yes* |
+
+
+ projectname |
+ The name of the StarTeam project. |
+ yes* |
+
viewname |
The name of the view in the StarTeam project. |
+ yes* |
+
+
+ label |
+ The name to be given to the label |
+ yes |
+
+
+ lastbuild |
+ The timestamp of the build that will be stored with the label. Must be formatted yyyyMMddHHmmss |
yes |
+
+ description |
+ A description of the view to be stored in the StarTeam project. |
+ no |
+
+
+* Either the URL attribute or all four of the servername, serverport, projectname and viewname attributes must be defined.
+
+Examples
+
+This example shows the use of this tag. It will create a label named Version 6.2 with
+"Thorough description" as its description.
+
+ <tstamp>
+ <format property="nowstamp" pattern="yyyyMMddHHmmss" locale="en"/>
+ </tstamp>
+ <starteamlabel URL="STARTEAM:49201/Aproject/AView"
+ username="auser"
+ password="secret"
+ label="Version 6.2"
+ lastbuild="${nowstamp}"
+ description-"Thorough description"
+ />
+
+
+
+
+
+Starteam
+Deprecated
+This task has been deprecated. Use the STCheckout task instead.
+Description
+
+Checks out files from a StarTeam project.
+
+
+The includes and excludes attributes function differently from
+other tasks in Ant. Multiple patterns must be separated by spaces, not
+commas. See the examples for more information.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
username |
The username of the account used to log in to the StarTeam server. |
@@ -59,7 +306,28 @@ the StarBase web site.
password |
The password of the account used to log in to the StarTeam server. |
yes |
+
+
+ servername |
+ The name of the StarTeam server. |
+ yes |
+
+ serverport |
+ The port number of the StarTeam server. |
+ yes |
+
+
+ projectname |
+ The name of the StarTeam project. |
+ yes |
+
+
+ viewname |
+ The name of the view in the StarTeam project. |
+ yes |
+
+
targetfolder |
The folder to which files are checked out. What this precisely means is determined by the targetFolderAbsolute param. |
diff --git a/docs/manual/optionaltasklist.html b/docs/manual/optionaltasklist.html
index 22f1bb326..7d002cc2a 100644
--- a/docs/manual/optionaltasklist.html
+++ b/docs/manual/optionaltasklist.html
@@ -43,7 +43,7 @@
Rpm
Script
Sound
-Starteam
+Starteam Tasks
Stylebook
Telnet
Test
diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
index c680c8f92..881908c7f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties
+++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties
@@ -79,7 +79,8 @@ ftp=org.apache.tools.ant.taskdefs.optional.net.FTP
icontract=org.apache.tools.ant.taskdefs.optional.IContract
javacc=org.apache.tools.ant.taskdefs.optional.javacc.JavaCC
jjtree=org.apache.tools.ant.taskdefs.optional.javacc.JJTree
-starteam=org.apache.tools.ant.taskdefs.optional.scm.AntStarTeamCheckOut
+stcheckout=org.apache.tools.ant.taskdefs.optional.starteam.StartTeamCheckout
+stlabel=org.apache.tools.ant.taskdefs.optional.starteam.StartTeamLabel
wljspc=org.apache.tools.ant.taskdefs.optional.jsp.WLJspc
jlink=org.apache.tools.ant.taskdefs.optional.jlink.JlinkTask
native2ascii=org.apache.tools.ant.taskdefs.optional.Native2Ascii
@@ -133,6 +134,7 @@ replaceregexp=org.apache.tools.ant.taskdefs.optional.ReplaceRegExp
translate=org.apache.tools.ant.taskdefs.optional.i18n.Translate
# deprecated ant tasks (kept for back compatibility)
+starteam=org.apache.tools.ant.taskdefs.optional.scm.AntStarTeamCheckOut
javadoc2=org.apache.tools.ant.taskdefs.Javadoc
#compileTask=org.apache.tools.ant.taskdefs.CompileTask
copydir=org.apache.tools.ant.taskdefs.Copydir
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java b/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java
index 9ecf525dd..1cef43cc6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/scm/AntStarTeamCheckOut.java
@@ -285,6 +285,9 @@ public class AntStarTeamCheckOut extends org.apache.tools.ant.Task
*/
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();
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamCheckout.java b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamCheckout.java
new file mode 100644
index 000000000..10485747b
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamCheckout.java
@@ -0,0 +1,264 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.starteam;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import com.starbase.starteam.File;
+import com.starbase.starteam.Folder;
+import com.starbase.starteam.Item;
+import com.starbase.starteam.Status;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+
+/**
+ * This class logs into StarTeam checks out any changes that have occurred since
+ * the last successful build. It also creates all working directories on the
+ * local directory if appropriate. Ant Usage:
+ *
+ *
+ * @author Christopher Charlier, ThoughtWorks, Inc. 2001
+ * @author Jason Yip
+ * @author Jason Pettiss
+ * @version 1.1
+ * @author Steve Cohen
+ * @see StarBase Web Site
+ */
+public class StarTeamCheckout extends TreeBasedTask {
+
+ private boolean createDirs = true;
+ private boolean deleteUncontrolled = true;
+ /**
+ * Set the attribute that tells ant if we want to create all directories
+ * that are in the Starteam repository regardless if they are empty.
+ */
+ public void setCreateWorkingDirs(boolean value) {
+ this.createDirs = value;
+ }
+
+ /**
+ * Sets the attribute that tells ant whether or not to remove local files
+ * that are NOT found in the Starteam repository.
+ */
+ public void setDeleteUncontrolled(boolean value) {
+ this.deleteUncontrolled = value;
+ }
+
+
+ /**
+ * 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
+ */
+ protected void visit(Folder starteamFolder, java.io.File targetFolder )
+ throws BuildException
+ {
+ try {
+ Hashtable localFiles = getLocalFiles(targetFolder);
+
+ // If we have been told to create the working folders
+ if (createDirs) {
+ // Create if it doesn't exist
+ if (!targetFolder.exists()) {
+ targetFolder.mkdir();
+ }
+ }
+ // For all Files in this folder, we need to check
+ // if there have been modifications.
+
+ Item[] files = starteamFolder.getItems("File");
+ for (int i = 0; i < files.length; i++) {
+ File eachFile = (File) files[i];
+ String filename = eachFile.getName();
+ java.io.File localFile = new java.io.File(targetFolder, filename);
+ localFiles.remove(localFile.toString());
+
+ 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);
+ }
+
+ // If the file is current then skip it.
+ // If the file doesn't pass the include/exclude tests, skip it.
+ if (fileStatus == Status.CURRENT || !shouldProcess(filename)) {
+ continue;
+ }
+
+ // Check out anything else.
+ // 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.
+
+ log("Checking Out: " + (localFile.toString()), Project.MSG_INFO);
+ eachFile.checkoutTo(localFile, Item.LockType.
+ UNCHANGED, true, true, true);
+ }
+
+ // Now we recursively call this method on all sub folders in this folder.
+ Folder[] subFolders = starteamFolder.getSubFolders();
+ for (int i = 0; i < subFolders.length; i++) {
+ localFiles.remove(subFolders[i].getPath());
+ visit(subFolders[i],
+ new java.io.File(targetFolder, subFolders[i].getName()));
+ }
+
+ // Delete all folders or files that are not in Starteam.
+ if (this.deleteUncontrolled && !localFiles.isEmpty()) {
+ delete(localFiles);
+ }
+ } catch (IOException e) {
+ throw new BuildException(e);
+ }
+ }
+
+ /**
+ * Deletes everything on the local machine that is not in Starteam.
+ *
+ * @param files
+ */
+ /**
+ * Deletes everything on the local machine that is not in Starteam.
+ *
+ * @param files an "identity" Hashtable
which we use only because
+ * of ant's requirement to be JDK 1.1 compatible. Otherwise, we
+ * could use a set. We are only interested in the keys,
+ * not the associated values in this Hashtable. Each of its keys
+ * represents the name of a local file to be deleted.
+ */
+ private void delete(Hashtable files) {
+ try {
+
+ Enumeration e = files.keys();
+ while (e.hasMoreElements()) {
+ java.io.File file = new java.io.File(e.nextElement().toString());
+ delete(file);
+ }
+
+ } catch (SecurityException e) {
+ log("Error deleting file: " + e, Project.MSG_ERR);
+ }
+ }
+
+ /**
+ * Deletes the file from the local drive.
+ * @param file the file or directory to delete.
+ * @return true if the file was successfully deleted otherwise false.
+ */
+ private boolean delete(java.io.File file) {
+ // If the current file is a Directory, we need to delete all its children as well.
+ if (file.isDirectory()) {
+ java.io.File[] children = file.listFiles();
+ for (int i = 0; i < children.length; i++) {
+ delete(children[i]);
+ }
+ }
+
+ log("Deleting: " + file.getAbsolutePath(), Project.MSG_INFO);
+ return file.delete();
+ }
+
+ /**
+ * Gets the collection of the local file names in the current directory We
+ * need to check this collection against what we find in Starteam to
+ * understand what we need to delete in order to synch with the repos.
+ *
+ * @param folder
+ * @return
+ */
+ private static Hashtable getLocalFiles(java.io.File localFolder) {
+
+ // we can't use java 2 collections so we will use an identity Hashtable to
+ // hold the file names. We only care about the keys, not the values
+ // (which will all be "").
+
+ Hashtable results = new Hashtable();
+
+ if (localFolder.exists()) {
+ String[] localFiles = localFolder.list();
+ for (int i = 0; i < localFiles.length; i++) {
+ results.put( localFolder.toString() +
+ java.io.File.separatorChar + localFiles[i], "");
+ }
+ }
+ return results;
+ }
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamLabel.java b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamLabel.java
new file mode 100644
index 000000000..31661a49f
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamLabel.java
@@ -0,0 +1,143 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.starteam;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.starbase.starteam.Label;
+import com.starbase.starteam.ServerException;
+import com.starbase.starteam.StarTeamFinder;
+import com.starbase.starteam.View;
+import com.starbase.starteam.ViewConfiguration;
+import com.starbase.starteam.vts.comm.CommandException;
+import com.starbase.util.OLEDate;
+
+import org.apache.tools.ant.BuildException;
+
+/**
+ * This class logs into StarTeam and creates a label for the repository at the
+ * time of the last successful build.
+ * Ant Usage:
+ *
+ *
+ *
+ * @author Christopher Charlier, ThoughtWorks, Inc. 2001
+ * @author Jason Yip
+ * @see StarBase Web Site
+ */
+public class StarTeamLabel extends StarTeamTask {
+
+ /**
+ * The name of the label to be set in Starteam.
+ */
+ private String labelName;
+
+ /**
+ * The label description to be set in Starteam.
+ */
+ private String description;
+
+ /**
+ * The time of the last successful. The new label will be a snapshot of the
+ * repository at this time. String should be formatted as "yyyyMMddHHmmss"
+ */
+ private Date lastBuildTime;
+
+ private static final SimpleDateFormat DATE_FORMAT =
+ new SimpleDateFormat("yyyyMMddHHmmss");
+
+
+ public void setLabel(String label) {
+ this.labelName = label;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setLastBuild(String lastbuild) throws BuildException {
+ try {
+ lastBuildTime = DATE_FORMAT.parse(lastbuild);
+ } catch (ParseException e) {
+ throw new BuildException("Unable to parse the date '" + lastbuild + "'", e);
+ }
+ }
+
+ /**
+ * This method does the work of creating the new view and checking it into
+ * Starteam.
+ *
+ */
+ public void execute() throws BuildException {
+ OLEDate buildDate = new OLEDate(lastBuildTime);
+
+ // Get view as of the last successful build time.
+ View view = StarTeamFinder.openView(getUserName() + ":" + getPassword()
+ + "@" + getURL());
+ View snapshot = new View(view, ViewConfiguration.createFromTime(buildDate));
+
+ // Create the new label and update the repository
+ new Label(snapshot, labelName, description, buildDate, true).update();
+ log("Created Label " + labelName);
+ }
+
+}
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java
new file mode 100644
index 000000000..ee532d60b
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java
@@ -0,0 +1,297 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.starteam;
+
+import com.starbase.starteam.ServerException;
+import com.starbase.starteam.vts.comm.CommandException;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+
+import java.io.FileNotFoundException;
+import java.util.StringTokenizer;
+
+ /**
+ * Common super class for all StarTeam tasks.
+ * At this level of the hierarchy we are concerned only with obtaining a
+ * connection to the StarTeam server. The subclass TreeBasedTask
,
+ * also abstract defines the tree-walking behavior common to many subtasks.
+ *
+ * @see TreeBasedTask
+ * @author Jason Yip
+ * @version 1.1
+ * @author Steve Cohen
+ */
+
+public abstract class StarTeamTask extends Task {
+
+ // ATTRIBUTES
+
+ /**
+ * The username of the connection
+ */
+ private String userName;
+
+ /**
+ * The username of the connection
+ */
+ private String password;
+
+ /**
+ * name of Starteam server to connect to
+ */
+ private String servername;
+
+ /**
+ * port of Starteam server to connect to
+ */
+ private String serverport;
+
+ /**
+ * name of Starteam project to connect to
+ */
+ private String projectname;
+
+ /**
+ * name of Starteam view to connect to
+ */
+ private String viewname;
+
+ /////////////////////////////////////////////////////////
+ // GET/SET methods.
+ // Setters, of course are where ant user passes in values.
+ /////////////////////////////////////////////////////////
+
+ /**
+ * Set the name of StarTeamServer
+ *
+ * @param servername a String
value
+ * @see setURL()
+ */
+ public void setServername(String servername) {
+ this.servername = servername;
+ }
+
+ /**
+ * returns the name of the StarTeamServer
+ *
+ * @return the name of the StarTeam server
+ * @see getURL()
+ */
+ public String getServername() {
+ return this.servername;
+ }
+
+ /**
+ * set the port number of the StarTeam connection
+ *
+ * @param serverport port number to be set
+ * @see setURL()
+ */
+ public void setServerport(String serverport) {
+ this.serverport = serverport;
+ }
+
+ /**
+ * returns the port number of the StarTeam connection
+ *
+ * @return the port number of the StarTeam connection
+ * @see getURL()
+ */
+ public String getServerport() {
+ return this.serverport;
+ }
+
+ /**
+ * set the name of the StarTeam project to be acted on
+ *
+ * @param projectname the name of the StarTeam project to be acted on
+ * @see setURL()
+ */
+ public void setProjectname(String projectname) {
+ this.projectname = projectname;
+ }
+
+ /**
+ * returns the name of the StarTeam project to be acted on
+ *
+ * @return the name of the StarTeam project to be acted on
+ * @see getURL()
+ */
+ public String getProjectname() {
+ return this.projectname;
+ }
+
+ /**
+ * set the name of the StarTeam view to be acted on
+ *
+ * @param projectname the name of the StarTeam view to be acted on
+ * @see setURL()
+ */
+ public void setViewname(String viewname) {
+ this.viewname = viewname;
+ }
+
+ /**
+ * returns the name of the StarTeam view to be acted on
+ *
+ * @return the name of the StarTeam view to be acted on
+ * @see getURL()
+ */ public String getViewname() {
+ return this.viewname;
+ }
+
+
+ /**
+ * This is a convenience method for setting the server name, server port,
+ * project name and project folder at one shot.
+ *
+ * @param url a String
of the form
+ * "servername:portnum/project/view"
+ * @see setServerame()
+ * @see setServerport()
+ * @see setProjectname()
+ * @see setViewname()
+ */
+ public void setURL(String url) {
+ StringTokenizer t = new StringTokenizer(url,"/");
+ if (t.hasMoreTokens()) {
+ String unpw = t.nextToken();
+ int pos = unpw.indexOf(":");
+ if (pos > 0) {
+ this.servername = unpw.substring(0,pos);
+ this.serverport = unpw.substring(pos+1);
+ if (t.hasMoreTokens()) {
+ this.projectname=t.nextToken();
+ if (t.hasMoreTokens()) {
+ this.viewname = t.nextToken();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * convenience method returns whole URL at once
+ * returns
+ * as a single string
+ */
+ /**
+ * a convenience method which returns the whole StarTeam
+ * connection information as a single URL string of
+ *
+ * @return a String
of the form
+ * "servername:portnum/project/view"
+ * @see getServername()
+ * @see getServerport()
+ * @see getProjectname()
+ * @see getViewname()
+ */
+ public String getURL() {
+ return
+ this.servername + ":" +
+ this.serverport + "/" +
+ this.projectname + "/" +
+ ((null==this.viewname)?"":this.viewname);
+ }
+
+ /**
+ * set the name of the StarTeam user, needed for the connection
+ *
+ * @param userName name of the user to be logged in
+ */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ /**
+ * returns the name of the StarTeam user
+ *
+ * @return the name of the StarTeam user
+ */
+ public String getUserName() {
+ return this.userName;
+ }
+
+ /**
+ * set the password to be used for login.
+ *
+ * @param password the password to be used for login
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * returns the password used for login
+ *
+ * @return the password used for login
+ */
+ public String getPassword() {
+ return this.password;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java
new file mode 100644
index 000000000..b742b2fe1
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java
@@ -0,0 +1,341 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.starteam;
+
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.BuildException;
+
+import java.util.StringTokenizer;
+import java.io.IOException;
+
+import com.starbase.starteam.File;
+import com.starbase.starteam.Folder;
+import com.starbase.starteam.View;
+import com.starbase.starteam.ViewConfiguration;
+import com.starbase.util.OLEDate;
+import com.starbase.starteam.StarTeamFinder;
+
+/**
+ * FileBasedTask.java
+ * This abstract class is the base for any tasks that are tree-based, that
+ * is, for tasks which iterate over a tree of folders in StarTeam which
+ * is reflected in a tree of folder the local machine.
+ *
+ * This class provides the tree-iteration functionality. Derived classes
+ * will implement their specific task functionality by the visitor pattern,
+ * specifically by implementing the method
+ * visit(Folder rootStarteamFolder, java.io.File rootLocalFolder)
+ *
+ * Created: Sat Dec 15 16:55:19 2001
+ *
+ * @author Steve Cohen
+ * @version 1.0
+ * @see StarBase Web Site
+ */
+
+public abstract class TreeBasedTask extends StarTeamTask {
+
+
+
+ ///////////////////////////////////////////////////////////////
+ // default values for attributes.
+ ///////////////////////////////////////////////////////////////
+ /**
+ * This constant sets the filter to include all files. This default has
+ * the same result as setIncludes("*")
.
+ *
+ * @see #getIncludes()
+ * @see #setIncludes(String includes)
+ */
+ public final static String DEFAULT_INCLUDESETTING = "*";
+
+ /**
+ * This disables the exclude filter by default. In other words, no files
+ * are excluded. This setting is equivalent to
+ * setExcludes(null)
.
+ *
+ * @see #getExcludes()
+ * @see #setExcludes(String excludes)
+ */
+ public final static String DEFAULT_EXCLUDESETTING = null;
+
+ //ATTRIBUTES settable from ant.
+
+ /**
+ * The root folder of the operation in StarTeam.
+ */
+ private String rootStarteamFolder = "/";
+
+ /**
+ * The local folder corresponding to starteamFolder. If not specified
+ * the Star Team defalt folder will be used.
+ */
+ private String rootLocalFolder = null;
+
+ /**
+ * 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;
+
+ ///////////////////////////////////////////////////////////////
+ // GET/SET methods.
+ // Setters, of course are where ant user passes in values.
+ ///////////////////////////////////////////////////////////////
+
+ /**
+ * Set the root folder in the Starteam repository for this operation
+ */
+ public void setRootStarteamFolder(String rootStarteamFolder) {
+ this.rootStarteamFolder = rootStarteamFolder;
+ }
+
+ /**
+ * returns the root folder in the Starteam repository
+ * used for this operation
+ */
+ public String getRootStarteamFolder() {
+ return this.rootStarteamFolder;
+ }
+
+ /**
+ * Set the local folder corresponding to the
+ * starteam folder for this operation.
+ * If not specified, the StarTeam default will be used
+ * the default is used.
+ */
+ public void setRootLocalFolder(String rootLocalFolder) {
+ this.rootLocalFolder = rootLocalFolder;
+ }
+ /**
+ * Returns the local folder specified by the user,
+ * corresponding to the starteam folder for this operation.
+ * or null if not specified
+ */
+ public String getRootLocalFolder() {
+ return this.rootLocalFolder;
+ }
+
+ /**
+ * sets the pattern of files to be included. See setExcludes() for a
+ * description
+ * @param includes A string of filter patterns to include. Separate the
+ * patterns by spaces.
+ * @see #getIncludes()
+ * @see #setExcludes(String excludes)
+ * @see #getExcludes()
+ */
+ public void setIncludes(String includes) {
+ this.includes = includes;
+ }
+
+ /**
+ * Gets the patterns from the include filter. Rather that duplicate the
+ * details of AntStarTeanCheckOut's filtering here, refer to these
+ * links:
+ *
+ * @return A string of filter patterns separated by spaces.
+ * @see #setIncludes(String includes)
+ * @see #setExcludes(String excludes)
+ * @see #getExcludes()
+ */
+ public String getIncludes() {
+ return includes;
+ }
+
+ /**
+ * Sets the exclude filter. When filtering files, AntStarTeamCheckOut
+ * uses an unmodified version of DirectoryScanner
's
+ * match
method, so here are the patterns straight from the
+ * Ant source code:
+ *
+ * Matches a string against a pattern. The pattern contains two special
+ * characters:
+ *
'*' which means zero or more characters,
+ *
'?' which means one and only one character.
+ *
+ * For example, if you want to check out all files except .XML and
+ * .HTML files, you would put the following line in your program:
+ * setExcludes("*.XML,*.HTML");
+ * Finally, note that filters have no effect on the directories
+ * that are scanned; you could not skip over all files in directories
+ * whose names begin with "project," for instance.
+ *
+ * Treatment of overlapping inlcudes and excludes: To give a simplistic
+ * example suppose that you set your include filter to "*.htm *.html"
+ * and your exclude filter to "index.*". What happens to index.html?
+ * AntStarTeamCheckOut will not check out index.html, as it matches an
+ * exclude filter ("index.*"), even though it matches the include
+ * filter, as well.
+ *
+ * Please also read the following sections before using filters:
+ *
+ * @param excludes A string of filter patterns to exclude. Separate the
+ * patterns by spaces.
+ * @see #setIncludes(String includes)
+ * @see #getIncludes()
+ * @see #getExcludes()
+ */
+ public void setExcludes(String excludes) {
+ this.excludes = excludes;
+ }
+
+ /**
+ * Gets the patterns from the exclude filter. Rather that duplicate the
+ * details of AntStarTeanCheckOut's filtering here, refer to these
+ * links:
+ *
+ * @return A string of filter patterns separated by spaces.
+ * @see #setExcludes(String excludes)
+ * @see #setIncludes(String includes)
+ * @see #getIncludes()
+ */
+ public String getExcludes() {
+ return excludes;
+ }
+
+ ///////////////////////////////////////////////////////////////
+ // INCLUDE-EXCLUDE processing
+ ///////////////////////////////////////////////////////////////
+
+ /**
+ * Look if the file should be processed by the task.
+ * Don't process it if it fits no include filters or if
+ * it fits an exclude filter.
+ * @param pName the item name to look for being included.
+ * @return whether the file should be checked out or not.
+ */
+ protected boolean shouldProcess(String pName){
+ boolean includeIt = matchPatterns(getIncludes(), pName);
+ boolean excludeIt = matchPatterns(getExcludes(), pName);
+ return (includeIt && !excludeIt);
+ }
+
+ /**
+ * Convenience method to see if a string match a one pattern
+ * in given set of space-separated patterns.
+ * @param patterns the space-separated list of patterns.
+ * @param pName the name to look for matching.
+ * @return whether the name match at least one pattern.
+ */
+ protected boolean matchPatterns(String patterns, String pName){
+ if (patterns == null){
+ return false;
+ }
+ StringTokenizer exStr = new StringTokenizer(patterns, ",");
+ while (exStr.hasMoreTokens())
+ {
+ if (DirectoryScanner.match(exStr.nextToken(), pName))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * This method does the work of opening the supplied Starteam view and calling
+ * the visit method to perform the task.
+ *
+ * @exception BuildException if any error occurs in the processing
+ */
+
+ public void execute() throws BuildException {
+ // Get view as of the current time?
+ View view = StarTeamFinder.openView(getUserName() + ":" + getPassword()
+ + "@" + getURL());
+ View snapshot = new View(view, ViewConfiguration.createFromTime(
+ new OLEDate()));
+ Folder starteamrootfolder =
+ StarTeamFinder.findFolder(snapshot.getRootFolder(), this.rootStarteamFolder);
+
+ if ( null == starteamrootfolder) {
+ throw new BuildException("Unable to find root folderin repository.");
+ }
+
+ java.io.File localrootfolder;
+
+ if (null == this.rootLocalFolder) {
+ // use Star Team's default
+ localrootfolder = new java.io.File(starteamrootfolder.getPath());
+ } else {
+ // force StarTeam to use our folder
+ localrootfolder = new java.io.File(getRootLocalFolder());
+ log("overriding local folder to " + localrootfolder);
+ }
+
+ // Inspect everything in the root folder and then recursively
+ visit(starteamrootfolder, localrootfolder);
+ }
+
+ /**
+ * Derived classes must override this class to define the actual processing
+ * to performed on each folder in the tree defined for the task
+ *
+ * @param rootStarteamFolder the StarTeam folderto be visited
+ * @param rootLocalFolder the local mapping of rootStarteamFolder
+ */
+ protected abstract void visit(Folder rootStarteamFolder, java.io.File rootLocalFolder)
+ throws BuildException;
+
+}
+
+
+
+