sbailliez 01/12/18 14:17:22
Added: src/main/org/apache/tools/ant/taskdefs/optional/starteam
StarTeamCheckout.java TreeBasedTask.java
StarTeamTask.java StarTeamLabel.java
Log:
Major refactoring of Starteam tasks.
This is based on the original submission from the CruiseControl project.
Original <starteam> task has been deprecated
Starteam tasks now resides in the starteam package rather than scm.
Submitted by: [EMAIL PROTECTED] (Steve Cohen)
Revision Changes Path
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamCheckout.java
Index: StarTeamCheckout.java
===================================================================
/*
* 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 [EMAIL PROTECTED]
*
* 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
* <http://www.apache.org/>.
*
*/
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: <taskdef name="starteamcheckout"
* classname="org.apache.tools.ant.taskdefs.StarTeamCheckout"/>
* <starteamcheckout username="BuildMaster" password="ant"
starteamFolder="Source"
* starteamurl="servername:portnum/project/view"
* createworkingdirectories="true"/>
*
* @author Christopher Charlier, ThoughtWorks, Inc. 2001
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Yip</a>
* @author Jason Pettiss
* @version 1.1
* @author <a href="mailto:[EMAIL PROTECTED]">Steve Cohen</a>
* @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
*/
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" <code>Hashtable</code> 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;
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java
Index: TreeBasedTask.java
===================================================================
/*
* 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 [EMAIL PROTECTED]
*
* 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
* <http://www.apache.org/>.
*
*/
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
* <code>visit(Folder rootStarteamFolder, java.io.File rootLocalFolder)</code>
*
* Created: Sat Dec 15 16:55:19 2001
*
* @author <a href="mailto:[EMAIL PROTECTED]">Steve Cohen</a>
* @version 1.0
* @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
*/
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 <CODE>setIncludes("*")</CODE>.
*
* @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
* <CODE>setExcludes(null)</CODE>.
*
* @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 <CODE>DirectoryScanner</CODE>'s
* <CODE>match</CODE> method, so here are the patterns straight from the
* Ant source code:
* <BR><BR>
* Matches a string against a pattern. The pattern contains two special
* characters:
* <BR>'*' which means zero or more characters,
* <BR>'?' which means one and only one character.
* <BR><BR>
* For example, if you want to check out all files except .XML and
* .HTML files, you would put the following line in your program:
* <CODE>setExcludes("*.XML,*.HTML");</CODE>
* Finally, note that filters have no effect on the <B>directories</B>
* that are scanned; you could not skip over all files in directories
* whose names begin with "project," for instance.
* <BR><BR>
* 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.
* <BR><BR>
* 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;
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamTask.java
Index: StarTeamTask.java
===================================================================
/*
* 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 [EMAIL PROTECTED]
*
* 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
* <http://www.apache.org/>.
*
*/
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
<code>TreeBasedTask</code>,
* also abstract defines the tree-walking behavior common to many subtasks.
*
* @see TreeBasedTask
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Yip</a>
* @version 1.1
* @author <a href="mailto:[EMAIL PROTECTED]">Steve Cohen</a>
*/
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 <code>String</code> 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 <code>String</code> 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 <code>String</code> 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;
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/starteam/StarTeamLabel.java
Index: StarTeamLabel.java
===================================================================
/*
* 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 [EMAIL PROTECTED]
*
* 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
* <http://www.apache.org/>.
*
*/
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:
* <taskdef name="stlabel"
*
classname="org.apache.tools.ant.taskdefs.optional.starteam.StarTeamLabel"/>
* <stlabel
* label="1.0" lastbuild="20011514100000" description="Successful Build"
* username="BuildMaster" password="ant"
* starteamurl="server:port/project/view"/>
*
* @author Christopher Charlier, ThoughtWorks, Inc. 2001
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Yip</a>
* @see <A HREF="http://www.starbase.com/">StarBase Web Site</A>
*/
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);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>