summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-17 17:08:13 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-18 09:36:10 +0200
commit9060cac655bd0484b27ec74758343230712a85c4 (patch)
tree2bd3ecdbeae9b7f93c2f2a522f1ff8a3f1f56de2
parent1fd988439a81be12b536a01d0080db18026f54f9 (diff)
downloadsonarqube-9060cac655bd0484b27ec74758343230712a85c4.tar.gz
sonarqube-9060cac655bd0484b27ec74758343230712a85c4.zip
SONAR-6767 Default mode should be named publish mode
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java28
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java18
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java3
5 files changed, 39 insertions, 29 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
index 74e32685711..39748be741d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.AnalysisMode;
+import java.util.Arrays;
import java.util.Map;
/**
@@ -82,7 +83,7 @@ public class DefaultAnalysisMode implements AnalysisMode {
issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED));
}
-
+
public void printMode() {
if (preview) {
LOG.info("Preview mode");
@@ -115,9 +116,8 @@ public class DefaultAnalysisMode implements AnalysisMode {
return;
}
- if (!CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode) && !CoreProperties.ANALYSIS_MODE_PUBLISH.equals(mode) &&
- !CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode)) {
- throw new IllegalStateException("Invalid analysis mode: " + mode);
+ if (!Arrays.asList(VALID_MODES).contains(mode)) {
+ throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java
index 245ca4d5688..a0f53ab8660 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java
@@ -19,13 +19,15 @@
*/
package org.sonar.batch.bootstrap;
-import org.apache.commons.lang.StringUtils;
+import java.util.Arrays;
+import org.sonar.api.batch.AnalysisMode;
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-public class GlobalMode {
+public class GlobalMode implements AnalysisMode {
private static final Logger LOG = LoggerFactory.getLogger(GlobalMode.class);
private boolean preview;
private boolean issues;
@@ -62,9 +64,8 @@ public class GlobalMode {
return;
}
- if (!CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode) && !CoreProperties.ANALYSIS_MODE_PUBLISH.equals(mode) &&
- !CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode)) {
- throw new IllegalStateException("Invalid analysis mode: " + mode);
+ if (!Arrays.asList(VALID_MODES).contains(mode)) {
+ throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
}
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java b/sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java
index 571760dc1b6..a6e967928c6 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java
@@ -19,8 +19,10 @@
*/
package org.sonar.batch.analysis;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import org.sonar.batch.analysis.AnalysisProperties;
import javax.annotation.Nullable;
@@ -35,6 +37,8 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultAnalysisModeTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
@Test
public void regular_analysis_by_default() {
@@ -49,20 +53,26 @@ public class DefaultAnalysisModeTest {
}
@Test
- public void support_pulblish_mode() {
+ public void support_publish_mode() {
DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PUBLISH);
assertThat(mode.isPreview()).isFalse();
assertThat(mode.isPublish()).isTrue();
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void validate_mode() {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("[publish, issues]");
+
createMode(CoreProperties.ANALYSIS_MODE_INCREMENTAL);
}
@Test
- public void support_preview_mode() {
+ public void dont_support_preview_mode() {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("[publish, issues]");
+
DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PREVIEW);
assertThat(mode.isPreview()).isTrue();
@@ -70,14 +80,7 @@ public class DefaultAnalysisModeTest {
@Test
public void default_publish_mode() {
- DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PREVIEW);
- assertThat(mode.isPublish()).isFalse();
-
- mode = createMode(CoreProperties.ANALYSIS_MODE_ISSUES);
- assertThat(mode.isPublish()).isFalse();
-
- mode = createMode(null);
-
+ DefaultAnalysisMode mode = createMode(null);
assertThat(mode.isPublish()).isTrue();
}
@@ -106,4 +109,3 @@ public class DefaultAnalysisModeTest {
}
}
-
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java
index 50a8e9beb5d..366d1b80b84 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.bootstrap;
+import org.junit.Rule;
+import org.junit.rules.ExpectedException;
import org.sonar.api.CoreProperties;
import org.junit.Test;
@@ -28,12 +30,15 @@ import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
public class GlobalModeTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
- public void testPreview() {
- GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
- assertThat(mode.isPreview()).isTrue();
- assertThat(mode.isIssues()).isFalse();
- assertThat(mode.isPublish()).isFalse();
+ public void testPreviewNotSupported() {
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("[publish, issues]");
+
+ createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
}
@Test
@@ -43,7 +48,7 @@ public class GlobalModeTest {
assertThat(mode.isIssues()).isFalse();
assertThat(mode.isPublish()).isTrue();
}
-
+
@Test
public void testIssuesMode() {
GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES);
@@ -74,4 +79,3 @@ public class GlobalModeTest {
return new GlobalMode(props);
}
}
-
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java
index 904d8386674..c1f8d9d208e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java
@@ -19,12 +19,15 @@
*/
package org.sonar.api.batch;
+import org.sonar.api.CoreProperties;
+
/**
* Use this component to find the current running mode.
* @since 5.1
*/
@BatchSide
public interface AnalysisMode {
+ static final String[] VALID_MODES = {CoreProperties.ANALYSIS_MODE_PUBLISH, CoreProperties.ANALYSIS_MODE_ISSUES};
boolean isPreview();