Skip to content

Commit

Permalink
Merge pull request #125 from nils-a/feature/GH-116
Browse files Browse the repository at this point in the history
(GH-116) updated the calculation for TFM
  • Loading branch information
nils-a authored Mar 16, 2021
2 parents 0d5f70c + 505ae01 commit d597e00
Show file tree
Hide file tree
Showing 24 changed files with 272 additions and 71 deletions.
2 changes: 2 additions & 0 deletions docs/input/guidelines/RecommendedCakeVersion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/input/guidelines/RecommendedReferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/input/guidelines/RecommendedTags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/input/guidelines/TargetFramework.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 13 additions & 4 deletions docs/input/settings/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<PropertyGroup>
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Guidelines/build/CakeContrib.Guidelines.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
<ItemGroup>
<ProjectNames Include="$(AssemblyName)" />
<ProjectNames Include="$(PackageId)" />
<CakeRequiredReference Include="cake.core" />
<CakeRequiredReference Include="cake.common" />
</ItemGroup>

<CalculateProjectType
ProjectType="$(CakeContribGuidelinesProjectType)"
ProjectNames="@(ProjectNames)">
ProjectNames="@(ProjectNames)"
References="@(PackageReference)"
CakeRequiredReference="@(CakeRequiredReference)">
<Output PropertyName="TempCakeContribGuidelinesProjectType" TaskParameter="Output"/>
</CalculateProjectType>
<CreateProperty
Expand Down
6 changes: 4 additions & 2 deletions src/Guidelines/build/RecommendedCakeVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

<Target Name="_checkRecommendedCakeVersion"
AfterTargets="BeforeBuild"
BeforeTargets="CoreBuild">
BeforeTargets="CoreBuild"
DependsOnTargets="EnsureProjectTypeIsSet">
<ItemGroup>
<CakeReferenceToCheck Include="cake.core" />
<CakeReferenceToCheck Include="cake.common" />
Expand All @@ -22,6 +23,7 @@
RecommendedVersion="$(RecommendedCakeVersion)"
References="@(PackageReference)"
Omitted="@(CakeContribGuidelinesOmitRecommendedCakeVersion)"
ReferencesToCheck="@(CakeReferenceToCheck)"/>
ReferencesToCheck="@(CakeReferenceToCheck)"
ProjectType="$(CakeContribGuidelinesProjectType)"/>
</Target>
</Project>
15 changes: 11 additions & 4 deletions src/Tasks.IntegrationTests/E2eTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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");

Expand All @@ -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");

Expand All @@ -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(@"
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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(@"
<ItemGroup>
Expand Down
45 changes: 43 additions & 2 deletions src/Tasks.IntegrationTests/Fixtures/E2eTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> customContent = new List<string>();
private string targetFrameworks = "netstandard2.0;net461";
private string targetFrameworks = "netstandard2.0;net461;net5.0";
private readonly List<string> references = new List<string>();
private string tags = "cake, cake-build, build, script, addin, cake-addin, module, cake-module, recipe, cake-recipe";

Expand All @@ -45,6 +47,7 @@ private string WriteProject()
<Import Project=""{0}"" />
<PropertyGroup>
<AssemblyName>{6}</AssemblyName>
<TargetFrameworks>{5}</TargetFrameworks>
{2}
</PropertyGroup>
Expand Down Expand Up @@ -97,6 +100,11 @@ private string WriteProject()
<PrivateAssets>all</PrivateAssets>
</PackageReference>");
}

if (hasDefaultCakeReference)
{
WithPackageReference("cake.core","1.0.0", "all");
}
items.AddRange(references);

File.WriteAllText(csproj, string.Format(template,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<string> WarningLines { get; internal set; }
Expand All @@ -300,5 +336,10 @@ public bool IsErrorExitCode
get { return ExitCode != 0; }
}
}

public void WithoutDefaultCakeReference()
{
hasDefaultCakeReference = false;
}
}
}
36 changes: 26 additions & 10 deletions src/Tasks.Tests/CalculateProjectTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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);
}
}
}
Loading

0 comments on commit d597e00

Please sign in to comment.