📄 msvss.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package org.apache.tools.ant.taskdefs.optional.vss;import org.apache.tools.ant.types.EnumeratedAttribute;import java.io.File;import java.io.IOException;import java.text.DateFormat;import java.text.ParseException;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Project;import org.apache.tools.ant.Task;import org.apache.tools.ant.taskdefs.Execute;import org.apache.tools.ant.taskdefs.LogStreamHandler;import org.apache.tools.ant.types.Commandline;import org.apache.tools.ant.util.FileUtils;/** * A base class for creating tasks for executing commands on Visual SourceSafe. * <p> * The class extends the 'exec' task as it operates by executing the ss.exe program * supplied with SourceSafe. By default the task expects ss.exe to be in the path, * you can override this be specifying the ssdir attribute. * </p> * <p> * This class provides set and get methods for 'login' and 'vsspath' attributes. It * also contains constants for the flags that can be passed to SS. * </p> * */public abstract class MSVSS extends Task implements MSVSSConstants { private String ssDir = null; private String vssLogin = null; private String vssPath = null; private String serverPath = null; /** Version */ private String version = null; /** Date */ private String date = null; /** Label */ private String label = null; /** Auto response */ private String autoResponse = null; /** Local path */ private String localPath = null; /** Comment */ private String comment = null; /** From label */ private String fromLabel = null; /** To label */ private String toLabel = null; /** Output file name */ private String outputFileName = null; /** User */ private String user = null; /** From date */ private String fromDate = null; /** To date */ private String toDate = null; /** History style */ private String style = null; /** Quiet defaults to false */ private boolean quiet = false; /** Recursive defaults to false */ private boolean recursive = false; /** Writable defaults to false */ private boolean writable = false; /** Fail on error defaults to true */ private boolean failOnError = true; /** Get local copy for checkout defaults to true */ private boolean getLocalCopy = true; /** Number of days offset for History */ private int numDays = Integer.MIN_VALUE; /** Date format for History */ private DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT); /** Timestamp for retreived files */ private CurrentModUpdated timestamp = null; /** Behaviour for writable files */ private WritableFiles writableFiles = null; /** * Each sub-class must implemnt this method and return the constructed * command line to be executed. It is up to the sub-task to determine the * required attrubutes and their order. * @return The Constructed command line. */ abstract Commandline buildCmdLine(); /** * Directory where <code>ss.exe</code> resides. * By default the task expects it to be in the PATH. * @param dir The directory containing ss.exe. */ public final void setSsdir(String dir) { this.ssDir = FileUtils.translatePath(dir); } /** * Login to use when accessing VSS, formatted as "username,password". * <p> * You can omit the password if your database is not password protected. * If you have a password and omit it, Ant will hang. * @param vssLogin The login string to use. */ public final void setLogin(final String vssLogin) { this.vssLogin = vssLogin; } /** * SourceSafe path which specifies the project/file(s) you wish to perform * the action on. * <p> * A prefix of 'vss://' will be removed if specified. * @param vssPath The VSS project path. * @ant.attribute group="required" */ public final void setVsspath(final String vssPath) { String projectPath; // CheckStyle:MagicNumber OFF if (vssPath.startsWith("vss://")) { //$NON-NLS-1$ projectPath = vssPath.substring(5); } else { projectPath = vssPath; } // CheckStyle:MagicNumber ON if (projectPath.startsWith(PROJECT_PREFIX)) { this.vssPath = projectPath; } else { this.vssPath = PROJECT_PREFIX + projectPath; } } /** * Directory where <code>srssafe.ini</code> resides. * @param serverPath The path to the VSS server. */ public final void setServerpath(final String serverPath) { this.serverPath = serverPath; } /** * Indicates if the build should fail if the Sourcesafe command does. Defaults to true. * @param failOnError True if task should fail on any error. */ public final void setFailOnError(final boolean failOnError) { this.failOnError = failOnError; } /** * Executes the task. <br> * Builds a command line to execute ss.exe and then calls Exec's run method * to execute the command line. * @throws BuildException if the command cannot execute. */ public void execute() throws BuildException { int result = 0; Commandline commandLine = buildCmdLine(); result = run(commandLine); if (Execute.isFailure(result) && getFailOnError()) { String msg = "Failed executing: " + formatCommandLine(commandLine) + " With a return code of " + result; throw new BuildException(msg, getLocation()); } } // Special setters for the sub-classes /** * Set the internal comment attribute. * @param comment the value to use. */ protected void setInternalComment(final String comment) { this.comment = comment; } /** * Set the auto response attribute. * @param autoResponse the value to use. */ protected void setInternalAutoResponse(final String autoResponse) { this.autoResponse = autoResponse; } /** * Set the date attribute. * @param date the value to use. */ protected void setInternalDate(final String date) { this.date = date; } /** * Set the date format attribute. * @param dateFormat the value to use. */ protected void setInternalDateFormat(final DateFormat dateFormat) { this.dateFormat = dateFormat; } /** * Set the failOnError attribute. * @param failOnError the value to use. */ protected void setInternalFailOnError(final boolean failOnError) { this.failOnError = failOnError; } /** * Set the from date attribute. * @param fromDate the value to use. */ protected void setInternalFromDate(final String fromDate) { this.fromDate = fromDate; } /** * Set the from label attribute. * @param fromLabel the value to use. */ protected void setInternalFromLabel(final String fromLabel) { this.fromLabel = fromLabel; } /** * Set the label attribute. * @param label the value to use. */ protected void setInternalLabel(final String label) { this.label = label; } /** * Set the local path comment attribute. * @param localPath the value to use. */ protected void setInternalLocalPath(final String localPath) { this.localPath = localPath; } /** * Set the num days attribute. * @param numDays the value to use. */ protected void setInternalNumDays(final int numDays) { this.numDays = numDays; } /** * Set the outputFileName comment attribute. * @param outputFileName the value to use. */ protected void setInternalOutputFilename(final String outputFileName) { this.outputFileName = outputFileName; } /** * Set the quiet attribute. * @param quiet the value to use. */ protected void setInternalQuiet(final boolean quiet) { this.quiet = quiet; } /** * Set the recursive attribute. * @param recursive the value to use. */ protected void setInternalRecursive(final boolean recursive) { this.recursive = recursive; } /** * Set the style attribute. * @param style the value to use. */ protected void setInternalStyle(final String style) { this.style = style; } /** * Set the to date attribute. * @param toDate the value to use. */ protected void setInternalToDate(final String toDate) { this.toDate = toDate; } /** * Set the to label attribute. * @param toLabel the value to use. */ protected void setInternalToLabel(final String toLabel) { this.toLabel = toLabel; } /** * Set the user attribute. * @param user the value to use. */ protected void setInternalUser(final String user) { this.user = user; } /** * Set the version attribute. * @param version the value to use. */ protected void setInternalVersion(final String version) { this.version = version; } /** * Set the writable attribute. * @param writable the value to use. */ protected void setInternalWritable(final boolean writable) { this.writable = writable; } /** * Set the timestamp attribute. * @param timestamp the value to use. */ protected void setInternalFileTimeStamp(final CurrentModUpdated timestamp) { this.timestamp = timestamp; } /** * Set the writableFiles attribute. * @param writableFiles the value to use. */ protected void setInternalWritableFiles(final WritableFiles writableFiles) { this.writableFiles = writableFiles; } /** * Set the getLocalCopy attribute. * @param getLocalCopy the value to use. */ protected void setInternalGetLocalCopy(final boolean getLocalCopy) { this.getLocalCopy = getLocalCopy; } /** * Gets the sscommand string. "ss" or "c:\path\to\ss" * @return The path to ss.exe or just ss if sscommand is not set. */ protected String getSSCommand() { if (ssDir == null) { return SS_EXE; } return ssDir.endsWith(File.separator) ? ssDir + SS_EXE : ssDir + File.separator + SS_EXE; } /** * Gets the vssserverpath string. * @return null if vssserverpath is not set. */ protected String getVsspath() { return vssPath; } /** * Gets the quiet string. -O- * @return An empty string if quiet is not set or is false. */ protected String getQuiet() { return quiet ? FLAG_QUIET : "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -