diff --git a/BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs b/BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..16a68f15 --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SharedLabeller")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SharedLabeller")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("71a8ae4e-af6d-42fd-b62a-96c09044e24a")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BuildFiles/Building/SharedLabeller/SharedLabeller.cs b/BuildFiles/Building/SharedLabeller/SharedLabeller.cs new file mode 100644 index 00000000..64ac1569 --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/SharedLabeller.cs @@ -0,0 +1,133 @@ +using System.IO; +using System.Text; + +using Exortech.NetReflector; +using ThoughtWorks.CruiseControl.Core; +using ThoughtWorks.CruiseControl.Remote; + +// this namespace could be altered and several classes could be put into the same if you'd want to combine several plugins in one dll +namespace ccnet.SharedLabeller.CruiseControl.plugin +{ + [ReflectorType("sharedLabeller")] + public class SharedLabeller : ILabeller + { + /// + /// The path where the file that holds the shared label should be located + /// + /// none + [ReflectorProperty("sharedLabelFilePath", Required = true)] + public string SharedLabelFilePath { get; set; } + + /// + /// Any string to be put in front of all labels. Mutually exclusive with PrefixFile. + /// + [ReflectorProperty("prefix", Required = false)] + public string Prefix { get; set; } + + /// + /// File with string to be put in front of all labels. Mutually exclusive with Prefix. + /// + [ReflectorProperty("prefixFile", Required = false)] + public string PrefixFile { get; set; } + + /// + /// If true, the label will be incremented even if the build fails. Otherwise it will only be incremented if the build succeeds. + /// + [ReflectorProperty("incrementOnFailure", Required = false)] + public bool IncrementOnFailure { get; set; } + + /// + /// If false, the label will never be incremented when this project is builded. This is usefull for deployment builds that + /// should use the last successfull of two or more builds + /// + [ReflectorProperty("increment", Required = false)] + public bool Increment { get; set; } + + /// + /// Allows you to set the initial build number. + /// This will only be used when on the first build of a project, meaning that when you change this value, + /// you'll have to stop the CCNet service and delete the state file. + /// + /// 0 + [ReflectorProperty("initialBuildLabel", Required = false)] + public int InitialBuildLabel { get; set; } + + public SharedLabeller() + { + IncrementOnFailure = false; + Increment = true; + InitialBuildLabel = 768; + } + + #region ILabeller Members + + public string Generate(IIntegrationResult integrationResult) + { + if (ShouldIncrementLabel(integrationResult.LastIntegration)) + { + return Prefix + this.GetLabel(); + } + else + { + return integrationResult.LastIntegration.Label; + } + } + + public void Run(IIntegrationResult integrationResult) + { + integrationResult.Label = Generate(integrationResult); + } + + #endregion + + /// + /// Get and increments the label, unless increment is false then it only gets the label + /// + /// + private string GetLabel() + { + ThoughtWorks.CruiseControl.Core.Util.Log.Debug("About to read label prefix file. Filename: {0}", PrefixFile); + string prefix = System.IO.File.ReadAllText (PrefixFile).Trim(); + + ThoughtWorks.CruiseControl.Core.Util.Log.Debug("About to read build number file. Filename: {0}", SharedLabelFilePath); + using (FileStream fileStream = File.Open(this.SharedLabelFilePath, + FileMode.OpenOrCreate, + FileAccess.ReadWrite, + FileShare.None)) + { + // read last build number from file + var bytes = new byte[fileStream.Length]; + fileStream.Read(bytes, 0, bytes.Length); + + string rawBuildNumber = Encoding.UTF8.GetString(bytes); + + // parse last build number + int previousBuildNumber; + if (!int.TryParse(rawBuildNumber, out previousBuildNumber)) + { + previousBuildNumber = InitialBuildLabel - 1; + } + + if (!Increment) + { + return previousBuildNumber.ToString(); + } + + int newBuildNumber = previousBuildNumber + 1; + + // increment build number and write back to file + bytes = Encoding.UTF8.GetBytes(newBuildNumber.ToString()); + + fileStream.Seek(0, SeekOrigin.Begin); + fileStream.Write(bytes, 0, bytes.Length); + + return newBuildNumber.ToString(); + } + } + + private bool ShouldIncrementLabel(IntegrationSummary integrationSummary) + { + return integrationSummary == null || integrationSummary.Status == IntegrationStatus.Success || IncrementOnFailure; + } + } +} \ No newline at end of file diff --git a/BuildFiles/Building/SharedLabeller/SharedLabeller.csproj b/BuildFiles/Building/SharedLabeller/SharedLabeller.csproj new file mode 100644 index 00000000..4e00f4e9 --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/SharedLabeller.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409} + Library + Properties + SharedLabeller + ccnet.SharedLabeller.CruiseControl.plugin + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\NetReflector.dll + + + + + + + + + ..\ThoughtWorks.CruiseControl.Core.dll + + + ..\ThoughtWorks.CruiseControl.MSBuild.dll + + + ..\ThoughtWorks.CruiseControl.Remote.dll + + + + + + + + + \ No newline at end of file diff --git a/BuildFiles/Building/SharedLabeller/SharedLabeller.sln b/BuildFiles/Building/SharedLabeller/SharedLabeller.sln new file mode 100644 index 00000000..239bb43d --- /dev/null +++ b/BuildFiles/Building/SharedLabeller/SharedLabeller.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedLabeller", "SharedLabeller.csproj", "{AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE5CF88B-2B4A-4A8B-93C2-2C399E1A0409}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/BuildFiles/Building/ThoughtWorks.CruiseControl.Core.dll b/BuildFiles/Building/ThoughtWorks.CruiseControl.Core.dll new file mode 100644 index 00000000..631ac4d3 Binary files /dev/null and b/BuildFiles/Building/ThoughtWorks.CruiseControl.Core.dll differ diff --git a/BuildFiles/Building/ThoughtWorks.CruiseControl.MSBuild.dll b/BuildFiles/Building/ThoughtWorks.CruiseControl.MSBuild.dll new file mode 100644 index 00000000..d27db741 Binary files /dev/null and b/BuildFiles/Building/ThoughtWorks.CruiseControl.MSBuild.dll differ diff --git a/BuildFiles/Building/ThoughtWorks.CruiseControl.Remote.dll b/BuildFiles/Building/ThoughtWorks.CruiseControl.Remote.dll new file mode 100644 index 00000000..79da05d0 Binary files /dev/null and b/BuildFiles/Building/ThoughtWorks.CruiseControl.Remote.dll differ diff --git a/BuildFiles/Building/ccnet.SharedLabeller.CruiseControl.plugin.dll b/BuildFiles/Building/ccnet.SharedLabeller.CruiseControl.plugin.dll new file mode 100644 index 00000000..1c9d33a3 Binary files /dev/null and b/BuildFiles/Building/ccnet.SharedLabeller.CruiseControl.plugin.dll differ diff --git a/BuildFiles/Building/precompile-deploy.cmd b/BuildFiles/Building/precompile-deploy.cmd index e18d8218..a01b5f3f 100644 --- a/BuildFiles/Building/precompile-deploy.cmd +++ b/BuildFiles/Building/precompile-deploy.cmd @@ -1,4 +1,5 @@ -if not exist C:\Lab\Swarmops\build\Deploy-Staging\BuildDropped.txt goto testSprint +if not exist C:\Lab\Swarmops\build\Deploy-Staging\BuildDropped.txt goto testSprint + cd \Lab\Swarmops\build\Deploy-Staging