From d92d4363dde94c33f4d31cf72656bb711eca4e2d Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sun, 11 Apr 2021 12:32:17 +0200 Subject: [PATCH] (GH-139) fixed detection of Recipe ProjectType --- src/Tasks.Tests/CalculateProjectTypeTests.cs | 17 ++++++- src/Tasks/CalculateProjectType.cs | 52 ++++++++++++-------- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/Tasks.Tests/CalculateProjectTypeTests.cs b/src/Tasks.Tests/CalculateProjectTypeTests.cs index b3822d8..427c879 100644 --- a/src/Tasks.Tests/CalculateProjectTypeTests.cs +++ b/src/Tasks.Tests/CalculateProjectTypeTests.cs @@ -88,7 +88,7 @@ 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.WithProjectNames("Cake.7zip","Cake.Buildsystems.Module","foo"); fixture.WithoutCakeReference(); // when @@ -97,5 +97,20 @@ public void Should_Return_Other_If_Cake_Is_Not_Referenced() // then fixture.Output.Should().BeEquivalentTo(ExpectedTypeOther); } + + [Fact] + public void Should_Return_Recipe_For_Recipes_Even_If_Cake_Is_Not_Referenced() + { + // given + var fixture = new CalculateProjectTypeFixture(); + fixture.WithProjectNames("Cake.Recipe"); + fixture.WithoutCakeReference(); + + // when + fixture.Execute(); + + // then + fixture.Output.Should().BeEquivalentTo(ExpectedTypeRecipe); + } } } diff --git a/src/Tasks/CalculateProjectType.cs b/src/Tasks/CalculateProjectType.cs index 37a63ea..9f78001 100644 --- a/src/Tasks/CalculateProjectType.cs +++ b/src/Tasks/CalculateProjectType.cs @@ -82,27 +82,6 @@ public override bool Execute() return true; } - 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(); - - if (!references.Any(x => requiredCakeReferences.Contains(x))) - { - Output = CakeProjectType.Other.ToString(); - Log.LogMessage( - LogLevel, - $"No reference to Cake found. Setting output to '{Output}'."); - return true; - } - var names = ProjectNames .Select(x => x.ToString()) .Where(x => !string.IsNullOrEmpty(x)) @@ -139,6 +118,37 @@ public override bool Execute() Log.LogMessage( LogLevel, $"The name '{match}' suggest a {Output} project. Setting output to '{Output}'."); + break; + } + + // Recipes are special, as they probably never have a reference to Cake.. + if (Output == CakeProjectType.Recipe.ToString()) + { + return true; + } + + 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(); + + if (!references.Any(x => requiredCakeReferences.Contains(x))) + { + Output = CakeProjectType.Other.ToString(); + Log.LogMessage( + LogLevel, + $"No reference to Cake found. Setting output to '{Output}'."); + } + + if (!string.IsNullOrEmpty(Output)) + { return true; }