*/
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;
}
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));
}
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));
- }
- }
}
--- /dev/null
+/*
+ * 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));
+ }
+ }
+
+}
*/
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) {
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));
- }
- }
}
}
@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
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
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);
*/
@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();