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