aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-12 11:37:55 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2017-09-12 11:41:16 +0200
commitf25d5fd106a0572344a250ec14930d2250e19efb (patch)
tree10c77b739f74f290e470113355a2261d3e45342a /sonar-scanner-engine
parent9f58cea8fb7b4ba2fbe1d8b8d905010632466152 (diff)
downloadsonarqube-f25d5fd106a0572344a250ec14930d2250e19efb.tar.gz
sonarqube-f25d5fd106a0572344a250ec14930d2250e19efb.zip
SONAR-9670 Introduce sonar.branch.longLivedBranches.regex
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/DefaultAnalysisMode.java8
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/IncrementalScannerHandler.java (renamed from sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/ValidateIncremental.java)4
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java8
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/analysis/DefaultAnalysisModeTest.java53
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java27
5 files changed, 61 insertions, 39 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 534dad293ad..1e669c1a5a2 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
@@ -41,7 +41,7 @@ public class DefaultAnalysisMode implements AnalysisMode {
private final GlobalAnalysisMode analysisMode;
private final BranchConfiguration branchConfig;
private final ProjectRepositories projectRepos;
- private final ValidateIncremental validateIncremental;
+ private final IncrementalScannerHandler validateIncremental;
private boolean scanAllFiles;
private boolean incremental;
@@ -51,7 +51,7 @@ public class DefaultAnalysisMode implements AnalysisMode {
}
public DefaultAnalysisMode(AnalysisProperties props, BranchConfiguration branchConfig,
- GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable ValidateIncremental validateIncremental) {
+ GlobalAnalysisMode analysisMode, ProjectRepositories projectRepos, @Nullable IncrementalScannerHandler validateIncremental) {
this.branchConfig = branchConfig;
this.analysisMode = analysisMode;
this.projectRepos = projectRepos;
@@ -84,12 +84,12 @@ public class DefaultAnalysisMode implements AnalysisMode {
private boolean incremental() {
String inc = analysisProps.get(KEY_INCREMENTAL);
if ("true".equals(inc)) {
- if (validateIncremental == null || !validateIncremental.validate()) {
+ if (validateIncremental == null || !validateIncremental.execute()) {
throw MessageException.of("Incremental mode is not available. Please contact your administrator.");
}
if (!analysisMode.isPublish()) {
- throw new IllegalStateException("Incremental analysis is only available in publish mode");
+ throw MessageException.of("Incremental analysis is only available in publish mode");
}
if (branchConfig.branchName() != null) {
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/ValidateIncremental.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/IncrementalScannerHandler.java
index 0db769b34b3..f657598b26a 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/ValidateIncremental.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/analysis/IncrementalScannerHandler.java
@@ -19,6 +19,6 @@
*/
package org.sonar.scanner.analysis;
-public interface ValidateIncremental {
- boolean validate();
+public interface IncrementalScannerHandler {
+ boolean execute();
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java
index 4823c8ec006..9029c3ed486 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectSettingsProvider.java
@@ -23,8 +23,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.picocontainer.injectors.ProviderAdapter;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.scanner.bootstrap.GlobalConfiguration;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
+import org.sonar.scanner.bootstrap.GlobalConfiguration;
import org.sonar.scanner.repository.settings.SettingsLoader;
public class ProjectSettingsProvider extends ProviderAdapter {
@@ -36,15 +36,11 @@ public class ProjectSettingsProvider extends ProviderAdapter {
Map<String, String> settings = new LinkedHashMap<>();
settings.putAll(globalSettings.getProperties());
- settings.putAll(loadProjectSettings(settingsLoader, reactor.getRoot().getKeyWithBranch()));
+ settings.putAll(settingsLoader.load(reactor.getRoot().getKeyWithBranch()));
settings.putAll(reactor.getRoot().properties());
projectSettings = new ProjectSettings(globalSettings.getDefinitions(), globalSettings.getEncryption(), mode, settings);
}
return projectSettings;
}
-
- private Map<String, String> loadProjectSettings(SettingsLoader settingsLoader, String projectKey) {
- return settingsLoader.load(projectKey);
- }
}
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 5b68fd567a4..d0f27a19245 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
@@ -20,10 +20,12 @@
package org.sonar.scanner.analysis;
import java.util.Collections;
+import java.util.Date;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.MessageException;
import org.sonar.scanner.bootstrap.GlobalAnalysisMode;
import org.sonar.scanner.repository.ProjectRepositories;
import org.sonar.scanner.scan.branch.BranchConfiguration;
@@ -36,14 +38,14 @@ public class DefaultAnalysisModeTest {
private BranchConfiguration branchConfig;
private ProjectRepositories projectRepos;
private GlobalAnalysisMode globalMode;
- private ValidateIncremental validateIncremental;
+ private IncrementalScannerHandler validateIncremental;
@Before
public void setUp() {
branchConfig = mock(BranchConfiguration.class);
projectRepos = mock(ProjectRepositories.class);
globalMode = mock(GlobalAnalysisMode.class);
- validateIncremental = mock(ValidateIncremental.class);
+ validateIncremental = mock(IncrementalScannerHandler.class);
}
@Rule
@@ -71,6 +73,53 @@ public class DefaultAnalysisModeTest {
}
@Test
+ public void incremental_not_found() {
+ AnalysisProperties analysisProps = new AnalysisProperties(Collections.singletonMap("sonar.incremental", "true"));
+ thrown.expect(MessageException.class);
+ thrown.expectMessage("Incremental mode is not available. Please contact your administrator.");
+ createmode(analysisProps);
+ }
+
+ @Test
+ public void no_incremental_if_not_publish() {
+ when(validateIncremental.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");
+ createmode(analysisProps);
+ }
+
+ @Test
+ public void no_incremental_mode_if_branches() {
+ when(globalMode.isPublish()).thenReturn(true);
+ when(validateIncremental.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();
+ }
+
+ @Test
+ public void no_incremental_mode_if_no_previous_analysis() {
+ when(validateIncremental.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();
+ }
+
+ @Test
+ public void incremental_mode() {
+ when(validateIncremental.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();
+ }
+
+ @Test
public void scan_all_if_publish() {
when(globalMode.isIssues()).thenReturn(false);
DefaultAnalysisMode mode = createmode(new AnalysisProperties(Collections.emptyMap()));
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
index d7cb80f787e..49f1c995652 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java
@@ -19,17 +19,13 @@
*/
package org.sonar.scanner.mediumtest.tasks;
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.File;
+import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.List;
-
import org.assertj.core.api.Condition;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
import org.sonar.api.SonarPlugin;
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskDefinition;
@@ -37,7 +33,7 @@ import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
import org.sonar.scanner.mediumtest.ScannerMediumTester;
-import com.google.common.collect.ImmutableMap;
+import static org.assertj.core.api.Assertions.assertThat;
public class TasksMediumTest {
@@ -48,9 +44,6 @@ public class TasksMediumTest {
public LogTester logTester = new LogTester();
@Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- @Rule
public ScannerMediumTester tester = new ScannerMediumTester()
.registerPlugin("faketask", new FakeTaskPlugin());
@@ -90,22 +83,6 @@ public class TasksMediumTest {
.execute();
}
- @Test
- public void incrementalNotFound() throws Exception {
- File baseDir = temp.newFolder();
- thrown.expect(MessageException.class);
- thrown.expectMessage(
- "Incremental mode is not available. Please contact your administrator.");
-
- tester.newTask()
- .properties(ImmutableMap.<String, String>builder()
- .put("sonar.projectKey", "key")
- .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
- .put("sonar.sources", ".")
- .put("sonar.incremental", "true").build())
- .execute();
- }
-
private static class FakeTaskPlugin extends SonarPlugin {
@Override