private static SonarWebService GetSonarWebService(AnalysisConfig config) { FilePropertiesProvider sonarRunnerProperties = new FilePropertiesProvider(config.SonarRunnerPropertiesPath); string server = sonarRunnerProperties.GetProperty(SonarProperties.HostUrl, DefaultSonarServerUrl); string username = sonarRunnerProperties.GetProperty(SonarProperties.SonarUserName, null); string password = sonarRunnerProperties.GetProperty(SonarProperties.SonarPassword, null); return(new SonarWebService(new WebClientDownloader(new WebClient(), username, password), server, "cs", "fxcop")); }
private static void AssertExpectedValueReturned(FilePropertiesProvider provider, string propertyName, string expectedValue) { // Both "GetProperty" methods should return the same expected value string actualValue = provider.GetProperty(propertyName); Assert.AreEqual(expectedValue, actualValue, "Provider did not return the expected value for property '{0}'", propertyName); actualValue = provider.GetProperty(propertyName, Guid.NewGuid().ToString() /* supply a unique default - not expecting it to be returned*/); Assert.AreEqual(expectedValue, actualValue, "Provider did not return the expected value for property '{0}'", propertyName); }
/// <summary> /// Gets the URL from the sonar-runner.properties file. Throws if the /// properties file cannot be located. /// </summary> private static string GetUrlFromPropertiesFile() { var sonarRunnerProperties = FileLocator.FindDefaultSonarRunnerProperties(); if (sonarRunnerProperties == null) { throw new ArgumentException(Resources.ERROR_CouldNotFindSonarRunnerProperties); } var propertiesProvider = new FilePropertiesProvider(sonarRunnerProperties); var server = propertiesProvider.GetProperty(SonarProperties.HostUrl); Debug.Assert(!string.IsNullOrWhiteSpace(server), "Not expecting the host url property in the sonar-runner.properties file to be null/empty"); return(server); }
public void FilePropertiesProvider_GetProperty_Throws() { // Arrange string contents = @" a.b.c.=exists "; string fullName = CreatePropertiesFile("GetProperty_Throws.properties", contents); // Act FilePropertiesProvider provider = new FilePropertiesProvider(fullName); // Assert AssertExpectedValueReturned(provider, "a.b.c.", "exists"); Exception ex = AssertException.Expects <ArgumentException>(() => provider.GetProperty("missing.property")); Assert.IsTrue(ex.Message.Contains(fullName), "Expecting the error message to contain the file name"); Assert.IsTrue(ex.Message.Contains("missing.property"), "Expecting the error message to contain the name of the requested property"); }
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); } }
private static void AssertExpectedValueReturned(FilePropertiesProvider provider, string propertyName, string suppliedDefault, string expectedValue) { string actualValue = provider.GetProperty(propertyName, suppliedDefault); Assert.AreEqual(expectedValue, actualValue, "Provider did not return the expected value for property '{0}'", propertyName); }