Skip to content

Commit

Permalink
Add support for net462
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Nov 15, 2022
1 parent 7b8cb2d commit adf1ac8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FullPathToCod
var logger = new TestLogger();
var config = new AnalysisConfig();
var filePath = Path.Combine(Environment.CurrentDirectory, "CodeCoverage.exe");
File.Create(filePath);
using var _ = new TestFile(filePath);
config.SetVsCoverageConverterToolPath(filePath);

var reporter = new BinaryToXmlCoverageReportConverter(logger, config);
Expand All @@ -224,19 +224,20 @@ public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FullPathToCod
logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}.");
}

[TestMethod]
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_NoExeInThePath_ShouldSeekForStandardInstall()
[DataTestMethod]
[DoNotParallelize]
[DataRow(@"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe")]
[DataRow(@"tools\net462\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe")]
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_NoExeInThePath_ShouldSeekForStandardInstall(string standardPath)
{
// 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");
var filePath = Path.Combine(Environment.CurrentDirectory, standardPath);
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
File.Create(filePath);

using var _ = new TestFile(filePath);
config.SetVsCoverageConverterToolPath(Environment.CurrentDirectory);

var reporter = new BinaryToXmlCoverageReportConverter(logger, config);

// Act
Expand Down Expand Up @@ -361,5 +362,19 @@ private static IVisualStudioSetupConfigurationFactory CreateVisualStudioSetupCon
}

#endregion Tests

private class TestFile : IDisposable
{
public string FilePath { get; }

public TestFile(string filePath)
{
FilePath = filePath;
using var _ = File.Create(filePath);
}

public void Dispose() =>
File.Delete(FilePath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ 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";
private static string[] vsTestToolPlatformInstallerPathToExe = new[]
{
@"tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe",
@"tools\net462\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"
};

/// <summary>
/// Code coverage package names for Visual Studio setup configuration
Expand Down Expand Up @@ -130,17 +134,17 @@ private string GetExeToolPath()
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
foreach (var subPath in vsTestToolPlatformInstallerPathToExe)
{
this.logger.LogWarning(Resources.CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable);
var standardToolInstallerPath = Path.Combine(userSuppliedVsCoverageToolPath, subPath);
this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageIsNotInVariable, userSuppliedVsCoverageToolPath, subPath);
if (File.Exists(standardToolInstallerPath))
{
this.logger.LogDebug(Resources.CONV_DIAG_CodeCoverageFound, standardToolInstallerPath);
return standardToolInstallerPath;
}
}
this.logger.LogWarning(Resources.CONV_WARN_UnableToFindCodeCoverageFileInUserSuppliedVariable);
}

return GetExeToolPathFromSetupConfiguration()
Expand Down
4 changes: 2 additions & 2 deletions 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.

56 changes: 28 additions & 28 deletions src/SonarScanner.MSBuild.TFS.Classic/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -121,7 +121,7 @@
<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>
<value>VsTestToolsInstallerInstalledToolLocation environment variable doesn't contain full path to CodeCoverage.exe tool, seeking in standard place set by VSTestPlatformToolInstaller: {0} + {1}</value>
</data>
<data name="CONV_DIAG_CommandLineToolInfo" xml:space="preserve">
<value>Code coverage command line tool: {0}</value>
Expand Down

0 comments on commit adf1ac8

Please sign in to comment.