KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > vss > MSVSSHISTORY


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs.optional.vss;
20
21 import java.io.File JavaDoc;
22 import java.text.SimpleDateFormat JavaDoc;
23
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.types.Commandline;
26 import org.apache.tools.ant.types.EnumeratedAttribute;
27
28 /**
29  * Performs History commands to Microsoft Visual SourceSafe.
30  *
31  * @ant.task name="vsshistory" category="scm"
32  */

33 public class MSVSSHISTORY extends MSVSS {
34
35     /**
36      * Builds a command line to execute ss.
37      * @return The constructed commandline.
38      */

39     Commandline buildCmdLine() {
40         Commandline commandLine = new Commandline();
41
42         // first off, make sure that we've got a command and a vssdir and a label ...
43
if (getVsspath() == null) {
44             String JavaDoc msg = "vsspath attribute must be set!";
45             throw new BuildException(msg, getLocation());
46         }
47
48         // build the command line from what we got the format is
49
// ss History elements [-H] [-L] [-N] [-O] [-V] [-Y] [-#] [-?]
50
// as specified in the SS.EXE help
51
commandLine.setExecutable(getSSCommand());
52         commandLine.createArgument().setValue(COMMAND_HISTORY);
53
54         // VSS items
55
commandLine.createArgument().setValue(getVsspath());
56         // -I-
57
commandLine.createArgument().setValue(FLAG_AUTORESPONSE_DEF); // ignore all errors
58
// -Vd
59
commandLine.createArgument().setValue(getVersionDate());
60         // -VL
61
commandLine.createArgument().setValue(getVersionLabel());
62         // -R
63
commandLine.createArgument().setValue(getRecursive());
64         // -B / -D / -F-
65
commandLine.createArgument().setValue(getStyle());
66         // -Y
67
commandLine.createArgument().setValue(getLogin());
68         // -O
69
commandLine.createArgument().setValue(getOutput());
70
71         return commandLine;
72     }
73
74     /**
75      * Retrieve history recursively. Defaults to false.
76      *
77      * @param recursive The boolean value for recursive.
78      */

79     public void setRecursive(boolean recursive) {
80         super.setInternalRecursive(recursive);
81     }
82
83     /**
84      * Name of the user whose change history is generated.
85      *
86      * @param user The username.
87      */

88     public void setUser(String JavaDoc user) {
89         super.setInternalUser(user);
90     }
91
92     /**
93      * Date representing the 'start' of the range.
94      *
95      * @param fromDate The start date.
96      */

97     public void setFromDate(String JavaDoc fromDate) {
98         super.setInternalFromDate(fromDate);
99     }
100
101     /**
102      * Date representing the 'end' of the range.
103      *
104      * @param toDate The end date.
105      */

106     public void setToDate(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc dateFormat) {
158         super.setInternalDateFormat(new SimpleDateFormat JavaDoc(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 JavaDoc 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.", getLocation());
184         }
185     }
186
187     /**
188      * Extention of EnumeratedAttribute to hold the values for style.
189      */

190     public static class BriefCodediffNofile extends EnumeratedAttribute {
191         /**
192          * Gets the list of allowable values.
193          * @return The values.
194          */

195         public String JavaDoc[] getValues() {
196             return new String JavaDoc[] {STYLE_BRIEF, STYLE_CODEDIFF, STYLE_NOFILE, STYLE_DEFAULT};
197         }
198     }
199 }
200
Popular Tags