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); }
public bool Execute(string[] args, AnalysisConfig config, ITeamBuildSettings settings) { _ = args ?? throw new ArgumentNullException(nameof(args)); _ = config ?? throw new ArgumentNullException(nameof(config)); _ = settings ?? throw new ArgumentNullException(nameof(settings)); logger.SuspendOutput(); targetUninstaller.UninstallTargets(config.SonarBinDir); 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 var 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); }
/// <summary> /// Generates summary reports for LegacyTeamBuild and for Build Vnext /// </summary> public void GenerateReports(ITeamBuildSettings settings, AnalysisConfig config, bool ranToCompletion, string fullPropertiesFilePath) { this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.config = config ?? throw new ArgumentNullException(nameof(config)); result = new ProjectInfoAnalysisResult(); result.RanToCompletion = ranToCompletion; result.FullPropertiesFilePath = fullPropertiesFilePath; new PropertiesFileGenerator(config, logger).TryWriteProperties(new PropertiesWriter(config, logger), out var allProjects); result.Projects.AddRange(allProjects); GenerateReports(); }
protected override bool TryGetVsCoverageFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> binaryFilePaths) { binaryFilePaths = new TrxFileReader(Logger).FindCodeCoverageFiles(settings.BuildDirectory); // Fallback to workround VSTS-179: if the standard searches for .trx/.converage failed // then try the fallback method to find coverage files if (!TrxFilesLocated && (binaryFilePaths == null || !binaryFilePaths.Any())) { Logger.LogInfo("Did not find any binary coverage files in the expected location."); binaryFilePaths = searchFallback.FindCoverageFiles(); } else { Logger.LogDebug("Not using the fallback mechanism to detect binary coverage files."); } return(true); // there aren't currently any conditions under which we'd want to stop processing }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, ITeamBuildSettings settings, ILogger logger, out string binaryFilePath) { var urls = urlProvider.GetCodeCoverageReportUrls(config.GetTfsUri(), config.GetBuildUri(), logger); Debug.Assert(urls != null, "Not expecting the returned list of urls to be null"); var continueProcessing = true; binaryFilePath = null; switch (urls.Count()) { case 0: logger.LogInfo(Resources.PROC_DIAG_NoCodeCoverageReportsFound); break; case 1: var url = urls.First(); var targetFileName = Path.Combine(config.SonarOutputDir, DownloadFileName); var result = 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, ITeamBuildSettings 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); }
/// <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 bool CheckEnvironmentConsistency(AnalysisConfig config, ITeamBuildSettings settings) { // 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); } var configUri = config.GetBuildUri(); var environmentUi = settings.BuildUri; if (!string.Equals(configUri, environmentUi, System.StringComparison.OrdinalIgnoreCase)) { logger.LogError(Resources.ERROR_BuildUrisDontMatch, environmentUi, configUri, settings.AnalysisConfigFilePath); return(false); } return(true); }
protected override bool TryGetBinaryReportFile(AnalysisConfig config, ITeamBuildSettings settings, out string binaryFilePath) { binaryFilePath = new TrxFileReader(Logger).LocateCodeCoverageFile(settings.BuildDirectory); return(true); // there aren't currently any conditions under which we'd want to stop processing }
protected override bool TryGetTrxFile(AnalysisConfig config, ITeamBuildSettings settings, out string trxFilePath) { trxFilePath = new TrxFileReader(Logger).FindTrxFile(settings.BuildDirectory); return(true); }
protected abstract bool TryGetBinaryReportFile(AnalysisConfig config, ITeamBuildSettings settings, ILogger logger, out string binaryFilePath);
public bool Initialise(AnalysisConfig context, ITeamBuildSettings settings, ILogger logger) { Assert.IsFalse(initalisedCalled, "Expecting Initialise to be called only once"); initalisedCalled = true; return(InitialiseValueToReturn); }
protected override bool TryGetTrxFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> trxFilePaths) { trxFilePaths = new TrxFileReader(Logger).FindTrxFiles(settings.BuildDirectory); return(true); }
internal /* for testing */ bool TryGetTrxFilesAccessor(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> trxFilePaths) => this.TryGetTrxFiles(config, settings, out trxFilePaths);
public void GenerateReports(ITeamBuildSettings settings, AnalysisConfig config, ProjectInfoAnalysisResult result, ILogger logger) { Assert.IsFalse(methodCalled, "Generate reports has already been called"); this.methodCalled = true; }
protected override bool TryGetTrxFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> trxFilePaths) { trxFilePaths = Enumerable.Empty <string>(); return(false); }
protected abstract bool TryGetTrxFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> trxFilePaths);
public void GenerateReports(ITeamBuildSettings settings, AnalysisConfig config, bool ranToCompletion, string fullPropertiesFilePath) { methodCalled.Should().BeFalse("Generate reports has already been called"); methodCalled = true; }
protected abstract bool TryGetVsCoverageFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> binaryFilePaths);
public void GenerateReports(ITeamBuildSettings settings, AnalysisConfig config, ProjectInfoAnalysisResult result) { methodCalled.Should().BeFalse("Generate reports has already been called"); methodCalled = true; }
protected abstract bool TryGetTrxFile(AnalysisConfig config, ITeamBuildSettings settings, out string trxFilePath);
private static void ExecuteReportBuilder(ILogger logger, AnalysisConfig config, ILegacyTeamBuildFactory teamBuildFactory, ITeamBuildSettings teamBuildSettings, bool ranToCompletion, string fullPropertiesFilePath) { var reportBuilder = new SummaryReportBuilder(teamBuildFactory, logger); reportBuilder.GenerateReports(teamBuildSettings, config, ranToCompletion, fullPropertiesFilePath); }
protected override bool TryGetTrxFile(AnalysisConfig config, ITeamBuildSettings settings, out string trxFilePath) { trxFilePath = null; return(false); }
private static void ExecuteCoverageConverter(ILogger logger, AnalysisConfig config, ILegacyTeamBuildFactory teamBuildFactory, ITeamBuildSettings teamBuildSettings, string fullPropertiesFilePath) { var binaryConverter = new BinaryToXmlCoverageReportConverter(logger, config); var coverageReportProcessor = new CoverageReportProcessor(teamBuildFactory, binaryConverter, logger); if (coverageReportProcessor.Initialise(config, teamBuildSettings, fullPropertiesFilePath)) { bool success = coverageReportProcessor.ProcessCoverageReports(); if (success) { logger.LogInfo("Coverage report conversion completed successfully."); } else { logger.LogWarning("Coverage report conversion has failed. Skipping..."); } } }
// We can't make the override internal, so this is a pass-through for testing internal /* for testing */ bool TryGetVsCoverageFilesAccessor(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> binaryFilePaths) => TryGetVsCoverageFiles(config, settings, out binaryFilePaths);
public bool Initialise(AnalysisConfig config, ITeamBuildSettings settings) { initalisedCalled.Should().BeFalse("Expecting Initialize to be called only once"); initalisedCalled = true; return(InitialiseValueToReturn); }
protected override bool TryGetVsCoverageFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> binaryFilePaths) { binaryFilePaths = new TrxFileReader(Logger).FindCodeCoverageFiles(settings.BuildDirectory); return(true); // there aren't currently any conditions under which we'd want to stop processing }