]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6761 Drop incremental mode
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 17 Aug 2015 15:25:24 +0000 (17:25 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 18 Aug 2015 07:36:10 +0000 (09:36 +0200)
sonar-batch/src/main/java/org/sonar/batch/analysis/DefaultAnalysisMode.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractAnalysisMode.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalMode.java
sonar-batch/src/test/java/org/sonar/batch/analysis/DefaultAnalysisModeTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalModeTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/AnalysisMode.java

index 39748be741dda28d01acf031809e9b343295e9fc..c49b4f4832752aef783f96fbc6c0f450451de8fc 100644 (file)
  */
 package org.sonar.batch.analysis;
 
+import org.sonar.batch.bootstrap.AbstractAnalysisMode;
+
 import org.sonar.batch.mediumtest.FakePluginInstaller;
-import org.apache.commons.lang.StringUtils;
 import org.sonar.batch.bootstrap.GlobalProperties;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.AnalysisMode;
 
-import java.util.Arrays;
 import java.util.Map;
 
 /**
  * @since 4.0
  */
-public class DefaultAnalysisMode implements AnalysisMode {
+public class DefaultAnalysisMode extends AbstractAnalysisMode implements AnalysisMode {
 
   private static final Logger LOG = LoggerFactory.getLogger(DefaultAnalysisMode.class);
 
-  private boolean preview;
-  private boolean issues;
   private boolean mediumTestMode;
 
   public DefaultAnalysisMode(GlobalProperties globalProps, AnalysisProperties props) {
     init(globalProps.properties(), props.properties());
   }
 
-  @Override
-  public boolean isPreview() {
-    return preview;
-  }
-
-  @Override
-  public boolean isIssues() {
-    return issues;
-  }
-
-  @Override
-  public boolean isPublish() {
-    return !preview && !issues;
-  }
-
   public boolean isMediumTest() {
     return mediumTestMode;
   }
@@ -79,8 +62,7 @@ public class DefaultAnalysisMode implements AnalysisMode {
   private void load(Map<String, String> globalProps, Map<String, String> analysisProps) {
     String mode = getPropertyWithFallback(analysisProps, globalProps, CoreProperties.ANALYSIS_MODE);
     validate(mode);
-    preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
-    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
+    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
     mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED));
   }
 
@@ -111,13 +93,4 @@ public class DefaultAnalysisMode implements AnalysisMode {
     return CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
   }
 
-  private static void validate(String mode) {
-    if (StringUtils.isEmpty(mode)) {
-      return;
-    }
-
-    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/AbstractAnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AbstractAnalysisMode.java
new file mode 100644 (file)
index 0000000..61726ba
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.bootstrap;
+
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.CoreProperties;
+
+import java.util.Arrays;
+
+import org.sonar.api.batch.AnalysisMode;
+
+public abstract class AbstractAnalysisMode implements AnalysisMode {
+  protected boolean preview;
+  protected boolean issues;
+
+  protected AbstractAnalysisMode() {
+  }
+
+  public boolean isPreview() {
+    return preview;
+  }
+
+  public boolean isIssues() {
+    return issues;
+  }
+
+  public boolean isPublish() {
+    return !preview && !issues;
+  }
+
+  protected static void validate(String mode) {
+    if (StringUtils.isEmpty(mode)) {
+      return;
+    }
+
+    if (CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(mode)) {
+      throw new IllegalStateException("Invalid analysis mode: " + mode + ". This mode was removed in SonarQube 5.2. Valid modes are: " + Arrays.toString(VALID_MODES));
+    }
+
+    if (!Arrays.asList(VALID_MODES).contains(mode)) {
+      throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
+    }
+  }
+
+}
index a0f53ab8660fe548ce0ee706faa8f9ad329df708..ecfcf6346e8c3369ef89ce702ae0f48921a79616 100644 (file)
  */
 package org.sonar.batch.bootstrap;
 
-import java.util.Arrays;
+import org.sonar.api.CoreProperties;
 
 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 implements AnalysisMode {
+public class GlobalMode extends AbstractAnalysisMode implements AnalysisMode {
   private static final Logger LOG = LoggerFactory.getLogger(GlobalMode.class);
-  private boolean preview;
-  private boolean issues;
-
-  public boolean isPreview() {
-    return preview;
-  }
-
-  public boolean isIssues() {
-    return issues;
-  }
-
-  public boolean isPublish() {
-    return !preview && !issues;
-  }
 
   public GlobalMode(GlobalProperties props) {
     String mode = props.property(CoreProperties.ANALYSIS_MODE);
     validate(mode);
-    preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
-    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
-
+    issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+    
     if (preview) {
       LOG.debug("Preview global mode");
     } else if (issues) {
@@ -58,14 +41,4 @@ public class GlobalMode implements AnalysisMode {
       LOG.debug("Publish global mode");
     }
   }
-
-  private static void validate(String mode) {
-    if (StringUtils.isEmpty(mode)) {
-      return;
-    }
-
-    if (!Arrays.asList(VALID_MODES).contains(mode)) {
-      throw new IllegalStateException("Invalid analysis mode: " + mode + ". Valid modes are: " + Arrays.toString(VALID_MODES));
-    }
-  }
 }
index a6e967928c610ff1ecdf351dd7bd527b00e42400..7ea7a4088d01ef4561d44da35724d074f142cdb0 100644 (file)
@@ -61,21 +61,27 @@ public class DefaultAnalysisModeTest {
   }
 
   @Test
-  public void validate_mode() {
+  public void incremental_mode_no_longer_valid() {
     thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("[publish, issues]");
+    thrown.expectMessage("This mode was removed in SonarQube 5.2");
 
     createMode(CoreProperties.ANALYSIS_MODE_INCREMENTAL);
   }
 
   @Test
-  public void dont_support_preview_mode() {
+  public void invalidate_mode() {
     thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("[publish, issues]");
+    thrown.expectMessage("[preview, publish, issues]");
 
+    createMode("invalid");
+  }
+
+  @Test
+  public void preview_mode_fallback_issues() {
     DefaultAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PREVIEW);
 
-    assertThat(mode.isPreview()).isTrue();
+    assertThat(mode.isIssues()).isTrue();
+    assertThat(mode.isPreview()).isFalse();
   }
 
   @Test
index 366d1b80b840c0b0ece8465ca270cd25ffce3164..0bda28bd00baf148961eb2eefdadd8bd408c143b 100644 (file)
@@ -34,11 +34,11 @@ public class GlobalModeTest {
   public ExpectedException thrown = ExpectedException.none();
 
   @Test
-  public void testPreviewNotSupported() {
+  public void testModeNotSupported() {
     thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("[publish, issues]");
+    thrown.expectMessage("[preview, publish, issues]");
 
-    createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
+    createMode(CoreProperties.ANALYSIS_MODE, "invalid");
   }
 
   @Test
@@ -57,6 +57,14 @@ public class GlobalModeTest {
     assertThat(mode.isPublish()).isFalse();
   }
 
+  @Test
+  public void preview_mode_fallback_issues() {
+    GlobalMode mode = createMode(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
+
+    assertThat(mode.isIssues()).isTrue();
+    assertThat(mode.isPreview()).isFalse();
+  }
+
   @Test
   public void testDefault() {
     GlobalMode mode = createMode(null, null);
index c1f8d9d208ee94e95f60bec66b4f09243db45d1d..e0f82b7a71d69ee6940a3d2ed45e937700a705eb 100644 (file)
@@ -27,7 +27,7 @@ import org.sonar.api.CoreProperties;
  */
 @BatchSide
 public interface AnalysisMode {
-  static final String[] VALID_MODES = {CoreProperties.ANALYSIS_MODE_PUBLISH, CoreProperties.ANALYSIS_MODE_ISSUES};
+  static final String[] VALID_MODES = {CoreProperties.ANALYSIS_MODE_PREVIEW, CoreProperties.ANALYSIS_MODE_PUBLISH, CoreProperties.ANALYSIS_MODE_ISSUES};
 
   boolean isPreview();