diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-08-11 10:58:37 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 10:59:55 +0200 |
commit | 0e99d43112e13db1bcd552896f82e4cce0329fc9 (patch) | |
tree | dc5ceb12e36748fa9c8b2ee495aafb2aa5772df0 /sonar-scanner-engine | |
parent | f87bdd9d007c372556a34e76dca2ab3da4b4b620 (diff) | |
download | sonarqube-0e99d43112e13db1bcd552896f82e4cce0329fc9.tar.gz sonarqube-0e99d43112e13db1bcd552896f82e4cce0329fc9.zip |
SONAR-9701 Skip unchanged components in short living branches
Diffstat (limited to 'sonar-scanner-engine')
2 files changed, 17 insertions, 10 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java index d0a847f828f..b90ab462a6e 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java @@ -27,6 +27,8 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.scanner.bootstrap.AbstractAnalysisMode; import org.sonar.scanner.bootstrap.GlobalProperties; +import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.BranchConfiguration.BranchType; @Immutable public class DefaultAnalysisMode extends AbstractAnalysisMode { @@ -36,33 +38,34 @@ public class DefaultAnalysisMode extends AbstractAnalysisMode { private boolean scanAllFiles; - public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props) { - init(globalProps.properties(), props.properties()); + public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props, BranchConfiguration branchConfig) { + init(globalProps.properties(), props.properties(), branchConfig); } public boolean scanAllFiles() { return scanAllFiles; } - private void init(Map<String, String> globalProps, Map<String, String> analysisProps) { + private void init(Map<String, String> globalProps, Map<String, String> analysisProps, BranchConfiguration branchConfig) { // make sure analysis is consistent with global properties boolean globalPreview = isIssues(globalProps); boolean analysisPreview = isIssues(analysisProps); + boolean shortLivingBranch = branchConfig.branchType() == BranchType.SHORT; if (!globalPreview && analysisPreview) { throw new IllegalStateException("Inconsistent properties: global properties doesn't enable issues mode while analysis properties enables it"); } - load(globalProps, analysisProps); + load(globalProps, analysisProps, shortLivingBranch); } - private void load(Map<String, String> globalProps, Map<String, String> analysisProps) { + private void load(Map<String, String> globalProps, Map<String, String> analysisProps, boolean isShortLivingBranch) { String mode = getPropertyWithFallback(analysisProps, globalProps, CoreProperties.ANALYSIS_MODE); validate(mode); issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode); mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, MEDIUM_TEST_ENABLED)); String scanAllStr = getPropertyWithFallback(analysisProps, globalProps, KEY_SCAN_ALL); - scanAllFiles = !issues || "true".equals(scanAllStr); + scanAllFiles = !isShortLivingBranch && (!issues || "true".equals(scanAllStr)); } public void printMode() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java index b7544e1f0ce..8841dd881c6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java @@ -27,6 +27,8 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.sonar.api.CoreProperties; import org.sonar.scanner.bootstrap.GlobalProperties; +import org.sonar.scanner.scan.BranchConfiguration; +import org.sonar.scanner.scan.DefaultBranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -83,21 +85,22 @@ public class DefaultAnalysisModeTest { Map<String, String> props = new HashMap<>(); props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES); GlobalProperties globalProps = new GlobalProperties(props); + BranchConfiguration branchConfig = new DefaultBranchConfiguration(); AnalysisProperties analysisProps = new AnalysisProperties(new HashMap<String, String>()); - DefaultAnalysisMode mode = new DefaultAnalysisMode(globalProps, analysisProps); + DefaultAnalysisMode mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig); assertThat(mode.scanAllFiles()).isFalse(); props.put("sonar.scanAllFiles", "true"); analysisProps = new AnalysisProperties(props); - mode = new DefaultAnalysisMode(globalProps, analysisProps); + mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig); assertThat(mode.scanAllFiles()).isTrue(); props.put(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PUBLISH); analysisProps = new AnalysisProperties(props); - mode = new DefaultAnalysisMode(globalProps, analysisProps); + mode = new DefaultAnalysisMode(globalProps, analysisProps, branchConfig); assertThat(mode.scanAllFiles()).isTrue(); } @@ -123,6 +126,7 @@ public class DefaultAnalysisModeTest { private static DefaultAnalysisMode createMode(@Nullable String bootstrapMode, @Nullable String analysisMode) { Map<String, String> bootstrapMap = new HashMap<>(); Map<String, String> analysisMap = new HashMap<>(); + BranchConfiguration branchConfig = new DefaultBranchConfiguration(); if (bootstrapMode != null) { bootstrapMap.put(CoreProperties.ANALYSIS_MODE, bootstrapMode); @@ -130,7 +134,7 @@ public class DefaultAnalysisModeTest { if (analysisMode != null) { analysisMap.put(CoreProperties.ANALYSIS_MODE, analysisMode); } - return new DefaultAnalysisMode(new GlobalProperties(bootstrapMap), new AnalysisProperties(analysisMap)); + return new DefaultAnalysisMode(new GlobalProperties(bootstrapMap), new AnalysisProperties(analysisMap), branchConfig); } } |