diff --git a/src/etc/testcases/taskdefs/optional/sos/sos.xml b/src/etc/testcases/taskdefs/optional/sos/sos.xml index 23f1cb9fc..4a31bca64 100644 --- a/src/etc/testcases/taskdefs/optional/sos/sos.xml +++ b/src/etc/testcases/taskdefs/optional/sos/sos.xml @@ -102,7 +102,7 @@ + projectpath="$/SourceRoot/Project"/> diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOS.java b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOS.java index 99bcbaa46..82dee8e63 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOS.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOS.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,39 +64,13 @@ import org.apache.tools.ant.types.Path; /** * A base class for creating tasks for executing commands on SourceOffSite. - *

- * The class extends the 'exec' task as it operates by executing the soscmd(.exe) program - * supplied with SOS. By default the task expects soscmd(.exe) to be in the path, - * you can override this be specifying the sosdir attribute. - *

- *

- * This class provides set and get methods for the following attributes - *
'vssserverpath' - *
'sosserverpath' - *
'vsspath' - *
'projectpath' - *
'username' - *
'password' - *
'soscmddir' - *
'file' - *
'soshome' - *
'localpath" - *
'comment' - *
'label' - *
'version' - *
'recursive' - *
'verbose' - *
'nocache' - *
'nocompression' - *
- * It also contains constants for the flags that can be passed to SOS. - *

+ * * These tasks were inspired by the VSS tasks * - * @author Jesse Stockall + * @author Jesse Stockall */ -public abstract class SOS extends Task { +public abstract class SOS extends Task implements SOSCmd { private String sosCmdDir = null; private String sosUsername = null; @@ -116,28 +90,28 @@ public abstract class SOS extends Task { private boolean recursive = false; private boolean verbose = false; + /** Commandline to be executed */ + protected Commandline commandLine; /** - * flag to disable the cache when set; - * optional needed if SOSHOME is set as an environment variable. + * Flag to disable the cache when set; + * optional needed if SOSHOME is set as an environment variable., default false * - * @param nocache The new noCache value + * @param nocache True to disable caching. */ - public void setNoCache(boolean nocache) { + public final void setNoCache(boolean nocache) { noCache = nocache; } - /** - * Flag that disables compression when set; optional, default + * Flag that disables compression when set; optional, default false * - * @param nocompress true to disable compression + * @param nocompress True to disable compression. */ - public void setNoCompress(boolean nocompress) { + public final void setNoCompress(boolean nocompress) { noCompress = nocompress; } - /** * Set the directory where soscmd(.exe) is located; * optional, soscmd must be on the path if omitted. @@ -148,7 +122,6 @@ public abstract class SOS extends Task { sosCmdDir = Project.translatePath(dir); } - /** * Set the SourceSafe username; required. * @@ -158,9 +131,8 @@ public abstract class SOS extends Task { sosUsername = username; } - /** - * Set the SourceSafe password; optional. + * Set the SourceSafe password; optional. * * @param password The new password value */ @@ -168,11 +140,10 @@ public abstract class SOS extends Task { sosPassword = password; } - /** - * Set the SourceSafe project path without the "$" prefix; required + * Set the SourceSafe project path; required. * - * @param projectpath The new projectPath value + * @param projectpath The new projectpath value */ public final void setProjectPath(String projectpath) { if (projectpath.startsWith(SOSCmd.PROJECT_PREFIX)) { @@ -182,9 +153,8 @@ public abstract class SOS extends Task { } } - /** - * Set the path to the location of the ss.ini file; + * Set the path to the location of the ss.ini file; * required. * * @param vssServerPath The new vssServerPath value @@ -193,7 +163,6 @@ public abstract class SOS extends Task { this.vssServerPath = vssServerPath; } - /** * The path to the SourceOffSite home directory * @@ -203,11 +172,9 @@ public abstract class SOS extends Task { this.sosHome = sosHome; } - /** * Sets the address and port of SourceOffSite Server, - * for example 192.168.0.1:8888. - * This attribute is required. + * for example 192.168.0.1:8888.; required. * * @param sosServerPath The new sosServerPath value */ @@ -215,92 +182,56 @@ public abstract class SOS extends Task { this.sosServerPath = sosServerPath; } - /** * Override the working directory and get to the specified path; optional. * * @param path The new localPath value */ - public void setLocalPath(Path path) { + public final void setLocalPath(Path path) { localPath = path.toString(); } - - /** - * Set the Filename to act upon; optional. - * If no file is specified then the tasks - * act upon the project - * - * @param filename The new file value - */ - public final void setFile(String filename) { - this.filename = filename; - } - - /** * Enable verbose output; optional, default false * - * @param verbose The new verbose value + * @param verbose True for verbose output. */ public void setVerbose(boolean verbose) { this.verbose = verbose; } + // Special setters for the sub-classes - /** - * Flag to recursively apply the action (not valid - * on all SOS tasks ); optional, default false - * - * @param recursive The new recursive value - */ - public void setRecursive(boolean recursive) { - this.recursive = recursive; + protected void setInternalFilename(String file) { + filename = file; } - - /** - * Set the a version number to get - - * only works with the SOSGet on a file; optional. - * - * @param version The new version value - */ - public void setVersion(String version) { - this.version = version; + protected void setInternalRecursive(boolean recurse) { + recursive = recurse; } - - /** - * Set the labeled version to operate on in SourceSafe - * - * @param label The new label value - */ - public void setLabel(String label) { - this.label = label; + protected void setInternalComment(String text) { + comment = text; } - - /** - * Set the comment to apply to all files being labelled; - * optional, only valid in SOSLabel - * - * @param comment The new comment value - */ - public void setComment(String comment) { - this.comment = comment; + protected void setInternalLabel(String text) { + label = text; } + protected void setInternalVersion(String text) { + version = text; + } /** * Get the executable to run. Add the path if it was specifed in the build file * * @return String the executable to run */ - public String getSosCommand() { + protected String getSosCommand() { if (sosCmdDir == null) { - return SOSCmd.COMMAND_SOS_EXE; + return COMMAND_SOS_EXE; } else { - return sosCmdDir + File.separator + SOSCmd.COMMAND_SOS_EXE; + return sosCmdDir + File.separator + COMMAND_SOS_EXE; } } @@ -308,148 +239,118 @@ public abstract class SOS extends Task { * Get the comment * @return String if it was set, null if not */ - public String getComment() { + protected String getComment() { return comment; } - /** * Get the version * @return String if it was set, null if not */ - public String getVersion() { + protected String getVersion() { return version; } - /** * Get the label * @return String if it was set, null if not */ - public String getLabel() { + protected String getLabel() { return label; } - /** * Get the username * @return String if it was set, null if not */ - public String getUsername() { + protected String getUsername() { return sosUsername; } - /** * Get the password * @return String empty string if it wans't set */ - public String getPassword() { + protected String getPassword() { return sosPassword; } - /** * Get the project path * @return String if it was set, null if not */ - public String getProjectPath() { + protected String getProjectPath() { return projectPath; } - /** * Get the VSS server path * @return String if it was set, null if not */ - public String getVssServerPath() { + protected String getVssServerPath() { return vssServerPath; } - /** * Get the SOS home directory * @return String if it was set, null if not */ - public String getSosHome() { + protected String getSosHome() { return sosHome; } - /** * Get the SOS serve path * @return String if it was set, null if not */ - public String getSosServerPath() { + protected String getSosServerPath() { return sosServerPath; } - /** * Get the filename to be acted upon * @return String if it was set, null if not */ - public String getFilename() { + protected String getFilename() { return filename; } - /** * Get the NoCompress flag * * @return String the 'nocompress' Flag if the attribute was 'true', otherwise an empty string */ - public String getNoCompress() { - if (!noCompress) { - return ""; - } else { - return SOSCmd.FLAG_NO_COMPRESSION; - } + protected String getNoCompress() { + return noCompress ? FLAG_NO_COMPRESSION : ""; } - /** * Get the NoCache flag * * @return String the 'nocache' Flag if the attribute was 'true', otherwise an empty string */ - public String getNoCache() { - if (!noCache) { - return ""; - } else { - return SOSCmd.FLAG_NO_CACHE; - } + protected String getNoCache() { + return noCache ? FLAG_NO_CACHE : ""; } - /** * Get the 'verbose' Flag * * @return String the 'verbose' Flag if the attribute was 'true', otherwise an empty string */ - public String getVerbose() { - if (!verbose) { - return ""; - } else { - return SOSCmd.FLAG_VERBOSE; - } + protected String getVerbose() { + return verbose ? FLAG_VERBOSE : ""; } - /** * Get the 'recursive' Flag * * @return String the 'recursive' Flag if the attribute was 'true', otherwise an empty string */ - public String getRecursive() { - if (!recursive) { - return ""; - } else { - return SOSCmd.FLAG_RECURSION; - } + protected String getRecursive() { + return recursive ? FLAG_RECURSION : ""; } - /** * Builds and returns the working directory. *

@@ -457,7 +358,7 @@ public abstract class SOS extends Task { * * @return String the absolute path of the working directory */ - public String getLocalPath() { + protected String getLocalPath() { if (localPath == null) { return getProject().getBaseDir().getAbsolutePath(); } else { @@ -476,12 +377,35 @@ public abstract class SOS extends Task { } } + /** + * Subclasses implement the logic required to construct the command line. + * + * @return The command line to execute. + */ + abstract Commandline buildCmdLine(); + /** - * Execute the created command line + * Execute the created command line. * - * @param cmd Description of Parameter - * @return int the exit code + * @throws BuildException + */ + public void execute() + throws BuildException { + int result = 0; + buildCmdLine(); + result = run(commandLine); + if (result == 255) { // This is the exit status + String msg = "Failed executing: " + commandLine.toString(); + throw new BuildException(msg, getLocation()); + } + } + + /** + * Execute the created command line. + * + * @param cmd The command line to run. + * @return int the exit code. * @throws BuildException */ protected int run(Commandline cmd) { @@ -493,10 +417,65 @@ public abstract class SOS extends Task { exe.setAntRun(getProject()); exe.setWorkingDirectory(getProject().getBaseDir()); exe.setCommandline(cmd.getCommandline()); + exe.setVMLauncher(false); // Use the OS VM launcher so we get environment variables return exe.execute(); } catch (java.io.IOException e) { throw new BuildException(e, getLocation()); } } -} + /** Sets the executable and add the required attributes to the command line. */ + protected void getRequiredAttributes() { + // Get the path to the soscmd(.exe) + commandLine.setExecutable(getSosCommand()); + // SOS server address is required + if (getSosServerPath() == null) { + throw new BuildException("sosserverpath attribute must be set!", getLocation()); + } + commandLine.createArgument().setValue(FLAG_SOS_SERVER); + commandLine.createArgument().setValue(getSosServerPath()); + // Login info is required + if (getUsername() == null) { + throw new BuildException("username attribute must be set!", getLocation()); + } + commandLine.createArgument().setValue(FLAG_USERNAME); + commandLine.createArgument().setValue(getUsername()); + // The SOS class knows that the SOS server needs the password flag, + // even if there is no password ,so we send a " " + commandLine.createArgument().setValue(FLAG_PASSWORD); + commandLine.createArgument().setValue(getPassword()); + // VSS Info is required + if (getVssServerPath() == null) { + throw new BuildException("vssserverpath attribute must be set!", getLocation()); + } + commandLine.createArgument().setValue(FLAG_VSS_SERVER); + commandLine.createArgument().setValue(getVssServerPath()); + // VSS project is required + if (getProjectPath() == null) { + throw new BuildException("projectpath attribute must be set!", getLocation()); + } + commandLine.createArgument().setValue(FLAG_PROJECT); + commandLine.createArgument().setValue(getProjectPath()); + } + + /** Adds the optional attributes to the command line. */ + protected void getOptionalAttributes() { + // -verbose + commandLine.createArgument().setValue(getVerbose()); + // Disable Compression + commandLine.createArgument().setValue(getNoCompress()); + // Path to the SourceOffSite home directory /home/user/.sos + if (getSosHome() == null) { + // If -soshome was not specified then we can look for nocache + commandLine.createArgument().setValue(getNoCache()); + } else { + commandLine.createArgument().setValue(FLAG_SOS_HOME); + commandLine.createArgument().setValue(getSosHome()); + } + //If a working directory was specified then add it to the command line + if (getLocalPath() != null) { + commandLine.createArgument().setValue(FLAG_WORKING_DIR); + commandLine.createArgument().setValue(getLocalPath()); + } + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckin.java b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckin.java index f76791a61..bb1cd068f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckin.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckin.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -85,7 +85,7 @@ import org.apache.tools.ant.types.Commandline; * * * projectpath - * SourceSafe project path without the "$" + * SourceSafe project path * Yes * * @@ -139,50 +139,58 @@ import org.apache.tools.ant.types.Commandline; * * * - * @author Jesse Stockall + * @author Jesse Stockall */ public class SOSCheckin extends SOS { - Commandline commandLine; - /** - * Executes the task. - *
- * Builds a command line to execute soscmd and then calls Exec's run method - * to execute the command line. + * Set the Filename to act upon; optional. + * If no file is specified then the tasks + * act upon the project * - * @exception BuildException Description of Exception + * @param filename The new file value */ - public void execute() throws BuildException { - int result = 0; - buildCmdLine(); - result = run(commandLine); - if (result == 255) { - // This is the exit status - String msg = "Failed executing: " + commandLine.toString(); - throw new BuildException(msg, getLocation()); - } + public final void setFile(String filename) { + super.setInternalFilename(filename); } + /** + * Flag to recursively apply the action; optional, default false + * + * @param recursive True for recursive operation. + */ + public void setRecursive(boolean recursive) { + super.setInternalRecursive(recursive); + } /** - * Build the command line
+ * Set the comment to apply to all files being labelled; + * optional * - * CheckInFile required parameters: -server -name -password -database -project -file
- * CheckInFile optional parameters: -workdir -log -verbose -nocache - * -nocompression -soshome
+ * @param comment The new comment value + */ + public void setComment(String comment) { + super.setInternalComment(comment); + } + + /** + * Build the command line

* - * CheckInProject required parameters: -server -name -password -database -project
- * CheckInProject optional parameters: workdir -recursive -log -verbose -nocache - * -nocompression -soshome
+ * CheckInFile required parameters: -server -name -password -database -project + * -file
+ * CheckInFile optional parameters: -workdir -log -verbose -nocache -nocompression + * -soshome
+ * CheckInProject required parameters: -server -name -password -database + * -project
+ * CheckInProject optional parameters: workdir -recursive -log -verbose + * -nocache -nocompression -soshome
* * @return Commandline the generated command to be executed */ protected Commandline buildCmdLine() { commandLine = new Commandline(); - // Get the path to the soscmd(.exe) - commandLine.setExecutable(getSosCommand()); + // If we find a "file" attribute then act on a file otherwise act on a project if (getFilename() != null) { // add -command CheckInFile to the commandline @@ -198,54 +206,10 @@ public class SOSCheckin extends SOS { // look for a recursive option commandLine.createArgument().setValue(getRecursive()); } - // SOS server address is required - if (getSosServerPath() == null) { - throw new BuildException("sosserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_SERVER); - commandLine.createArgument().setValue(getSosServerPath()); - // Login info is required - if (getUsername() == null) { - throw new BuildException("username attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_USERNAME); - commandLine.createArgument().setValue(getUsername()); - // The SOS class knows that the SOS server needs the password flag, - // even if there is no password ,so we send a " " - commandLine.createArgument().setValue(SOSCmd.FLAG_PASSWORD); - commandLine.createArgument().setValue(getPassword()); - // VSS Info is required - if (getVssServerPath() == null) { - throw new BuildException("vssserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_VSS_SERVER); - commandLine.createArgument().setValue(getVssServerPath()); - // VSS project is required - if (getProjectPath() == null) { - throw new BuildException("projectpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_PROJECT); - commandLine.createArgument().setValue(getProjectPath()); - // The following options are optional. + getRequiredAttributes(); + getOptionalAttributes(); - // -verbose - commandLine.createArgument().setValue(getVerbose()); - // Disable Compression - commandLine.createArgument().setValue(getNoCompress()); - // Path to the SourceOffSite home directory /home/user/.sos - if (getSosHome() == null) { - // If -soshome was not specified then we can look for nocache - commandLine.createArgument().setValue(getNoCache()); - } else { - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_HOME); - commandLine.createArgument().setValue(getSosHome()); - } - // If a working directory was specified then add it to the command line - if (getLocalPath() != null) { - commandLine.createArgument().setValue(SOSCmd.FLAG_WORKING_DIR); - commandLine.createArgument().setValue(getLocalPath()); - } // Look for a comment if (getComment() != null) { commandLine.createArgument().setValue(SOSCmd.FLAG_COMMENT); @@ -254,4 +218,3 @@ public class SOSCheckin extends SOS { return commandLine; } } - diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckout.java b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckout.java index 16f10c85a..bb0c21aaa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckout.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCheckout.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -85,7 +85,7 @@ import org.apache.tools.ant.types.Commandline; * * * projectpath - * SourceSafe project path without the "$" + * SourceSafe project path * Yes * * @@ -135,32 +135,30 @@ import org.apache.tools.ant.types.Commandline; * * * - * @author Jesse Stockall + * @author Jesse Stockall */ public class SOSCheckout extends SOS { - Commandline commandLine; - /** - * Executes the task. - *
- * Builds a command line to execute soscmd and then calls Exec's run method - * to execute the command line. + * Set the Filename to act upon; optional. + * If no file is specified then the tasks + * act upon the project * - * @exception BuildException Description of Exception + * @param filename The new file value */ - public void execute() throws BuildException { - int result = 0; - buildCmdLine(); - result = run(commandLine); - if (result == 255) { - // This is the exit status - String msg = "Failed executing: " + commandLine.toString(); - throw new BuildException(msg, getLocation()); - } + public final void setFile(String filename) { + super.setInternalFilename(filename); } + /** + * Flag to recursively apply the action; optional, default false + * + * @param recursive True for recursive operation. + */ + public void setRecursive(boolean recursive) { + super.setInternalRecursive(recursive); + } /** * Build the command line
@@ -176,8 +174,7 @@ public class SOSCheckout extends SOS { */ protected Commandline buildCmdLine() { commandLine = new Commandline(); - // Get the path to the soscmd(.exe) - commandLine.setExecutable(getSosCommand()); + // If we find a "file" attribute then act on a file otherwise act on a project if (getFilename() != null) { // add -command CheckOutFile to the commandline @@ -193,55 +190,10 @@ public class SOSCheckout extends SOS { // look for a recursive option commandLine.createArgument().setValue(getRecursive()); } - // SOS server address is required - if (getSosServerPath() == null) { - throw new BuildException("sosserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_SERVER); - commandLine.createArgument().setValue(getSosServerPath()); - // Login info is required - if (getUsername() == null) { - throw new BuildException("username attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_USERNAME); - commandLine.createArgument().setValue(getUsername()); - // The SOS class knows that the SOS server needs the password flag, - // even if there is no password ,so we send a " " - commandLine.createArgument().setValue(SOSCmd.FLAG_PASSWORD); - commandLine.createArgument().setValue(getPassword()); - // VSS Info is required - if (getVssServerPath() == null) { - throw new BuildException("vssserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_VSS_SERVER); - commandLine.createArgument().setValue(getVssServerPath()); - // VSS project is required - if (getProjectPath() == null) { - throw new BuildException("projectpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_PROJECT); - commandLine.createArgument().setValue(getProjectPath()); - // The following options are optional. + getRequiredAttributes(); + getOptionalAttributes(); - // -verbose - commandLine.createArgument().setValue(getVerbose()); - // Disable Compression - commandLine.createArgument().setValue(getNoCompress()); - // Path to the SourceOffSite home directory /home/user/.sos - if (getSosHome() == null) { - // If -soshome was not specified then we can look for nocache - commandLine.createArgument().setValue(getNoCache()); - } else { - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_HOME); - commandLine.createArgument().setValue(getSosHome()); - } - // If a working directory was specified then add it to the command line - if (getLocalPath() != null) { - commandLine.createArgument().setValue(SOSCmd.FLAG_WORKING_DIR); - commandLine.createArgument().setValue(getLocalPath()); - } return commandLine; } } - diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCmd.java b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCmd.java index 7f990bd78..1aa1fcaa4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCmd.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSCmd.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,7 @@ package org.apache.tools.ant.taskdefs.optional.sos; /** * Interface to hold constants used by the SOS tasks * - * @author Jesse Stockall + * @author Jesse Stockall */ public interface SOSCmd { // soscmd Command options @@ -88,4 +88,3 @@ public interface SOSCmd { String FLAG_FILE = "-file"; String FLAG_VERBOSE = "-verbose"; } - diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSGet.java b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSGet.java index 5ccd25ea6..0459d2437 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSGet.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSGet.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -86,7 +86,7 @@ import org.apache.tools.ant.types.Commandline; * * * projectpath - * SourceSafe project path without the "$" + * SourceSafe project path * Yes * * @@ -146,32 +146,49 @@ import org.apache.tools.ant.types.Commandline; * No * * - * @author Jesse Stockall + * @author Jesse Stockall */ public class SOSGet extends SOS { - Commandline commandLine; + /** + * Set the Filename to act upon; optional. + * If no file is specified then the tasks + * act upon the project + * + * @param filename The new file value + */ + public final void setFile(String filename) { + super.setInternalFilename(filename); + } /** - * Executes the task. - *
- * Builds a command line to execute soscmd and then calls Exec's run method - * to execute the command line. + * Flag to recursively apply the action; optional, default false * - * @exception BuildException Description of Exception + * @param recursive True for recursive operation. */ - public void execute() throws BuildException { - int result = 0; - buildCmdLine(); - result = run(commandLine); - if (result == 255) { - // This is the exit status - String msg = "Failed executing: " + commandLine.toString(); - throw new BuildException(msg, getLocation()); - } + public void setRecursive(boolean recursive) { + super.setInternalRecursive(recursive); } + /** + * Set the version number to get - + * only works with SOSGet on a file; optional. + * + * @param version The new version value + */ + public void setVersion(String version) { + super.setInternalVersion(version); + } + + /** + * Set the labeled version to operate on in SourceSafe + * + * @param label The new label value + */ + public void setLabel(String label) { + super.setInternalLabel(label); + } /** * Build the command line
@@ -187,8 +204,7 @@ public class SOSGet extends SOS { */ protected Commandline buildCmdLine() { commandLine = new Commandline(); - // Get the path to the soscmd(.exe) - commandLine.setExecutable(getSosCommand()); + // If we find a "file" attribute then act on a file otherwise act on a project if (getFilename() != null) { // add -command GetFile to the commandline @@ -215,55 +231,10 @@ public class SOSGet extends SOS { commandLine.createArgument().setValue(getLabel()); } } - // SOS server address is required - if (getSosServerPath() == null) { - throw new BuildException("sosserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_SERVER); - commandLine.createArgument().setValue(getSosServerPath()); - // Login info is required - if (getUsername() == null) { - throw new BuildException("username attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_USERNAME); - commandLine.createArgument().setValue(getUsername()); - // The SOS class knows that the SOS server needs the password flag, - // even if there is no password ,so we send a " " - commandLine.createArgument().setValue(SOSCmd.FLAG_PASSWORD); - commandLine.createArgument().setValue(getPassword()); - // VSS Info is required - if (getVssServerPath() == null) { - throw new BuildException("vssserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_VSS_SERVER); - commandLine.createArgument().setValue(getVssServerPath()); - // SS project path is required - if (getProjectPath() == null) { - throw new BuildException("projectpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_PROJECT); - commandLine.createArgument().setValue(getProjectPath()); - // The following options are optional. + getRequiredAttributes(); + getOptionalAttributes(); - // -verbose - commandLine.createArgument().setValue(getVerbose()); - // Disable Compression - commandLine.createArgument().setValue(getNoCompress()); - // Path to the SourceOffSite home directory /home/user/.sos - if (getSosHome() == null) { - // If -soshome was not specified then we can look for nocache - commandLine.createArgument().setValue(getNoCache()); - } else { - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_HOME); - commandLine.createArgument().setValue(getSosHome()); - } - //If a working directory was specified then add it to the command line - if (getLocalPath() != null) { - commandLine.createArgument().setValue(SOSCmd.FLAG_WORKING_DIR); - commandLine.createArgument().setValue(getLocalPath()); - } return commandLine; } } - diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSLabel.java b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSLabel.java index f46dcd02a..ee9e4b805 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSLabel.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/sos/SOSLabel.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -84,7 +84,7 @@ import org.apache.tools.ant.types.Commandline; * * * projectpath - * SourceSafe project path without the "$" + * SourceSafe project * Yes * * @@ -114,31 +114,38 @@ import org.apache.tools.ant.types.Commandline; * * * - * @author Jesse Stockall + * @author Jesse Stockall */ public class SOSLabel extends SOS { - Commandline commandLine; + /** + * Set the version number to label; optional. + * + * @param version The new version value + */ + public void setVersion(String version) { + super.setInternalVersion(version); + } /** - * Executes the task.
- * Builds a command line to execute soscmd and then calls Exec's run method - * to execute the command line. + * Set the label to apply the the files in SourceSafe. * - * @exception BuildException Description of Exception + * @param label The new label value */ - public void execute() throws BuildException { - int result = 0; - buildCmdLine(); - result = run(commandLine); - if (result == 255) { - // This is the exit status - String msg = "Failed executing: " + commandLine.toString(); - throw new BuildException(msg, getLocation()); - } + public void setLabel(String label) { + super.setInternalLabel(label); } + /** + * Set the comment to apply to all files being labelled; + * optional + * + * @param comment The new comment value + */ + public void setComment(String comment) { + super.setInternalComment(comment); + } /** * Build the command line
@@ -149,39 +156,13 @@ public class SOSLabel extends SOS { */ protected Commandline buildCmdLine() { commandLine = new Commandline(); - // Get the path to the soscmd(.exe) - commandLine.setExecutable(getSosCommand()); + // add -command AddLabel to the commandline commandLine.createArgument().setValue(SOSCmd.FLAG_COMMAND); commandLine.createArgument().setValue(SOSCmd.COMMAND_LABEL); - // SOS server address is required - if (getSosServerPath() == null) { - throw new BuildException("sosserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_SOS_SERVER); - commandLine.createArgument().setValue(getSosServerPath()); - // Login info is required - if (getUsername() == null) { - throw new BuildException("username attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_USERNAME); - commandLine.createArgument().setValue(getUsername()); - // The SOS class knows that the SOS server needs the password flag, - // even if there is no password ,so we send a " " - commandLine.createArgument().setValue(SOSCmd.FLAG_PASSWORD); - commandLine.createArgument().setValue(getPassword()); - // VSS Info is required - if (getVssServerPath() == null) { - throw new BuildException("vssserverpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_VSS_SERVER); - commandLine.createArgument().setValue(getVssServerPath()); - // SS project path is required - if (getProjectPath() == null) { - throw new BuildException("projectpath attribute must be set!", getLocation()); - } - commandLine.createArgument().setValue(SOSCmd.FLAG_PROJECT); - commandLine.createArgument().setValue(getProjectPath()); + + getRequiredAttributes(); + // a label is required if (getLabel() == null) { throw new BuildException("label attribute must be set!", getLocation()); @@ -189,8 +170,6 @@ public class SOSLabel extends SOS { commandLine.createArgument().setValue(SOSCmd.FLAG_LABEL); commandLine.createArgument().setValue(getLabel()); - // The following options are optional. - // -verbose commandLine.createArgument().setValue(getVerbose()); // Look for a comment @@ -201,4 +180,3 @@ public class SOSLabel extends SOS { return commandLine; } } - diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java index 33de540c2..bf0109a27 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -55,18 +55,16 @@ package org.apache.tools.ant.taskdefs.optional.sos; import java.io.File; -import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.util.FileUtils; /** * Testcase to ensure that command line generation and required attributes are * correct. * - * @author Jesse Stockall + * @author Jesse Stockall */ public class SOSTest extends BuildFileTest {