]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9670 Introduce sonar.branch.longLivedBranches.regex 2328/head
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 12 Sep 2017 11:30:16 +0000 (13:30 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 12 Sep 2017 11:30:16 +0000 (13:30 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/GlobalAnalysisMode.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java

index 1e669c1a5a2d15550ebcd986de35fe634cc01648..77fd14c63517c361076e0b90c05c417910a49f05 100644 (file)
@@ -41,7 +41,7 @@ public class DefaultAnalysisMode implements AnalysisMode {
   private final GlobalAnalysisMode analysisMode;
   private final BranchConfiguration branchConfig;
   private final ProjectRepositories projectRepos;
-  private final IncrementalScannerHandler validateIncremental;
+  private final IncrementalScannerHandler incrementalScannerHandler;
 
   private boolean scanAllFiles;
   private boolean incremental;
@@ -51,13 +51,14 @@ public class DefaultAnalysisMode implements AnalysisMode {
   }
 
   public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig,
-    GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler validateIncremental) {
+    GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler incrementalScannerHandler) {
     this.branchConfig = branchConfig;
     this.analysisMode = analysisMode;
     this.projectRepos = projectRepos;
-    this.validateIncremental = validateIncremental;
+    this.incrementalScannerHandler = incrementalScannerHandler;
     this.analysisProps = props.properties();
     load();
+    printFlags();
   }
 
   @Override
@@ -69,7 +70,10 @@ public class DefaultAnalysisMode implements AnalysisMode {
     return scanAllFiles;
   }
 
-  public void printFlags() {
+  private void printFlags() {
+    if (incremental) {
+      LOG.info("Incremental mode");
+    }
     if (!scanAllFiles) {
       LOG.info("Scanning only changed files");
     }
@@ -77,14 +81,14 @@ public class DefaultAnalysisMode implements AnalysisMode {
 
   private void load() {
     String scanAllStr = analysisProps.get(KEY_SCAN_ALL);
-    scanAllFiles = !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
     incremental = incremental();
+    scanAllFiles = !incremental && !branchConfig.isShortLivingBranch() && (!analysisMode.isIssues() || "true".equals(scanAllStr));
   }
 
   private boolean incremental() {
     String inc = analysisProps.get(KEY_INCREMENTAL);
     if ("true".equals(inc)) {
-      if (validateIncremental == null || !validateIncremental.execute()) {
+      if (incrementalScannerHandler == null || !incrementalScannerHandler.execute()) {
         throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
       }
 
index a6dddc7f92e517ef54784f6213118c15e2111f42..8bc053566e5a8d14f09a8a1773f0808eece4fd57 100644 (file)
@@ -36,6 +36,23 @@ public class GlobalAnalysisMode {
   protected boolean issues;
   protected boolean mediumTestMode;
 
+  public GlobalAnalysisMode(GlobalProperties props) {
+    String mode = props.property(CoreProperties.ANALYSIS_MODE);
+    validate(mode);
+    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+    mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
+    if (preview) {
+      LOG.info("Preview mode");
+    } else if (issues) {
+      LOG.info("Issues mode");
+    } else {
+      LOG.info("Publish mode");
+    }
+    if (mediumTestMode) {
+      LOG.info("Medium test mode");
+    }
+  }
+  
   public boolean isPreview() {
     return preview;
   }
@@ -66,21 +83,4 @@ public class GlobalAnalysisMode {
     }
 
   }
-
-  public GlobalAnalysisMode(GlobalProperties props) {
-    String mode = props.property(CoreProperties.ANALYSIS_MODE);
-    validate(mode);
-    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
-    mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED));
-    if (preview) {
-      LOG.debug("Preview mode");
-    } else if (issues) {
-      LOG.debug("Issues mode");
-    } else {
-      LOG.debug("Publish mode");
-    }
-    if (mediumTestMode) {
-      LOG.info("Medium test mode");
-    }
-  }
 }
index d0f27a192453ad99d63da07359eb0ab6012c75c3..44ce642e99b1e574569f0e9750a1085f29b50e90 100644 (file)
@@ -38,14 +38,14 @@ public class DefaultAnalysisModeTest {
   private BranchConfiguration branchConfig;
   private ProjectRepositories projectRepos;
   private GlobalAnalysisMode globalMode;
-  private IncrementalScannerHandler validateIncremental;
+  private IncrementalScannerHandler incrementalScannerHandler;
 
   @Before
   public void setUp() {
     branchConfig = mock(BranchConfiguration.class);
     projectRepos = mock(ProjectRepositories.class);
     globalMode = mock(GlobalAnalysisMode.class);
-    validateIncremental = mock(IncrementalScannerHandler.class);
+    incrementalScannerHandler = mock(IncrementalScannerHandler.class);
   }
 
   @Rule
@@ -82,7 +82,7 @@ public class DefaultAnalysisModeTest {
 
   @Test
   public void no_incremental_if_not_publish() {
-    when(validateIncremental.execute()).thenReturn(true);
+    when(incrementalScannerHandler.execute()).thenReturn(true);
     AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
     thrown.expect(MessageException.class);
     thrown.expectMessage("Incremental analysis is only available in publish mode");
@@ -92,31 +92,34 @@ public class DefaultAnalysisModeTest {
   @Test
   public void no_incremental_mode_if_branches() {
     when(globalMode.isPublish()).thenReturn(true);
-    when(validateIncremental.execute()).thenReturn(true);
+    when(incrementalScannerHandler.execute()).thenReturn(true);
     when(branchConfig.branchName()).thenReturn("branch1");
     AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
     DefaultAnalysisMode analysisMode = createmode(analysisProps);
     assertThat(analysisMode.isIncremental()).isFalse();
+    assertThat(analysisMode.scanAllFiles()).isTrue();
   }
 
   @Test
   public void no_incremental_mode_if_no_previous_analysis() {
-    when(validateIncremental.execute()).thenReturn(true);
+    when(incrementalScannerHandler.execute()).thenReturn(true);
     when(globalMode.isPublish()).thenReturn(true);
     AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
     DefaultAnalysisMode analysisMode = createmode(analysisProps);
     assertThat(analysisMode.isIncremental()).isFalse();
+    assertThat(analysisMode.scanAllFiles()).isTrue();
   }
 
   @Test
   public void incremental_mode() {
-    when(validateIncremental.execute()).thenReturn(true);
+    when(incrementalScannerHandler.execute()).thenReturn(true);
     when(globalMode.isPublish()).thenReturn(true);
     when(projectRepos.lastAnalysisDate()).thenReturn(new Date());
     when(projectRepos.exists()).thenReturn(true);
     AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
     DefaultAnalysisMode analysisMode = createmode(analysisProps);
     assertThat(analysisMode.isIncremental()).isTrue();
+    assertThat(analysisMode.scanAllFiles()).isFalse();
   }
 
   @Test
@@ -144,7 +147,7 @@ public class DefaultAnalysisModeTest {
   }
 
   private DefaultAnalysisMode createmode(AnalysisProperties analysisProps) {
-    return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, validateIncremental);
+    return new DefaultAnalysisMode(analysisProps, branchConfig, globalMode, projectRepos, incrementalScannerHandler);
   }
 
 }