1 | /*
|
---|
2 | * Copyright 2001-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.optional.vss;
|
---|
19 |
|
---|
20 | import java.io.File;
|
---|
21 | import java.text.SimpleDateFormat;
|
---|
22 |
|
---|
23 | import org.apache.tools.ant.BuildException;
|
---|
24 | import org.apache.tools.ant.types.Commandline;
|
---|
25 | import org.apache.tools.ant.types.EnumeratedAttribute;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Performs History commands to Microsoft Visual SourceSafe.
|
---|
29 | *
|
---|
30 | * @ant.task name="vsshistory" category="scm"
|
---|
31 | */
|
---|
32 | public class MSVSSHISTORY extends MSVSS {
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Builds a command line to execute ss.
|
---|
36 | * @return The constructed commandline.
|
---|
37 | */
|
---|
38 | Commandline buildCmdLine() {
|
---|
39 | Commandline commandLine = new Commandline();
|
---|
40 |
|
---|
41 | // first off, make sure that we've got a command and a vssdir and a label ...
|
---|
42 | if (getVsspath() == null) {
|
---|
43 | String msg = "vsspath attribute must be set!";
|
---|
44 | throw new BuildException(msg, getLocation());
|
---|
45 | }
|
---|
46 |
|
---|
47 | // build the command line from what we got the format is
|
---|
48 | // ss History elements [-H] [-L] [-N] [-O] [-V] [-Y] [-#] [-?]
|
---|
49 | // as specified in the SS.EXE help
|
---|
50 | commandLine.setExecutable(getSSCommand());
|
---|
51 | commandLine.createArgument().setValue(COMMAND_HISTORY);
|
---|
52 |
|
---|
53 | // VSS items
|
---|
54 | commandLine.createArgument().setValue(getVsspath());
|
---|
55 | // -I-
|
---|
56 | commandLine.createArgument().setValue(FLAG_AUTORESPONSE_DEF); // ignore all errors
|
---|
57 | // -Vd
|
---|
58 | commandLine.createArgument().setValue(getVersionDate());
|
---|
59 | // -VL
|
---|
60 | commandLine.createArgument().setValue(getVersionLabel());
|
---|
61 | // -R
|
---|
62 | commandLine.createArgument().setValue(getRecursive());
|
---|
63 | // -B / -D / -F-
|
---|
64 | commandLine.createArgument().setValue(getStyle());
|
---|
65 | // -Y
|
---|
66 | commandLine.createArgument().setValue(getLogin());
|
---|
67 | // -O
|
---|
68 | commandLine.createArgument().setValue(getOutput());
|
---|
69 |
|
---|
70 | return commandLine;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Retrieve history recursively. Defaults to false.
|
---|
75 | *
|
---|
76 | * @param recursive The boolean value for recursive.
|
---|
77 | */
|
---|
78 | public void setRecursive(boolean recursive) {
|
---|
79 | super.setInternalRecursive(recursive);
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Name of the user whose change history is generated.
|
---|
84 | *
|
---|
85 | * @param user The username.
|
---|
86 | */
|
---|
87 | public void setUser(String user) {
|
---|
88 | super.setInternalUser(user);
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Date representing the 'start' of the range.
|
---|
93 | *
|
---|
94 | * @param fromDate The start date.
|
---|
95 | */
|
---|
96 | public void setFromDate(String fromDate) {
|
---|
97 | super.setInternalFromDate(fromDate);
|
---|
98 | }
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Date representing the 'end' of the range.
|
---|
102 | *
|
---|
103 | * @param toDate The end date.
|
---|
104 | */
|
---|
105 | public void setToDate(String toDate) {
|
---|
106 | super.setInternalToDate(toDate);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Label representing the 'start' of the range.
|
---|
111 | *
|
---|
112 | * @param fromLabel The start label.
|
---|
113 | */
|
---|
114 | public void setFromLabel(String fromLabel) {
|
---|
115 | super.setInternalFromLabel(fromLabel);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Label representing the 'end' of the range.
|
---|
120 | *
|
---|
121 | * @param toLabel The end label.
|
---|
122 | */
|
---|
123 | public void setToLabel(String toLabel) {
|
---|
124 | super.setInternalToLabel(toLabel);
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Number of days for comparison.
|
---|
129 | * Defaults to 2 days.
|
---|
130 | *
|
---|
131 | * @param numd The number of days.
|
---|
132 | */
|
---|
133 | public void setNumdays(int numd) {
|
---|
134 | super.setInternalNumDays(numd);
|
---|
135 | }
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * Output file name for the history.
|
---|
139 | *
|
---|
140 | * @param outfile The output file name.
|
---|
141 | */
|
---|
142 | public void setOutput(File outfile) {
|
---|
143 | if (outfile != null) {
|
---|
144 | super.setInternalOutputFilename(outfile.getAbsolutePath());
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | /**
|
---|
149 | * Format of dates in <code>fromDate</code and <code>toDate</code>.
|
---|
150 | * Used when calculating dates with the numdays attribute.
|
---|
151 | * This string uses the formatting rules of <code>SimpleDateFormat</code>.
|
---|
152 | * Defaults to <code>DateFormat.SHORT</code>.
|
---|
153 | *
|
---|
154 | * @param dateFormat The date format.
|
---|
155 | */
|
---|
156 | public void setDateFormat(String dateFormat) {
|
---|
157 | super.setInternalDateFormat(new SimpleDateFormat(dateFormat));
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Output style. Valid options are:
|
---|
162 | * <ul>
|
---|
163 | * <li>brief: -B Display a brief history.
|
---|
164 | * <li>codediff: -D Display line-by-line file changes.
|
---|
165 | * <li>nofile: -F- Do not display individual file updates in the project history.
|
---|
166 | * <li>default: No option specified. Display in Source Safe's default format.
|
---|
167 | * </ul>
|
---|
168 | *
|
---|
169 | * @param attr The history style:
|
---|
170 | */
|
---|
171 | public void setStyle(BriefCodediffNofile attr) {
|
---|
172 | String option = attr.getValue();
|
---|
173 | if (option.equals(STYLE_BRIEF)) {
|
---|
174 | super.setInternalStyle(FLAG_BRIEF);
|
---|
175 | } else if (option.equals(STYLE_CODEDIFF)) {
|
---|
176 | super.setInternalStyle(FLAG_CODEDIFF);
|
---|
177 | } else if (option.equals(STYLE_DEFAULT)) {
|
---|
178 | super.setInternalStyle("");
|
---|
179 | } else if (option.equals(STYLE_NOFILE)) {
|
---|
180 | super.setInternalStyle(FLAG_NO_FILE);
|
---|
181 | } else {
|
---|
182 | throw new BuildException("Style " + attr + " unknown.", getLocation());
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Extention of EnumeratedAttribute to hold the values for style.
|
---|
188 | */
|
---|
189 | public static class BriefCodediffNofile extends EnumeratedAttribute {
|
---|
190 | /**
|
---|
191 | * Gets the list of allowable values.
|
---|
192 | * @return The values.
|
---|
193 | */
|
---|
194 | public String[] getValues() {
|
---|
195 | return new String[] {STYLE_BRIEF, STYLE_CODEDIFF, STYLE_NOFILE, STYLE_DEFAULT};
|
---|
196 | }
|
---|
197 | }
|
---|
198 | }
|
---|