コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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"]}'");
                }
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 internal static bool IsProjectOutput(AdditionalText file) =>
 ParameterLoader.ConfigurationFilePathMatchesExpected(file.Path, ConfigurationAdditionalFile);
コード例 #6
0
 private static bool IsProjectOutFolderPath(AdditionalText file) =>
 ParameterLoader.ConfigurationFilePathMatchesExpected(file.Path, ProjectOutFolderPathFileName);