diff options
Diffstat (limited to 'sonar-scanner-engine')
3 files changed, 24 insertions, 4 deletions
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 a33a00961f4..461fe146a76 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 @@ -28,6 +28,7 @@ import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; +import org.sonar.scanner.scan.branch.BranchConfiguration; @ThreadSafe public class ModuleSensorContext extends ProjectSensorContext { @@ -35,8 +36,8 @@ 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) { - super(project, config, mutableModuleSettings, fs, activeRules, sensorStorage, sonarRuntime); + SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration) { + super(project, config, mutableModuleSettings, fs, activeRules, sensorStorage, sonarRuntime, branchConfiguration); 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 653baa3bf50..fc78598b80a 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 @@ -53,6 +53,7 @@ import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.api.scanner.fs.InputProject; import org.sonar.api.utils.Version; +import org.sonar.scanner.scan.branch.BranchConfiguration; import org.sonar.scanner.sensor.noop.NoOpNewAnalysisError; @ThreadSafe @@ -67,9 +68,10 @@ public class ProjectSensorContext implements SensorContext { private final DefaultInputProject project; private final SonarRuntime sonarRuntime; private final Configuration config; + private final boolean skipUnchangedFiles; public ProjectSensorContext(DefaultInputProject project, Configuration config, Settings mutableSettings, FileSystem fs, ActiveRules activeRules, - SensorStorage sensorStorage, SonarRuntime sonarRuntime) { + SensorStorage sensorStorage, SonarRuntime sonarRuntime, BranchConfiguration branchConfiguration) { this.project = project; this.config = config; this.mutableSettings = mutableSettings; @@ -77,6 +79,7 @@ public class ProjectSensorContext implements SensorContext { this.activeRules = activeRules; this.sensorStorage = sensorStorage; this.sonarRuntime = sonarRuntime; + this.skipUnchangedFiles = branchConfiguration.isPullRequest(); } @Override @@ -184,4 +187,9 @@ public class ProjectSensorContext implements SensorContext { public NewSignificantCode newSignificantCode() { return new DefaultSignificantCode(sensorStorage); } + + @Override + public boolean canSkipUnchangedFiles() { + return this.skipUnchangedFiles; + } } 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 7caadeb8aec..5b886662ecf 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 @@ -37,6 +37,7 @@ import org.sonar.api.config.internal.MapSettings; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.Version; +import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -53,6 +54,7 @@ public class ModuleSensorContextTest { private MapSettings settings; private SensorStorage sensorStorage; private SonarRuntime runtime; + private BranchConfiguration branchConfiguration; @Before public void prepare() throws Exception { @@ -63,16 +65,18 @@ public class ModuleSensorContextTest { when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); settings = new MapSettings(); sensorStorage = mock(SensorStorage.class); + branchConfiguration = mock(BranchConfiguration.class); runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY); - adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime); } @Test public void shouldProvideComponents() { + adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime, branchConfiguration); assertThat(adaptor.activeRules()).isEqualTo(activeRules); assertThat(adaptor.fileSystem()).isEqualTo(fs); assertThat(adaptor.getSonarQubeVersion()).isEqualTo(Version.parse("5.5")); assertThat(adaptor.runtime()).isEqualTo(runtime); + assertThat(adaptor.canSkipUnchangedFiles()).isFalse(); assertThat(adaptor.newIssue()).isNotNull(); assertThat(adaptor.newExternalIssue()).isNotNull(); @@ -83,4 +87,11 @@ public class ModuleSensorContextTest { assertThat(adaptor.newSignificantCode()).isNotNull(); } + @Test + public void pull_request_can_skip_unchanged_files() { + when(branchConfiguration.isPullRequest()).thenReturn(true); + adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime, branchConfiguration); + assertThat(adaptor.canSkipUnchangedFiles()).isTrue(); + } + } |