/src/Tasks/SurroundSCM/SSCMCheckin.cs

https://github.com/dguder/nantcontrib · C# · 382 lines · 193 code · 44 blank · 145 comment · 31 complexity · b9a127c330ef018c88baacad678a3a5c MD5 · raw file

  1. //
  2. // NAntContrib
  3. // Copyright (C) 2001-2004
  4. //
  5. //
  6. // This library is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU Lesser General Public
  8. // License as published by the Free Software Foundation; either
  9. // version 2.1 of the License, or (at your option) any later version.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. // Lesser General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Lesser General Public
  17. // License along with this library; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. //
  20. // Matt Harp; Seapine Software, Inc.
  21. //
  22. using System.Text;
  23. using NAnt.Core.Attributes;
  24. using NAnt.Core.Util;
  25. namespace NAnt.Contrib.Tasks.SurroundSCM {
  26. /// <summary>
  27. /// Checks in files in <see href="http://www.seapine.com/surroundscm.html">Surround SCM</see>
  28. /// repository.
  29. /// </summary>
  30. /// <remarks>
  31. /// Check in updated Surround SCM files with changes, removes the lock on
  32. /// the files, and makes changes available to other users.
  33. /// </remarks>
  34. /// <example>
  35. /// <para>
  36. /// Check In all files and repositories from repository 'Mainline/Widget'
  37. /// recursively from the 'Widget 1.0' branch to the working directory setup
  38. /// for user 'administrator'. This call outputs the progress of the Check In
  39. /// to the console.
  40. /// </para>
  41. /// <code>
  42. /// &lt;sscmcheckin
  43. /// serverconnect=&quot;localhost:4900&quot;
  44. /// serverlogin=&quot;administrator:&quot;
  45. /// file=&quot;/&quot;
  46. /// branch=&quot;Widget 1.0&quot;
  47. /// repository=&quot;Mainline/Widget&quot;
  48. /// recursive=&quot;true&quot;
  49. /// comment=&quot;I made some changes&quot;
  50. /// /&gt;
  51. /// </code>
  52. /// </example>
  53. /// <example>
  54. /// <para>
  55. /// Check in file 'Mainline/Widget/Widget.java' from the 'Widget 1.0'
  56. /// branch from the working directory setup for user 'administrator'
  57. /// with comment 'I made some changes'. Set the 'Release 1.1.1' label
  58. /// to this new version, even if the label already exists on an earlier
  59. /// version.
  60. /// </para>
  61. /// <code>
  62. /// &lt;sscmcheckin
  63. /// serverconnect=&quot;localhost:4900&quot;
  64. /// serverlogin=&quot;administrator:&quot;
  65. /// file=&quot;Widget.java&quot;
  66. /// branch=&quot;Widget 1.0&quot;
  67. /// repository=&quot;Mainline/Widget&quot;
  68. /// comment=&quot;I made some changes&quot;
  69. /// label=&quot;Release 1.1.1&quot;
  70. /// overwritelabel=&quot;true&quot;
  71. /// /&gt;
  72. /// </code>
  73. /// </example>
  74. [TaskName("sscmcheckin")]
  75. public class SSCMCheckin : SSCMTask {
  76. #region Private Instance Fields
  77. private string _branch;
  78. private string _repository;
  79. private string _file;
  80. private string _comment;
  81. private bool _skipAutomerge;
  82. private bool _getLocal = true;
  83. private bool _keepLocked;
  84. private string _label;
  85. private bool _overwriteLabel;
  86. private bool _quiet;
  87. private bool _recursive;
  88. private string _ttpDatabase;
  89. private string _ttpLogin;
  90. private string _ttpDefects;
  91. private bool _writable;
  92. private bool _forceUpdate;
  93. private bool _deleteLocal;
  94. #endregion Private Instance Fields
  95. #region Public Instance Properties
  96. /// <summary>
  97. /// Surround SCM branch name. The default is pulled from the local
  98. /// working directory.
  99. /// </summary>
  100. [TaskAttribute("branch", Required=false)]
  101. public string Branch {
  102. get { return _branch; }
  103. set { _branch = StringUtils.ConvertEmptyToNull(value); }
  104. }
  105. /// <summary>
  106. /// Surround SCM repository path. The default is pulled from the local
  107. /// working directory.
  108. /// </summary>
  109. [TaskAttribute("repository", Required=false)]
  110. public string Repository {
  111. get { return _repository; }
  112. set { _repository = StringUtils.ConvertEmptyToNull(value); }
  113. }
  114. /// <summary>
  115. /// File or repository name. Can be / or empty, which means the
  116. /// repository specified by the repository option or the default
  117. /// repository.
  118. /// </summary>
  119. [TaskAttribute("file", Required=false)]
  120. public string File {
  121. get { return _file; }
  122. set { _file = StringUtils.ConvertEmptyToNull(value); }
  123. }
  124. /// <summary>
  125. /// Comment for the check-in.
  126. /// </summary>
  127. [TaskAttribute("comment", Required=false)]
  128. public string Comment {
  129. get { return _comment; }
  130. set { _comment = StringUtils.ConvertEmptyToNull(value); }
  131. }
  132. /// <summary>
  133. /// Force check in without merge. Ignores code changes checked in after
  134. /// the user's last checkout or merge. The default is <see langword="false" />.
  135. /// </summary>
  136. [TaskAttribute("skipautomerge", Required=false)]
  137. public bool SkipAutomerge {
  138. get { return _skipAutomerge; }
  139. set { _skipAutomerge = value; }
  140. }
  141. /// <summary>
  142. /// Get file after check in. The default is <see langword="true" />.
  143. /// </summary>
  144. [TaskAttribute("getlocal", Required=false)]
  145. public bool GetLocal {
  146. get { return _getLocal; }
  147. set { _getLocal = value; }
  148. }
  149. /// <summary>
  150. /// Keep the lock after check in. The default is <see langword="false" />.
  151. /// </summary>
  152. [TaskAttribute("keeplocked", Required=false)]
  153. public bool KeepLocked{
  154. get { return _keepLocked; }
  155. set { _keepLocked = value; }
  156. }
  157. /// <summary>
  158. /// A label for the check in code.
  159. /// </summary>
  160. [TaskAttribute("label", Required=false)]
  161. public string Label {
  162. get { return _label; }
  163. set { _label = StringUtils.ConvertEmptyToNull(value); }
  164. }
  165. /// <summary>
  166. /// Overwrite previous label on file. The default is
  167. /// <see langword="false" />.
  168. /// </summary>
  169. [TaskAttribute("overwritelabel", Required=false)]
  170. public bool OverwriteLabel {
  171. get { return _overwriteLabel; }
  172. set { _overwriteLabel = value; }
  173. }
  174. /// <summary>
  175. /// Do not list repository and local full path of the Surround
  176. /// SCM server. The default is <see langword="false" />.
  177. /// </summary>
  178. [TaskAttribute("quiet", Required=false)]
  179. public bool Quiet {
  180. get { return _quiet; }
  181. set { _quiet = value; }
  182. }
  183. /// <summary>
  184. /// Recursively check in all files and sub-repositories.
  185. /// The default is <see langword="false" />.
  186. /// </summary>
  187. [TaskAttribute("recursive", Required=false)]
  188. public bool Recursive {
  189. get { return _recursive; }
  190. set { _recursive = value; }
  191. }
  192. /// <summary>
  193. /// The TestTrack Pro database configuration name.
  194. /// </summary>
  195. [TaskAttribute("ttpdatabase", Required=false)]
  196. public string TtpDatabase {
  197. get { return _ttpDatabase; }
  198. set { _ttpDatabase = StringUtils.ConvertEmptyToNull(value); }
  199. }
  200. /// <summary>
  201. /// The TestTrack Pro username and password.
  202. /// </summary>
  203. [TaskAttribute("ttplogin", Required=false)]
  204. public string TtpLogin {
  205. get { return _ttpLogin; }
  206. set { _ttpLogin = StringUtils.ConvertEmptyToNull(value); }
  207. }
  208. /// <summary>
  209. /// The TestTrack Pro defect number(s) for attachment. Format is "#:#:#:#".
  210. /// </summary>
  211. [TaskAttribute("ttpdefects", Required=false)]
  212. public string TtpDefects {
  213. get { return _ttpDefects; }
  214. set { _ttpDefects = StringUtils.ConvertEmptyToNull(value); }
  215. }
  216. /// <summary>
  217. /// Make file writable after check in. The default is
  218. /// <see langword="false" />.
  219. /// </summary>
  220. [TaskAttribute("writable", Required=false)]
  221. public bool Writable {
  222. get { return _writable; }
  223. set { _writable = value; }
  224. }
  225. /// <summary>
  226. /// Update version even if no changes. The default is
  227. /// <see langword="false" />.
  228. /// </summary>
  229. [TaskAttribute("forceupdate", Required=false)]
  230. public bool ForceUpdate {
  231. get { return _forceUpdate; }
  232. set { _forceUpdate = value; }
  233. }
  234. /// <summary>
  235. /// Remove local file after check in. The default is
  236. /// <see langword="false" />.
  237. /// </summary>
  238. [TaskAttribute("deletelocal", Required=false)]
  239. public bool DeleteLocal {
  240. get { return _deleteLocal; }
  241. set { _deleteLocal = value; }
  242. }
  243. #endregion Public Instance Properties
  244. #region Override implementation of SSCMTask
  245. /// <summary>
  246. /// Writes the task-specific arguments to the specified
  247. /// <see cref="StringBuilder" />.
  248. /// </summary>
  249. /// <param name="argBuilder">The <see cref="StringBuilder" /> to write the task-specific arguments to.</param>
  250. protected override void WriteCommandLineArguments(StringBuilder argBuilder) {
  251. argBuilder.Append("checkin");
  252. // filename
  253. if (File != null && File != "/") {
  254. argBuilder.Append(" \"");
  255. argBuilder.Append(File);
  256. argBuilder.Append("\"");
  257. } else {
  258. argBuilder.Append(" /");
  259. }
  260. // branch
  261. if (Branch != null) {
  262. argBuilder.Append(" -b\"");
  263. argBuilder.Append(Branch);
  264. argBuilder.Append("\"");
  265. }
  266. // repository
  267. if (Repository != null) {
  268. argBuilder.Append(" -p\"");
  269. argBuilder.Append(Repository);
  270. argBuilder.Append("\"");
  271. }
  272. // comment
  273. if (Comment != null) {
  274. argBuilder.Append(" -cc\"");
  275. argBuilder.Append(Comment);
  276. argBuilder.Append("\"");
  277. } else {
  278. argBuilder.Append(" -c-");
  279. }
  280. // label
  281. if (Label != null) {
  282. argBuilder.Append(" -l\"");
  283. argBuilder.Append(Label);
  284. argBuilder.Append("\"");
  285. if (OverwriteLabel) {
  286. argBuilder.Append(" -o");
  287. }
  288. }
  289. // TestTrack DB
  290. if (TtpDatabase != null) {
  291. argBuilder.Append(" -s\"");
  292. argBuilder.Append(TtpDatabase);
  293. argBuilder.Append("\"");
  294. }
  295. // TestTrack login
  296. if (TtpLogin != null) {
  297. argBuilder.Append(" -i\"");
  298. argBuilder.Append(TtpLogin);
  299. argBuilder.Append("\"");
  300. }
  301. // TestTrack defects
  302. if (TtpDefects != null) {
  303. argBuilder.Append(" -a");
  304. argBuilder.Append(TtpDefects);
  305. }
  306. // misc flags
  307. if (SkipAutomerge) {
  308. argBuilder.Append(" -f");
  309. }
  310. if (KeepLocked) {
  311. argBuilder.Append(" -k");
  312. }
  313. if (Quiet) {
  314. argBuilder.Append(" -q");
  315. }
  316. if (Recursive) {
  317. argBuilder.Append(" -r");
  318. }
  319. if (Writable) {
  320. argBuilder.Append(" -w");
  321. }
  322. if (ForceUpdate) {
  323. argBuilder.Append(" -u");
  324. }
  325. if (GetLocal) {
  326. argBuilder.Append(" -g");
  327. } else {
  328. argBuilder.Append(" -g-");
  329. }
  330. if (DeleteLocal) {
  331. argBuilder.Append(" -d");
  332. } else {
  333. argBuilder.Append(" -d-");
  334. }
  335. }
  336. #endregion Override implementation of SSCMTask
  337. }
  338. }