Skip to content

Commit

Permalink
Merge pull request #874 from gep13/issue-873
Browse files Browse the repository at this point in the history
(#873) Remove usage of DupFinder
  • Loading branch information
gep13 committed Dec 16, 2021
2 parents e2b0390 + 7447a40 commit 8904754
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 141 deletions.
37 changes: 0 additions & 37 deletions Source/Cake.Recipe/Content/analyzing.cake
Original file line number Diff line number Diff line change
@@ -1,42 +1,6 @@
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
BuildParameters.Tasks.DupFinderTask = Task("DupFinder")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows")
.WithCriteria(() => BuildParameters.ShouldRunDupFinder, "Skipping because DupFinder has been disabled")
.Does(() => RequireTool(ToolSettings.ReSharperTools, () => {
var dupFinderLogFilePath = BuildParameters.Paths.Directories.DupFinderTestResults.CombineWithFilePath("dupfinder.xml");
var settings = new DupFinderSettings() {
ShowStats = true,
ShowText = true,
OutputFile = dupFinderLogFilePath,
ExcludeCodeRegionsByNameSubstring = new string [] { "DupFinder Exclusion" },
ThrowExceptionOnFindingDuplicates = ToolSettings.DupFinderThrowExceptionOnFindingDuplicates ?? true
};
if (ToolSettings.DupFinderExcludePattern != null)
{
settings.ExcludePattern = ToolSettings.DupFinderExcludePattern;
}
if (ToolSettings.DupFinderExcludeFilesByStartingCommentSubstring != null)
{
settings.ExcludeFilesByStartingCommentSubstring = ToolSettings.DupFinderExcludeFilesByStartingCommentSubstring;
}
if (ToolSettings.DupFinderDiscardCost != null)
{
settings.DiscardCost = ToolSettings.DupFinderDiscardCost.Value;
}
DupFinder(BuildParameters.SolutionFilePath, settings);
// Pass path to dupFinder log file to Cake.Issues.Recipe
IssuesParameters.InputFiles.DupFinderLogFilePath = dupFinderLogFilePath;
})
);

BuildParameters.Tasks.InspectCodeTask = Task("InspectCode")
.WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows")
.WithCriteria(() => BuildParameters.ShouldRunInspectCode, "Skipping because InspectCode has been disabled")
Expand All @@ -61,5 +25,4 @@ BuildParameters.Tasks.InspectCodeTask = Task("InspectCode")
);

BuildParameters.Tasks.AnalyzeTask = Task("Analyze")
.IsDependentOn("DupFinder")
.IsDependentOn("InspectCode");
2 changes: 0 additions & 2 deletions Source/Cake.Recipe/Content/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ BuildParameters.Tasks.ShowInfoTask = Task("Show-Info")
Information("IsTagged: {0}", BuildParameters.IsTagged);
Information("Solution FilePath: {0}", MakeAbsolute((FilePath)BuildParameters.SolutionFilePath));
Information("Solution DirectoryPath: {0}", MakeAbsolute((DirectoryPath)BuildParameters.SolutionDirectoryPath));
Information("Source DirectoryPath: {0}", MakeAbsolute(BuildParameters.SourceDirectoryPath));
Information("Build DirectoryPath: {0}", MakeAbsolute(BuildParameters.Paths.Directories.Build));
});
Expand Down Expand Up @@ -504,7 +503,6 @@ public class Builder
BuildParameters.Tasks.CreateNuGetPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.CreateChocolateyPackagesTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.DupFinderTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.InspectCodeTask.IsDependentOn(prefix + "Build");
BuildParameters.Tasks.PackageTask.IsDependentOn("Analyze");
BuildParameters.Tasks.PackageTask.IsDependentOn("Test");
Expand Down
6 changes: 0 additions & 6 deletions Source/Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public static class BuildParameters
public static DirectoryPath RootDirectoryPath { get; private set; }
public static FilePath SolutionFilePath { get; private set; }
public static DirectoryPath SourceDirectoryPath { get; private set; }
public static DirectoryPath SolutionDirectoryPath { get; private set; }
public static DirectoryPath TestDirectoryPath { get; private set; }
public static FilePath IntegrationTestScriptPath { get; private set; }
public static string TestFilePattern { get; private set; }
Expand Down Expand Up @@ -122,7 +121,6 @@ public static class BuildParameters
public static FilePath MilestoneReleaseNotesFilePath { get; private set; }
public static FilePath FullReleaseNotesFilePath { get; private set; }

public static bool ShouldRunDupFinder { get; private set; }
public static bool ShouldRunInspectCode { get; private set; }
public static bool ShouldRunCoveralls { get; private set; }
public static bool ShouldRunCodecov { get; private set; }
Expand Down Expand Up @@ -345,7 +343,6 @@ public static class BuildParameters
DirectoryPath sourceDirectoryPath,
string title,
FilePath solutionFilePath = null,
DirectoryPath solutionDirectoryPath = null,
DirectoryPath rootDirectoryPath = null,
DirectoryPath testDirectoryPath = null,
string testFilePattern = null,
Expand All @@ -371,7 +368,6 @@ public static class BuildParameters
bool shouldPublishGitHub = true,
bool shouldGenerateDocumentation = true,
bool shouldDocumentSourceFiles = true,
bool shouldRunDupFinder = true,
bool shouldRunInspectCode = true,
bool shouldRunCoveralls = true,
bool shouldRunCodecov = true,
Expand Down Expand Up @@ -433,7 +429,6 @@ public static class BuildParameters
SourceDirectoryPath = sourceDirectoryPath;
Title = title;
SolutionFilePath = solutionFilePath ?? SourceDirectoryPath.CombineWithFilePath(Title + ".sln");
SolutionDirectoryPath = solutionDirectoryPath ?? SourceDirectoryPath.Combine(Title);
RootDirectoryPath = rootDirectoryPath ?? context.MakeAbsolute(context.Environment.WorkingDirectory);
TestDirectoryPath = testDirectoryPath ?? sourceDirectoryPath;
TestFilePattern = testFilePattern;
Expand Down Expand Up @@ -471,7 +466,6 @@ public static class BuildParameters
ShouldDownloadMilestoneReleaseNotes = shouldDownloadMilestoneReleaseNotes;
ShouldNotifyBetaReleases = shouldNotifyBetaReleases;
ShouldDeleteCachedFiles = shouldDeleteCachedFiles;
ShouldRunDupFinder = shouldRunDupFinder;
ShouldRunInspectCode = shouldRunInspectCode;
ShouldRunCoveralls = shouldRunCoveralls;
ShouldRunCodecov = shouldRunCodecov;
Expand Down
5 changes: 0 additions & 5 deletions Source/Cake.Recipe/Content/paths.cake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class BuildPaths

var testResultsDirectory = buildDirectoryPath + "/TestResults";
var inspectCodeResultsDirectory = testResultsDirectory + "/InspectCode";
var dupFinderResultsDirectory = testResultsDirectory + "/DupFinder";
var NUnitTestResultsDirectory = testResultsDirectory + "/NUnit";
var xUnitTestResultsDirectory = testResultsDirectory + "/xUnit";
var MSTestTestResultsDirectory = testResultsDirectory + "/MSTest";
Expand Down Expand Up @@ -64,7 +63,6 @@ public class BuildPaths
chocolateyNuspecDirectory,
testResultsDirectory,
inspectCodeResultsDirectory,
dupFinderResultsDirectory,
NUnitTestResultsDirectory,
xUnitTestResultsDirectory,
MSTestTestResultsDirectory,
Expand Down Expand Up @@ -145,7 +143,6 @@ public class BuildDirectories
public DirectoryPath ChocolateyNuspecDirectory { get; private set; }
public DirectoryPath TestResults { get; private set; }
public DirectoryPath InspectCodeTestResults { get; private set; }
public DirectoryPath DupFinderTestResults { get; private set; }
public DirectoryPath NUnitTestResults { get; private set; }
public DirectoryPath xUnitTestResults { get; private set; }
public DirectoryPath MSTestTestResults { get; private set; }
Expand All @@ -171,7 +168,6 @@ public class BuildDirectories
DirectoryPath chocolateyNuspecDirectory,
DirectoryPath testResults,
DirectoryPath inspectCodeTestResults,
DirectoryPath dupFinderTestResults,
DirectoryPath nunitTestResults,
DirectoryPath xunitTestResults,
DirectoryPath msTestTestResults,
Expand All @@ -196,7 +192,6 @@ public class BuildDirectories
ChocolateyNuspecDirectory = chocolateyNuspecDirectory;
TestResults = testResults;
InspectCodeTestResults = inspectCodeTestResults;
DupFinderTestResults = dupFinderTestResults;
NUnitTestResults = nunitTestResults;
xUnitTestResults = xunitTestResults;
MSTestTestResults = msTestTestResults;
Expand Down
1 change: 0 additions & 1 deletion Source/Cake.Recipe/Content/tasks.cake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
public class BuildTasks
{
public CakeTaskBuilder DupFinderTask { get; set; }
public CakeTaskBuilder InspectCodeTask { get; set; }
public CakeTaskBuilder AnalyzeTask { get; set; }
public CakeTaskBuilder PrintCiProviderEnvironmentVariablesTask { get; set; }
Expand Down
18 changes: 0 additions & 18 deletions Source/Cake.Recipe/Content/toolsettings.cake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ public static class ToolSettings
SetToolPreprocessorDirectives();
}

public static string[] DupFinderExcludePattern { get; private set; }
public static string[] DupFinderExcludeFilesByStartingCommentSubstring { get; private set; }
public static int? DupFinderDiscardCost { get; private set; }
public static bool? DupFinderThrowExceptionOnFindingDuplicates { get; private set; }
public static string TestCoverageFilter { get; private set; }
public static string TestCoverageExcludeByAttribute { get; private set; }
public static string TestCoverageExcludeByFile { get; private set; }
Expand Down Expand Up @@ -90,33 +86,19 @@ public static class ToolSettings

public static void SetToolSettings(
ICakeContext context,
string[] dupFinderExcludePattern = null,
string testCoverageFilter = null,
string testCoverageExcludeByAttribute = null,
string testCoverageExcludeByFile = null,
PlatformTarget? buildPlatformTarget = null,
MSBuildToolVersion buildMSBuildToolVersion = MSBuildToolVersion.Default,
int? maxCpuCount = null,
DirectoryPath targetFrameworkPathOverride = null,
string[] dupFinderExcludeFilesByStartingCommentSubstring = null,
int? dupFinderDiscardCost = null,
bool? dupFinderThrowExceptionOnFindingDuplicates = null,
bool skipDuplicatePackages = false
)
{
context.Information("Setting up tools...");

var absoluteTestDirectory = context.MakeAbsolute(BuildParameters.TestDirectoryPath);
var absoluteSourceDirectory = context.MakeAbsolute(BuildParameters.SolutionDirectoryPath);
DupFinderExcludePattern = dupFinderExcludePattern ??
new string[]
{
string.Format("{0}/{1}.Tests/**/*.cs", absoluteTestDirectory, BuildParameters.Title),
string.Format("{0}/**/*.AssemblyInfo.cs", absoluteSourceDirectory)
};
DupFinderExcludeFilesByStartingCommentSubstring = dupFinderExcludeFilesByStartingCommentSubstring;
DupFinderDiscardCost = dupFinderDiscardCost;
DupFinderThrowExceptionOnFindingDuplicates = dupFinderThrowExceptionOnFindingDuplicates;
TestCoverageFilter = testCoverageFilter ?? string.Format("+[{0}*]* -[*.Tests]*", BuildParameters.Title);
TestCoverageExcludeByAttribute = testCoverageExcludeByAttribute ?? "*.ExcludeFromCodeCoverage*";
TestCoverageExcludeByFile = testCoverageExcludeByFile ?? "*/*Designer.cs;*/*.g.cs;*/*.g.i.cs";
Expand Down
3 changes: 1 addition & 2 deletions docs/input/docs/fundamentals/recipe-cake.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ BuildParameters.SetParameters(context: Context,
BuildParameters.PrintParameters(Context);

ToolSettings.SetToolSettings(context: Context,
dupFinderExcludePattern: new string[] {
BuildParameters.RootDirectoryPath + "/Source/Cake.Example.Tests/*.cs",
BuildParameters.RootDirectoryPath + "/Source/Cake.Example/**/*.AssemblyInfo.cs" },
testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* ",
Expand Down Expand Up @@ -50,6 +49,6 @@ This recipe.cake file is broken up to distinct sections, some of which have more
* A call to the [BuildParameters.PrintParameters](./print-parameters) method
* It is really helpful, when running a build to know the value of the parameters that are being used. Calling this method will cause them to be printed out to the build log.
* A call to the [ToolSettings.SetToolSettings](./set-tool-settings) method
* Cake.Recipe uses a number of different tools, for example, DupFinder. When required, you can override the settings that are passed to these tools. Cake.Recipe attempts to provide sensible defaults for these tools.
* Cake.Recipe uses a number of different tools, for example, InspectCode. When required, you can override the settings that are passed to these tools. Cake.Recipe attempts to provide sensible defaults for these tools.
* A call to one of the three available [Build](./build) methods
* Cake.Recipe has three different build modes. .NET Framework, .NET Core and NuGet. Depending on what you are doing, you call the required one here. This method is what causes the actual build to execute.
25 changes: 0 additions & 25 deletions docs/input/docs/fundamentals/set-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ BuildParameters.SetParameters(context: Context,
buildSystem: BuildSystem,
sourceDirectoryPath: "./Source",
solutionFilePath: "./Source/ChocolateyGui.sln",
solutionDirectoryPath: "./Source/ChocolateyGui",
resharperSettingsFileName: "ChocolateyGui.sln.DotSettings",
title: "Chocolatey GUI",
repositoryOwner: "chocolatey",
Expand Down Expand Up @@ -74,18 +73,6 @@ Default Value:
SourceDirectoryPath.CombineWithFilePath(Title + ".sln")
```

### solutionDirectoryPath

This value is only used to feed into the default value for the DupFinderExcludePattern, which can be overridden in the SetToolSettings method.

Type: `DirectoryPath`

Default Value:

```csharp
SourceDirectoryPath.Combine(Title)
```

### rootDirectoryPath

This is intended to store the root directory path for the repository that Cake.Recipe is running in. This is derived from the WorkingDirectory of Cake by default.
Expand Down Expand Up @@ -382,18 +369,6 @@ Default Value:
true
```

### shouldRunDupFinder

This is used as a final control variable for whether or not the DupFinder tool should be executed as part of the build.

Type: `bool`

Default Value:

```csharp
true
```

### shouldRunInspectCode

This is used as a final control variable for whether or not the InspectCode tool should be executed as part of the build.
Expand Down
45 changes: 1 addition & 44 deletions docs/input/docs/fundamentals/set-tool-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ Title: SetToolSettings Method
Description: Override the default tool settings used by Cake.Recipe
---

Cake.Recipe makes use of a number of different tools, for example DupFinder, MSBuild, OpenCover, etc. While Cake.Recipe attempts to provide sensible defaults for all of these tools, there are times when it is necessary to override these for specific project requirements.
Cake.Recipe makes use of a number of different tools, for example InspectCode, MSBuild, OpenCover, etc. While Cake.Recipe attempts to provide sensible defaults for all of these tools, there are times when it is necessary to override these for specific project requirements.

This can be done by calling the `SetToolSettings` method.

As an example, you could override some tool settings using the following:

```csharp
ToolSettings.SetToolSettings(context: Context,
dupFinderExcludePattern: new string[] {
BuildParameters.RootDirectoryPath + "/Source/Cake.Example.Tests/*.cs",
BuildParameters.RootDirectoryPath + "/Source/Cake.Example/**/*.AssemblyInfo.cs" },
testCoverageFilter: "+[*]* -[xunit.*]* -[Cake.Core]* -[Cake.Testing]* -[*.Tests]* ",
Expand All @@ -24,24 +23,6 @@ ToolSettings.SetToolSettings(context: Context,

The `SetToolSettings` method uses the concept of optional parameters, in fact, all but one of the parameters to the `SetToolSettings` method are optional. To override a specific tool setting, you need to use a named parameter. The following is a list of all the named parameters that can be used on the method.

### dupFinderExcludePattern

This is used when executing the DupFinder command line tool. It provides a list of strings, representing file paths, which should be excluded from the DupFinder analysis.

Type: `string[]`

Default Value:

```csharp
var absoluteSourceDirectory = context.MakeAbsolute(BuildParameters.SolutionDirectoryPath);

new string[]
{
string.Format("{0}/{1}.Tests/**/*.cs", absoluteTestDirectory, BuildParameters.Title),
string.Format("{0}/**/*.AssemblyInfo.cs", absoluteSourceDirectory)
}
```

### testCoverageFilter

This is used in conjunction with both OpenCover and Coverlet. It controls which assemblies/namespaces should be included within the Unit Test coverage.
Expand Down Expand Up @@ -138,30 +119,6 @@ If a value for `targetFrameworkPathOverride` is provided, then the default value
TargetFrameworkPathOverride = targetFrameworkPathOverride?.FullPath;
```

### dupFinderExcludeFilesByStartingCommentSubstring

This is used when executing the DupFinder command line tool. It provides a list of strings, which should be matched in the opening comments of a file, which should be excluded from the DupFinder analysis.

Type: `string[]`

Default Value: `null`

### dupFinderDiscardCost

This is used when executing the DupFinder command line tool. It allows setting a threshold for code complexity of the duplicated fragments. The fragments with lower complexity are discarded as non-duplicates.

Type: `int?`

Default Value: `null`

### dupFinderThrowExceptionOnFindingDuplicates

This is used when executing the DupFinder command line tool. If set to true, an exception will be thrown is duplicates are found.

Type: `bool?`

Default Value: `null`

### skipDuplicatesPackages

This is used to tell NuGet to ignore issues with trying to push package versions when the version already exist upstream, instead of failing the build.
Expand Down
1 change: 0 additions & 1 deletion recipe.cake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ BuildParameters.SetParameters(context: Context,
repositoryName: "Cake.Recipe",
appVeyorAccountName: "cakecontrib",
shouldRunInspectCode: false,
shouldRunDupFinder: false,
shouldRunCoveralls: false,
shouldRunCodecov: false,
shouldRunDotNetCorePack: true,
Expand Down

0 comments on commit 8904754

Please sign in to comment.