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> /// 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; }