Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection of CodeCoverage.exe tool. #928

Merged
merged 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AssemblyInfo.Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyVersion("5.0.3")]
[assembly: AssemblyFileVersion("5.0.3.0")]
[assembly: AssemblyInformationalVersion("Version:5.0.3.0 Branch:not-set Sha1:not-set")]
[assembly: AssemblyVersion("5.0.4")]
[assembly: AssemblyFileVersion("5.0.4.0")]
[assembly: AssemblyInformationalVersion("Version:5.0.4.0 Branch:not-set Sha1:not-set")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SonarSource and Microsoft")]
[assembly: AssemblyCopyright("Copyright © SonarSource and Microsoft 2015-2020")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,14 @@ public void Initialize_CanGetGetExeToolPathFromSetupConfiguration()
}

[TestMethod]
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable()
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FullPathToCodeCoverageToolGiven()
{
// Arrange
var logger = new TestLogger();
var config = new AnalysisConfig();
config.SetVsCoverageConverterToolPath(@"My:\Path\To\CodeCoverage.exe");
var filePath = Path.Combine(Environment.CurrentDirectory, "CodeCoverage.exe");
File.Create(filePath);
config.SetVsCoverageConverterToolPath(filePath);

var reporter = new BinaryToXmlCoverageReportConverter(logger, config);

Expand All @@ -219,7 +221,52 @@ public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable()
// Assert
result.Should().BeTrue();

logger.AssertDebugLogged(@"VsTestToolsInstallerInstalledToolLocation environment variable detected, taking this one as tool path for CodeCoverage.exe.");
logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}.");
}

[TestMethod]
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_NoExeInThePath_ShouldSeekForStandardInstall()
{
// Arrange
var logger = new TestLogger();
var config = new AnalysisConfig();

var filePath = Path.Combine(Environment.CurrentDirectory, @"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe");
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
File.Create(filePath);

config.SetVsCoverageConverterToolPath(Environment.CurrentDirectory);

var reporter = new BinaryToXmlCoverageReportConverter(logger, config);

// Act
var result = reporter.Initialize();

// Assert
result.Should().BeTrue();
logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}.");
}

[TestMethod]
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FileDoesntExist_ShouldFallback()
{
// Arrange
var logger = new TestLogger();
var config = new AnalysisConfig();
var factory = CreateVisualStudioSetupConfigurationFactory("Microsoft.VisualStudio.TestTools.CodeCoverage");

config.SetVsCoverageConverterToolPath(Path.GetTempPath());

var reporter = new BinaryToXmlCoverageReportConverter(factory, logger, config);

// Act
var result = reporter.Initialize();

// Assert
result.Should().BeTrue();

logger.Warnings.Contains("CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable.");
logger.AssertDebugLogged("Code coverage command line tool: x:\\foo\\Team Tools\\Dynamic Code Coverage Tools\\CodeCoverage.exe");
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion nuspec/netcoreglobaltool/dotnet-sonarscanner.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>dotnet-sonarscanner</id>
<version>5.0.3</version>
<version>5.0.4</version>
<title>SonarScanner for .Net Core</title>
<authors>SonarSource,Microsoft</authors>
<projectUrl>http://redirect.sonarsource.com/doc/msbuild-sq-runner.html</projectUrl>
Expand Down
2 changes: 1 addition & 1 deletion scripts/version/Version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MainVersion>5.0.3</MainVersion>
<MainVersion>5.0.4</MainVersion>
<BuildNumber>0</BuildNumber>
<Sha1>not-set</Sha1>
<BranchName>not-set</BranchName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class BinaryToXmlCoverageReportConverter : ICoverageReportConverter
/// </summary>
private const string TeamToolPathandExeName = @"Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe";

private const string VsTestToolPlatformInstallerPathToExe = @"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe";

/// <summary>
/// Code coverage package names for Visual Studio setup configuration
/// </summary>
Expand Down Expand Up @@ -119,10 +121,26 @@ private string GetExeToolPath()
this.logger.LogDebug(Resources.CONV_DIAG_LocatingCodeCoverageTool);

var userSuppliedVsCoverageToolPath = this.config.GetVsCoverageConverterToolPath();
if (userSuppliedVsCoverageToolPath != null)
if (!string.IsNullOrEmpty(userSuppliedVsCoverageToolPath))
{
this.logger.LogDebug(Resources.CONV_DIAG_LocatingCodeCoverageToolUserSuppliedProperty);
return userSuppliedVsCoverageToolPath;
if (userSuppliedVsCoverageToolPath.EndsWith("CodeCoverage.exe") && File.Exists(userSuppliedVsCoverageToolPath))
{
this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageFound, userSuppliedVsCoverageToolPath);
return userSuppliedVsCoverageToolPath;
}

this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageIsNotInVariable);
var standardToolInstallerPath = Path.Combine(userSuppliedVsCoverageToolPath, VsTestToolPlatformInstallerPathToExe);
if (File.Exists(standardToolInstallerPath))
{
this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageFound, standardToolInstallerPath);
return standardToolInstallerPath;
}
else
{
this.logger.LogWarning(Resources.CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable);
}
}

return GetExeToolPathFromSetupConfiguration()
Expand Down
29 changes: 28 additions & 1 deletion src/SonarScanner.MSBuild.TFS.Classic/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/SonarScanner.MSBuild.TFS.Classic/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CONV_DIAG_CodeCoverageFound" xml:space="preserve">
<value>CodeCoverage.exe found at {0}.</value>
</data>
<data name="CONV_DIAG_CodeCoverageIsNotInVariable" xml:space="preserve">
<value>VsTestToolsInstallerInstalledToolLocation environment variable doesn't contain full path to CodeCoverage.exe tool, seeking in standard place set by VSTestPlatformToolInstaller...</value>
</data>
<data name="CONV_DIAG_CommandLineToolInfo" xml:space="preserve">
<value>Code coverage command line tool: {0}</value>
</data>
Expand All @@ -130,7 +136,7 @@
<value>Attempting to locate the CodeCoverage.exe tool using setup configuration...</value>
</data>
<data name="CONV_DIAG_LocatingCodeCoverageToolUserSuppliedProperty" xml:space="preserve">
<value>VsTestToolsInstallerInstalledToolLocation environment variable detected, taking this one as tool path for CodeCoverage.exe.</value>
<value>VsTestToolsInstallerInstalledToolLocation environment variable detected, seeking for CodeCoverage.exe location...</value>
</data>
<data name="CONV_DIAG_MultipleVsVersionsInstalled" xml:space="preserve">
<value>Multiple versions of VS are installed: {0}</value>
Expand All @@ -149,6 +155,9 @@ Check that the downloaded code coverage file ({0}) is valid by opening it in Vis
<data name="CONV_WARN_FailToFindConversionTool" xml:space="preserve">
<value>Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage.</value>
</data>
<data name="CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable" xml:space="preserve">
<value>CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable.</value>
</data>
<data name="DOWN_DIAG_ConnectedToTFS" xml:space="preserve">
<value>Connected to {0}</value>
</data>
Expand Down