Exemplo n.º 1
0
        protected override bool TryGetVsCoverageFiles(AnalysisConfig config, ITeamBuildSettings settings, out IEnumerable <string> binaryFilePaths)
        {
            var urls = this.urlProvider.GetCodeCoverageReportUrls(config.GetTfsUri(), config.GetBuildUri());

            Debug.Assert(urls != null, "Not expecting the returned list of urls to be null");

            if (!urls.Any())
            {
                Logger.LogInfo(Resources.PROC_DIAG_NoCodeCoverageReportsFound);
                binaryFilePaths = Enumerable.Empty <string>();
                return(true);
            }

            var downloadedReports = new List <string>();

            foreach (var url in urls)
            {
                var targetFileName = Path.Combine(config.SonarOutputDir, DownloadFileName);
                var result         = this.downloader.DownloadReport(config.GetTfsUri(), url, targetFileName);

                if (result)
                {
                    downloadedReports.Add(targetFileName);
                }
                else
                {
                    Logger.LogError(Resources.PROC_ERROR_FailedToDownloadReport);
                    binaryFilePaths = Enumerable.Empty <string>();
                    return(false);
                }
            }

            binaryFilePaths = downloadedReports;
            return(true);
        }
        public void AnalysisConfGen_Simple()
        {
            // Arrange
            string analysisDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            TestLogger logger = new TestLogger();

            ListPropertiesProvider propertyProvider = new ListPropertiesProvider();

            propertyProvider.AddProperty(SonarProperties.HostUrl, "http://foo");
            ProcessedArgs args = new ProcessedArgs("valid.key", "valid.name", "1.0", false, EmptyPropertyProvider.Instance, propertyProvider);

            TeamBuildSettings tbSettings = TeamBuildSettings.CreateNonTeamBuildSettingsForTesting(analysisDir);

            Dictionary <string, string> serverSettings = new Dictionary <string, string>();

            serverSettings.Add("server.key.1", "server.value.1");

            AnalyzerSettings analyzerSettings = new AnalyzerSettings();

            analyzerSettings.RuleSetFilePath     = "c:\\xxx.ruleset";
            analyzerSettings.AdditionalFilePaths = new List <string>();
            analyzerSettings.AdditionalFilePaths.Add("f:\\additionalPath1.txt");
            analyzerSettings.AnalyzerAssemblyPaths = new List <string>();
            analyzerSettings.AnalyzerAssemblyPaths.Add("f:\\temp\\analyzer1.dll");

            List <AnalyzerSettings> analyzersSettings = new List <AnalyzerSettings>();

            analyzersSettings.Add(analyzerSettings);
            Directory.CreateDirectory(tbSettings.SonarConfigDirectory); // config directory needs to exist

            // Act
            AnalysisConfig actualConfig = AnalysisConfigGenerator.GenerateFile(args, tbSettings, serverSettings, analyzersSettings, logger);

            // Assert
            AssertConfigFileExists(actualConfig);
            logger.AssertErrorsLogged(0);
            logger.AssertWarningsLogged(0);

            Assert.AreEqual("valid.key", actualConfig.SonarProjectKey);
            Assert.AreEqual("valid.name", actualConfig.SonarProjectName);
            Assert.AreEqual("1.0", actualConfig.SonarProjectVersion);

            Assert.AreEqual("http://foo", actualConfig.SonarQubeHostUrl);

            Assert.AreEqual(tbSettings.SonarBinDirectory, actualConfig.SonarBinDir);
            Assert.AreEqual(tbSettings.SonarConfigDirectory, actualConfig.SonarConfigDir);
            Assert.AreEqual(tbSettings.SonarOutputDirectory, actualConfig.SonarOutputDir);
            Assert.AreEqual(tbSettings.SonarScannerWorkingDirectory, actualConfig.SonarScannerWorkingDirectory);
            Assert.AreEqual(tbSettings.BuildUri, actualConfig.GetBuildUri());
            Assert.AreEqual(tbSettings.TfsUri, actualConfig.GetTfsUri());

            Assert.IsNotNull(actualConfig.ServerSettings);
            Property serverProperty = actualConfig.ServerSettings.SingleOrDefault(s => string.Equals(s.Id, "server.key.1", System.StringComparison.Ordinal));

            Assert.IsNotNull(serverProperty);
            Assert.AreEqual("server.value.1", serverProperty.Value);
            Assert.AreSame(analyzerSettings, actualConfig.AnalyzersSettings[0]);
        }
Exemplo n.º 3
0
        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 void PreProc_EmptySonarRunnerProperties()
        {
            // Checks the pre-processor creates a valid config file

            // Arrange
            string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string propertiesFile = CreateEmptyPropertiesFile(testDir);

            MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher();
            MockRulesetGenerator  mockRulesetGenerator  = new MockRulesetGenerator();
            TestLogger            logger = new TestLogger();

            string expectedConfigFileName;

            using (PreprocessTestUtils.CreateValidLegacyTeamBuildScope("tfs uri", "http://builduri", testDir))
            {
                TeamBuildSettings settings = TeamBuildSettings.GetSettingsFromEnvironment(new ConsoleLogger());
                Assert.IsNotNull(settings, "Test setup error: TFS environment variables have not been set correctly");
                expectedConfigFileName = settings.AnalysisConfigFilePath;

                TeamBuildPreProcessor preProcessor = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator);

                // Act
                preProcessor.Execute(logger, "key", "name", "ver", propertiesFile);
            }

            // Assert
            Assert.IsTrue(File.Exists(expectedConfigFileName), "Config file does not exist: {0}", expectedConfigFileName);
            AnalysisConfig config = AnalysisConfig.Load(expectedConfigFileName);

            Assert.IsTrue(Directory.Exists(config.SonarOutputDir), "Output directory was not created: {0}", config.SonarOutputDir);
            Assert.IsTrue(Directory.Exists(config.SonarConfigDir), "Config directory was not created: {0}", config.SonarConfigDir);
            Assert.AreEqual("key", config.SonarProjectKey);
            Assert.AreEqual("name", config.SonarProjectName);
            Assert.AreEqual("ver", config.SonarProjectVersion);
            Assert.AreEqual("http://builduri", config.GetBuildUri());
            Assert.AreEqual("tfs uri", config.GetTfsUri());
            Assert.AreEqual(propertiesFile, config.SonarRunnerPropertiesPath);

            mockPropertiesFetcher.AssertFetchPropertiesCalled();
            mockPropertiesFetcher.CheckFetcherArguments("http://localhost:9000", "key");

            mockRulesetGenerator.AssertGenerateCalled();
            mockRulesetGenerator.CheckGeneratorArguments("http://localhost:9000", "key");
        }
Exemplo n.º 5
0
        private static void UpdateTeamBuildSummary(AnalysisConfig config, ProjectInfoAnalysisResult result, ILogger logger)
        {
            logger.LogMessage(Resources.Report_UpdatingTeamBuildSummary);

            int skippedProjectCount = GetProjectsByStatus(result, ProjectInfoValidity.NoFilesToAnalyze).Count();
            int invalidProjectCount = GetProjectsByStatus(result, ProjectInfoValidity.InvalidGuid).Count();

            invalidProjectCount += GetProjectsByStatus(result, ProjectInfoValidity.DuplicateGuid).Count();

            int excludedProjectCount = GetProjectsByStatus(result, ProjectInfoValidity.ExcludeFlagSet).Count();

            IEnumerable <ProjectInfo> validProjects = GetProjectsByStatus(result, ProjectInfoValidity.Valid);
            int productProjectCount = validProjects.Count(p => p.ProjectType == ProjectType.Product);
            int testProjectCount    = validProjects.Count(p => p.ProjectType == ProjectType.Test);

            using (BuildSummaryLogger summaryLogger = new BuildSummaryLogger(config.GetTfsUri(), config.GetBuildUri()))
            {
                string projectDescription = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                          Resources.Report_SonarQubeProjectDescription, config.SonarProjectName, config.SonarProjectKey, config.SonarProjectVersion);

                // Add a link to SonarQube dashboard if analysis succeeded
                Debug.Assert(config.SonarRunnerPropertiesPath != null, "Not expecting the sonar-runner properties path to be null");
                if (config.SonarRunnerPropertiesPath != null && result.RanToCompletion)
                {
                    ISonarPropertyProvider propertyProvider = new FilePropertiesProvider(config.SonarRunnerPropertiesPath);
                    string hostUrl = propertyProvider.GetProperty(SonarProperties.HostUrl).TrimEnd('/');

                    string sonarUrl = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                    "{0}/dashboard/index/{1}", hostUrl, config.SonarProjectKey);

                    summaryLogger.WriteMessage(Resources.Report_AnalysisSucceeded, projectDescription, sonarUrl);
                }

                if (!result.RanToCompletion)
                {
                    summaryLogger.WriteMessage(Resources.Report_AnalysisFailed, projectDescription);
                }

                summaryLogger.WriteMessage(Resources.Report_ProductAndTestMessage, productProjectCount, testProjectCount);
                summaryLogger.WriteMessage(Resources.Report_InvalidSkippedAndExcludedMessage, invalidProjectCount, skippedProjectCount, excludedProjectCount);
            }
        }
Exemplo n.º 6
0
        private void UpdateLegacyTeamBuildSummary(SummaryReportData summaryData)
        {
            logger.LogInfo(Resources.Report_UpdatingTeamBuildSummary);

            using (var summaryLogger = new BuildSummaryLogger(config.GetTfsUri(), config.GetBuildUri()))
            {
                // Add a link to SonarQube dashboard if analysis succeeded
                if (summaryData.Succeeded)
                {
                    summaryLogger.WriteMessage(Resources.Report_AnalysisSucceeded, summaryData.ProjectDescription, summaryData.DashboardUrl);
                }
                else
                {
                    summaryLogger.WriteMessage(Resources.Report_AnalysisFailed, summaryData.ProjectDescription);
                }

                summaryLogger.WriteMessage(Resources.Report_ProductAndTestMessage, summaryData.ProductProjects, summaryData.TestProjects);
                summaryLogger.WriteMessage(Resources.Report_InvalidSkippedAndExcludedMessage, summaryData.InvalidProjects, summaryData.SkippedProjects, summaryData.ExcludedProjects);
            }
        }