Search in sources :

Example 11 with AnalysisResults

use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.

the class ConnectedModeTest method parsingErrorJava.

@Test
public void parsingErrorJava() throws IOException {
    String fileContent = "pac kage its; public class MyTest { }";
    Path testFile = temp.newFile("MyTestParseError.java").toPath();
    Files.write(testFile, fileContent.getBytes(StandardCharsets.UTF_8));
    updateGlobal();
    updateModule(PROJECT_KEY_JAVA);
    SaveIssueListener issueListener = new SaveIssueListener();
    AnalysisResults results = engine.analyze(createAnalysisConfiguration(PROJECT_KEY_JAVA, testFile.toString()), issueListener, null, null);
    assertThat(results.failedAnalysisFiles()).hasSize(1);
}
Also used : Path(java.nio.file.Path) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) Test(org.junit.Test)

Example 12 with AnalysisResults

use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(ConnectedAnalysisConfiguration configuration, IssueListener issueListener, @Nullable LogOutput logOutput, @Nullable ProgressMonitor monitor) {
    checkNotNull(configuration);
    checkNotNull(issueListener);
    setLogging(logOutput);
    LoggedErrorHandler errorHandler = new LoggedErrorHandler(configuration.inputFiles());
    SonarLintLogging.setErrorHandler(errorHandler);
    return withReadLock(() -> {
        try {
            AnalysisResults results = getHandler().analyze(storageContainer.getGlobalExtensionContainer(), configuration, issueListener, new ProgressWrapper(monitor));
            errorHandler.getErrorFiles().forEach(results.failedAnalysisFiles()::add);
            return results;
        } catch (RuntimeException e) {
            throw SonarLintWrappedException.wrap(e);
        }
    });
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)

Example 13 with AnalysisResults

use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-core by SonarSource.

the class StandaloneSonarLintEngineImpl method analyze.

@Override
public AnalysisResults analyze(StandaloneAnalysisConfiguration configuration, IssueListener issueListener, @Nullable LogOutput logOutput, @Nullable ProgressMonitor monitor) {
    checkNotNull(configuration);
    checkNotNull(issueListener);
    setLogging(logOutput);
    LoggedErrorHandler errorHandler = new LoggedErrorHandler(configuration.inputFiles());
    SonarLintLogging.setErrorHandler(errorHandler);
    rwl.readLock().lock();
    try {
        AnalysisResults results = globalContainer.analyze(configuration, issueListener, new ProgressWrapper(monitor));
        errorHandler.getErrorFiles().forEach(results.failedAnalysisFiles()::add);
        return results;
    } catch (RuntimeException e) {
        throw SonarLintWrappedException.wrap(e);
    } finally {
        rwl.readLock().unlock();
    }
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) LoggedErrorHandler(org.sonarsource.sonarlint.core.util.LoggedErrorHandler) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)

Example 14 with AnalysisResults

use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-intellij by SonarSource.

the class SonarLintTask method run.

@Override
public void run(ProgressIndicator indicator) {
    AccumulatorIssueListener listener = new AccumulatorIssueListener();
    try {
        checkCanceled(indicator, myProject);
        List<AnalysisResults> results = analyze(myProject, indicator, listener);
        // last chance to cancel (to avoid the possibility of having interrupt flag set)
        checkCanceled(indicator, myProject);
        LOGGER.info("SonarLint analysis done");
        indicator.setIndeterminate(false);
        indicator.setFraction(.9);
        List<Issue> issues = listener.getIssues();
        indicator.setText("Creating SonarLint issues: " + issues.size());
        List<ClientInputFile> allFailedAnalysisFiles = results.stream().flatMap(r -> r.failedAnalysisFiles().stream()).collect(Collectors.toList());
        processor.process(job, indicator, issues, allFailedAnalysisFiles);
    } catch (CanceledException e1) {
        console.info("Analysis canceled");
        return;
    } catch (Throwable e) {
        handleError(e, indicator);
    } finally {
        myProject.getMessageBus().syncPublisher(TaskListener.SONARLINT_TASK_TOPIC).ended(job);
    }
}
Also used : AccumulatorIssueListener(org.sonarlint.intellij.editor.AccumulatorIssueListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) Task(com.intellij.openapi.progress.Task) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) LinkedList(java.util.LinkedList) IssueProcessor(org.sonarlint.intellij.issue.IssueProcessor) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) TaskListener(org.sonarlint.intellij.messages.TaskListener) Collection(java.util.Collection) ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) Collectors(java.util.stream.Collectors) SonarLintConsole(org.sonarlint.intellij.ui.SonarLintConsole) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ApplicationManager(com.intellij.openapi.application.ApplicationManager) TaskProgressMonitor(org.sonarlint.intellij.util.TaskProgressMonitor) CanceledException(org.sonarsource.sonarlint.core.client.api.exceptions.CanceledException) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) AccumulatorIssueListener(org.sonarlint.intellij.editor.AccumulatorIssueListener) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)

Example 15 with AnalysisResults

use of org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults in project sonarlint-intellij by SonarSource.

the class ConnectedSonarLintFacadeTest method should_start_analysis.

@Test
public void should_start_analysis() {
    AnalysisResults results = mock(AnalysisResults.class);
    when(engine.analyze(any(ConnectedAnalysisConfiguration.class), any(IssueListener.class), any(LogOutput.class), any(ProgressMonitor.class))).thenReturn(results);
    assertThat(facade.startAnalysis(Collections.emptyList(), mock(IssueListener.class), Collections.emptyMap(), mock(ProgressMonitor.class))).isEqualTo(results);
}
Also used : ProgressMonitor(org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) AnalysisResults(org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) LogOutput(org.sonarsource.sonarlint.core.client.api.common.LogOutput) Test(org.junit.Test)

Aggregations

AnalysisResults (org.sonarsource.sonarlint.core.client.api.common.analysis.AnalysisResults)15 Test (org.junit.Test)9 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)7 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)6 Path (java.nio.file.Path)4 ProgressMonitor (org.sonarsource.sonarlint.core.client.api.common.ProgressMonitor)4 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)4 ArrayList (java.util.ArrayList)3 Module (com.intellij.openapi.module.Module)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 TaskProgressMonitor (org.sonarlint.intellij.util.TaskProgressMonitor)2 TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)2 LogOutput (org.sonarsource.sonarlint.core.client.api.common.LogOutput)2 IssueListener (org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener)2 LoggedErrorHandler (org.sonarsource.sonarlint.core.util.LoggedErrorHandler)2 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1