/// <summary> /// Generates summary reports for LegacyTeamBuild and for Build Vnext /// </summary> public void GenerateReports(TeamBuildSettings settings, AnalysisConfig config, ProjectInfoAnalysisResult result, ILogger logger) { if (settings == null) { throw new ArgumentNullException("settings"); } if (config == null) { throw new ArgumentNullException("config"); } if (result == null) { throw new ArgumentNullException("result"); } if (logger == null) { throw new ArgumentNullException("logger"); } this.settings = settings; this.config = config; this.result = result; this.logger = logger; this.GenerateReports(); }
private static bool TryCreateRuleset(ISonarQubeServer server, TeamBuildSettings settings, string projectKey, ILogger logger) { logger.LogDebug(Resources.SLAP_FetchingSonarLintRuleset); string rulesetContent; string parametersContent; if (TryGetProfileExportForProject(server, projectKey, logger, out rulesetContent, out parametersContent)) { if (IsValidRuleset(rulesetContent)) { string ruleSetFilePath = GetRulesetFilePath(settings); logger.LogDebug(Resources.SLAP_SonarLintRulesetCreated, ruleSetFilePath); File.WriteAllText(ruleSetFilePath, rulesetContent); string parametersFilePath = GetParametersFilePath(settings); logger.LogDebug(Resources.SLAP_SonarLintParametersCreated, parametersFilePath); File.WriteAllText(parametersFilePath, parametersContent); return true; } else { logger.LogError(Resources.SLAP_InvalidRulesetReturned); } } return false; }
public AnalyzerSettings SetupAnalyzers(ISonarQubeServer sqServer, TeamBuildSettings teamBuildSettings, string sqProjectKey) { if (sqServer == null) { throw new ArgumentNullException("server"); } if (teamBuildSettings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(sqProjectKey)) { throw new ArgumentNullException("projectKey"); } if (!IsCSharpPluginInstalled(sqServer)) { logger.LogDebug(Resources.SLAP_CSharpPluginNotInstalled); return null; } this.server = sqServer; this.settings = teamBuildSettings; this.projectKey = sqProjectKey; AnalyzerSettings analyzerSettings = null; RoslynExportProfile profile = TryGetRoslynConfigForProject(); if (profile != null) { analyzerSettings = ProcessProfile(profile); } return analyzerSettings; }
/// <summary> /// Sets up the client to run the SonarLint analyzer as part of the build /// i.e. creates the Rolsyn ruleset and provisions the analyzer assemblies /// </summary> public static void SetupAnalyzers(ISonarQubeServer server, TeamBuildSettings settings, string projectKey, ILogger logger) { if (server == null) { throw new ArgumentNullException("server"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(projectKey)) { throw new ArgumentNullException("projectKey"); } if (logger == null) { throw new ArgumentNullException("logger"); } if (IsCSharpPluginInstalled(server)) { if (TryCreateRuleset(server, settings, projectKey, logger)) { FetchBinaries(server, settings, logger); } } else { logger.LogDebug(Resources.SLAP_CSharpPluginNotInstalled); } }
public static AnalysisConfig GenerateFile(ProcessedArgs args, TeamBuildSettings settings, IDictionary<string, string> serverProperties, ILogger logger) { if (args == null) { throw new ArgumentNullException("args"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (serverProperties == null) { throw new ArgumentNullException("serverProperties"); } if (logger == null) { throw new ArgumentNullException("logger"); } AnalysisConfig config = new AnalysisConfig(); config.SonarProjectKey = args.ProjectKey; config.SonarProjectName = args.ProjectName; config.SonarProjectVersion = args.ProjectVersion; config.SonarQubeHostUrl = args.GetSetting(SonarProperties.HostUrl); config.SetBuildUri(settings.BuildUri); config.SetTfsUri(settings.TfsUri); config.SonarConfigDir = settings.SonarConfigDirectory; config.SonarOutputDir = settings.SonarOutputDirectory; config.SonarBinDir = settings.SonarBinDirectory; config.SonarRunnerWorkingDirectory = settings.SonarRunnerWorkingDirectory; // Add the server properties to the config config.ServerSettings = new AnalysisProperties(); foreach (var property in serverProperties) { if (!IsSecuredServerProperty(property.Key)) { AddSetting(config.ServerSettings, property.Key, property.Value); } } // Add command line arguments config.LocalSettings = new AnalysisProperties(); foreach (var property in args.LocalProperties.GetAllProperties()) { AddSetting(config.LocalSettings, property.Id, property.Value); } // Set the pointer to the properties file if (args.PropertiesFileName != null) { config.SetSettingsFilePath(args.PropertiesFileName); } config.Save(settings.AnalysisConfigFilePath); return config; }
AnalyzerSettings IAnalyzerProvider.SetupAnalyzers(ISonarQubeServer server, TeamBuildSettings settings, string projectKey) { Assert.IsNotNull(server); Assert.IsNotNull(settings); Assert.IsFalse(string.IsNullOrWhiteSpace(projectKey)); return this.SettingsToReturn; }
/// <summary> /// Factory method to create and return a new set of team build settings /// calculated from environment variables. /// Returns null if all of the required environment variables are not present. /// </summary> public static TeamBuildSettings GetSettingsFromEnvironment(ILogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } TeamBuildSettings settings = null; BuildEnvironment env = GetBuildEnvironment(); switch (env) { case BuildEnvironment.LegacyTeamBuild: settings = new TeamBuildSettings() { BuildEnvironment = env, BuildUri = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildUri_Legacy), TfsUri = Environment.GetEnvironmentVariable(EnvironmentVariables.TfsCollectionUri_Legacy), BuildDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildDirectory_Legacy), SourcesDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.SourcesDirectory_Legacy), }; break; case BuildEnvironment.TeamBuild: settings = new TeamBuildSettings() { BuildEnvironment = env, BuildUri = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildUri_TFS2015), TfsUri = Environment.GetEnvironmentVariable(EnvironmentVariables.TfsCollectionUri_TFS2015), BuildDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildDirectory_TFS2015), SourcesDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.SourcesDirectory_TFS2015), }; break; default: settings = new TeamBuildSettings() { BuildEnvironment = env, // there's no reliable of way of finding the SourcesDirectory, except after the build }; break; } // We expect the bootstrapper to have set the WorkingDir of the processors to be the temp dir (i.e. .sonarqube) settings.AnalysisBaseDirectory = Directory.GetCurrentDirectory(); // https://jira.sonarsource.com/browse/SONARMSBRU-100 the sonar-runner should be able to locate files such as the resharper output // via relative paths, at least in the msbuild scenario, so the working directory should be The directory from which the user issued the command // Note that this will not work for TFS Build / XAML Build as the sources directory is more difficult to compute settings.SonarRunnerWorkingDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; return settings; }
public bool Initialise(AnalysisConfig config, TeamBuildSettings settings, ILogger logger) { if (settings == null) { throw new ArgumentNullException("settings"); } this.TryCreateCoverageReportProcessor(settings); this.initialisedSuccesfully = (this.processor != null && this.processor.Initialise(config, settings, logger)); return this.initialisedSuccesfully; }
/// <summary> /// Factory method to create a coverage report processor for the current build environment. /// </summary> private void TryCreateCoverageReportProcessor(TeamBuildSettings settings) { if (settings.BuildEnvironment == BuildEnvironment.TeamBuild) { this.processor = new BuildVNextCoverageReportProcessor(); } else if (settings.BuildEnvironment == BuildEnvironment.LegacyTeamBuild && !TeamBuildSettings.SkipLegacyCodeCoverageProcessing) { this.processor = new TfsLegacyCoverageReportProcessor(); } }
/// <summary> /// Factory method to create and return a new set of team build settings /// calculated from environment variables. /// Returns null if all of the required environment variables are not present. /// </summary> public static TeamBuildSettings GetSettingsFromEnvironment(ILogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } TeamBuildSettings settings = null; BuildEnvironment env = GetBuildEnvironment(); switch (env) { case BuildEnvironment.LegacyTeamBuild: settings = new TeamBuildSettings() { BuildEnvironment = env, BuildUri = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildUri_Legacy), TfsUri = Environment.GetEnvironmentVariable(EnvironmentVariables.TfsCollectionUri_Legacy), BuildDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildDirectory_Legacy), AnalysisBaseDirectory = Directory.GetCurrentDirectory() }; break; case BuildEnvironment.TeamBuild: settings = new TeamBuildSettings() { BuildEnvironment = env, BuildUri = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildUri_TFS2015), TfsUri = Environment.GetEnvironmentVariable(EnvironmentVariables.TfsCollectionUri_TFS2015), BuildDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildDirectory_TFS2015), AnalysisBaseDirectory = Directory.GetCurrentDirectory() }; break; default: settings = new TeamBuildSettings() { BuildEnvironment = env, AnalysisBaseDirectory = Directory.GetCurrentDirectory() }; break; } return(settings); }
/// <summary> /// Creates and returns settings for a non-TeamBuild environment /// </summary> public static TeamBuildSettings CreateNonTeamBuildSettings(string analysisBaseDirectory) { if (string.IsNullOrWhiteSpace(analysisBaseDirectory)) { throw new ArgumentNullException("analysisBaseDirectory"); } TeamBuildSettings settings = new TeamBuildSettings() { BuildEnvironment = BuildEnvironment.NotTeamBuild, AnalysisBaseDirectory = analysisBaseDirectory, }; return(settings); }
/// <summary> /// Creates and returns settings for a non-TeamBuild environment - for testing purposes. Use <see cref="GetSettingsFromEnvironment(ILogger)"/> /// in product code. /// </summary> public static TeamBuildSettings CreateNonTeamBuildSettingsForTesting(string analysisBaseDirectory) { if (string.IsNullOrWhiteSpace(analysisBaseDirectory)) { throw new ArgumentNullException("analysisBaseDirectory"); } TeamBuildSettings settings = new TeamBuildSettings() { BuildEnvironment = BuildEnvironment.NotTeamBuild, AnalysisBaseDirectory = analysisBaseDirectory, SonarRunnerWorkingDirectory = Directory.GetParent(analysisBaseDirectory).FullName }; return(settings); }
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; }
private static void FetchBinaries(ISonarQubeServer server, TeamBuildSettings settings, ILogger logger) { // For the 1.1 release of the runner/scanner, we are hard-coding support for a single known version // of SonarLint. The required assemblies will be packaged in the "static" folder of the jar (in the // same way that the SonarQube.MSBuild.Runner.Implementation.zip file is). logger.LogDebug(Resources.SLAP_FetchingSonarLintAnalyzer); if (server.TryDownloadEmbeddedFile(CSharpPluginKey, EmbeddedSonarLintZipFileName, settings.SonarBinDirectory)) { string filePath = Path.Combine(settings.SonarBinDirectory, EmbeddedSonarLintZipFileName); logger.LogDebug(Resources.MSG_ExtractingFiles, settings.SonarBinDirectory); ZipFile.ExtractToDirectory(filePath, settings.SonarBinDirectory); } else { logger.LogDebug(Resources.SLAP_AnalyzerNotFound); } }
/// <summary> /// Attempts to load the analysis config file. The location of the file is /// calculated from TeamBuild-specific environment variables. /// Returns null if the required environment variables are not available. /// </summary> private static AnalysisConfig GetAnalysisConfig(TeamBuildSettings teamBuildSettings, ILogger logger) { AnalysisConfig config = null; if (teamBuildSettings != null) { string configFilePath = teamBuildSettings.AnalysisConfigFilePath; Debug.Assert(!string.IsNullOrWhiteSpace(configFilePath), "Expecting the analysis config file path to be set"); if (File.Exists(configFilePath)) { config = AnalysisConfig.Load(teamBuildSettings.AnalysisConfigFilePath); } else { logger.LogError(Resources.ERROR_ConfigFileNotFound, configFilePath); } } return config; }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, TeamBuildSettings settings, ILogger logger, out string binaryFilePath) { IEnumerable <string> urls = this.urlProvider.GetCodeCoverageReportUrls(config.GetTfsUri(), config.GetBuildUri(), logger); Debug.Assert(urls != null, "Not expecting the returned list of urls to be null"); bool continueProcessing = true; binaryFilePath = null; switch (urls.Count()) { case 0: logger.LogInfo(Resources.PROC_DIAG_NoCodeCoverageReportsFound); break; case 1: string url = urls.First(); string targetFileName = Path.Combine(config.SonarOutputDir, DownloadFileName); bool result = this.downloader.DownloadReport(config.GetTfsUri(), url, targetFileName, logger); if (result) { binaryFilePath = targetFileName; } else { continueProcessing = false; logger.LogError(Resources.PROC_ERROR_FailedToDownloadReport); } break; default: // More than one continueProcessing = false; logger.LogError(Resources.PROC_ERROR_MultipleCodeCoverageReportsFound); break; } return(continueProcessing); }
public bool Initialise(AnalysisConfig config, TeamBuildSettings settings, ILogger logger) { if (config == null) { throw new ArgumentNullException("config"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (logger == null) { throw new ArgumentNullException("logger"); } this.config = config; this.settings = settings; this.logger = logger; this.succesfullyInitialised = this.converter.Initialize(logger); return succesfullyInitialised; }
public bool Initialise(AnalysisConfig config, TeamBuildSettings settings, ILogger logger) { if (config == null) { throw new ArgumentNullException("config"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (logger == null) { throw new ArgumentNullException("logger"); } this.config = config; this.settings = settings; this.logger = logger; this.succesfullyInitialised = this.converter.Initialize(logger); return(succesfullyInitialised); }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, TeamBuildSettings settings, ILogger logger, out string binaryFilePath) { IEnumerable<string> urls = this.urlProvider.GetCodeCoverageReportUrls(config.GetTfsUri(), config.GetBuildUri(), logger); Debug.Assert(urls != null, "Not expecting the returned list of urls to be null"); bool continueProcessing = true; binaryFilePath = null; switch (urls.Count()) { case 0: logger.LogInfo(Resources.PROC_DIAG_NoCodeCoverageReportsFound); break; case 1: string url = urls.First(); string targetFileName = Path.Combine(config.SonarOutputDir, DownloadFileName); bool result = this.downloader.DownloadReport(config.GetTfsUri(), url, targetFileName, logger); if (result) { binaryFilePath = targetFileName; } else { continueProcessing = false; logger.LogError(Resources.PROC_ERROR_FailedToDownloadReport); } break; default: // More than one continueProcessing = false; logger.LogError(Resources.PROC_ERROR_MultipleCodeCoverageReportsFound); break; } return continueProcessing; }
/// <summary> /// Factory method to create and return a new set of team build settings /// calculated from environment variables. /// Returns null if all of the required environment variables are not present. /// </summary> public static TeamBuildSettings GetSettingsFromEnvironment(ILogger logger) { if (logger == null) { throw new ArgumentNullException("logger"); } TeamBuildSettings settings = null; BuildEnvironment env = GetBuildEnvironment(); switch (env) { case BuildEnvironment.LegacyTeamBuild: settings = new TeamBuildSettings() { BuildEnvironment = env, BuildUri = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildUri_Legacy), TfsUri = Environment.GetEnvironmentVariable(EnvironmentVariables.TfsCollectionUri_Legacy), BuildDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildDirectory_Legacy), AnalysisBaseDirectory = Directory.GetCurrentDirectory() }; break; case BuildEnvironment.TeamBuild: settings = new TeamBuildSettings() { BuildEnvironment = env, BuildUri = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildUri_TFS2015), TfsUri = Environment.GetEnvironmentVariable(EnvironmentVariables.TfsCollectionUri_TFS2015), BuildDirectory = Environment.GetEnvironmentVariable(EnvironmentVariables.BuildDirectory_TFS2015), AnalysisBaseDirectory = Directory.GetCurrentDirectory() }; break; default: settings = new TeamBuildSettings() { BuildEnvironment = env, AnalysisBaseDirectory = Directory.GetCurrentDirectory() }; break; } return settings; }
public bool Initialise(AnalysisConfig context, TeamBuildSettings settings, ILogger logger) { Assert.IsFalse(this.initalisedCalled, "Expecting Initialise to be called only once"); this.initalisedCalled = true; return InitialiseValueToReturn; }
/// <summary> /// Returns a boolean indicating whether the information in the environment variables /// matches that in the analysis config file. /// Used to detect invalid setups on the build agent. /// </summary> private static bool CheckEnvironmentConsistency(AnalysisConfig config, TeamBuildSettings settings, ILogger logger) { // Currently we're only checking that the build uris match as this is the most likely error // - it probably means that an old analysis config file has been left behind somehow // e.g. a build definition used to include analysis but has changed so that it is no // longer an analysis build, but there is still an old analysis config on disc. if (settings.BuildEnvironment == BuildEnvironment.NotTeamBuild) { return true; } string configUri = config.GetBuildUri(); string environmentUi = settings.BuildUri; if (!string.Equals(configUri, environmentUi, System.StringComparison.OrdinalIgnoreCase)) { logger.LogError(Resources.ERROR_BuildUrisDontMatch, environmentUi, configUri, settings.AnalysisConfigFilePath); return false; } return true; }
private static void LogStartupSettings(AnalysisConfig config, TeamBuildSettings settings, ILogger logger) { string configFileName = config == null ? string.Empty : config.FileName; logger.LogDebug(Resources.MSG_LoadingConfig, configFileName); switch (settings.BuildEnvironment) { case BuildEnvironment.LegacyTeamBuild: logger.LogDebug(Resources.SETTINGS_InLegacyTeamBuild); break; case BuildEnvironment.TeamBuild: logger.LogDebug(Resources.SETTINGS_InTeamBuild); break; case BuildEnvironment.NotTeamBuild: logger.LogDebug(Resources.SETTINGS_NotInTeamBuild); break; default: break; } logger.LogDebug(Resources.SETTING_DumpSettings, settings.AnalysisBaseDirectory, settings.BuildDirectory, settings.SonarBinDirectory, settings.SonarConfigDirectory, settings.SonarOutputDirectory, settings.AnalysisConfigFilePath); }
/// <summary> /// Creates and returns settings for a non-TeamBuild environment - for testing purposes. Use <see cref="GetSettingsFromEnvironment(ILogger)"/> /// in product code. /// </summary> public static TeamBuildSettings CreateNonTeamBuildSettingsForTesting(string analysisBaseDirectory) { if (string.IsNullOrWhiteSpace(analysisBaseDirectory)) { throw new ArgumentNullException("analysisBaseDirectory"); } TeamBuildSettings settings = new TeamBuildSettings() { BuildEnvironment = BuildEnvironment.NotTeamBuild, AnalysisBaseDirectory = analysisBaseDirectory, SonarRunnerWorkingDirectory = Directory.GetParent(analysisBaseDirectory).FullName }; return settings; }
public void GenerateReports(TeamBuildSettings settings, AnalysisConfig config, ProjectInfoAnalysisResult result, ILogger logger) { Assert.IsFalse(methodCalled, "Generate reports has already been called"); this.methodCalled = true; }
private bool FetchArgumentsAndRulesets(ProcessedArgs args, TeamBuildSettings settings, ILogger logger, out IDictionary<string, string> serverSettings) { string hostUrl = args.GetSetting(SonarProperties.HostUrl); serverSettings = null; ISonarQubeServer server = this.serverFactory.Create(args, logger); try { // Fetch the SonarQube project properties logger.LogInfo(Resources.MSG_FetchingAnalysisConfiguration); serverSettings = server.GetProperties(args.ProjectKey); // Generate the FxCop rulesets logger.LogInfo(Resources.MSG_GeneratingRulesets); GenerateFxCopRuleset(server, args.ProjectKey, "csharp", "cs", "fxcop", Path.Combine(settings.SonarConfigDirectory, FxCopCSharpRuleset), logger); GenerateFxCopRuleset(server, args.ProjectKey, "vbnet", "vbnet", "fxcop-vbnet", Path.Combine(settings.SonarConfigDirectory, FxCopVBNetRuleset), logger); SonarLintAnalyzerProvider.SetupAnalyzers(server, settings, args.ProjectKey, logger); } catch (WebException ex) { if (Utilities.HandleHostUrlWebException(ex, hostUrl, logger)) { return false; } throw; } finally { Utilities.SafeDispose(server); } return true; }
public PostProcTestContext(TestContext testContext) { this.Config = new AnalysisConfig(); this.settings = TeamBuildSettings.CreateNonTeamBuildSettings(testContext.DeploymentDirectory); this.logger = new TestLogger(); this.codeCoverage = new MockCodeCoverageProcessor(); this.runner = new MockSonarRunner(); this.reportBuilder = new MockSummaryReportBuilder(); this.codeCoverage.InitialiseValueToReturn = true; this.codeCoverage.ProcessValueToReturn = true; }
private static string GetRulesetFilePath(TeamBuildSettings settings) { return Path.Combine(settings.SonarConfigDirectory, RoslynCSharpRulesetFileName); }
/// <summary> /// Creates and returns settings for a non-TeamBuild environment /// </summary> public static TeamBuildSettings CreateNonTeamBuildSettings(string analysisBaseDirectory) { if (string.IsNullOrWhiteSpace(analysisBaseDirectory)) { throw new ArgumentNullException("analysisBaseDirectory"); } TeamBuildSettings settings = new TeamBuildSettings() { BuildEnvironment = BuildEnvironment.NotTeamBuild, AnalysisBaseDirectory = analysisBaseDirectory, }; return settings; }
protected abstract bool TryGetBinaryReportFile(AnalysisConfig config, TeamBuildSettings settings, ILogger logger, out string binaryFilePath);
private static string GetParametersFilePath(TeamBuildSettings settings) { return Path.Combine(settings.SonarConfigDirectory, SonarLintCSharpParametersFileName); }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, TeamBuildSettings settings, ILogger logger, out string binaryFilePath) { binaryFilePath = TrxFileReader.LocateCodeCoverageFile(settings.BuildDirectory, logger); return true; // there aren't currently any conditions under which we'd want to stop processing }
private static bool TryCreateRuleset(ISonarQubeServer server, TeamBuildSettings settings, string projectKey, ILogger logger) { logger.LogDebug(Resources.SLAP_FetchingSonarLintRuleset); string content = TryGetProfileExportForProject(server, projectKey, logger); if (content != null) { if (IsValidRuleset(content)) { string ruleSetFilePath = GetRulesetFilePath(settings); logger.LogDebug(Resources.SLAP_SonarLintRulesetCreated, ruleSetFilePath); File.WriteAllText(ruleSetFilePath, content); return true; } else { // TODO: decide on an appropriate error message once we know whether could // happen in the 1.1 release. logger.LogError(Resources.SLAP_InvalidRulesetReturned); } } return false; }
private static void FetchBinaries(ISonarQubeServer server, TeamBuildSettings settings, ILogger logger) { // TODO: https://jira.sonarsource.com/browse/SONARCS-556 }
private bool FetchArgumentsAndRulesets(ProcessedArgs args, TeamBuildSettings settings, out IDictionary<string, string> serverSettings, out AnalyzerSettings analyzerSettings) { string hostUrl = args.GetSetting(SonarProperties.HostUrl); serverSettings = null; analyzerSettings = null; ISonarQubeServer server = this.factory.CreateSonarQubeServer(args, this.logger); try { this.logger.LogInfo(Resources.MSG_FetchingAnalysisConfiguration); // Respect sonar.branch setting if set string projectBranch = null; args.TryGetSetting(SonarProperties.ProjectBranch, out projectBranch); // Fetch the SonarQube project properties serverSettings = server.GetProperties(args.ProjectKey, projectBranch); // Generate the FxCop rulesets this.logger.LogInfo(Resources.MSG_GeneratingRulesets); GenerateFxCopRuleset(server, args.ProjectKey, projectBranch, "csharp", "cs", "fxcop", Path.Combine(settings.SonarConfigDirectory, FxCopCSharpRuleset)); GenerateFxCopRuleset(server, args.ProjectKey, projectBranch, "vbnet", "vbnet", "fxcop-vbnet", Path.Combine(settings.SonarConfigDirectory, FxCopVBNetRuleset)); IAnalyzerProvider analyzerProvider = this.factory.CreateAnalyzerProvider(this.logger); Debug.Assert(analyzerProvider != null, "Factory should not return null"); analyzerSettings = analyzerProvider.SetupAnalyzers(server, settings, args.ProjectKey, projectBranch); } catch (WebException ex) { if (Utilities.HandleHostUrlWebException(ex, hostUrl, this.logger)) { return false; } throw; } finally { Utilities.SafeDispose(server); } return true; }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, TeamBuildSettings settings, ILogger logger, out string binaryFilePath) { binaryFilePath = TrxFileReader.LocateCodeCoverageFile(settings.BuildDirectory, logger); return(true); // there aren't currently any conditions under which we'd want to stop processing }