From a65a115fd45330e71b57ff78136af680d06633d9 Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Fri, 9 Jan 2015 07:50:24 +0000 Subject: [PATCH] Throw error when user is using legacy configuration values --- GitVersion.sln.DotSettings | 1 + GitVersionCore.Tests/ConfigProviderTests.cs | 13 +++-- .../GitFlow/DevelopScenarios.cs | 7 +-- .../GitFlow/ReleaseBranchTests.cs | 4 +- .../GitHubFlow/ReleaseBranchTests.cs | 4 +- GitVersionCore/Configuration/Config.cs | 57 ++----------------- .../Configuration/ConfigurationProvider.cs | 7 +-- GitVersionCore/Configuration/LegacyConfig.cs | 18 ++++++ .../Configuration/LegacyConfigNotifier.cs | 33 +++++++++++ .../OldConfigurationException.cs | 19 +++++++ GitVersionCore/GitVersionCore.csproj | 3 + .../AssemblyInfoBuilder/UpdateAssemblyInfo.cs | 14 ----- GitVersionTask/GetVersion.cs | 14 ----- 13 files changed, 97 insertions(+), 97 deletions(-) create mode 100644 GitVersionCore/Configuration/LegacyConfig.cs create mode 100644 GitVersionCore/Configuration/LegacyConfigNotifier.cs create mode 100644 GitVersionCore/Configuration/OldConfigurationException.cs diff --git a/GitVersion.sln.DotSettings b/GitVersion.sln.DotSettings index 74fd05fb95..a084751574 100644 --- a/GitVersion.sln.DotSettings +++ b/GitVersion.sln.DotSettings @@ -54,6 +54,7 @@ ERROR WARNING ERROR + DO_NOT_SHOW ERROR ERROR ERROR diff --git a/GitVersionCore.Tests/ConfigProviderTests.cs b/GitVersionCore.Tests/ConfigProviderTests.cs index 9677f28a31..97b90c49b5 100644 --- a/GitVersionCore.Tests/ConfigProviderTests.cs +++ b/GitVersionCore.Tests/ConfigProviderTests.cs @@ -63,8 +63,8 @@ public void CanInheritVersioningMode() SetupConfigFileContent(text); var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); config.Branches["develop"].VersioningMode.ShouldBe(VersioningMode.ContinuousDeployment); - config.Release.VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery); - config.Develop.Tag.ShouldBe("unstable"); + config.Branches["develop"].Tag.ShouldBe("unstable"); + config.Branches["release[/-]"].VersioningMode.ShouldBe(VersioningMode.ContinuousDelivery); } [Test] @@ -76,10 +76,11 @@ public void CanReadOldDocument() release-branch-tag: rc "; SetupConfigFileContent(text); - var config = ConfigurationProvider.Provide(gitDirectory, fileSystem); - config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor); - config.Branches["develop"].Tag.ShouldBe("alpha"); - config.Branches["release[/-]"].Tag.ShouldBe("rc"); + var error = Should.Throw(() => ConfigurationProvider.Provide(gitDirectory, fileSystem)); + error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors: +assemblyVersioningScheme has been replaced by assembly-versioning-scheme +develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration +release-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration"); } [Test] diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs index 1c166561a3..debfe50352 100644 --- a/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs +++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/DevelopScenarios.cs @@ -62,10 +62,9 @@ public void CanHandleContinuousDelivery() [Test] public void CanClearDevelopTagViaConfig() { - using (var fixture = new EmptyRepositoryFixture(new Config - { - Develop = {Tag= ""} - })) + var config = new Config(); + config.Branches["develop"].Tag = ""; + using (var fixture = new EmptyRepositoryFixture(config)) { fixture.Repository.MakeATaggedCommit("1.0.0"); fixture.Repository.CreateBranch("develop").Checkout(); diff --git a/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs b/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs index 4d47306041..c10f9dc3a7 100644 --- a/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs +++ b/GitVersionCore.Tests/IntegrationTests/GitFlow/ReleaseBranchTests.cs @@ -23,7 +23,9 @@ public void CanTakeVersionFromReleaseBranch() [Test] public void CanTakeVersionFromReleaseBranchWithTagOverriden() { - using (var fixture = new EmptyRepositoryFixture(new Config { ReleaseBranchTag = "rc" })) + var config = new Config(); + config.Branches["release[/-]"].Tag = "rc"; + using (var fixture = new EmptyRepositoryFixture(config)) { fixture.Repository.MakeATaggedCommit("1.0.3"); fixture.Repository.CreateBranch("develop"); diff --git a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs index d6fe14854c..52b2f7896a 100644 --- a/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs +++ b/GitVersionCore.Tests/IntegrationTests/GitHubFlow/ReleaseBranchTests.cs @@ -22,7 +22,9 @@ public void CanTakeVersionFromReleaseBranch() [Test] public void CanTakeVersionFromReleaseBranchWithTagOverriden() { - using (var fixture = new EmptyRepositoryFixture(new Config { ReleaseBranchTag = "rc" })) + var config = new Config(); + config.Branches["release[/-]"].Tag = "rc"; + using (var fixture = new EmptyRepositoryFixture(config)) { fixture.Repository.MakeATaggedCommit("1.0.3"); fixture.Repository.MakeCommits(5); diff --git a/GitVersionCore/Configuration/Config.cs b/GitVersionCore/Configuration/Config.cs index a3cc136c48..84fb23ee74 100644 --- a/GitVersionCore/Configuration/Config.cs +++ b/GitVersionCore/Configuration/Config.cs @@ -1,9 +1,7 @@ namespace GitVersion { - using System; using System.Collections.Generic; using System.Linq; - using YamlDotNet.Serialization; public class Config @@ -16,44 +14,19 @@ public Config() { AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatch; TagPrefix = "[vV]"; + VersioningMode = VersioningMode.ContinuousDelivery; Branches["release[/-]"] = new BranchConfig { Tag = "beta" }; Branches["hotfix[/-]"] = new BranchConfig { Tag = "beta" }; - Branches["develop"] = new BranchConfig { Tag = "unstable" }; - VersioningMode = VersioningMode.ContinuousDelivery; - Develop.VersioningMode = VersioningMode.ContinuousDeployment; + Branches["develop"] = new BranchConfig + { + Tag = "unstable", + VersioningMode = VersioningMode.ContinuousDeployment + }; } [YamlAlias("assembly-versioning-scheme")] public AssemblyVersioningScheme AssemblyVersioningScheme { get; set; } - [YamlAlias("develop-branch-tag")] - [Obsolete] - public string DevelopBranchTag - { - set - { - Develop.Tag = value; - } - get - { - return Develop.Tag; - } - } - - [YamlAlias("release-branch-tag")] - [Obsolete] - public string ReleaseBranchTag - { - set - { - Release.Tag = value; - } - get - { - return Release.Tag; - } - } - [YamlAlias("mode")] public VersioningMode VersioningMode { @@ -97,23 +70,5 @@ private T MergeObjects(T target, T source) [YamlAlias("next-version")] public string NextVersion { get; set; } - - [Obsolete] - public BranchConfig Develop - { - get - { - return Branches["develop"]; - } - } - - [Obsolete] - public BranchConfig Release - { - get - { - return Branches["release[/-]"]; - } - } } } \ No newline at end of file diff --git a/GitVersionCore/Configuration/ConfigurationProvider.cs b/GitVersionCore/Configuration/ConfigurationProvider.cs index ca9bb7218d..8a164b8ff6 100644 --- a/GitVersionCore/Configuration/ConfigurationProvider.cs +++ b/GitVersionCore/Configuration/ConfigurationProvider.cs @@ -15,12 +15,7 @@ public static Config Provide(string gitDirectory, IFileSystem fileSystem) if (fileSystem.Exists(configFilePath)) { var readAllText = fileSystem.ReadAllText(configFilePath); - if (oldAssemblyVersioningScheme.IsMatch(readAllText)) - { - readAllText = oldAssemblyVersioningScheme.Replace(readAllText, "assembly-versioning-scheme"); - fileSystem.WriteAllText(configFilePath, readAllText); - Logger.WriteWarning("Found legacy configuration value 'assemblyVersioningScheme', replaced with 'assembly-versioning-scheme"); - } + LegacyConfigNotifier.Notify(new StringReader(readAllText)); return ConfigReader.Read(new StringReader(readAllText)); } diff --git a/GitVersionCore/Configuration/LegacyConfig.cs b/GitVersionCore/Configuration/LegacyConfig.cs new file mode 100644 index 0000000000..0152428458 --- /dev/null +++ b/GitVersionCore/Configuration/LegacyConfig.cs @@ -0,0 +1,18 @@ +namespace GitVersion +{ + using YamlDotNet.Serialization; + + /// + /// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration + /// + public class LegacyConfig + { + public string assemblyVersioningScheme { get; set; } + + [YamlAlias("develop-branch-tag")] + public string DevelopBranchTag { get; set; } + + [YamlAlias("release-branch-tag")] + public string ReleaseBranchTag { get; set; } + } +} \ No newline at end of file diff --git a/GitVersionCore/Configuration/LegacyConfigNotifier.cs b/GitVersionCore/Configuration/LegacyConfigNotifier.cs new file mode 100644 index 0000000000..7dba3c5624 --- /dev/null +++ b/GitVersionCore/Configuration/LegacyConfigNotifier.cs @@ -0,0 +1,33 @@ +namespace GitVersion +{ + using System.Collections.Generic; + using System.IO; + using System.Linq; + using YamlDotNet.Serialization; + using YamlDotNet.Serialization.NamingConventions; + + public class LegacyConfigNotifier + { + public static void Notify(StringReader reader) + { + var deserializer = new Deserializer(null, new NullNamingConvention(), ignoreUnmatched: true); + var legacyConfig = deserializer.Deserialize(reader); + if (legacyConfig == null) + return; + + var issues = new List(); + + if (legacyConfig.assemblyVersioningScheme != null) + issues.Add("assemblyVersioningScheme has been replaced by assembly-versioning-scheme"); + + if (legacyConfig.DevelopBranchTag != null) + issues.Add("develop-branch-tag has been replaced by branch specific configuration. See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration"); + + if (legacyConfig.ReleaseBranchTag != null) + issues.Add("release-branch-tag has been replaced by branch specific configuration. See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration"); + + if (issues.Any()) + throw new OldConfigurationException("GitVersionConfig.yaml contains old configuration, please fix the following errors:\r\n" + string.Join("\r\n", issues)); + } + } +} \ No newline at end of file diff --git a/GitVersionCore/Configuration/OldConfigurationException.cs b/GitVersionCore/Configuration/OldConfigurationException.cs new file mode 100644 index 0000000000..08603b4daf --- /dev/null +++ b/GitVersionCore/Configuration/OldConfigurationException.cs @@ -0,0 +1,19 @@ +namespace GitVersion +{ + using System; + using System.Runtime.Serialization; + + [Serializable] + public class OldConfigurationException : Exception + { + public OldConfigurationException(string message) : base(message) + { + } + + protected OldConfigurationException( + SerializationInfo info, + StreamingContext context) : base(info, context) + { + } + } +} \ No newline at end of file diff --git a/GitVersionCore/GitVersionCore.csproj b/GitVersionCore/GitVersionCore.csproj index 844bc72d74..f93b38be90 100644 --- a/GitVersionCore/GitVersionCore.csproj +++ b/GitVersionCore/GitVersionCore.csproj @@ -74,6 +74,9 @@ + + + diff --git a/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs b/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs index 14ed69be2f..1b567b89b8 100644 --- a/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs +++ b/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs @@ -12,10 +12,6 @@ public class UpdateAssemblyInfo : Task { public string AssemblyVersioningScheme { get; set; } - public string DevelopBranchTag { get; set; } - - public string ReleaseBranchTag { get; set; } - public string TagPrefix { get; set; } public string NextVersion { get; set; } @@ -101,16 +97,6 @@ public void InnerExecute() // TODO This should be covered by tests // TODO would be good to not have to duplicate this in both msbuild tasks // Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag - if (DevelopBranchTag != null) - { - configuration.DevelopBranchTag = DevelopBranchTag; - } - - if (ReleaseBranchTag != null) - { - configuration.ReleaseBranchTag = ReleaseBranchTag; - } - if (TagPrefix != null) { configuration.TagPrefix = TagPrefix; diff --git a/GitVersionTask/GetVersion.cs b/GitVersionTask/GetVersion.cs index 5e5d44f866..7f256dcbc4 100644 --- a/GitVersionTask/GetVersion.cs +++ b/GitVersionTask/GetVersion.cs @@ -75,10 +75,6 @@ public class GetVersion : Task [Output] public string NuGetVersion { get; set; } - public string DevelopBranchTag { get; set; } - - public string ReleaseBranchTag { get; set; } - public string TagPrefix { get; set; } public string NextVersion { get; set; } @@ -104,16 +100,6 @@ public override bool Execute() // TODO This should be covered by tests // Null is intentional. Empty string means the user has set the value to an empty string and wants to clear the tag - if (DevelopBranchTag != null) - { - configuration.DevelopBranchTag = DevelopBranchTag; - } - - if (ReleaseBranchTag != null) - { - configuration.ReleaseBranchTag = ReleaseBranchTag; - } - if (TagPrefix != null) { configuration.TagPrefix = TagPrefix;