protected void ReadParameters(AnalyzerOptions options, string language) { var sonarLintAdditionalFile = options.AdditionalFiles .FirstOrDefault(f => ParameterLoader.ConfigurationFilePathMatchesExpected(f.Path)); var projectOutputAdditionalFile = options.AdditionalFiles .FirstOrDefault(f => ParameterLoader.ConfigurationFilePathMatchesExpected(f.Path, ConfigurationAdditionalFile)); if (sonarLintAdditionalFile == null || projectOutputAdditionalFile == null) { return; } lock (parameterReadLock) { var xml = XDocument.Load(sonarLintAdditionalFile.Path); var settings = xml.Descendants("Setting"); ReadHeaderCommentProperties(settings); WorkDirectoryBasePath = File.ReadAllLines(projectOutputAdditionalFile.Path).FirstOrDefault(l => !string.IsNullOrEmpty(l)); if (!string.IsNullOrEmpty(WorkDirectoryBasePath)) { var suffix = language == LanguageNames.CSharp ? "cs" : "vbnet"; WorkDirectoryBasePath = Path.Combine(WorkDirectoryBasePath, "output-" + suffix); IsAnalyzerEnabled = true; } } }
public Configuration(string path, AnalyzerLanguage language) { if (!ParameterLoader.ConfigurationFilePathMatchesExpected(path)) { throw new ArgumentException( $"Input configuration doesn't match expected file name: '{ParameterLoader.ParameterConfigurationFileName}'", nameof(path)); } Path = path; analyzers = ImmutableArray.Create(GetAnalyzers(language).ToArray()); var xml = XDocument.Load(path); var settings = ParseSettings(xml); IgnoreHeaderComments = "true".Equals(settings[$"sonar.{language}.ignoreHeaderComments"], StringComparison.OrdinalIgnoreCase); Files = xml.Descendants("File").Select(e => e.Value).ToImmutableList(); AnalyzerIds = xml.Descendants("Rule").Select(e => e.Elements("Key").Single().Value).ToImmutableHashSet(); }
public Configuration(string sonarLintFilePath, string protoFolderFilePath, AnalyzerLanguage language) { if (!ParameterLoader.ConfigurationFilePathMatchesExpected(sonarLintFilePath)) { throw new ArgumentException( $"Input configuration doesn't match expected file name: '{ParameterLoader.ParameterConfigurationFileName}'", nameof(sonarLintFilePath)); } this.language = language; ProtoFolderAdditionalPath = protoFolderFilePath; SonarLintAdditionalPath = sonarLintFilePath; analyzers = ImmutableArray.Create(GetAnalyzers(language).ToArray()); var xml = XDocument.Load(sonarLintFilePath); var settings = ParseSettings(xml); IgnoreHeaderComments = "true".Equals(settings[$"sonar.{language}.ignoreHeaderComments"], StringComparison.OrdinalIgnoreCase); Files = xml.Descendants("File").Select(e => e.Value).ToImmutableList(); AnalyzerIds = xml.Descendants("Rule").Select(e => e.Elements("Key").Single().Value).ToImmutableHashSet(); if (settings.ContainsKey("sonar.sourceEncoding")) { try { var encodingName = settings["sonar.sourceEncoding"]; Encoding = Encoding.GetEncoding(encodingName); } catch (ArgumentException) { Program.Write($"Could not get encoding '{settings["sonar.sourceEncoding"]}'"); } } }
public void Read(AnalyzerOptions options) { var projectOutputAdditionalFile = options.AdditionalFiles .FirstOrDefault(UtilityAnalyzerBase.IsProjectOutput); var sonarLintAdditionalFile = options.AdditionalFiles .FirstOrDefault(f => ParameterLoader.ConfigurationFilePathMatchesExpected(f.Path)); if (sonarLintAdditionalFile == null || projectOutputAdditionalFile == null) { return; } var xml = XDocument.Load(sonarLintAdditionalFile.Path); EnabledRules = xml.Descendants("Rule") .Select(r => r.Element("Key")?.Value) .WhereNotNull() .ToHashSet(); ProjectOutputPath = File.ReadAllLines(projectOutputAdditionalFile.Path) .FirstOrDefault(l => !string.IsNullOrEmpty(l)); }
internal static bool IsProjectOutput(AdditionalText file) => ParameterLoader.ConfigurationFilePathMatchesExpected(file.Path, ConfigurationAdditionalFile);
private static bool IsProjectOutFolderPath(AdditionalText file) => ParameterLoader.ConfigurationFilePathMatchesExpected(file.Path, ProjectOutFolderPathFileName);