diff options
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks')
6 files changed, 174 insertions, 18 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj b/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj index 365bec5..7993ed5 100644 --- a/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj +++ b/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.csproj @@ -27,6 +27,7 @@ <IsWebBootstrapper>false</IsWebBootstrapper> <UseApplicationTrust>false</UseApplicationTrust> <BootstrapperEnabled>true</BootstrapperEnabled> + <CodeContractsAssemblyMode>1</CodeContractsAssemblyMode> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -64,6 +65,7 @@ <CodeContractsRuntimeCheckingLevel>Full</CodeContractsRuntimeCheckingLevel> <CodeContractsReferenceAssembly>%28none%29</CodeContractsReferenceAssembly> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> + <CodeContractsExtraRewriteOptions /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>pdbonly</DebugType> @@ -119,6 +121,7 @@ <Compile Include="NativeMethods.cs" /> <Compile Include="ParseMaster.cs" /> <Compile Include="PathSegment.cs" /> + <Compile Include="PrepareOhlohRelease.cs" /> <Compile Include="Publicize.cs" /> <Compile Include="Purge.cs" /> <Compile Include="ReSignDelaySignedAssemblies.cs" /> diff --git a/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.sln b/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.sln index f3e3982..dbc8e60 100644 --- a/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.sln +++ b/src/DotNetOpenAuth.BuildTasks/DotNetOpenAuth.BuildTasks.sln @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\..\tools\DotNetOpenAuth.targets = ..\..\tools\DotNetOpenAuth.targets ..\..\tools\DotNetOpenAuth.Versioning.targets = ..\..\tools\DotNetOpenAuth.Versioning.targets ..\..\tools\drop.proj = ..\..\tools\drop.proj + ..\..\tools\ohloh.proj = ..\..\tools\ohloh.proj ..\..\projecttemplates\projecttemplates.proj = ..\..\projecttemplates\projecttemplates.proj ..\..\samples\Samples.proj = ..\..\samples\Samples.proj ..\..\samples\tools.proj = ..\..\samples\tools.proj diff --git a/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs b/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs index 1d60ca4..dfb3468 100644 --- a/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs +++ b/src/DotNetOpenAuth.BuildTasks/GetBuildVersion.cs @@ -10,6 +10,11 @@ using Microsoft.Build.Utilities; namespace DotNetOpenAuth.BuildTasks { public class GetBuildVersion : Task { + /// <summary> + /// Initializes a new instance of the <see cref="GetBuildVersion"/> class. + /// </summary> + public GetBuildVersion() { + } /// <summary> /// Gets the version string to use in the compiled assemblies. @@ -18,6 +23,12 @@ namespace DotNetOpenAuth.BuildTasks { public string Version { get; private set; } /// <summary> + /// Gets the version string to use in the official release name (lacks revision number). + /// </summary> + [Output] + public string SimpleVersion { get; private set; } + + /// <summary> /// Gets the Git revision control commit id for HEAD (the current source code version). /// </summary> [Output] @@ -37,9 +48,11 @@ namespace DotNetOpenAuth.BuildTasks { public override bool Execute() { try { Version typedVersion = ReadVersionFromFile(); - typedVersion = new Version(typedVersion.Major, typedVersion.Minor, typedVersion.Build, CalculateJDate(DateTime.Now)); - Version = typedVersion.ToString(); + SimpleVersion = typedVersion.ToString(); + var fullVersion = new Version(typedVersion.Major, typedVersion.Minor, typedVersion.Build, CalculateJDate(DateTime.Now)); + Version = fullVersion.ToString(); + this.GitCommitId = GetGitHeadCommitId(); } catch (ArgumentOutOfRangeException ex) { Log.LogErrorFromException(ex); diff --git a/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs b/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs index af2d1d0..fa7ca06 100644 --- a/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs +++ b/src/DotNetOpenAuth.BuildTasks/HardLinkCopy.cs @@ -7,11 +7,11 @@ namespace DotNetOpenAuth.BuildTasks { using System; using System.Collections.Generic; + using System.IO; using System.Linq; using System.Text; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; - using System.IO; public class HardLinkCopy : Task { [Required] diff --git a/src/DotNetOpenAuth.BuildTasks/PathSegment.cs b/src/DotNetOpenAuth.BuildTasks/PathSegment.cs index 56655ff..1f17b5e 100644 --- a/src/DotNetOpenAuth.BuildTasks/PathSegment.cs +++ b/src/DotNetOpenAuth.BuildTasks/PathSegment.cs @@ -16,7 +16,6 @@ namespace DotNetOpenAuth.BuildTasks { internal class PathSegment { private const float ParentChildResizeThreshold = 0.30f; - private readonly PathSegment parent; private readonly string originalName; private string currentName; private bool minimized; @@ -34,14 +33,16 @@ namespace DotNetOpenAuth.BuildTasks { Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(originalName)); Contract.Requires<ArgumentNullException>(parent != null); this.currentName = this.originalName = originalName; - this.parent = parent; + this.Parent = parent; this.minimized = false; } + internal PathSegment Parent { get; private set; } + internal string OriginalPath { get { - if (this.parent != null) { - return Path.Combine(this.parent.OriginalPath, this.originalName); + if (this.Parent != null) { + return Path.Combine(this.Parent.OriginalPath, this.originalName); } else { return this.originalName; } @@ -50,8 +51,8 @@ namespace DotNetOpenAuth.BuildTasks { internal string CurrentPath { get { - if (this.parent != null) { - return Path.Combine(this.parent.CurrentPath, this.currentName); + if (this.Parent != null) { + return Path.Combine(this.Parent.CurrentPath, this.currentName); } else { return this.currentName; } @@ -68,15 +69,15 @@ namespace DotNetOpenAuth.BuildTasks { private int SegmentCount { get { - int parents = this.parent != null ? this.parent.SegmentCount : 0; + int parents = this.Parent != null ? this.Parent.SegmentCount : 0; return parents + 1; } } internal int FullLength { get { - if (this.parent != null) { - int parentLength = this.parent.FullLength; + if (this.Parent != null) { + int parentLength = this.Parent.FullLength; if (parentLength > 0) { parentLength++; // allow for an in between slash } @@ -108,10 +109,10 @@ namespace DotNetOpenAuth.BuildTasks { internal IEnumerable<PathSegment> Ancestors { get { - PathSegment parent = this.parent; + PathSegment parent = this.Parent; while (parent != null) { yield return parent; - parent = parent.parent; + parent = parent.Parent; } } } @@ -143,7 +144,7 @@ namespace DotNetOpenAuth.BuildTasks { } internal IEnumerable<PathSegment> Siblings { - get { return this.parent != null ? this.parent.Children : Enumerable.Empty<PathSegment>(); } + get { return this.Parent != null ? this.Parent.Children : Enumerable.Empty<PathSegment>(); } } internal Collection<PathSegment> Children { get; private set; } @@ -160,8 +161,8 @@ namespace DotNetOpenAuth.BuildTasks { path += "\\"; } - if (this.parent != null) { - path = parent.ToString() + path; + if (this.Parent != null) { + path = Parent.ToString() + path; } return path; @@ -182,7 +183,7 @@ namespace DotNetOpenAuth.BuildTasks { internal int EnsureSelfAndChildrenNoLongerThan(int maxLength) { Contract.Requires<ArgumentOutOfRangeException>(maxLength > 0, "A path can only have a positive length."); - Contract.Requires<ArgumentOutOfRangeException>(this.parent == null || maxLength > this.parent.FullLength + 1, "A child path cannot possibly be made shorter than its parent."); + Contract.Requires<ArgumentOutOfRangeException>(this.Parent == null || maxLength > this.Parent.FullLength + 1, "A child path cannot possibly be made shorter than its parent."); Contract.Ensures(Contract.Result<int>() <= maxLength); const int uniqueBase = 16; diff --git a/src/DotNetOpenAuth.BuildTasks/PrepareOhlohRelease.cs b/src/DotNetOpenAuth.BuildTasks/PrepareOhlohRelease.cs new file mode 100644 index 0000000..fe13824 --- /dev/null +++ b/src/DotNetOpenAuth.BuildTasks/PrepareOhlohRelease.cs @@ -0,0 +1,138 @@ +//----------------------------------------------------------------------- +// <copyright file="PrepareOhlohRelease.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.BuildTasks { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Text; + using System.Text.RegularExpressions; + using System.Xml; + using System.Xml.Linq; + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; + + /// <summary> + /// Creates an Ohloh.net upload instruct XLM file and bash script that uses it. + /// </summary> + public class PrepareOhlohRelease : Task { + /// <summary> + /// Initializes a new instance of the <see cref="PrepareOhlohUpload"/> class. + /// </summary> + public PrepareOhlohRelease() { + } + + [Required] + public string Release { get; set; } + + public string ReleaseNotes { get; set; } + + [Required] + public string InstructFile { get; set; } + + [Required] + public string UploadScript { get; set; } + + [Required] + public string OhlohUser { get; set; } + + [Required] + public string OhlohProject { get; set; } + + [Required] + public ITaskItem[] RedistributableFiles { get; set; } + + public override bool Execute() { + this.WriteInstructFile(); + this.WriteUploadScript(); + + return !this.Log.HasLoggedErrors; + } + + private void WriteInstructFile() { + var packages = from redist in this.RedistributableFiles + let file = new { Path = redist.ItemSpec, Package = redist.GetMetadata("Package"), Platform = redist.GetMetadata("Platform"), Icon = redist.GetMetadata("Icon") } + group file by file.Package into package + select new XElement( + "package", + new XAttribute("name", package.Key), + new XElement( + "releases", + new XElement( + "release", + new XAttribute("name", this.Release), + new XAttribute("date", XmlConvert.ToString(DateTime.Now)), + new XElement("notes", this.ReleaseNotes), + new XElement( + "files", + package.Select( + f => new XElement( + "file", + new XAttribute("name", Path.GetFileName(f.Path)), + new XAttribute("date", XmlConvert.ToString(DateTime.Now)), + new XAttribute("platform", f.Platform), + new XAttribute("icon", f.Icon) + ) + ) + ) + ) + ) + ); + + var instructXml = new XElement("packages", packages); + + var writerSettings = new XmlWriterSettings { + OmitXmlDeclaration = true, + Indent = true, + IndentChars = "\t", + }; + using (var writer = XmlWriter.Create(this.InstructFile, writerSettings)) { + instructXml.Save(writer); + } + + this.Log.LogMessage("Ohloh instruct file written to: \"{0}\"", this.InstructFile); + + } + + private void WriteUploadScript() { + int longestPath = Math.Max( + GetLinuxPath(Path.GetFullPath(this.InstructFile)).Length, + this.RedistributableFiles.Max(f => GetLinuxPath(f.GetMetadata("FullPath")).Length)); + + using (StreamWriter writer = new StreamWriter(this.UploadScript)) { + writer.WriteLine("#!/bin/bash"); + writer.WriteLine(); + foreach (var file in this.RedistributableFiles) { + writer.WriteLine("scp {0,-" + longestPath + "} {1}@upload.ohloh.net:{2}/files", GetLinuxPath(file.GetMetadata("FullPath")), this.OhlohUser, this.OhlohProject); + } + + writer.WriteLine(); + writer.WriteLine("scp {0,-" + longestPath + "} {1}@upload.ohloh.net:{2}/instructs", GetLinuxPath(Path.GetFullPath(this.InstructFile)), this.OhlohUser, this.OhlohProject); + writer.WriteLine(); + writer.WriteLine("# Download the instruct log by executing this command:"); + writer.WriteLine("# scp {0}@upload.ohloh.net:{1}/logs/upload.log .", this.OhlohUser, this.OhlohProject); + } + + this.Log.LogMessage("Ohloh upload script written to: \"{0}\".", this.UploadScript); + } + + private static string GetLinuxPath(string windowsPath) { + if (String.IsNullOrEmpty(windowsPath)) { + throw new ArgumentNullException("windowsPath"); + } + + string linuxPath = Regex.Replace( + windowsPath, + @"^([A-Za-z])\:", + m => "/" + m.Groups[1].Value) + .Replace('\\', '/') + .Replace(" ", "\\ "); + return linuxPath; + } + } +} |