public static RoslynExportProfile Load(TextReader reader) { XmlSerializer serializer = new XmlSerializer(typeof(RoslynExportProfile)); RoslynExportProfile profile = serializer.Deserialize(reader) as RoslynExportProfile; return(profile); }
private RoslynExportProfile TryGetRoslynConfigForProject() { string qualityProfile; if (!this.sqServer.TryGetQualityProfile(sqProjectKey, sqProjectBranch, CSharpLanguage, out qualityProfile)) { this.logger.LogDebug(Resources.RAP_NoProfileForProject, this.sqProjectKey); return(null); } string profileContent = null; if (!sqServer.TryGetProfileExport(qualityProfile, CSharpLanguage, RoslynCSharpFormatName, out profileContent)) { this.logger.LogDebug(Resources.RAP_ProfileExportNotFound, RoslynCSharpFormatName, this.sqProjectKey); return(null); } this.logger.LogDebug(Resources.RAP_ProfileExportFound, RoslynCSharpFormatName, this.sqProjectKey); RoslynExportProfile profile = null; using (StringReader reader = new StringReader(profileContent)) { profile = RoslynExportProfile.Load(reader); } return(profile); }
private static void AssertExpectedAdditionalFileExists(string fileName, RoslynExportProfile profile) { Assert.IsNotNull(profile.Configuration.AdditionalFiles); IEnumerable<AdditionalFile> matches = profile.Configuration.AdditionalFiles.Where(f => string.Equals(fileName, f.FileName, System.StringComparison.OrdinalIgnoreCase)); Assert.AreNotEqual(0, matches.Count(), "Expected additional file was not found. File name: {0}", fileName); Assert.AreEqual(1, matches.Count(), "Expecting only one matching file. File name: {0}", fileName); Assert.IsNotNull(matches.First().Content, "File content should not be null. File name: {0}", fileName); }
private IEnumerable <string> FetchAnalyzerAssemblies(RoslynExportProfile profile) { IEnumerable <string> analyzerAssemblyPaths = null; if (profile.Deployment == null || profile.Deployment.Plugins == null || profile.Deployment.Plugins.Count == 0) { this.logger.LogInfo(Resources.RAP_NoAnalyzerPluginsSpecified); } else { this.logger.LogInfo(Resources.RAP_ProvisioningAnalyzerAssemblies); analyzerAssemblyPaths = this.analyzerInstaller.InstallAssemblies(profile.Deployment.Plugins); } return(analyzerAssemblyPaths); }
private IEnumerable <string> UnpackAdditionalFiles(RoslynExportProfile profile) { Debug.Assert(profile.Configuration != null, "Supplied configuration should not be null"); List <string> additionalFiles = new List <string>(); foreach (AdditionalFile item in profile.Configuration.AdditionalFiles) { string filePath = ProcessAdditionalFile(item); if (filePath != null) { Debug.Assert(File.Exists(filePath), "Expecting the additional file to exist: {0}", filePath); additionalFiles.Add(filePath); } } return(additionalFiles); }
private string UnpackRuleset(RoslynExportProfile profile) { string rulesetFilePath = null; if (profile.Configuration.RuleSet == null) { this.logger.LogDebug(Resources.RAP_ProfileDoesNotContainRuleset); } else { rulesetFilePath = GetRulesetFilePath(this.sqSettings); this.logger.LogDebug(Resources.RAP_UnpackingRuleset, rulesetFilePath); XmlDocument doc = new XmlDocument(); doc.LoadXml(profile.Configuration.RuleSet.OuterXml); doc.Save(rulesetFilePath); } return(rulesetFilePath); }
private AnalyzerSettings ProcessProfile(RoslynExportProfile profile) { Debug.Assert(profile != null, "Expecting a valid profile"); string rulesetFilePath = this.UnpackRuleset(profile); if (rulesetFilePath == null) { return(null); } IEnumerable <string> additionalFiles = this.UnpackAdditionalFiles(profile); IEnumerable <string> analyzersAssemblies = this.FetchAnalyzerAssemblies(profile); AnalyzerSettings compilerConfig = new AnalyzerSettings(rulesetFilePath, analyzersAssemblies ?? Enumerable.Empty <string>(), additionalFiles ?? Enumerable.Empty <string>()); return(compilerConfig); }
public AnalyzerSettings SetupAnalyzers(ISonarQubeServer server, TeamBuildSettings settings, string projectKey, string projectBranch) { if (server == null) { throw new ArgumentNullException("server"); } if (settings == null) { throw new ArgumentNullException("settings"); } if (string.IsNullOrWhiteSpace(projectKey)) { throw new ArgumentNullException("projectKey"); } AnalyzerSettings analyzerSettings = null; if (IsCSharpPluginInstalled(server)) { this.sqServer = server; this.sqSettings = settings; this.sqProjectKey = projectKey; this.sqProjectBranch = projectBranch; RoslynExportProfile profile = TryGetRoslynConfigForProject(); if (profile != null) { analyzerSettings = ProcessProfile(profile); } } else { logger.LogDebug(Resources.RAP_CSharpPluginNotInstalled); } return(analyzerSettings ?? new AnalyzerSettings()); // return emtpy settings rather than null }
private IEnumerable<string> FetchAnalyzerAssemblies(RoslynExportProfile profile) { IEnumerable<string> analyzerAssemblyPaths = null; if (profile.Deployment == null || profile.Deployment.NuGetPackages == null || profile.Deployment.NuGetPackages.Count == 0) { this.logger.LogInfo(Resources.SLAP_NoAnalyzerPackagesSpecified); } else { this.logger.LogInfo(Resources.SLAP_ProvisioningAnalyzerAssemblies); analyzerAssemblyPaths = this.analyzerInstaller.InstallAssemblies(profile.Deployment.NuGetPackages); } return analyzerAssemblyPaths; }
private IEnumerable<string> UnpackAdditionalFiles(RoslynExportProfile profile) { Debug.Assert(profile.Configuration != null, "Supplied configuration should not be null"); List<string> additionalFiles = new List<string>(); foreach(AdditionalFile item in profile.Configuration.AdditionalFiles) { string filePath = ProcessAdditionalFile(item); if (filePath != null) { Debug.Assert(File.Exists(filePath), "Expecting the additional file to exist: {0}", filePath); additionalFiles.Add(filePath); } } return additionalFiles; }
private string UnpackRuleset(RoslynExportProfile profile) { string rulesetFilePath = null; if (profile.Configuration.RuleSet == null) { this.logger.LogDebug(Resources.SLAP_ProfileDoesNotContainRuleset); } else { rulesetFilePath = GetRulesetFilePath(this.settings); this.logger.LogDebug(Resources.SLAP_UnpackingRuleset, rulesetFilePath); XmlDocument doc = new XmlDocument(); doc.LoadXml(profile.Configuration.RuleSet.OuterXml); doc.Save(rulesetFilePath); } return rulesetFilePath; }
private AnalyzerSettings ProcessProfile(RoslynExportProfile profile) { Debug.Assert(profile != null, "Expecting a valid profile"); string rulesetFilePath = this.UnpackRuleset(profile); if (rulesetFilePath == null) { return null; } IEnumerable<string> additionalFiles = this.UnpackAdditionalFiles(profile); IEnumerable<string> analyzersAssemblies = this.FetchAnalyzerAssemblies(profile); AnalyzerSettings compilerConfig = new AnalyzerSettings(rulesetFilePath, analyzersAssemblies ?? Enumerable.Empty<string>(), additionalFiles ?? Enumerable.Empty<string>()); return compilerConfig; }
private static void AssertExpectedPackageExists(string packageId, string version, RoslynExportProfile profile) { Assert.IsNotNull(profile.Deployment); NuGetPackageInfo[] matches = profile.Deployment.NuGetPackages.Where( p => string.Equals(packageId, p.Id, System.StringComparison.Ordinal) && string.Equals(version, p.Version, System.StringComparison.Ordinal)).ToArray(); Assert.AreNotEqual(0, matches.Length, "Expected package was not found. Package: {0}, Version: {1}", packageId, version); Assert.AreEqual(1, matches.Length, "Expecting only one matching package. Package: {0}, Version: {1}", packageId, version); }
private static void AssertExpectedPluginExists(string pluginKey, string version, string staticResourceName, RoslynExportProfile profile) { Assert.IsNotNull(profile.Deployment); Plugin[] matches = profile.Deployment.Plugins.Where( p => string.Equals(pluginKey, p.Key, System.StringComparison.Ordinal) && string.Equals(version, p.Version, System.StringComparison.Ordinal) && string.Equals(staticResourceName, p.StaticResourceName, System.StringComparison.Ordinal)).ToArray(); Assert.AreNotEqual(0, matches.Length, "Expected plugin entry was not found. Plugin: {0}, Version: {1}, Resource: {2}", pluginKey, version, staticResourceName); Assert.AreEqual(1, matches.Length, "Expecting only one matching plugin. Package: {0}, Version: {1}, Resource: {2}", pluginKey, version, staticResourceName); }