import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
-import java.text.MessageFormat;
import java.util.List;
import java.util.Set;
private static final Logger LOG = Loggers.get(BatchPluginPredicate.class);
private static final String BUILDBREAKER_PLUGIN_KEY = "buildbreaker";
- private static final String PROPERTY_IS_DEPRECATED_MSG = "Property {0} is deprecated. Please use {1} instead.";
private static final Joiner COMMA_JOINER = Joiner.on(", ");
private final Set<String> whites = newHashSet();
if (mode.isPreview()) {
// These default values are not supported by Settings because the class CorePlugin
// is not loaded yet.
- if (settings.hasKey(CoreProperties.DRY_RUN_INCLUDE_PLUGINS)) {
- LOG.warn(MessageFormat.format(PROPERTY_IS_DEPRECATED_MSG, CoreProperties.DRY_RUN_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS));
- whites.addAll(propertyValues(settings,
- CoreProperties.DRY_RUN_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE));
- } else {
- whites.addAll(propertyValues(settings,
- CoreProperties.PREVIEW_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE));
- }
- if (settings.hasKey(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS)) {
- LOG.warn(MessageFormat.format(PROPERTY_IS_DEPRECATED_MSG, CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS));
- blacks.addAll(propertyValues(settings,
- CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE));
- } else {
- blacks.addAll(propertyValues(settings,
- CoreProperties.PREVIEW_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE));
- }
+ whites.addAll(propertyValues(settings,
+ CoreProperties.PREVIEW_INCLUDE_PLUGINS, CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE));
+ blacks.addAll(propertyValues(settings,
+ CoreProperties.PREVIEW_EXCLUDE_PLUGINS, CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE));
}
if (!whites.isEmpty()) {
LOG.info("Include plugins: " + COMMA_JOINER.join(whites));
@Override
public boolean apply(@Nonnull String pluginKey) {
if (BUILDBREAKER_PLUGIN_KEY.equals(pluginKey) && mode.isPreview()) {
- LOG.info("Build Breaker plugin is no more supported in preview/incremental mode");
+ LOG.info("Build Breaker plugin is no more supported in preview mode");
return false;
}
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-import java.text.MessageFormat;
-
public class GlobalMode {
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(BootstrapProperties props) {
- if (props.property(CoreProperties.DRY_RUN) != null) {
- LOG.warn(MessageFormat.format("Property {0} is deprecated. Please use {1} instead.", CoreProperties.DRY_RUN, CoreProperties.ANALYSIS_MODE));
- preview = "true".equals(props.property(CoreProperties.DRY_RUN));
- } else {
- String mode = props.property(CoreProperties.ANALYSIS_MODE);
- validate(mode);
- preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode) || CoreProperties.ANALYSIS_MODE_QUICK.equals(mode);
- }
+ String mode = props.property(CoreProperties.ANALYSIS_MODE);
+ validate(mode);
+ preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+ issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
if (preview) {
LOG.info("Preview global mode");
+ } else if (issues) {
+ LOG.info("Issues global mode");
+ } else {
+ LOG.info("Publish global mode");
}
}
- private void validate(String mode) {
+ private static void validate(String mode) {
if (StringUtils.isEmpty(mode)) {
return;
}
- if (!CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode) && !CoreProperties.ANALYSIS_MODE_QUICK.equals(mode) &&
- !CoreProperties.ANALYSIS_MODE_ANALYSIS.equals(mode)) {
+ 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);
}
}
addProperties(globalReferentials.globalSettings());
addProperties(bootstrapProps.properties());
- // To stay compatible with plugins that use the old property to check mode
- if (mode.isPreview()) {
- setProperty(CoreProperties.DRY_RUN, "true");
- }
-
LOG.info("Server id: " + getString(CoreProperties.SERVER_ID));
}
*/
package org.sonar.batch.scan;
+import org.sonar.batch.mediumtest.FakePluginInstaller;
+
import org.apache.commons.lang.StringUtils;
import org.sonar.batch.bootstrap.BootstrapProperties;
import org.sonar.batch.bootstrap.AnalysisProperties;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.AnalysisMode;
-import org.sonar.batch.mediumtest.BatchMediumTester;
-import java.text.MessageFormat;
import java.util.Map;
/**
public boolean isIssues() {
return issues;
}
-
+
@Override
public boolean isPublish() {
return !preview && !issues;
}
private void load(Map<String, String> globalProps, Map<String, String> analysisProps) {
- if (getPropertyWithFallback(analysisProps, globalProps, CoreProperties.DRY_RUN) != null) {
- LOG.warn(MessageFormat.format("Property {0} is deprecated. Please use {1} instead.", CoreProperties.DRY_RUN, CoreProperties.ANALYSIS_MODE));
- preview = "true".equals(getPropertyWithFallback(analysisProps, globalProps, CoreProperties.DRY_RUN));
- } else {
- String mode = getPropertyWithFallback(analysisProps, globalProps, CoreProperties.ANALYSIS_MODE);
- validate(mode);
- preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
- issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
- }
- mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, BatchMediumTester.MEDIUM_TEST_ENABLED));
+ String mode = getPropertyWithFallback(analysisProps, globalProps, CoreProperties.ANALYSIS_MODE);
+ validate(mode);
+ preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+ issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
+ mediumTestMode = "true".equals(getPropertyWithFallback(analysisProps, globalProps, FakePluginInstaller.MEDIUM_TEST_ENABLED));
if (preview) {
LOG.info("Preview mode");
return CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode);
}
- private void validate(String mode) {
+ private static void validate(String mode) {
if (StringUtils.isEmpty(mode)) {
return;
}
- if (!CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode) && !CoreProperties.ANALYSIS_MODE_QUICK.equals(mode) &&
- !CoreProperties.ANALYSIS_MODE_ANALYSIS.equals(mode)) {
+ 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);
}
}
}
+
assertThat(predicate.apply("cobertura")).isTrue();
}
- /**
- * The properties sonar.dryRun.includePlugins and sonar.dryRun.excludePlugins
- * are deprecated. They are replaced by sonar.preview.includePlugins and
- * sonar.preview.excludePlugins.
- */
- @Test
- public void support_deprecated_dry_run_settings() {
- when(mode.isPreview()).thenReturn(true);
- settings
- .setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit")
- .setProperty(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, "views,pmd");
- BatchPluginPredicate predicate = new BatchPluginPredicate(settings, mode);
-
- assertThat(predicate.getWhites()).containsOnly("cockpit");
- assertThat(predicate.getBlacks()).containsOnly("views", "pmd");
- }
-
@Test
public void trim_inclusions_and_exclusions() {
settings
assertThat(mode.isPreview()).isFalse();
}
- @Test
- public void testDeprecatedDryRun() {
- GlobalMode mode = createMode(CoreProperties.DRY_RUN, "true");
- assertThat(mode.isPreview()).isTrue();
- }
-
private GlobalMode createMode(String key, String value) {
Map<String, String> map = new HashMap<>();
map.put(key, value);
*/
package org.sonar.batch.bootstrap;
-import org.sonar.api.CoreProperties;
-
import java.util.Collections;
-import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
}
-
- @Test
- public void support_deprecated_dry_run() {
- when(mode.isPreview()).thenReturn(true);
- GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), globalRef, mode);
- assertThat(batchSettings.getString(CoreProperties.DRY_RUN)).isEqualTo("true");
- }
@Test
public void should_log_warn_msg_for_each_jdbc_property_if_present() {
assertThat(mode.isPreview()).isTrue();
}
-
+
@Test
public void default_publish_mode() {
ProjectAnalysisMode mode = createMode(CoreProperties.ANALYSIS_MODE_PREVIEW);
assertThat(mode.isPublish()).isFalse();
-
+
mode = createMode(CoreProperties.ANALYSIS_MODE_ISSUES);
assertThat(mode.isPublish()).isFalse();
-
+
mode = createMode(null);
assertThat(mode.isPublish()).isTrue();
assertThat(mode.isIssues()).isTrue();
}
- @Test
- public void support_deprecated_dryrun_property() {
- Map<String, String> bootstrapMap = new HashMap<>();
- Map<String, String> analysisMap = new HashMap<>();
-
- analysisMap.put(CoreProperties.DRY_RUN, "true");
- bootstrapMap.put(CoreProperties.DRY_RUN, "true");
-
- ProjectAnalysisMode mode = new ProjectAnalysisMode(new BootstrapProperties(bootstrapMap), new AnalysisProperties(analysisMap));
-
- assertThat(mode.isPreview()).isTrue();
- }
-
private static ProjectAnalysisMode createMode(@Nullable String mode) {
return createMode(mode, mode);
}
}
@Test
- public void should_fail_when_accessing_secured_properties_in_dryrun() {
+ public void should_fail_when_accessing_secured_properties_in_issues_mode() {
projectRef.addSettings("struts", ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
when(mode.isIssues()).thenReturn(true);
.hidden()
.build(),
PropertyDefinition.builder(CoreProperties.PREVIEW_INCLUDE_PLUGINS)
- .deprecatedKey(CoreProperties.DRY_RUN_INCLUDE_PLUGINS)
- .name("Plugins accepted for Preview and Incremental modes")
- .description("Comma-separated list of plugin keys. Those plugins will be used during preview or incremental analyses.")
+ .name("Plugins accepted for Preview mode")
+ .description("Comma-separated list of plugin keys. Those plugins will be used during preview analyses.")
.category(CoreProperties.CATEGORY_GENERAL)
.defaultValue(CoreProperties.PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE)
.build(),
PropertyDefinition.builder(CoreProperties.PREVIEW_EXCLUDE_PLUGINS)
- .deprecatedKey(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS)
- .name("Plugins excluded for Preview and Incremental modes")
- .description("Comma-separated list of plugin keys. Those plugins will not be used during preview or incremental analyses.")
+ .name("Plugins excluded for Preview mode")
+ .description("Comma-separated list of plugin keys. Those plugins will not be used during preview analyses.")
.category(CoreProperties.CATEGORY_GENERAL)
.defaultValue(CoreProperties.PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE)
.build(),
*/
package org.sonar.api;
-import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.FileSystem;
/**
*/
String PASSWORD = "sonar.password";
- /**
- * @since 3.4
- * @deprecated since 5.1 use {@link AnalysisMode} to check existing mode
- */
- @Deprecated
- String DRY_RUN = "sonar.dryRun";
-
/**
* @since 3.5
* @deprecated since 5.2 no more task concept on batch side
String GLOBAL_WORKING_DIRECTORY = "sonar.globalWorking.directory";
String GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE = ".";
- /**
- * @since 3.4
- * @deprecated in 4.0 replaced by {@link CoreProperties#PREVIEW_INCLUDE_PLUGINS}
- */
- @Deprecated
- String DRY_RUN_INCLUDE_PLUGINS = "sonar.dryRun.includePlugins";
- /**
- * @since 3.4
- * @deprecated in 4.0 replaced by {@link CoreProperties#PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE}
- */
- @Deprecated
- String DRY_RUN_INCLUDE_PLUGINS_DEFAULT_VALUE = PREVIEW_INCLUDE_PLUGINS_DEFAULT_VALUE;
-
- /**
- * @since 3.4
- * @deprecated in 4.0 replaced by {@link CoreProperties#PREVIEW_EXCLUDE_PLUGINS}
- */
- @Deprecated
- String DRY_RUN_EXCLUDE_PLUGINS = "sonar.dryRun.excludePlugins";
- /**
- * @since 3.4
- * @deprecated in 4.0 replaced by {@link CoreProperties#PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE}
- */
- @Deprecated
- String DRY_RUN_EXCLUDE_PLUGINS_DEFAULT_VALUE = PREVIEW_EXCLUDE_PLUGINS_DEFAULT_VALUE;
-
/**
* @since 4.2
*/