public void ConfigExt_GetAnalysisSettings_ServerOnly() { // Check that local settings are only retrieved by GetAnalysisSettings // if includeServerSettings is true // 0. Setup var config = new AnalysisConfig { ServerSettings = new AnalysisProperties() }; config.ServerSettings.Add(new Property() { Id = "server.1", Value = "server.value.1" }); config.ServerSettings.Add(new Property() { Id = "server.2", Value = "server.value.2" }); // 1. Local only var localProperties = config.GetAnalysisSettings(false); localProperties.AssertExpectedPropertyCount(0); localProperties.AssertPropertyDoesNotExist("server.1"); localProperties.AssertPropertyDoesNotExist("server.2"); // 2. Local and server var allProperties = config.GetAnalysisSettings(true); allProperties.AssertExpectedPropertyCount(2); allProperties.AssertExpectedPropertyValue("server.1", "server.value.1"); allProperties.AssertExpectedPropertyValue("server.2", "server.value.2"); }
public void ConfigExt_GetAnalysisSettings_LocalOnly() { // Check that local settings are always retrieved by GetAnalysisSettings // 0. Setup var config = new AnalysisConfig { LocalSettings = new AnalysisProperties() }; config.LocalSettings.Add(new Property() { Id = "local.1", Value = "local.value.1" }); config.LocalSettings.Add(new Property() { Id = "local.2", Value = "local.value.2" }); // 1. Local only var localProperties = config.GetAnalysisSettings(false); localProperties.AssertExpectedPropertyCount(2); localProperties.AssertExpectedPropertyValue("local.1", "local.value.1"); localProperties.AssertExpectedPropertyValue("local.2", "local.value.2"); // 2. Local and server var allProperties = config.GetAnalysisSettings(true); allProperties.AssertExpectedPropertyCount(2); allProperties.AssertExpectedPropertyValue("local.1", "local.value.1"); allProperties.AssertExpectedPropertyValue("local.2", "local.value.2"); }
public bool Execute(string[] args, AnalysisConfig config, ITeamBuildSettings settings) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } logger.SuspendOutput(); targetUninstaller.UninstallTargets(); if (!ArgumentProcessor.TryProcessArgs(args, logger, out IAnalysisPropertyProvider provider)) { logger.ResumeOutput(); // logging already done return(false); } logger.Verbosity = VerbosityCalculator.ComputeVerbosity(config.GetAnalysisSettings(true), logger); logger.ResumeOutput(); LogStartupSettings(config, settings); if (!CheckCredentialsInCommandLineArgs(config, provider) || !CheckEnvironmentConsistency(config, settings)) { // logging already done return(false); } var propertyResult = GenerateAndValidatePropertiesFile(config); if (propertyResult.FullPropertiesFilePath != null) { #if NET46 ProcessCoverageReport(config, Path.Combine(config.SonarConfigDir, FileConstants.ConfigFileName), propertyResult.FullPropertiesFilePath); #endif bool result = false; if (propertyResult.RanToCompletion) { result = InvokeSonarScanner(provider, config, propertyResult.FullPropertiesFilePath); } #if NET46 if (settings.BuildEnvironment == BuildEnvironment.LegacyTeamBuild) { ProcessSummaryReportBuilder(config, result, Path.Combine(config.SonarConfigDir, FileConstants.ConfigFileName), propertyResult.FullPropertiesFilePath); } #endif return(result); } return(false); }
private static void AssertSettingDoesNotExist(string key, AnalysisConfig actualConfig) { Property setting; bool found = actualConfig.GetAnalysisSettings(true).TryGetProperty(key, out setting); Assert.IsFalse(found, "The setting should not exist. Key: {0}", key); }
public void ConfigExt_GetAnalysisSettings_ServerOnly() { // Check that local settings are only retrieved by GetAnalysisSettings // if includeServerSettings is true // 0. Setup AnalysisConfig config = new AnalysisConfig(); config.ServerSettings = new AnalysisProperties(); config.ServerSettings.Add(new Property() { Id = "server.1", Value = "server.value.1" }); config.ServerSettings.Add(new Property() { Id = "server.2", Value = "server.value.2" }); // 1. Local only IAnalysisPropertyProvider localProperties = config.GetAnalysisSettings(false); localProperties.AssertExpectedPropertyCount(0); localProperties.AssertPropertyDoesNotExist("server.1"); localProperties.AssertPropertyDoesNotExist("server.2"); // 2. Local and server IAnalysisPropertyProvider allProperties = config.GetAnalysisSettings(true); allProperties.AssertExpectedPropertyCount(2); allProperties.AssertExpectedPropertyValue("server.1", "server.value.1"); allProperties.AssertExpectedPropertyValue("server.2", "server.value.2"); }
private static IEnumerable <string> GetSensitiveFileSettings(AnalysisConfig config, IEnumerable <string> userCmdLineArguments) { var allPropertiesFromConfig = config.GetAnalysisSettings(false).GetAllProperties(); return(allPropertiesFromConfig.Where(p => p.ContainsSensitiveData() && !UserSettingExists(p, userCmdLineArguments)) .Select(p => p.AsSonarScannerArg())); }
public void ConfigExt_GetAnalysisSettings_NoSettings() { // 0. Setup var config = new AnalysisConfig(); // 1. No server settings var provider = config.GetAnalysisSettings(false); Assert.IsNotNull(provider, "Returned provider should not be null"); provider.AssertExpectedPropertyCount(0); // 2. With server settings provider = config.GetAnalysisSettings(true); Assert.IsNotNull(provider, "Returned provider should not be null"); provider.AssertExpectedPropertyCount(0); }
private static void VerifySummaryReportData( SummaryReportBuilder.SummaryReportData summaryReportData, ProjectInfoAnalysisResult analysisResult, string expectedHostUrl, AnalysisConfig config) { string expectedUrl; config.GetAnalysisSettings(false).TryGetValue("sonar.branch", out string branch); if (string.IsNullOrEmpty(branch)) { expectedUrl = string.Format( SummaryReportBuilder.DashboardUrlFormat, expectedHostUrl, config.SonarProjectKey); } else { expectedUrl = string.Format( SummaryReportBuilder.DashboardUrlFormatWithBranch, expectedHostUrl, config.SonarProjectKey, branch); } Assert.AreEqual(expectedUrl, summaryReportData.DashboardUrl, "Invalid dashboard url"); Assert.AreEqual(analysisResult.RanToCompletion, summaryReportData.Succeeded, "Invalid outcome"); }
/// <summary> /// Returns the analysis properties specified through the call. /// </summary> private static AnalysisProperties GetAnalysisProperties(AnalysisConfig config) { AnalysisProperties properties = new AnalysisProperties(); properties.AddRange(config.GetAnalysisSettings(false).GetAllProperties() .Where(p => !p.ContainsSensitiveData())); return(properties); }
private static string FindBranch(AnalysisConfig config) { var localSettings = config.GetAnalysisSettings(includeServerSettings: false); Debug.Assert(localSettings != null); localSettings.TryGetValue(SonarProperties.ProjectBranch, out string branch); return(branch); }
public bool Execute(string[] args, AnalysisConfig config, ITeamBuildSettings settings) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } this.targetUninstaller.UninstallTargets(logger); logger.SuspendOutput(); IAnalysisPropertyProvider provider; if (!ArgumentProcessor.TryProcessArgs(args, logger, out provider)) { logger.ResumeOutput(); // logging already done return(false); } logger.Verbosity = VerbosityCalculator.ComputeVerbosity(config.GetAnalysisSettings(true), logger); logger.ResumeOutput(); LogStartupSettings(config, settings); if (!CheckEnvironmentConsistency(config, settings)) { // logging already done return(false); } // if initialisation fails a warning will have been logged at the source of the failure bool initialised = this.codeCoverageProcessor.Initialise(config, settings, logger); if (initialised && !this.codeCoverageProcessor.ProcessCoverageReports()) { // if processing fails, stop the workflow return(false); } ProjectInfoAnalysisResult result = InvokeSonarScanner(provider, config); this.reportBuilder.GenerateReports(settings, config, result, logger); return(result.RanToCompletion); }
/// <summary> /// Returns all of the analysis properties that should /// be written to the sonar-project properties file /// </summary> private static AnalysisProperties GetAnalysisPropertiesToWrite(AnalysisConfig config, ILogger logger) { AnalysisProperties properties = new AnalysisProperties(); properties.AddRange(config.GetAnalysisSettings(false).GetAllProperties() // Strip out any sensitive properties .Where(p => !p.ContainsSensitiveData())); // There are some properties we want to override regardless of what the user sets AddOrSetProperty(VSBootstrapperPropertyKey, "false", properties, logger); return(properties); }
private string TryGetRegularExpression(AnalysisConfig config) { Debug.Assert(config != null, "Not expecting the supplied config to be null"); config.GetAnalysisSettings(true).TryGetValue(TestRegExSettingId, out string regEx); if (!string.IsNullOrWhiteSpace(regEx)) { Log.LogMessage(MessageImportance.Low, Resources.IsTest_UsingRegExFromConfig, regEx); } return(regEx); }
public void ConfigExt_GetAnalysisSettings_LocalOnly() { // Check that local settings are always retrieved by GetAnalysisSettings // 0. Setup AnalysisConfig config = new AnalysisConfig(); config.LocalSettings = new AnalysisProperties(); config.LocalSettings.Add(new Property() { Id = "local.1", Value = "local.value.1" }); config.LocalSettings.Add(new Property() { Id = "local.2", Value = "local.value.2" }); // 1. Local only IAnalysisPropertyProvider localProperties = config.GetAnalysisSettings(false); localProperties.AssertExpectedPropertyCount(2); localProperties.AssertExpectedPropertyValue("local.1", "local.value.1"); localProperties.AssertExpectedPropertyValue("local.2", "local.value.2"); // 2. Local and server IAnalysisPropertyProvider allProperties = config.GetAnalysisSettings(true); allProperties.AssertExpectedPropertyCount(2); allProperties.AssertExpectedPropertyValue("local.1", "local.value.1"); allProperties.AssertExpectedPropertyValue("local.2", "local.value.2"); }
/// <summary> /// Returns the analysis properties specified through the call. /// </summary> public static AnalysisProperties ToAnalysisProperties(this AnalysisConfig config, ILogger logger) { var properties = new AnalysisProperties(); properties.AddRange( config.GetAnalysisSettings(includeServerSettings: false) .GetAllProperties() .Where(p => !p.ContainsSensitiveData())); // There are some properties we want to override regardless of what the user sets AddOrSetProperty(VSBootstrapperPropertyKey, "false", properties, logger); return(properties); }
public bool Execute(string[] args, AnalysisConfig config, TeamBuildSettings settings, ILogger logger) { if (args == null) { throw new ArgumentNullException("args"); } if (config == null) { throw new ArgumentNullException("config"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (logger == null) { throw new ArgumentNullException("logger"); } IAnalysisPropertyProvider provider; if (!ArgumentProcessor.TryProcessArgs(args, logger, out provider)) { return(false); } logger.Verbosity = VerbosityCalculator.ComputeVerbosity(config.GetAnalysisSettings(true), logger); LogStartupSettings(config, settings, logger); if (!CheckEnvironmentConsistency(config, settings, logger)) { return(false); } // if initialisation fails a warning will have been logged at the source of the failure bool initialised = this.codeCoverageProcessor.Initialise(config, settings, logger); if (initialised && !this.codeCoverageProcessor.ProcessCoverageReports()) { // if processing fails, stop the workflow return(false); } ProjectInfoAnalysisResult result = InvokeSonarRunner(provider, config, logger); this.reportBuilder.GenerateReports(settings, config, result, logger); return(result.RanToCompletion); }
public void ConfigExt_GetAnalysisSettings_FileSettings() { // Check that file settings are always retrieved by GetAnalysisSettings // and that the file name config property is set and retrieved correctly // 0. Setup var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var config = new AnalysisConfig(); // File settings var fileSettings = new AnalysisProperties { new Property() { Id = "file.1", Value = "file.value.1" }, new Property() { Id = "file.2", Value = "file.value.2" } }; var settingsFilePath = Path.Combine(testDir, "settings.txt"); fileSettings.Save(settingsFilePath); // 1. Get path when not set -> null Assert.IsNull(config.GetSettingsFilePath(), "Expecting the settings file path to be null"); // 2. Set and get config.SetSettingsFilePath(settingsFilePath); Assert.AreEqual(settingsFilePath, config.GetSettingsFilePath(), "Unexpected settings file path value returned"); // 3. Check file properties are retrieved var provider = config.GetAnalysisSettings(false); provider.AssertExpectedPropertyCount(2); provider.AssertExpectedPropertyValue("file.1", "file.value.1"); provider.AssertExpectedPropertyValue("file.2", "file.value.2"); }
public void ConfigExt_GetAnalysisSettings_Precedence() { // Expected precedence: local -> file -> server // 0. Setup string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); AnalysisConfig config = new AnalysisConfig(); // File settings AnalysisProperties fileSettings = new AnalysisProperties(); fileSettings.Add(new Property() { Id = "file.1", Value = "file.value.1" }); fileSettings.Add(new Property() { Id = "shared.property", Value = "shared value from file - should never be returned" }); fileSettings.Add(new Property() { Id = "shared.property2", Value = "shared value 2 from file" }); string settingsFilePath = Path.Combine(testDir, "settings.txt"); fileSettings.Save(settingsFilePath); config.SetSettingsFilePath(settingsFilePath); // Local settings config.LocalSettings = new AnalysisProperties(); config.LocalSettings.Add(new Property() { Id = "local.1", Value = "local.value.1" }); config.LocalSettings.Add(new Property() { Id = "local.2", Value = "local.value.2" }); config.LocalSettings.Add(new Property() { Id = "shared.property", Value = "shared value from local" }); // Server settings config.ServerSettings = new AnalysisProperties(); config.ServerSettings.Add(new Property() { Id = "server.1", Value = "server.value.1" }); config.ServerSettings.Add(new Property() { Id = "server.2", Value = "server.value.2" }); config.ServerSettings.Add(new Property() { Id = "shared.property", Value = "shared value from server - should never be returned" }); config.ServerSettings.Add(new Property() { Id = "shared.property2", Value = "shared value 2 from server - should never be returned" }); // 1. Precedence - local should win over file IAnalysisPropertyProvider provider = config.GetAnalysisSettings(false); provider.AssertExpectedPropertyCount(5); provider.AssertExpectedPropertyValue("local.1", "local.value.1"); provider.AssertExpectedPropertyValue("local.2", "local.value.2"); provider.AssertExpectedPropertyValue("file.1", "file.value.1"); provider.AssertExpectedPropertyValue("shared.property", "shared value from local"); provider.AssertExpectedPropertyValue("shared.property2", "shared value 2 from file"); provider.AssertPropertyDoesNotExist("server.1"); provider.AssertPropertyDoesNotExist("server.2"); // 2. Server and non-server provider = config.GetAnalysisSettings(true); provider.AssertExpectedPropertyCount(7); provider.AssertExpectedPropertyValue("local.1", "local.value.1"); provider.AssertExpectedPropertyValue("local.2", "local.value.2"); provider.AssertExpectedPropertyValue("file.1", "file.value.1"); provider.AssertExpectedPropertyValue("shared.property", "shared value from local"); provider.AssertExpectedPropertyValue("shared.property2", "shared value 2 from file"); provider.AssertExpectedPropertyValue("server.1", "server.value.1"); provider.AssertExpectedPropertyValue("server.2", "server.value.2"); }
public void ConfigExt_GetAnalysisSettings_NoSettings() { // 0. Setup AnalysisConfig config = new AnalysisConfig(); // 1. No server settings IAnalysisPropertyProvider provider = config.GetAnalysisSettings(false); Assert.IsNotNull(provider, "Returned provider should not be null"); provider.AssertExpectedPropertyCount(0); // 2. With server settings provider = config.GetAnalysisSettings(true); Assert.IsNotNull(provider, "Returned provider should not be null"); provider.AssertExpectedPropertyCount(0); }
public void ConfigExt_GetAnalysisSettings_FileSettings() { // Check that file settings are always retrieved by GetAnalysisSettings // and that the file name config property is set and retrieved correctly // 0. Setup string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); AnalysisConfig config = new AnalysisConfig(); // File settings AnalysisProperties fileSettings = new AnalysisProperties(); fileSettings.Add(new Property() { Id = "file.1", Value = "file.value.1" }); fileSettings.Add(new Property() { Id = "file.2", Value = "file.value.2" }); string settingsFilePath = Path.Combine(testDir, "settings.txt"); fileSettings.Save(settingsFilePath); // 1. Get path when not set -> null Assert.IsNull(config.GetSettingsFilePath(), "Expecting the settings file path to be null"); // 2. Set and get config.SetSettingsFilePath(settingsFilePath); Assert.AreEqual(settingsFilePath, config.GetSettingsFilePath(), "Unexpected settings file path value returned"); // 3. Check file properties are retrieved IAnalysisPropertyProvider provider = config.GetAnalysisSettings(false); provider.AssertExpectedPropertyCount(2); provider.AssertExpectedPropertyValue("file.1", "file.value.1"); provider.AssertExpectedPropertyValue("file.2", "file.value.2"); }
public void ConfigExt_GetAnalysisSettings_Precedence() { // Expected precedence: local -> file -> server // 0. Setup var testDir = TestUtils.CreateTestSpecificFolder(TestContext); var config = new AnalysisConfig(); // File settings var fileSettings = new AnalysisProperties { new Property() { Id = "file.1", Value = "file.value.1" }, new Property() { Id = "shared.property", Value = "shared value from file - should never be returned" }, new Property() { Id = "shared.property2", Value = "shared value 2 from file" } }; var settingsFilePath = Path.Combine(testDir, "settings.txt"); fileSettings.Save(settingsFilePath); config.SetSettingsFilePath(settingsFilePath); // Local settings config.LocalSettings = new AnalysisProperties { new Property() { Id = "local.1", Value = "local.value.1" }, new Property() { Id = "local.2", Value = "local.value.2" }, new Property() { Id = "shared.property", Value = "shared value from local" } }; // Server settings config.ServerSettings = new AnalysisProperties { new Property() { Id = "server.1", Value = "server.value.1" }, new Property() { Id = "server.2", Value = "server.value.2" }, new Property() { Id = "shared.property", Value = "shared value from server - should never be returned" }, new Property() { Id = "shared.property2", Value = "shared value 2 from server - should never be returned" } }; // 1. Precedence - local should win over file var provider = config.GetAnalysisSettings(false); provider.AssertExpectedPropertyCount(5); provider.AssertExpectedPropertyValue("local.1", "local.value.1"); provider.AssertExpectedPropertyValue("local.2", "local.value.2"); provider.AssertExpectedPropertyValue("file.1", "file.value.1"); provider.AssertExpectedPropertyValue("shared.property", "shared value from local"); provider.AssertExpectedPropertyValue("shared.property2", "shared value 2 from file"); provider.AssertPropertyDoesNotExist("server.1"); provider.AssertPropertyDoesNotExist("server.2"); // 2. Server and non-server provider = config.GetAnalysisSettings(true); provider.AssertExpectedPropertyCount(7); provider.AssertExpectedPropertyValue("local.1", "local.value.1"); provider.AssertExpectedPropertyValue("local.2", "local.value.2"); provider.AssertExpectedPropertyValue("file.1", "file.value.1"); provider.AssertExpectedPropertyValue("shared.property", "shared value from local"); provider.AssertExpectedPropertyValue("shared.property2", "shared value 2 from file"); provider.AssertExpectedPropertyValue("server.1", "server.value.1"); provider.AssertExpectedPropertyValue("server.2", "server.value.2"); }