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"); }
public void Initialize_CanGetGetExeToolPathFromEnvironmentVariable_FullPathToCodeCoverageToolGiven() { // Arrange var logger = new TestLogger(); var config = new AnalysisConfig(); var filePath = Path.Combine(Environment.CurrentDirectory, "CodeCoverage.exe"); File.Create(filePath); config.SetVsCoverageConverterToolPath(filePath); var reporter = new BinaryToXmlCoverageReportConverter(logger, config); // Act var result = reporter.Initialize(); // Assert result.Should().BeTrue(); logger.AssertDebugLogged($@"CodeCoverage.exe found at {filePath}."); }
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}."); }
/// <summary> /// Combines the various configuration options into the AnalysisConfig file /// used by the build and post-processor. Saves the file and returns the config instance. /// </summary> /// <param name="localSettings">Processed local settings, including command line arguments supplied the user</param> /// <param name="buildSettings">Build environment settings</param> /// <param name="serverProperties">Analysis properties downloaded from the SonarQube server</param> /// <param name="analyzerSettings">Specifies the Roslyn analyzers to use. Can be empty</param> public static AnalysisConfig GenerateFile(ProcessedArgs localSettings, TeamBuildSettings buildSettings, IDictionary <string, string> serverProperties, List <AnalyzerSettings> analyzersSettings, ISonarQubeServer sonarQubeServer, ILogger logger) { if (localSettings == null) { throw new ArgumentNullException(nameof(localSettings)); } if (buildSettings == null) { throw new ArgumentNullException(nameof(buildSettings)); } if (serverProperties == null) { throw new ArgumentNullException(nameof(serverProperties)); } if (sonarQubeServer == null) { throw new ArgumentNullException(nameof(sonarQubeServer)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } var config = new AnalysisConfig { SonarProjectKey = localSettings.ProjectKey, SonarProjectName = localSettings.ProjectName, SonarProjectVersion = localSettings.ProjectVersion, SonarQubeHostUrl = localSettings.SonarQubeUrl, HasBeginStepCommandLineCredentials = localSettings.CmdLineProperties.HasProperty(SonarProperties.SonarUserName), SonarQubeVersion = sonarQubeServer.GetServerVersion().Result.ToString() }; config.SetBuildUri(buildSettings.BuildUri); config.SetTfsUri(buildSettings.TfsUri); config.SetVsCoverageConverterToolPath(buildSettings.CoverageToolUserSuppliedPath); config.SonarConfigDir = buildSettings.SonarConfigDirectory; config.SonarOutputDir = buildSettings.SonarOutputDirectory; config.SonarBinDir = buildSettings.SonarBinDirectory; config.SonarScannerWorkingDirectory = buildSettings.SonarScannerWorkingDirectory; config.SourcesDirectory = buildSettings.SourcesDirectory; // Add the server properties to the config config.ServerSettings = new AnalysisProperties(); foreach (var property in serverProperties) { if (!Utilities.IsSecuredServerProperty(property.Key)) { AddSetting(config.ServerSettings, property.Key, property.Value); } } config.LocalSettings = new AnalysisProperties(); // From the local settings, we only write the ones coming from the cmd line foreach (var property in localSettings.CmdLineProperties.GetAllProperties()) { AddSetting(config.LocalSettings, property.Id, property.Value); } if (!string.IsNullOrEmpty(localSettings.Organization)) { AddSetting(config.LocalSettings, SonarProperties.Organization, localSettings.Organization); } // Set the pointer to the properties file if (localSettings.PropertiesFileName != null) { config.SetSettingsFilePath(localSettings.PropertiesFileName); } config.AnalyzersSettings = analyzersSettings ?? throw new ArgumentNullException(nameof(analyzersSettings)); config.Save(buildSettings.AnalysisConfigFilePath); return(config); }