/src/Tasks/ClearCase/MkLabelType.cs

https://github.com/dguder/nantcontrib · C# · 218 lines · 108 code · 25 blank · 85 comment · 13 complexity · 5a109f746f766a6c9f4249eba64ba383 MD5 · raw file

  1. #region GNU Lesser General Public License
  2. //
  3. // NAntContrib
  4. // Copyright (C) 2001-2006 Gerry Shaw
  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 Trentini (matt.trentini@gmail.com)
  21. //
  22. #endregion
  23. using System;
  24. using System.IO;
  25. using System.Text;
  26. using NAnt.Core;
  27. using NAnt.Core.Attributes;
  28. namespace NAnt.Contrib.Tasks.ClearCase {
  29. /// <summary>
  30. /// Creates a label object in a ClearCase VOB.
  31. /// <seealso cref="ClearCaseMkLabel"/>
  32. /// </summary>
  33. /// <remarks>
  34. /// <para>
  35. /// This task uses the <c>cleartool mklabeltype</c> command to create a ClearCase label object.
  36. /// </para>
  37. /// </remarks>
  38. /// <example>
  39. /// <para>
  40. /// Performs a ClearCase mklbtype to create a label type named <c>VERSION_1</c>.
  41. /// It is created as <c>ordinary</c> so it is available only to the current VOB.
  42. /// The text <c>Development version 1</c> is added as a comment.
  43. /// </para>
  44. /// <code>
  45. /// <![CDATA[
  46. /// <ccmklbtype typename="VERSION_1"
  47. /// ordinary="true"
  48. /// comment="Development version 1"/>
  49. /// ]]>
  50. /// </code>
  51. /// </example>
  52. [TaskName("ccmklbtype")]
  53. public class ClearCaseMkLbType : ClearCaseBase {
  54. #region Private Instance Fields
  55. private string _typename;
  56. private string _vob;
  57. private bool _replace;
  58. private bool _global;
  59. private bool _ordinary;
  60. private bool _pbranch;
  61. private bool _shared;
  62. private string _comment;
  63. private FileInfo _commentFile;
  64. #endregion Private Instance Fields
  65. #region Public Properties
  66. /// <summary>
  67. /// Name of the label type to create.
  68. /// </summary>
  69. [TaskAttribute("typename", Required=true)]
  70. public string Typename {
  71. get { return _typename; }
  72. set { _typename = value; }
  73. }
  74. /// <summary>
  75. /// Name of the VOB. Must be a valid path to somewhere on a VOB.
  76. /// </summary>
  77. [TaskAttribute("vob")]
  78. public string Vob {
  79. get { return _vob; }
  80. set { _vob = value; }
  81. }
  82. /// <summary>
  83. /// If <see langword="true" />, allow an existing label definition to be replaced.
  84. /// The default is <see langword="false" />.
  85. /// </summary>
  86. [TaskAttribute("replace")]
  87. [BooleanValidator()]
  88. public bool Replace {
  89. get { return _replace; }
  90. set { _replace = value; }
  91. }
  92. /// <summary>
  93. /// Creates a label type that is global to the VOB or to VOB's that use this VOB.
  94. /// Either global or ordinary can be specified, not both.
  95. /// The default is <see langword="false" />.
  96. /// </summary>
  97. [TaskAttribute("global")]
  98. [BooleanValidator()]
  99. public bool Global {
  100. get { return _global; }
  101. set { _global = value; }
  102. }
  103. /// <summary>
  104. /// Creates a label type that can be used only in the current VOB.
  105. /// Either global or ordinary can be specified, not both.
  106. /// Although <see langword="false" /> by default, if global is also <see langword="false" /> or not specified ordinary is the default behaviour.
  107. /// </summary>
  108. [TaskAttribute("ordinary")]
  109. [BooleanValidator()]
  110. public bool Ordinary {
  111. get { return _ordinary; }
  112. set { _ordinary = value; }
  113. }
  114. /// <summary>
  115. /// If <see langword="true" /> the label type is allowed to be used once per branch in a given element's version tree.
  116. /// The default is <see langword="false" />.
  117. /// </summary>
  118. [TaskAttribute("pbranch")]
  119. [BooleanValidator()]
  120. public bool PBranch {
  121. get { return _pbranch; }
  122. set { _pbranch = value; }
  123. }
  124. /// <summary>
  125. /// Sets the way mastership is checked by ClearCase. See ClearCase documentation for details.
  126. /// The default is <see langword="false" />.
  127. /// </summary>
  128. [TaskAttribute("shared")]
  129. [BooleanValidator()]
  130. public bool Shared {
  131. get { return _shared; }
  132. set { _shared = value; }
  133. }
  134. /// <summary>
  135. /// Specify a comment. Only one of <see cref="Comment" /> or
  136. /// <see cref="CommentFile" /> may be used.
  137. /// </summary>
  138. [TaskAttribute("comment")]
  139. public string Comment {
  140. get { return _comment; }
  141. set { _comment = value; }
  142. }
  143. /// <summary>
  144. /// Specify a file containing a comment. Only one of <see cref="Comment" />
  145. /// or <see cref="CommentFile" /> may be used.
  146. /// </summary>
  147. [TaskAttribute("commentfile")]
  148. public FileInfo CommentFile {
  149. get { return _commentFile; }
  150. set { _commentFile = value; }
  151. }
  152. #endregion Public Properties
  153. /// <summary>
  154. /// This is an override used by the base class to get command specific args.
  155. /// </summary>
  156. protected override string CommandSpecificArguments {
  157. get {
  158. StringBuilder arguments = new StringBuilder();
  159. arguments.Append("mklbtype ");
  160. if (Replace) {
  161. arguments.Append("-replace ");
  162. }
  163. if (Global) {
  164. arguments.Append("-global ");
  165. }
  166. if (Ordinary) {
  167. arguments.Append("-ordinary ");
  168. }
  169. if (PBranch) {
  170. arguments.Append("-pbranch ");
  171. }
  172. if (Shared) {
  173. arguments.Append("-shared ");
  174. }
  175. // Either Comment or CommentFile
  176. // TODO: Throw exception if both are specified.
  177. if (Comment != null) {
  178. arguments.AppendFormat("-comment \"{0}\" ", Comment);
  179. } else if (CommentFile != null) {
  180. arguments.AppendFormat("-cfile \"{0}\" ", CommentFile.FullName);
  181. } else {
  182. arguments.Append("-ncomment ");
  183. }
  184. // Should always have a label typename
  185. arguments.Append(Typename);
  186. if (Vob != null) {
  187. arguments.AppendFormat("@{0}", Vob);
  188. }
  189. return arguments.ToString();
  190. }
  191. }
  192. }
  193. }