001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.optional.vss;
020:
021: import java.io.File;
022: import java.text.SimpleDateFormat;
023:
024: import org.apache.tools.ant.BuildException;
025: import org.apache.tools.ant.types.Commandline;
026: import org.apache.tools.ant.types.EnumeratedAttribute;
027:
028: /**
029: * Performs History commands to Microsoft Visual SourceSafe.
030: *
031: * @ant.task name="vsshistory" category="scm"
032: */
033: public class MSVSSHISTORY extends MSVSS {
034:
035: /**
036: * Builds a command line to execute ss.
037: * @return The constructed commandline.
038: */
039: Commandline buildCmdLine() {
040: Commandline commandLine = new Commandline();
041:
042: // first off, make sure that we've got a command and a vssdir and a label ...
043: if (getVsspath() == null) {
044: String msg = "vsspath attribute must be set!";
045: throw new BuildException(msg, getLocation());
046: }
047:
048: // build the command line from what we got the format is
049: // ss History elements [-H] [-L] [-N] [-O] [-V] [-Y] [-#] [-?]
050: // as specified in the SS.EXE help
051: commandLine.setExecutable(getSSCommand());
052: commandLine.createArgument().setValue(COMMAND_HISTORY);
053:
054: // VSS items
055: commandLine.createArgument().setValue(getVsspath());
056: // -I-
057: commandLine.createArgument().setValue(FLAG_AUTORESPONSE_DEF); // ignore all errors
058: // -Vd
059: commandLine.createArgument().setValue(getVersionDate());
060: // -VL
061: commandLine.createArgument().setValue(getVersionLabel());
062: // -R
063: commandLine.createArgument().setValue(getRecursive());
064: // -B / -D / -F-
065: commandLine.createArgument().setValue(getStyle());
066: // -Y
067: commandLine.createArgument().setValue(getLogin());
068: // -O
069: commandLine.createArgument().setValue(getOutput());
070:
071: return commandLine;
072: }
073:
074: /**
075: * Retrieve history recursively. Defaults to false.
076: *
077: * @param recursive The boolean value for recursive.
078: */
079: public void setRecursive(boolean recursive) {
080: super .setInternalRecursive(recursive);
081: }
082:
083: /**
084: * Name of the user whose change history is generated.
085: *
086: * @param user The username.
087: */
088: public void setUser(String user) {
089: super .setInternalUser(user);
090: }
091:
092: /**
093: * Date representing the 'start' of the range.
094: *
095: * @param fromDate The start date.
096: */
097: public void setFromDate(String fromDate) {
098: super .setInternalFromDate(fromDate);
099: }
100:
101: /**
102: * Date representing the 'end' of the range.
103: *
104: * @param toDate The end date.
105: */
106: public void setToDate(String toDate) {
107: super .setInternalToDate(toDate);
108: }
109:
110: /**
111: * Label representing the 'start' of the range.
112: *
113: * @param fromLabel The start label.
114: */
115: public void setFromLabel(String fromLabel) {
116: super .setInternalFromLabel(fromLabel);
117: }
118:
119: /**
120: * Label representing the 'end' of the range.
121: *
122: * @param toLabel The end label.
123: */
124: public void setToLabel(String toLabel) {
125: super .setInternalToLabel(toLabel);
126: }
127:
128: /**
129: * Number of days for comparison.
130: * Defaults to 2 days.
131: *
132: * @param numd The number of days.
133: */
134: public void setNumdays(int numd) {
135: super .setInternalNumDays(numd);
136: }
137:
138: /**
139: * Output file name for the history.
140: *
141: * @param outfile The output file name.
142: */
143: public void setOutput(File outfile) {
144: if (outfile != null) {
145: super .setInternalOutputFilename(outfile.getAbsolutePath());
146: }
147: }
148:
149: /**
150: * Format of dates in <code>fromDate</code and <code>toDate</code>.
151: * Used when calculating dates with the numdays attribute.
152: * This string uses the formatting rules of <code>SimpleDateFormat</code>.
153: * Defaults to <code>DateFormat.SHORT</code>.
154: *
155: * @param dateFormat The date format.
156: */
157: public void setDateFormat(String dateFormat) {
158: super .setInternalDateFormat(new SimpleDateFormat(dateFormat));
159: }
160:
161: /**
162: * Output style. Valid options are:
163: * <ul>
164: * <li>brief: -B Display a brief history.
165: * <li>codediff: -D Display line-by-line file changes.
166: * <li>nofile: -F- Do not display individual file updates in the project history.
167: * <li>default: No option specified. Display in Source Safe's default format.
168: * </ul>
169: *
170: * @param attr The history style:
171: */
172: public void setStyle(BriefCodediffNofile attr) {
173: String option = attr.getValue();
174: if (option.equals(STYLE_BRIEF)) {
175: super .setInternalStyle(FLAG_BRIEF);
176: } else if (option.equals(STYLE_CODEDIFF)) {
177: super .setInternalStyle(FLAG_CODEDIFF);
178: } else if (option.equals(STYLE_DEFAULT)) {
179: super .setInternalStyle("");
180: } else if (option.equals(STYLE_NOFILE)) {
181: super .setInternalStyle(FLAG_NO_FILE);
182: } else {
183: throw new BuildException("Style " + attr + " unknown.",
184: getLocation());
185: }
186: }
187:
188: /**
189: * Extention of EnumeratedAttribute to hold the values for style.
190: */
191: public static class BriefCodediffNofile extends EnumeratedAttribute {
192: /**
193: * Gets the list of allowable values.
194: * @return The values.
195: */
196: public String[] getValues() {
197: return new String[] { STYLE_BRIEF, STYLE_CODEDIFF,
198: STYLE_NOFILE, STYLE_DEFAULT };
199: }
200: }
201: }
|