diff options
Diffstat (limited to 'sonar-scanner-engine')
7 files changed, 36 insertions, 8 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java index 9fe8fc5a7f5..4ca7c8be780 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ComponentsPublisher.java @@ -66,6 +66,7 @@ public class ComponentsPublisher implements ReportPublisherStep { fileBuilder.setIsTest(file.type() == InputFile.Type.TEST); fileBuilder.setLines(file.lines()); fileBuilder.setStatus(convert(file.status())); + fileBuilder.setMarkedAsUnchanged(file.isMarkedAsUnchanged()); String lang = getLanguageKey(file); if (lang != null) { diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java index 7aaf4b5eebe..f2c25f372e4 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/DefaultSensorStorage.java @@ -186,6 +186,10 @@ public class DefaultSensorStorage implements SensorStorage { reportPublisher.getWriter().appendComponentMeasure(((DefaultInputComponent) component).scannerId(), toReportMeasure(measure)); } + public boolean hasIssues(DefaultInputComponent inputComponent) { + return reportPublisher.getReader().hasIssues(inputComponent.scannerId()); + } + public static ScannerReport.Measure toReportMeasure(DefaultMeasure measureToSave) { ScannerReport.Measure.Builder builder = ScannerReport.Measure.newBuilder(); builder.setMetricKey(measureToSave.metric().key()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java index 86c54c41d69..a573f94ff0e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ModuleSensorContext.java @@ -27,7 +27,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.cache.ReadCache; import org.sonar.api.batch.sensor.cache.WriteCache; -import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.scanner.cache.AnalysisCacheEnabled; @@ -39,7 +38,7 @@ public class ModuleSensorContext extends ProjectSensorContext { private final InputModule module; public ModuleSensorContext(DefaultInputProject project, InputModule module, Configuration config, Settings mutableModuleSettings, FileSystem fs, ActiveRules activeRules, - SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration, + DefaultSensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration, WriteCache writeCache, ReadCache readCache, AnalysisCacheEnabled analysisCacheEnabled) { super(project, config, mutableModuleSettings, fs, activeRules, sensorStorage, sonarRuntime, branchConfiguration, writeCache, readCache, analysisCacheEnabled); this.module = module; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java index a4cd85157d6..4c72730b94c 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/sensor/ProjectSensorContext.java @@ -40,7 +40,6 @@ import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens; import org.sonar.api.batch.sensor.error.NewAnalysisError; import org.sonar.api.batch.sensor.highlighting.NewHighlighting; import org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting; -import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.issue.NewExternalIssue; import org.sonar.api.batch.sensor.issue.NewIssue; import org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue; @@ -67,7 +66,7 @@ public class ProjectSensorContext implements SensorContext { private final Settings mutableSettings; private final FileSystem fs; private final ActiveRules activeRules; - private final SensorStorage sensorStorage; + private final DefaultSensorStorage sensorStorage; private final DefaultInputProject project; private final SonarRuntime sonarRuntime; private final Configuration config; @@ -77,7 +76,7 @@ public class ProjectSensorContext implements SensorContext { private final AnalysisCacheEnabled analysisCacheEnabled; public ProjectSensorContext(DefaultInputProject project, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules, - SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration, WriteCache writeCache, ReadCache readCache, + DefaultSensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration, WriteCache writeCache, ReadCache readCache, AnalysisCacheEnabled analysisCacheEnabled) { this.project = project; this.config = config; @@ -194,6 +193,12 @@ public class ProjectSensorContext implements SensorContext { } @Override + public void markAsUnchanged(InputFile inputFile) { + DefaultInputFile defaultInputFile = (DefaultInputFile) inputFile; + defaultInputFile.setMarkedAsUnchanged(true); + } + + @Override public WriteCache nextCache() { return writeCache; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index cc440601a2f..ae2f877d384 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -24,6 +24,7 @@ import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -40,6 +41,7 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.fs.InputModuleHierarchy; +import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.scan.ScanProperties; import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonarqube.ws.Ce; @@ -93,6 +95,14 @@ public class ReportPublisherTest { } @Test + public void checks_if_component_has_issues() { + underTest.getWriter().writeComponentIssues(1, List.of(ScannerReport.Issue.newBuilder().build())); + + assertThat(underTest.getReader().hasIssues(1)).isTrue(); + assertThat(underTest.getReader().hasIssues(2)).isFalse(); + } + + @Test public void use_30s_write_timeout() { MockWsResponse submitMockResponse = new MockWsResponse(); submitMockResponse.setContent(Ce.SubmitResponse.newBuilder().setTaskId("task-1234").build().toByteArray()); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java index bb5d8f78bea..877e2e3e8ac 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java @@ -205,6 +205,16 @@ public class DefaultSensorStorageTest { } @Test + public void has_issues_delegates_to_report_publisher() { + DefaultInputFile file1 = new TestInputFileBuilder("foo", "src/Foo1.php").setStatus(InputFile.Status.SAME).build(); + DefaultInputFile file2 = new TestInputFileBuilder("foo", "src/Foo2.php").setStatus(InputFile.Status.SAME).build(); + + reportWriter.writeComponentIssues(file1.scannerId(), List.of(ScannerReport.Issue.newBuilder().build())); + assertThat(underTest.hasIssues(file1)).isTrue(); + assertThat(underTest.hasIssues(file2)).isFalse(); + } + + @Test public void should_save_highlighting() { DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php") .setContents("// comment").build(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java index d40c7344bee..fb719656262 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java @@ -32,7 +32,6 @@ import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; -import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.measures.CoreMetrics; @@ -55,7 +54,7 @@ public class ModuleSensorContextTest { private DefaultFileSystem fs; private ModuleSensorContext adaptor; private MapSettings settings; - private SensorStorage sensorStorage; + private DefaultSensorStorage sensorStorage; private SonarRuntime runtime; private BranchConfiguration branchConfiguration; private WriteCacheImpl writeCache; @@ -70,7 +69,7 @@ public class ModuleSensorContextTest { when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC); when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); settings = new MapSettings(); - sensorStorage = mock(SensorStorage.class); + sensorStorage = mock(DefaultSensorStorage.class); branchConfiguration = mock(BranchConfiguration.class); writeCache = mock(WriteCacheImpl.class); readCache = mock(ReadCacheImpl.class); |