protected void ReadParameters(AnalyzerOptions options, string language)
        {
            var sonarLintAdditionalFile = options.AdditionalFiles
                                          .FirstOrDefault(f => ParameterLoader.IsSonarLintXml(f.Path));

            var projectOutputAdditionalFile = options.AdditionalFiles
                                              .FirstOrDefault(IsProjectOutput);

            if (sonarLintAdditionalFile == null ||
                projectOutputAdditionalFile == null)
            {
                return;
            }

            lock (this.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;
                }
            }
        }
Example #2
0
            public void Initialize(AnalyzerOptions options)
            {
                if (isInitialized)
                {
                    return;
                }

                lock (@lock)
                {
                    if (isInitialized)
                    {
                        return;
                    }

                    isInitialized = true;

                    var sonarLintXml = options.AdditionalFiles
                                       .FirstOrDefault(f => ParameterLoader.IsSonarLintXml(f.Path));

                    if (sonarLintXml == null)
                    {
                        return;
                    }

                    var document = XDocument.Load(sonarLintXml.Path);

                    enabledRules = document.Descendants("Rule")
                                   .Select(r => r.Element("Key")?.Value)
                                   .WhereNotNull()
                                   .ToHashSet();
                }
            }
 private static string GetSonarLintXmlPath(AnalyzerOptions options) =>
 options.AdditionalFiles.FirstOrDefault(f => ParameterLoader.IsSonarLintXml(f.Path))?.Path;