diff --git a/ImageSharp.sln b/ImageSharp.sln index a5e1e12b0..1f848b34d 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -50,6 +50,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{9E574A07-F879-4811-9C41-5CBDC6BAFDB7}" ProjectSection(SolutionItems) = preProject src\Shared\AssemblyInfo.Common.cs = src\Shared\AssemblyInfo.Common.cs + src\Shared\stylecop.json = src\Shared\stylecop.json EndProjectSection EndProject Global diff --git a/build/Program.cs b/build/Program.cs index a3ae8b2ee..9c70b2490 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -1,67 +1,80 @@ -using Microsoft.DotNet.ProjectModel; -using System; -using System.IO; -using System.Linq; -using NuGet.Versioning; -using System.Collections.Generic; -using LibGit2Sharp; -using Newtonsoft.Json; -using System.Text; +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// namespace ConsoleApplication { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Text; + + using LibGit2Sharp; + using Microsoft.DotNet.ProjectModel; + using Newtonsoft.Json; + using NuGet.Versioning; + /// /// This updates the version numbers for all the projects in the src folder. /// The version number it will geneate is dependent on if this is a build from master or a branch/PR - /// + /// /// If its a build on master - /// We take the version number specified in project.json, + /// We take the version number specified in project.json, /// count how meny commits the repo has had that will affect this project or its dependencies since the version number of manually changed /// If this is the first commit that effected this project since number change then leave the version number as defined i.e. will build 1.0.0 if thats in project.json /// unless it is a preview build number in which case we always add the counter - /// + /// /// If the build is from a PR/branch /// We take the version number specified in project.json, append a tag for the branch/PR (so we can determin how each package was built) - /// append number of commits effecting the project. - /// - /// Examples + /// append number of commits effecting the project. + /// + /// + /// /// for PR#123 and project.json version 2.0.1 and we have had 30 commits affecting the project /// we would end up with version number 2.0.1-PR124-00030 - /// + /// /// for branch `fix-stuff` project.json version 2.0.1-alpha1 and we have had 832 commits affecting the project /// we would end up with version number 2.0.1-alpha1-fix-stuff-00832 - /// + /// /// for `master` project.json version 2.0.1-alpha1 and we have had 832 commits affecting the project /// we would end up with version number 2.0.1-alpha1-00832 - /// + /// /// for `master` project.json version 2.0.1 and we have had 132 commits affecting the project /// we would end up with version number 2.0.1-CI-00132 - /// + /// /// for `master` project.json version 2.0.1 and we have had 1 commits affecting the project /// we would end up with version number 2.0.1 - /// + /// /// for `master` project.json version 2.0.1-alpha1 and we have had 1 commits affecting the project /// we would end up with version number 2.0.1-alpha1 - /// + /// + /// + /// TODO Add the option for using this to update the version numbers in a project and its dependent references. + /// public class Program { - const string fallbackTag = "CI"; + private const string FallbackTag = "CI"; + /// + /// Main entry point. + /// + /// The arguments. public static void Main(string[] args) { - // TODO add options to updating the version number for indirvidual projects - var resetmode = args.Contains("reset"); - // find the project root where glbal.json lives + // Find the project root where glbal.json lives var root = ProjectRootResolver.ResolveRootDirectory("."); - //lets find the repo + + // Lets find the repo var repo = new LibGit2Sharp.Repository(root); - //lets find all the project.json files in the src folder (don't care about versioning `tests`) + // Lets find all the project.json files in the src folder (don't care about versioning `tests`) var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), Project.FileName, SearchOption.AllDirectories); - //open them and convert them to source projects + // Open them and convert them to source projects var projects = projectFiles.Select(x => ProjectReader.GetProject(x)) .Select(x => new SourceProject(x, repo.Info.WorkingDirectory)) .ToList(); @@ -77,7 +90,7 @@ namespace ConsoleApplication UpdateVersionNumbers(projects); CreateBuildScript(projects); - + foreach (var p in projects) { Console.WriteLine($"{p.Name} {p.FinalVersionNumber}"); @@ -100,11 +113,10 @@ namespace ConsoleApplication { foreach (var p in projects) { - //TODO force update of all dependent projects to point to the newest build. - - //we skip the build number and standard CI prefix on first commits + // TODO force update of all dependent projects to point to the newest build. + // we skip the build number and standard CI prefix on first commits var newVersion = p.FinalVersionNumber; - + // create a backup file so we can rollback later without breaking formatting File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true); @@ -116,7 +128,7 @@ namespace ConsoleApplication } private static string CurrentBranch(Repository repo) - { + { // lets build version friendly commit string branch = repo.Head.FriendlyName; @@ -164,7 +176,7 @@ namespace ConsoleApplication File.Delete("build-inner.bak"); } - //revert the project.json change be reverting it but skipp all the git stuff as its not needed + // revert the project.json change be reverting it but skipp all the git stuff as its not needed foreach (var p in projects) { if (File.Exists($"{p.FullProjectFilePath}.bak")) @@ -174,63 +186,146 @@ namespace ConsoleApplication } } } - + + /// + /// Project level logic + /// public class SourceProject { private readonly IEnumerable dependencies; + /// + /// Initializes a new instance of the class. + /// + /// The project. + /// The root. + public SourceProject(Project project, string root) + { + this.Name = project.Name; + this.ProjectDirectory = project.ProjectDirectory.Substring(root.Length); + this.ProjectFilePath = project.ProjectFilePath.Substring(root.Length); + this.FullProjectFilePath = project.ProjectFilePath; + this.Version = project.Version; + this.dependencies = project.Dependencies.Select(x => x.Name); + this.FinalVersionNumber = this.Version.ToFullString(); + } + + /// + /// Gets the project directory. + /// + /// + /// The project directory. + /// public string ProjectDirectory { get; } + /// + /// Gets the version. + /// + /// + /// The version. + /// public NuGetVersion Version { get; } + /// + /// Gets the dependent projects. + /// + /// + /// The dependent projects. + /// public List DependentProjects { get; private set; } + + /// + /// Gets the name. + /// + /// + /// The name. + /// public string Name { get; private set; } + + /// + /// Gets the project file path. + /// + /// + /// The project file path. + /// public string ProjectFilePath { get; private set; } + /// + /// Gets the commit count since version change. + /// + /// + /// The commit count since version change. + /// public int CommitCountSinceVersionChange { get; private set; } = 0; + + /// + /// Gets the full project file path. + /// + /// + /// The full project file path. + /// public string FullProjectFilePath { get; private set; } + + /// + /// Gets the final version number. + /// + /// + /// The final version number. + /// public string FinalVersionNumber { get; private set; } - public SourceProject(Project project, string root) + /// + /// Populates the dependencies. + /// + /// The projects. + public void PopulateDependencies(IEnumerable projects) { - this.Name = project.Name; - this.ProjectDirectory = project.ProjectDirectory.Substring(root.Length); - this.ProjectFilePath = project.ProjectFilePath.Substring(root.Length); - this.FullProjectFilePath = project.ProjectFilePath; - this.Version = project.Version; - this.dependencies = project.Dependencies.Select(x => x.Name); - this.FinalVersionNumber = Version.ToFullString(); + this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.Name)).ToList(); } - public void PopulateDependencies(IEnumerable projects) + /// + /// Calculates the version. + /// + /// The repo. + /// The branch. + internal void CalculateVersion(Repository repo, string branch) { - DependentProjects = projects.Where(x => dependencies.Contains(x.Name)).ToList(); - + foreach (var c in repo.Commits) + { + if (!this.ApplyCommit(c, repo)) + { + // we have finished lets populate the final version number + this.FinalVersionNumber = this.CalculateVersionNumber(branch); + + return; + } + } } private bool MatchPath(string path) { - if(path.StartsWith(this.ProjectDirectory, StringComparison.OrdinalIgnoreCase)) + if (path.StartsWith(this.ProjectDirectory, StringComparison.OrdinalIgnoreCase)) { return true; } - if (DependentProjects.Any()) + if (this.DependentProjects.Any()) { - return DependentProjects.Any(x => x.MatchPath(path)); + return this.DependentProjects.Any(x => x.MatchPath(path)); } + return false; } private bool ApplyCommitInternal(Commit commit, TreeChanges changes, Repository repo) { - CommitCountSinceVersionChange++; + this.CommitCountSinceVersionChange++; - //return false if this is a version number root + // return false if this is a version number root var projectFileChange = changes.Where(x => x.Path?.Equals(this.ProjectFilePath, StringComparison.OrdinalIgnoreCase) == true).FirstOrDefault(); - if(projectFileChange != null) + if (projectFileChange != null) { - if(projectFileChange.Status == ChangeKind.Added) + if (projectFileChange.Status == ChangeKind.Added) { // the version must have been set here return false; @@ -241,9 +336,9 @@ namespace ConsoleApplication using (var s = blob.GetContentStream()) { var project = new ProjectReader().ReadProject(s, this.Name, this.FullProjectFilePath, null); - if(project.Version != this.Version) + if (project.Version != this.Version) { - //version changed + // version changed return false; } } @@ -256,42 +351,27 @@ namespace ConsoleApplication return true; } - internal void CalculateVersion(Repository repo, string branch) - { - foreach(var c in repo.Commits) - { - if(!ApplyCommit(c, repo)) - { - - //we have finished lets populate the final version number - this.FinalVersionNumber = CalculateVersionNumber(branch); - - return; - } - } - } - private bool ApplyCommit(Commit commit, Repository repo) { foreach (var parent in commit.Parents) { var changes = repo.Diff.Compare(parent.Tree, commit.Tree); - + foreach (TreeEntryChanges change in changes) { if (!string.IsNullOrWhiteSpace(change.OldPath)) { - if (MatchPath(change.OldPath)) + if (this.MatchPath(change.OldPath)) { - return ApplyCommitInternal(commit, changes, repo); + return this.ApplyCommitInternal(commit, changes, repo); } } if (!string.IsNullOrWhiteSpace(change.Path)) { - if (MatchPath(change.Path)) + if (this.MatchPath(change.Path)) { - return ApplyCommitInternal(commit, changes, repo); + return this.ApplyCommitInternal(commit, changes, repo); } } } @@ -303,20 +383,21 @@ namespace ConsoleApplication private string CalculateVersionNumber(string branch) { var version = this.Version.ToFullString(); - - if (this.CommitCountSinceVersionChange == 1 && branch == "master") //master only + + // master only + if (this.CommitCountSinceVersionChange == 1 && branch == "master") { if (this.Version.IsPrerelease) { - //prerelease always needs the build counter just not on a branch name + // prerelease always needs the build counter just not on a branch name return $"{version}-{this.CommitCountSinceVersionChange:00000}"; } - + // this is the full release happy path, first commit after changing the version number return version; } - var rootSpecialVersion = ""; + var rootSpecialVersion = string.Empty; if (this.Version.IsPrerelease) { @@ -331,10 +412,11 @@ namespace ConsoleApplication { if (!this.Version.IsPrerelease) { - branch = fallbackTag; - }else + branch = FallbackTag; + } + else { - branch = ""; + branch = string.Empty; } } @@ -342,6 +424,7 @@ namespace ConsoleApplication { rootSpecialVersion = "-" + rootSpecialVersion; } + if (branch.Length > 0) { branch = "-" + branch; @@ -350,12 +433,12 @@ namespace ConsoleApplication var maxLength = 20; // dotnet will fail to populate the package if the tag is > 20 maxLength -= rootSpecialVersion.Length; // this is a required tag maxLength -= 7; // for the counter and dashes - - if(branch.Length > maxLength) + + if (branch.Length > maxLength) { branch = branch.Substring(0, maxLength); } - + return $"{version}{rootSpecialVersion}{branch}-{this.CommitCountSinceVersionChange:00000}"; } } diff --git a/build/project.json b/build/project.json index 1075b8724..d62c456cb 100644 --- a/build/project.json +++ b/build/project.json @@ -2,11 +2,17 @@ "version": "1.0.0-*", "buildOptions": { "debugType": "portable", - "emitEntryPoint": true + "emitEntryPoint": true, + "xmlDoc": true, + "additionalArguments": [ "/additionalfile:../src/ImageSharp/stylecop.json", "/ruleset:../ImageSharp.ruleset" ] }, "dependencies": { "Microsoft.DotNet.ProjectModel": "1.0.0-rc3-003121", - "LibGit2Sharp": "0.23.0" + "LibGit2Sharp": "0.23.0", + "StyleCop.Analyzers": { + "version": "1.1.0-beta001", + "type": "build" + } }, "frameworks": { "net46": { diff --git a/src/ImageSharp.Drawing/project.json b/src/ImageSharp.Drawing/project.json index bcc435191..ece92f438 100644 --- a/src/ImageSharp.Drawing/project.json +++ b/src/ImageSharp.Drawing/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp.Formats.Bmp/project.json b/src/ImageSharp.Formats.Bmp/project.json index 9583f869b..4ed92c7e5 100644 --- a/src/ImageSharp.Formats.Bmp/project.json +++ b/src/ImageSharp.Formats.Bmp/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp.Formats.Bmp/stylecop.json b/src/ImageSharp.Formats.Bmp/stylecop.json deleted file mode 100644 index df8f120a5..000000000 --- a/src/ImageSharp.Formats.Bmp/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Formats.Gif/project.json b/src/ImageSharp.Formats.Gif/project.json index 4d99635f0..c0710a3e4 100644 --- a/src/ImageSharp.Formats.Gif/project.json +++ b/src/ImageSharp.Formats.Gif/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp.Formats.Gif/stylecop.json b/src/ImageSharp.Formats.Gif/stylecop.json deleted file mode 100644 index df8f120a5..000000000 --- a/src/ImageSharp.Formats.Gif/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Formats.Jpeg/project.json b/src/ImageSharp.Formats.Jpeg/project.json index bb2da4a2f..6366f507e 100644 --- a/src/ImageSharp.Formats.Jpeg/project.json +++ b/src/ImageSharp.Formats.Jpeg/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp.Formats.Jpeg/stylecop.json b/src/ImageSharp.Formats.Jpeg/stylecop.json deleted file mode 100644 index df8f120a5..000000000 --- a/src/ImageSharp.Formats.Jpeg/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Formats.Png/project.json b/src/ImageSharp.Formats.Png/project.json index 4ff5f3748..bce68ddca 100644 --- a/src/ImageSharp.Formats.Png/project.json +++ b/src/ImageSharp.Formats.Png/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp.Formats.Png/stylecop.json b/src/ImageSharp.Formats.Png/stylecop.json deleted file mode 100644 index df8f120a5..000000000 --- a/src/ImageSharp.Formats.Png/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Processing/project.json b/src/ImageSharp.Processing/project.json index 7a8349b4b..eb3ea59db 100644 --- a/src/ImageSharp.Processing/project.json +++ b/src/ImageSharp.Processing/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp.Processing/stylecop.json b/src/ImageSharp.Processing/stylecop.json deleted file mode 100644 index df8f120a5..000000000 --- a/src/ImageSharp.Processing/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 2596e71b0..daf68d81b 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -26,7 +26,7 @@ namespace ImageSharp /// /// An object that can be used to synchronize access to the . /// - private readonly object SyncRoot = new object(); + private readonly object syncRoot = new object(); /// /// The list of supported . @@ -76,7 +76,7 @@ namespace ImageSharp internal static Configuration CreateDefaultInstance() { Configuration config = new Configuration(); - + // lets try auto loading the known image formats config.TryAddImageFormat("ImageSharp.Formats.PngFormat, ImageSharp.Formats.Png"); config.TryAddImageFormat("ImageSharp.Formats.JpegFormat, ImageSharp.Formats.Jpeg"); @@ -117,7 +117,7 @@ namespace ImageSharp /// The image format. private void AddImageFormatLocked(IImageFormat format) { - lock (SyncRoot) + lock (this.syncRoot) { if (this.GuardDuplicate(format)) { diff --git a/src/ImageSharp/project.json b/src/ImageSharp/project.json index dcda4bac5..8ddaa8bcc 100644 --- a/src/ImageSharp/project.json +++ b/src/ImageSharp/project.json @@ -24,7 +24,7 @@ "buildOptions": { "allowUnsafe": true, "xmlDoc": true, - "additionalArguments": [ "/additionalfile:stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], "compile": [ "../Shared/*.cs" ] diff --git a/src/ImageSharp/stylecop.json b/src/ImageSharp/stylecop.json deleted file mode 100644 index df8f120a5..000000000 --- a/src/ImageSharp/stylecop.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "companyName": "James Jackson-South", - "copyrightText": "Copyright (c) James Jackson-South and contributors.\nLicensed under the Apache License, Version 2.0." - } - } -} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/stylecop.json b/src/Shared/stylecop.json similarity index 100% rename from src/ImageSharp.Drawing/stylecop.json rename to src/Shared/stylecop.json