PlasticSCM.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Sourcecontrol » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Core » Sourcecontrol » PlasticSCM.cs
using System.Globalization;
using Exortech.NetReflector;
using ThoughtWorks.CruiseControl.Core.Util;

namespace ThoughtWorks.CruiseControl.Core.Sourcecontrol{
    /// <summary>
    /// This supports Cdice Software's Plastic SCM source control system.
    /// </summary>
    /// <title>PlasticSCM Source Control Block</title>
    /// <version>1.3</version>
    /// <key name="type">
    /// <description>The type of source control block.</description>
    /// <value>plasticscm</value>
    /// </key>
    /// <example>
    /// <code title="Basic Example">
    /// &lt;sourcecontrol type="plasticscm"&gt;
    /// &lt;workingDirectory&gt;c:\workspace&lt;/workingDirectory&gt;
    /// &lt;branch&gt;br:/main&lt;/branch&gt;
    /// &lt;/sourcecontrol&gt;
    /// </code>
    /// <code title="Full Example">
    /// &lt;sourcecontrol type="plasticscm"&gt;
    /// &lt;executable&gt;c:\Program Files\PlasticSCM\client\cm.exe&lt;/executable&gt;
    /// &lt;workingDirectory&gt;c:\workspace&lt;/workingDirectory&gt;
    /// &lt;branch&gt;br:/main&lt;/branch&gt;
    /// &lt;repository&gt;mainrep&lt;/repository&gt;
    /// &lt;forced&gt;true&lt;/forced&gt;
    /// &lt;labelOnSuccess&gt;true&lt;/labelOnSuccess&gt;
    /// &lt;labelPrefix&gt;BL&lt;/labelPrefix&gt;
    /// &lt;timeout units="minutes"&gt;10&lt;/timeout&gt;
    /// &lt;/sourcecontrol&gt;
    /// </code>
    /// </example>
  [ReflectorType("plasticscm")]
  public class PlasticSCM : ProcessSourceControl
  {
    public const string DefaultPlasticExecutable = "cm";
    public const char DELIMITER = '?';

    //Format used in the query to Plastic SCM
    public const string DATEFORMAT = "dd/MM/yyyy HH:mm:ss";
    public static string FORMAT = DELIMITER + "{item}" + DELIMITER + "{owner}" + DELIMITER + "{date}" + DELIMITER + "{changeset}";


    public PlasticSCM() : this(new PlasticSCMHistoryParser(), new ProcessExecutor())
    {
    }

    public PlasticSCM(IHistoryParser parser, ProcessExecutor executor)
      : base(parser, executor)
    {
    }

        /// <summary>
        /// Should we automatically obtain updated source from PlasticSCM or not? 
        /// </summary>
        /// <version>1.3</version>
        /// <default>true</default>
        [ReflectorProperty("autoGetSource", Required = false)]
        public bool AutoGetSource = true;
        
        /// <summary>
        /// Name of the PlasticSCM executable.  
        /// </summary>
        /// <version>1.3</version>
        /// <default>cm</default>
        [ReflectorProperty("executable", Required = false)]
    public string Executable = DefaultPlasticExecutable;

        /// <summary>
        /// The Plastic SCM branch to monitor. 
        /// </summary>
        /// <version>1.3</version>
        /// <default>n/a</default>
        [ReflectorProperty("branch", Required = true)]
    public string Branch = string.Empty;

        /// <summary>
        /// The Plastic SCM repository to monitor. 
        /// </summary>
        /// <version>1.3</version>
        /// <default>Current in workspace</default>
        [ReflectorProperty("repository", Required = false)]
    public string Repository = string.Empty;

        /// <summary>
        /// Valid Plastic SCM workspace path. 
        /// </summary>
        /// <version>1.3</version>
        /// <default>Project Working Directory</default>
        [ReflectorProperty("workingDirectory", Required = false)]
    public string WorkingDirectory = string.Empty;

        /// <summary>
        /// Specifies whether or not CCNet should create an Plastic SCM baseline when the build is successful. 
        /// </summary>
        /// <version>1.3</version>
        /// <default>false</default>
        [ReflectorProperty("labelOnSuccess", Required = false)]
    public bool LabelOnSuccess = false;

        /// <summary>
        /// Specifies the prefix label name. 
        /// </summary>
        /// <version>1.3</version>
        /// <default>ccver-</default>
        [ReflectorProperty("labelPrefix", Required = false)]
    public string LabelPrefix = "ccver-";

        /// <summary>
        /// Do the update with the "--forced" option.
        /// </summary>
        /// <version>1.3</version>
        /// <default>false</default>
        [ReflectorProperty("forced", Required = false)]
    public bool Forced = false;

    public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
    {
      // Without the stb if the selector is pointing to a different repository
      // it can't solve path correctly
      Execute(GoToBranchProcessInfo(from));
      
      //Get and parse the modified files.
            Modification[] modifications = GetModifications(CreateQueryProcessInfo(from, to), from.StartTime, to.StartTime);
            base.FillIssueUrl(modifications);
            return modifications;
    }

    public override void LabelSourceControl(IIntegrationResult result)
    {
      if (LabelOnSuccess && result.Succeeded)
      {
                //The label could exist or the label process find private elements
                Execute(CreateLabelProcessInfo(result));
                Execute(LabelProcessInfo(result));
      }
    }

    public override void GetSource(IIntegrationResult result)
    {
            result.BuildProgressInformation.SignalStartRunTask("Getting source from PlasticSCM");

            if (AutoGetSource)
            {
                Execute(GoToBranchProcessInfo(result));
                Execute(NewGetSourceProcessInfo(result));
            }
    }

    public ProcessInfo NewGetSourceProcessInfo(IIntegrationResult result)
    {
      ProcessArgumentBuilder builder = new ProcessArgumentBuilder();
            builder.AppendArgument(string.Format("update {0}", result.BaseFromWorkingDirectory(WorkingDirectory)));
      if (Forced)
      {
        builder.AppendArgument("--forced");
      }
      return NewProcessInfoWithArgs(result, builder.ToString());
    }

    public ProcessInfo GoToBranchProcessInfo(IIntegrationResult result)
    {
      ProcessArgumentBuilder builder = new ProcessArgumentBuilder();
      builder.AppendArgument(string.Format("stb {0}", Branch));
      if (Repository != string.Empty)
      {
        builder.AppendArgument(string.Format("-repository={0}", Repository));
      }
      builder.AppendArgument("--noupdate");
      return NewProcessInfoWithArgs(result, builder.ToString());
    }

    public ProcessInfo CreateQueryProcessInfo(IIntegrationResult from, IIntegrationResult to)
    {
      ProcessArgumentBuilder builder = new ProcessArgumentBuilder();
      builder.AppendArgument(
        string.Format("find revision where branch = '{0}' "+
                "and revno != 'CO' "+
                "and date between '{1}' and '{2}'",
        Branch, from.StartTime.ToString(DATEFORMAT, CultureInfo.InvariantCulture), to.StartTime.ToString(DATEFORMAT, CultureInfo.InvariantCulture)));
        
      if (Repository != string.Empty) 
      {
        builder.AppendArgument(string.Format("on repository '{0}'", Repository));
      }

      builder.AppendArgument(string.Format("--dateformat=\"{0}\"", DATEFORMAT));
      builder.AppendArgument(string.Format("--format=\"{0}\"", FORMAT));

      return NewProcessInfoWithArgs(from, builder.ToString());
    }

    public ProcessInfo CreateLabelProcessInfo(IIntegrationResult result)
    {
      string labelName = LabelPrefix + result.Label;
      ProcessArgumentBuilder buffer = new ProcessArgumentBuilder();
      buffer.AppendArgument(string.Format("mklb {0}", labelName));
      return NewProcessInfoWithArgs(result, buffer.ToString());
    }

    public ProcessInfo LabelProcessInfo(IIntegrationResult result)
    {
      string labelName = LabelPrefix + result.Label;
      ProcessArgumentBuilder buffer = new ProcessArgumentBuilder();
      buffer.AppendArgument(string.Format("label -R lb:{0} .", labelName));
      return NewProcessInfoWithArgs(result, buffer.ToString());
    }

    private ProcessInfo NewProcessInfoWithArgs(IIntegrationResult result, string args)
    {
      return new ProcessInfo(Executable, args, result.BaseFromWorkingDirectory(WorkingDirectory));
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.