Search in sources :

Example 1 with AnalyzeCommand

use of org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand in project sonarlint-core by SonarSource.

the class StandaloneSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(StandaloneAnalysisConfiguration configuration, IssueListener issueListener, @Nullable ClientLogOutput logOutput, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(configuration);
    requireNonNull(issueListener);
    setLogging(logOutput);
    var analysisConfig = AnalysisConfiguration.builder().addInputFiles(configuration.inputFiles()).putAllExtraProperties(configuration.extraProperties()).addActiveRules(identifyActiveRules(configuration)).setBaseDir(configuration.baseDir()).build();
    try {
        var analysisResults = analysisEngine.post(new AnalyzeCommand(configuration.moduleKey(), analysisConfig, i -> issueListener.handle(new DefaultClientIssue(i, allRulesDefinitionsByKey.get(i.getRuleKey()))), logOutput), new ProgressMonitor(monitor)).get();
        return analysisResults == null ? new AnalysisResults() : analysisResults;
    } catch (Exception e) {
        throw SonarLintWrappedException.wrap(e);
    }
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) AnalysisResults(org.sonarsource.sonarlint.core.analysis.api.AnalysisResults) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) DefaultClientIssue(org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue)

Example 2 with AnalyzeCommand

use of org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand in project sonarlint-core by SonarSource.

the class AnalysisEngineMediumTests method should_analyze_a_file_inside_a_module.

@Test
void should_analyze_a_file_inside_a_module(@TempDir Path baseDir) throws Exception {
    var content = "def foo():\n" + "  x = 9; # trailing comment\n";
    ClientInputFile inputFile = preparePythonInputFile(baseDir, content);
    AnalysisConfiguration analysisConfig = AnalysisConfiguration.builder().addInputFiles(inputFile).addActiveRules(trailingCommentRule()).setBaseDir(baseDir).build();
    List<Issue> issues = new ArrayList<>();
    analysisEngine.post(new RegisterModuleCommand(new ClientModuleInfo("moduleKey", aModuleFileSystem())), progressMonitor).get();
    analysisEngine.post(new AnalyzeCommand("moduleKey", analysisConfig, issues::add, null), progressMonitor).get();
    assertThat(issues).extracting("ruleKey", "message", "inputFile", "flows", "quickFixes", "textRange.startLine", "textRange.startLineOffset", "textRange.endLine", "textRange.endLineOffset").containsOnly(tuple("python:S139", "Move this trailing comment on the previous empty line.", inputFile, List.of(), List.of(), 2, 9, 2, 27));
}
Also used : Issue(org.sonarsource.sonarlint.core.analysis.api.Issue) AnalysisConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration) ArrayList(java.util.ArrayList) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) RegisterModuleCommand(org.sonarsource.sonarlint.core.analysis.command.RegisterModuleCommand) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) Test(org.junit.jupiter.api.Test)

Example 3 with AnalyzeCommand

use of org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(ConnectedAnalysisConfiguration configuration, IssueListener issueListener, @Nullable ClientLogOutput logOutput, @Nullable ClientProgressMonitor monitor) {
    requireNonNull(configuration);
    requireNonNull(issueListener);
    setLogging(logOutput);
    checkStatus(configuration.projectKey());
    var analysisConfigBuilder = AnalysisConfiguration.builder().addInputFiles(configuration.inputFiles());
    var projectKey = configuration.projectKey();
    if (projectKey != null) {
        analysisConfigBuilder.putAllExtraProperties(projectStorage.getAnalyzerConfiguration(projectKey).getSettings().getAll());
        analysisConfigBuilder.putAllExtraProperties(globalConfig.extraProperties());
    }
    var activeRulesContext = buildActiveRulesContext(configuration);
    analysisConfigBuilder.putAllExtraProperties(configuration.extraProperties()).addActiveRules(activeRulesContext.activeRules).setBaseDir(configuration.baseDir()).build();
    var analysisConfiguration = analysisConfigBuilder.build();
    try {
        var analysisResults = getAnalysisEngine().post(new AnalyzeCommand(configuration.moduleKey(), analysisConfiguration, issue -> streamIssue(issueListener, issue, activeRulesContext), logOutput), new ProgressMonitor(monitor)).get();
        return analysisResults == null ? new AnalysisResults() : analysisResults;
    } catch (Exception e) {
        throw SonarLintWrappedException.wrap(e);
    }
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) AnalysisResults(org.sonarsource.sonarlint.core.analysis.api.AnalysisResults) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) SonarLintWrappedException(org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException) DownloadException(org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand)

Aggregations

AnalyzeCommand (org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand)3 AnalysisResults (org.sonarsource.sonarlint.core.analysis.api.AnalysisResults)2 SonarLintWrappedException (org.sonarsource.sonarlint.core.client.api.exceptions.SonarLintWrappedException)2 ClientProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor)2 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)2 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 AnalysisConfiguration (org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration)1 ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)1 ClientModuleInfo (org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo)1 Issue (org.sonarsource.sonarlint.core.analysis.api.Issue)1 RegisterModuleCommand (org.sonarsource.sonarlint.core.analysis.command.RegisterModuleCommand)1 DefaultClientIssue (org.sonarsource.sonarlint.core.client.api.common.analysis.DefaultClientIssue)1 DownloadException (org.sonarsource.sonarlint.core.client.api.exceptions.DownloadException)1 StorageException (org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)1 OnDiskTestClientInputFile (testutils.OnDiskTestClientInputFile)1