diff --git a/docs/input/guidelines/RecommendedCakeVersion.md b/docs/input/guidelines/RecommendedCakeVersion.md index b0a2161..cfaf240 100644 --- a/docs/input/guidelines/RecommendedCakeVersion.md +++ b/docs/input/guidelines/RecommendedCakeVersion.md @@ -23,6 +23,8 @@ This is currently version 1.0.0. * [CCG0009](../rules/ccg0009) +This rule is only applied for [project types](../settings#projecttype) `addin` and `module`. + ## Usage Using this package automatically enables this guideline. diff --git a/docs/input/guidelines/RecommendedReferences.md b/docs/input/guidelines/RecommendedReferences.md index 4f76f07..b140fb7 100644 --- a/docs/input/guidelines/RecommendedReferences.md +++ b/docs/input/guidelines/RecommendedReferences.md @@ -28,7 +28,7 @@ Example-Files can be found at: * [CCG0005](../rules/ccg0005) * [CCG0006](../rules/ccg0006) -These rules are not applied for package type recipe. +These rules are only applied for [project types](../settings#projecttype) `addin` and `module`. ## Usage diff --git a/docs/input/guidelines/RecommendedTags.md b/docs/input/guidelines/RecommendedTags.md index 8d8b928..89f111d 100644 --- a/docs/input/guidelines/RecommendedTags.md +++ b/docs/input/guidelines/RecommendedTags.md @@ -48,6 +48,8 @@ addin further. (E.g. add `twitter` tag to the `Cake.Twitter` addin.) * [CCG0008](../rules/ccg0008) +These rules are only applied for [project types](../settings#projecttype) `addin`, `module` and `recipe`. + ## Usage Using this package automatically enables this guideline. diff --git a/docs/input/guidelines/TargetFramework.md b/docs/input/guidelines/TargetFramework.md index 4524faf..76ab7c5 100644 --- a/docs/input/guidelines/TargetFramework.md +++ b/docs/input/guidelines/TargetFramework.md @@ -45,6 +45,8 @@ For package type recipe no framework reference is required or suggested. * [CCG0007](../rules/ccg0007) +These rules are only applied for [project types](../settings#projecttype) `addin` and `module`. + ## Usage Using this package automatically enables this guideline. diff --git a/docs/input/settings/index.md b/docs/input/settings/index.md index 846f4f2..f169fe1 100644 --- a/docs/input/settings/index.md +++ b/docs/input/settings/index.md @@ -25,9 +25,18 @@ NoSidebar: true ## General ### ProjectType -A project can be one of two types: `addin` or `module`. Some rules have different behavior for -different project types. -The project type is automatically detected. To override auto-detection use the following: +A project can be one of different types: `addin`, `module`, `recipe` or `other`. +Some rules have different behavior for different project types. +The project type is automatically detected but can be overridden. + +The rules on how project type detection is done are as follows (first matching rule applies): +* Projects not referencing `Cake.Core` or `Cake.Common` are always of type `other` +* Project names (AssemblyName, PackageId) starting with `Cake.` and ending in `.Module` will be treated as `module` +* Project names (AssemblyName, PackageId) starting with `Cake.` and ending in `.Recipe` will be treated as `recipe` +* Project names (AssemblyName, PackageId) starting with `Cake.` will be treated as `addin` +* All other projects are of type `other` + +To override auto-detection use the following: ```xml @@ -37,7 +46,7 @@ The project type is automatically detected. To override auto-detection use the f :::{.alert .alert-info} Though you can technically set `CakeContribGuidelinesProjectType` to anything you want, setting it to -different values than `addin` or `module` might yield unexpected results. +different values than `addin`, `module` or `recipe` might yield unexpected results. ::: ## Icons diff --git a/src/Guidelines/build/CakeContrib.Guidelines.targets b/src/Guidelines/build/CakeContrib.Guidelines.targets index c0c636c..dd211ee 100644 --- a/src/Guidelines/build/CakeContrib.Guidelines.targets +++ b/src/Guidelines/build/CakeContrib.Guidelines.targets @@ -22,11 +22,15 @@ + + + ProjectNames="@(ProjectNames)" + References="@(PackageReference)" + CakeRequiredReference="@(CakeRequiredReference)"> + BeforeTargets="CoreBuild" + DependsOnTargets="EnsureProjectTypeIsSet"> @@ -22,6 +23,7 @@ RecommendedVersion="$(RecommendedCakeVersion)" References="@(PackageReference)" Omitted="@(CakeContribGuidelinesOmitRecommendedCakeVersion)" - ReferencesToCheck="@(CakeReferenceToCheck)"/> + ReferencesToCheck="@(CakeReferenceToCheck)" + ProjectType="$(CakeContribGuidelinesProjectType)"/> diff --git a/src/Tasks.IntegrationTests/E2eTests.cs b/src/Tasks.IntegrationTests/E2eTests.cs index b582b64..769d235 100644 --- a/src/Tasks.IntegrationTests/E2eTests.cs +++ b/src/Tasks.IntegrationTests/E2eTests.cs @@ -120,6 +120,7 @@ public void PackageIcon_Tag_with_wrong_extension_and_custom_Icon_include_results public void Referencing_Cake_Core_with_PrivateAssets_results_in_no_error() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("Cake.Core", "0.38.5", "all"); // when @@ -134,6 +135,7 @@ public void Referencing_Cake_Core_with_PrivateAssets_results_in_no_error() public void Referencing_Cake_Core_without_PrivateAssets_results_in_CCG0004_error() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("Cake.Core", "0.38.5"); // when @@ -240,6 +242,7 @@ public void Missing_Suggested_Target_results_in_CCG0007_warning() public void Missing_Suggested_Target_net5_for_Cake_v100_results_in_CCG0007_warning() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("Cake.Core", "1.0.0", "all"); fixture.WithTargetFrameworks("netstandard2.0;net461"); @@ -256,6 +259,7 @@ public void Missing_Suggested_Target_net5_for_Cake_v100_results_in_CCG0007_warni public void Referencing_CakeCore_With_all_targets_raises_no_warning() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("Cake.Core", "1.0.0", "all"); fixture.WithTargetFrameworks("netstandard2.0;net461;net5.0"); @@ -271,6 +275,7 @@ public void Referencing_CakeCore_With_all_targets_raises_no_warning() public void Referencing_CakeCore_With_NetStandard_raises_no_warning_If_PackageType_Is_Module() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("Cake.Core", "1.0.0", "all"); fixture.WithTargetFrameworks("netstandard2.0"); fixture.WithCustomContent(@" @@ -307,7 +312,7 @@ public void ProjectType_Default_Is_Addin() var output = result.WarningLines .First(x => x.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase) > -1); output = output.Substring(output.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase)+11); - output.Should().Be("Addin"); + output.Should().BeEquivalentTo("Addin"); } [Fact] @@ -363,7 +368,7 @@ public void ProjectType_When_Assembly_Is_Module_Is_Module() var output = result.WarningLines .First(x => x.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase) > -1); output = output.Substring(output.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase)+11); - output.Should().Be("Module"); + output.Should().BeEquivalentTo("Module"); } [Fact] @@ -391,7 +396,7 @@ public void ProjectType_When_PackageId_Is_Module_Is_Module() var output = result.WarningLines .First(x => x.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase) > -1); output = output.Substring(output.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase)+11); - output.Should().Be("Module"); + output.Should().BeEquivalentTo("Module"); } [Fact] @@ -419,7 +424,7 @@ public void ProjectType_When_Assembly_Is_Not_Module_Is_Addin() var output = result.WarningLines .First(x => x.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase) > -1); output = output.Substring(output.IndexOf("!FOR-TEST!:", StringComparison.OrdinalIgnoreCase)+11); - output.Should().Be("Addin"); + output.Should().BeEquivalentTo("Addin"); } [Fact] @@ -576,6 +581,7 @@ public void Missing_Recipe_Tag_Should_Raise_CCG0008_For_Recipes() public void Incorrect_Cake_Reference_Should_Raise_CCG0009() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("cake.core", "0.38.5", "All"); // when @@ -593,6 +599,7 @@ public void Incorrect_Cake_Reference_Should_Raise_CCG0009() public void Incorrect_But_Omitted_Cake_Reference_Should_Not_Raise_CCG0009() { // given + fixture.WithoutDefaultCakeReference(); fixture.WithPackageReference("cake.core", "0.38.5", "All"); fixture.WithCustomContent(@" diff --git a/src/Tasks.IntegrationTests/Fixtures/E2eTestFixture.cs b/src/Tasks.IntegrationTests/Fixtures/E2eTestFixture.cs index f752267..3799c49 100644 --- a/src/Tasks.IntegrationTests/Fixtures/E2eTestFixture.cs +++ b/src/Tasks.IntegrationTests/Fixtures/E2eTestFixture.cs @@ -16,11 +16,13 @@ public class E2eTestFixture : IDisposable private string packageIcon = "$(CakeContribGuidelinesIconDestinationLocation)"; private string packageIconUrl = "https://some/icon/somewhere.png"; + private string assemblyName = "Cake.Test"; private bool hasStylecopJson = true; private bool hasStylecopReference = true; private bool hasEditorConfig = true; + private bool hasDefaultCakeReference = true; private readonly List customContent = new List(); - private string targetFrameworks = "netstandard2.0;net461"; + private string targetFrameworks = "netstandard2.0;net461;net5.0"; private readonly List references = new List(); private string tags = "cake, cake-build, build, script, addin, cake-addin, module, cake-module, recipe, cake-recipe"; @@ -45,6 +47,7 @@ private string WriteProject() + {6} {5} {2} @@ -97,6 +100,11 @@ private string WriteProject() all "); } + + if (hasDefaultCakeReference) + { + WithPackageReference("cake.core","1.0.0", "all"); + } items.AddRange(references); File.WriteAllText(csproj, string.Format(template, @@ -105,7 +113,8 @@ private string WriteProject() string.Join(Environment.NewLine, properties), string.Join(Environment.NewLine, items), string.Join(Environment.NewLine, customContent), - targetFrameworks)); + targetFrameworks, + assemblyName)); return csproj; } @@ -285,9 +294,36 @@ private BuildRunResult BuildProject(string projectFile) public void Dispose() { + ShutdownDotnetBuild(tempFolder); Directory.Delete(tempFolder, true); } + private void ShutdownDotnetBuild(string dir) + { + var arg = "build-server shutdown"; + +#if !NETCORE + arg += " --msbuild"; +#endif + var psi = new ProcessStartInfo + { + UseShellExecute = false, + RedirectStandardError = false, + RedirectStandardOutput = false, + WindowStyle = ProcessWindowStyle.Hidden, + CreateNoWindow = true, + ErrorDialog = false, + WorkingDirectory = dir, + FileName = "dotnet", + Arguments = arg + }; + + using (Process process = Process.Start(psi)) + { + process.WaitForExit(); + } + } + public class BuildRunResult { public List WarningLines { get; internal set; } @@ -300,5 +336,10 @@ public bool IsErrorExitCode get { return ExitCode != 0; } } } + + public void WithoutDefaultCakeReference() + { + hasDefaultCakeReference = false; + } } } diff --git a/src/Tasks.Tests/CalculateProjectTypeTests.cs b/src/Tasks.Tests/CalculateProjectTypeTests.cs index 15b17bf..b3822d8 100644 --- a/src/Tasks.Tests/CalculateProjectTypeTests.cs +++ b/src/Tasks.Tests/CalculateProjectTypeTests.cs @@ -8,9 +8,10 @@ namespace CakeContrib.Guidelines.Tasks.Tests { public class CalculateProjectTypeTests { - private const string ExpectedTypeAddin = "Addin"; - private const string ExpectedTypeModule = "Module"; - private const string ExpectedTypeRecipe = "Recipe"; + private const string ExpectedTypeOther = "other"; + private const string ExpectedTypeAddin = "addin"; + private const string ExpectedTypeModule = "module"; + private const string ExpectedTypeRecipe = "recipe"; [Fact] public void Should_Return_The_ProjectType_If_Set() @@ -24,11 +25,11 @@ public void Should_Return_The_ProjectType_If_Set() fixture.Execute(); // then - fixture.Output.Should().Be(existingType); + fixture.Output.Should().BeEquivalentTo(existingType); } [Fact] - public void Should_Return_Addin_If_Nothing_Is_Set() + public void Should_Return_Other_If_Nothing_Is_Set() { // given var fixture = new CalculateProjectTypeFixture(); @@ -37,11 +38,11 @@ public void Should_Return_Addin_If_Nothing_Is_Set() fixture.Execute(); // then - fixture.Output.Should().Be(ExpectedTypeAddin); + fixture.Output.Should().BeEquivalentTo(ExpectedTypeOther); } [Fact] - public void Should_Return_Addin_Names_Point_To_Addin() + public void Should_Return_Addin_If_Names_Point_To_Addin() { // given var fixture = new CalculateProjectTypeFixture(); @@ -51,7 +52,7 @@ public void Should_Return_Addin_Names_Point_To_Addin() fixture.Execute(); // then - fixture.Output.Should().Be(ExpectedTypeAddin); + fixture.Output.Should().BeEquivalentTo(ExpectedTypeAddin); } [Fact] @@ -65,7 +66,7 @@ public void Should_Return_Module_If_Names_Point_To_Module() fixture.Execute(); // then - fixture.Output.Should().Be(ExpectedTypeModule); + fixture.Output.Should().BeEquivalentTo(ExpectedTypeModule); } [Fact] @@ -79,7 +80,22 @@ public void Should_Return_Recipe_If_Names_Point_To_Recipe() fixture.Execute(); // then - fixture.Output.Should().Be(ExpectedTypeRecipe); + fixture.Output.Should().BeEquivalentTo(ExpectedTypeRecipe); + } + + [Fact] + public void Should_Return_Other_If_Cake_Is_Not_Referenced() + { + // given + var fixture = new CalculateProjectTypeFixture(); + fixture.WithProjectNames("Cake.7zip","Cake.Buildsystems.Module","Cake.Recipe","foo"); + fixture.WithoutCakeReference(); + + // when + fixture.Execute(); + + // then + fixture.Output.Should().BeEquivalentTo(ExpectedTypeOther); } } } diff --git a/src/Tasks.Tests/Fixtures/CalculateProjectTypeFixture.cs b/src/Tasks.Tests/Fixtures/CalculateProjectTypeFixture.cs index 7c17fcd..6115fd6 100644 --- a/src/Tasks.Tests/Fixtures/CalculateProjectTypeFixture.cs +++ b/src/Tasks.Tests/Fixtures/CalculateProjectTypeFixture.cs @@ -8,11 +8,13 @@ namespace CakeContrib.Guidelines.Tasks.Tests.Fixtures public class CalculateProjectTypeFixture : BaseBuildFixture { private readonly List projectNames; + private readonly List references; private string existingType; public CalculateProjectTypeFixture() { projectNames = new List(); + references = new List(new[]{ GetMockTaskItem("cake.core").Object }); } public string Output { get; private set; } @@ -21,6 +23,8 @@ public override bool Execute() { Task.ProjectType = existingType; Task.ProjectNames = projectNames.ToArray(); + Task.References = references.ToArray(); + Task.CakeRequiredReference = new[] { GetMockTaskItem("cake.core").Object }; var result = base.Execute(); Output = Task.Output; return result; @@ -35,5 +39,11 @@ public void WithProjectNames(params string[] names) { projectNames.AddRange(names.Select(n => GetMockTaskItem(n).Object)); } + + public void WithoutCakeReference() + { + references.Clear(); + } + } } diff --git a/src/Tasks.Tests/Fixtures/RecommendedCakeVersionFixture.cs b/src/Tasks.Tests/Fixtures/RecommendedCakeVersionFixture.cs index f8b71c7..a0b1c14 100644 --- a/src/Tasks.Tests/Fixtures/RecommendedCakeVersionFixture.cs +++ b/src/Tasks.Tests/Fixtures/RecommendedCakeVersionFixture.cs @@ -16,7 +16,7 @@ public RecommendedCakeVersionFixture() references = new List(); omitted = new List(); referencesToCheck = new List(); - Task.ProjectType = CalculateProjectType.TypeAddin; + Task.ProjectType = CakeProjectType.Addin.ToString(); } public override bool Execute() diff --git a/src/Tasks.Tests/Fixtures/RequiredFileEditorconfigFixture.cs b/src/Tasks.Tests/Fixtures/RequiredFileEditorconfigFixture.cs index 00878ea..b7f087c 100644 --- a/src/Tasks.Tests/Fixtures/RequiredFileEditorconfigFixture.cs +++ b/src/Tasks.Tests/Fixtures/RequiredFileEditorconfigFixture.cs @@ -18,6 +18,7 @@ public RequiredFileEditorconfigFixture() omittedFiles = new List(); fileSearcher = new Mock(); Task.FileSearcher = fileSearcher.Object; + Task.ProjectType = CakeProjectType.Addin.ToString(); } public void WithExistingEditorconfig() diff --git a/src/Tasks.Tests/Fixtures/RequiredFileStylecopJsonFixture.cs b/src/Tasks.Tests/Fixtures/RequiredFileStylecopJsonFixture.cs index ec2088d..b719cdb 100644 --- a/src/Tasks.Tests/Fixtures/RequiredFileStylecopJsonFixture.cs +++ b/src/Tasks.Tests/Fixtures/RequiredFileStylecopJsonFixture.cs @@ -11,6 +11,7 @@ public class RequiredFileStylecopJsonFixture : BaseBuildFixture(); omittedFiles = new List(); } diff --git a/src/Tasks.Tests/Fixtures/RequiredReferencesFixture.cs b/src/Tasks.Tests/Fixtures/RequiredReferencesFixture.cs index 0395c6e..5938945 100644 --- a/src/Tasks.Tests/Fixtures/RequiredReferencesFixture.cs +++ b/src/Tasks.Tests/Fixtures/RequiredReferencesFixture.cs @@ -18,6 +18,7 @@ public RequiredReferencesFixture() references = new List(); requiredReferences = new List(); omittedReferences = new List(); + Task.ProjectType = CakeProjectType.Addin.ToString(); } public override bool Execute() diff --git a/src/Tasks.Tests/Fixtures/TargetFrameworkVersionsFixture.cs b/src/Tasks.Tests/Fixtures/TargetFrameworkVersionsFixture.cs index 7bd18a5..08a1fc2 100644 --- a/src/Tasks.Tests/Fixtures/TargetFrameworkVersionsFixture.cs +++ b/src/Tasks.Tests/Fixtures/TargetFrameworkVersionsFixture.cs @@ -17,6 +17,7 @@ public class TargetFrameworkVersionsFixture : BaseBuildFixture(); omittedTargets = new List(); targetFrameworks = new List(); diff --git a/src/Tasks.Tests/TargetFrameworkVersionsTests.cs b/src/Tasks.Tests/TargetFrameworkVersionsTests.cs index e7b0f6f..54984ec 100644 --- a/src/Tasks.Tests/TargetFrameworkVersionsTests.cs +++ b/src/Tasks.Tests/TargetFrameworkVersionsTests.cs @@ -48,6 +48,7 @@ public void Should_Warn_If_SuggestedTargetFramework_Is_Not_Targeted() { // given var fixture = new TargetFrameworkVersionsFixture(); + fixture.WithCakeCoreReference(0, 38, 5); fixture.WithTargetFramework(NetStandard20); // when @@ -64,6 +65,7 @@ public void Should_Not_Warn_If_SuggestedTargetFramework_Is_Not_Targeted_But_Omit { // given var fixture = new TargetFrameworkVersionsFixture(); + fixture.WithCakeCoreReference(0, 38, 5); fixture.WithTargetFramework(NetStandard20); fixture.WithOmittedTargetFramework(Net461); @@ -80,6 +82,7 @@ public void Should_Not_Warn_If_Required_And_SuggestedTargetFramework_Is_Targeted { // given var fixture = new TargetFrameworkVersionsFixture(); + fixture.WithCakeCoreReference(0, 38, 5); fixture.WithTargetFrameworks(NetStandard20, Net461); // when @@ -97,7 +100,7 @@ public void Should_Warn_For_Broken_CakeCore_Reference() const string brokenVersion = "1.2.3.4.5.6.7.8.9"; var fixture = new TargetFrameworkVersionsFixture(); fixture.WithCakeCoreReference(brokenVersion); - fixture.WithTargetFrameworks(NetStandard20, Net461); + fixture.WithTargetFrameworks(NetStandard20, Net461, Net50); // when fixture.Execute(); @@ -114,6 +117,7 @@ public void Should_Not_Warn_If_Required_And_Alternative_SuggestedTargetFramework { // given var fixture = new TargetFrameworkVersionsFixture(); + fixture.WithCakeCoreReference(0, 38, 5); fixture.WithTargetFrameworks(NetStandard20, Net46); // when diff --git a/src/Tasks/CakeProjectType.cs b/src/Tasks/CakeProjectType.cs new file mode 100644 index 0000000..847f530 --- /dev/null +++ b/src/Tasks/CakeProjectType.cs @@ -0,0 +1,65 @@ +using System; +using System.Linq; + +namespace CakeContrib.Guidelines.Tasks +{ + /// + /// This is the outcome of the Task. + /// + public sealed class CakeProjectType + { + private readonly string id; + + private CakeProjectType(string id) + { + this.id = id; + } + + /// + /// Type: Addin. + /// + public static CakeProjectType Addin { get; } = new CakeProjectType("addin"); + + /// + /// Type: Module. + /// + public static CakeProjectType Module { get; } = new CakeProjectType("module"); + + /// + /// Type: Recipe. + /// + public static CakeProjectType Recipe { get; } = new CakeProjectType("recipe"); + + /// + /// Type: Other + /// + public static CakeProjectType Other { get; } = new CakeProjectType("other"); + + /// + /// Checks whether a calculated type is of this type. + /// + /// The msbuild calculated Type. + /// true, if the calculated type is equal to this type. + public bool Is(string calculatedType) + { + return id.Equals(calculatedType, StringComparison.OrdinalIgnoreCase); + } + + /// + /// Checks whether a calculated type is one of the given types. + /// + /// the msbuild calculated type. + /// Types to check. + /// true, if the calculated type one of the given types. + public static bool IsOneOf(string calculatedType, params CakeProjectType[] types) + { + return types.Any(x => x.Is(calculatedType)); + } + + /// + public override string ToString() + { + return id; + } + } +} diff --git a/src/Tasks/CalculateProjectType.cs b/src/Tasks/CalculateProjectType.cs index 024a646..37a63ea 100644 --- a/src/Tasks/CalculateProjectType.cs +++ b/src/Tasks/CalculateProjectType.cs @@ -12,15 +12,18 @@ namespace CakeContrib.Guidelines.Tasks /// /// - /// + /// unknown /// /// /// /// + /// + /// /// /// + /// ProjectNames="@(ProjectNames)" + /// References="@(PackageReference)"> /// /// /// @@ -29,21 +32,6 @@ namespace CakeContrib.Guidelines.Tasks /// ]]> public class CalculateProjectType : Task { - /// - /// Type: Addin. - /// - public const string TypeAddin = "Addin"; - - /// - /// Type: Module. - /// - public const string TypeModule = "Module"; - - /// - /// Type: Recipe. - /// - public const string TypeRecipe = "Recipe"; - #if DEBUG private const MessageImportance LogLevel = MessageImportance.High; #else @@ -64,6 +52,18 @@ public class CalculateProjectType : Task [Required] public ITaskItem[] ProjectNames { get; set; } + /// + /// Gets or sets the References. + /// + [Required] + public ITaskItem[] References { get; set; } + + /// + /// Gets or sets the CakeRequiredReference. + /// + [Required] + public ITaskItem[] CakeRequiredReference { get; set; } + /// /// Gets the output of this Task. /// @@ -82,37 +82,70 @@ public override bool Execute() return true; } - var names = ProjectNames + var requiredCakeReferences = CakeRequiredReference + .Select(x => x.ToString()) + .Where(x => !string.IsNullOrEmpty(x)) + .Select(x => x.ToLowerInvariant()) + .ToList(); + + var references = References .Select(x => x.ToString()) .Where(x => !string.IsNullOrEmpty(x)) + .Select(x => x.ToLowerInvariant()) .ToList(); - var match = names - .FirstOrDefault(x => x.EndsWith(".module", StringComparison.InvariantCultureIgnoreCase)); - if (match != null) + if (!references.Any(x => requiredCakeReferences.Contains(x))) { + Output = CakeProjectType.Other.ToString(); Log.LogMessage( LogLevel, - $"The name '{match}' suggest a module project. Setting output to '{TypeModule}'."); - Output = TypeModule; + $"No reference to Cake found. Setting output to '{Output}'."); return true; } - match = names - .FirstOrDefault(x => x.EndsWith(".recipe", StringComparison.InvariantCultureIgnoreCase)); - if (match != null) + var names = ProjectNames + .Select(x => x.ToString()) + .Where(x => !string.IsNullOrEmpty(x)) + .ToList(); + + var thisCouldHaveBeenAConfiguration = new[] { + new Tuple, string>( + x => + x.StartsWith("cake.", StringComparison.InvariantCultureIgnoreCase) && + x.EndsWith(".module", StringComparison.InvariantCultureIgnoreCase), + CakeProjectType.Module.ToString()), + new Tuple, string>( + x => + x.StartsWith("cake.", StringComparison.InvariantCultureIgnoreCase) && + x.EndsWith(".recipe", StringComparison.InvariantCultureIgnoreCase), + CakeProjectType.Recipe.ToString()), + new Tuple, string>( + x => + x.StartsWith("cake.", StringComparison.InvariantCultureIgnoreCase), + CakeProjectType.Addin.ToString()), + }; + + foreach (var tuple in thisCouldHaveBeenAConfiguration) + { + var match = names + .FirstOrDefault(x => tuple.Item1(x)); + if (match == null) + { + continue; + } + + Output = tuple.Item2; Log.LogMessage( LogLevel, - $"The name '{match}' suggest a recipe project. Setting output to '{TypeRecipe}'."); - Output = TypeRecipe; + $"The name '{match}' suggest a {Output} project. Setting output to '{Output}'."); return true; } + Output = CakeProjectType.Other.ToString(); Log.LogMessage( LogLevel, - $"Setting output to the default of '{TypeAddin}'."); - Output = TypeAddin; + $"Setting output to the default of '{Output}'."); return true; } } diff --git a/src/Tasks/RecommendedCakeVersion.cs b/src/Tasks/RecommendedCakeVersion.cs index 6df0ff9..907fdf7 100644 --- a/src/Tasks/RecommendedCakeVersion.cs +++ b/src/Tasks/RecommendedCakeVersion.cs @@ -57,10 +57,8 @@ public class RecommendedCakeVersion : Task /// public override bool Execute() { - if (!CalculateProjectType.TypeModule.Equals(ProjectType, StringComparison.OrdinalIgnoreCase) - && !CalculateProjectType.TypeAddin.Equals(ProjectType, StringComparison.OrdinalIgnoreCase)) + if (!CakeProjectType.IsOneOf(ProjectType, CakeProjectType.Addin, CakeProjectType.Module)) { - // only for addins & modules! Log.LogMessage( LogLevel, $"No Cake reference required for {ProjectType} projects."); diff --git a/src/Tasks/RequiredFileEditorconfig.cs b/src/Tasks/RequiredFileEditorconfig.cs index ac76411..87899ec 100644 --- a/src/Tasks/RequiredFileEditorconfig.cs +++ b/src/Tasks/RequiredFileEditorconfig.cs @@ -55,12 +55,11 @@ public RequiredFileEditorconfig() /// public override bool Execute() { - if (CalculateProjectType.TypeRecipe.Equals(ProjectType, StringComparison.OrdinalIgnoreCase)) + if (!CakeProjectType.IsOneOf(ProjectType, CakeProjectType.Addin, CakeProjectType.Module)) { - // not for recipes! Log.LogMessage( LogLevel, - "No .editorconfig required for recipe projects."); + $".editorconfig not required for {ProjectType} projects."); return true; } diff --git a/src/Tasks/RequiredFileStylecopJson.cs b/src/Tasks/RequiredFileStylecopJson.cs index d234b78..288c10b 100644 --- a/src/Tasks/RequiredFileStylecopJson.cs +++ b/src/Tasks/RequiredFileStylecopJson.cs @@ -49,12 +49,12 @@ public class RequiredFileStylecopJson : Task /// public override bool Execute() { - if (CalculateProjectType.TypeRecipe.Equals(ProjectType, StringComparison.OrdinalIgnoreCase)) + if (!CakeProjectType.IsOneOf(ProjectType, CakeProjectType.Addin, CakeProjectType.Module)) { // not for recipes! Log.LogMessage( LogLevel, - "No stylecop.json required for recipe projects."); + $"stylecop.json not required for {ProjectType} projects."); return true; } diff --git a/src/Tasks/RequiredReferences.cs b/src/Tasks/RequiredReferences.cs index 3f2b206..51c27b2 100644 --- a/src/Tasks/RequiredReferences.cs +++ b/src/Tasks/RequiredReferences.cs @@ -51,12 +51,12 @@ public class RequiredReferences : Task /// public override bool Execute() { - if (CalculateProjectType.TypeRecipe.Equals(ProjectType, StringComparison.OrdinalIgnoreCase)) + if (!CakeProjectType.IsOneOf(ProjectType, CakeProjectType.Addin, CakeProjectType.Module)) { // not for recipes! Log.LogMessage( LogLevel, - "No stylecop.json required for recipe projects."); + $"References are not required for {ProjectType} projects."); return true; } diff --git a/src/Tasks/TargetFrameworkVersions.cs b/src/Tasks/TargetFrameworkVersions.cs index 79071aa..bb98d43 100644 --- a/src/Tasks/TargetFrameworkVersions.cs +++ b/src/Tasks/TargetFrameworkVersions.cs @@ -33,7 +33,11 @@ public class TargetFrameworkVersions : Task { Name = "Default", RequiredTargets = new[] { TargetsDefinition.From(NetStandard20) }, - SuggestedTargets = new[] { TargetsDefinition.From(Net461, Net46) }, + SuggestedTargets = new[] + { + TargetsDefinition.From(Net461, Net46), + TargetsDefinition.From(Net50), + }, }; private static readonly Dictionary, TargetsDefinitions> SpecificTargets = @@ -109,12 +113,11 @@ public class TargetFrameworkVersions : Task /// public override bool Execute() { - if (CalculateProjectType.TypeRecipe.Equals(ProjectType, StringComparison.OrdinalIgnoreCase)) + if (!CakeProjectType.IsOneOf(ProjectType, CakeProjectType.Addin, CakeProjectType.Module)) { - // no required references for recipes! Log.LogMessage( LogLevel, - "No TargetFrameworks suggested for recipe projects."); + $"No TFM suggested for {ProjectType} projects."); return true; } @@ -146,7 +149,7 @@ public override bool Execute() { var differentiator = new Differentiator { - IsModuleProject = CalculateProjectType.TypeModule.Equals(ProjectType, StringComparison.OrdinalIgnoreCase), + IsModuleProject = CakeProjectType.Module.Is(ProjectType), Version = version, }; var match = targetsDefinition.Key(differentiator);