aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-11-07 00:38:59 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-11-07 00:38:59 +0100
commit61dcae545b51dba75728c0460d3aab541d0595e9 (patch)
treedc6b8be8ca3b98618daa24b3a56fe386e8d8db3a
parent07d2a0d30c6f11b42273659378f4ee63fcfc05e5 (diff)
downloadsonarqube-61dcae545b51dba75728c0460d3aab541d0595e9.tar.gz
sonarqube-61dcae545b51dba75728c0460d3aab541d0595e9.zip
SONAR-3895 define properties to include/exclude plugins of dry runs
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java23
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/IndexFactory.java2
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/IndexFactoryTest.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java69
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java104
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java43
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java10
14 files changed, 173 insertions, 103 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index 1713209d4ea..2816675c32e 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -323,8 +323,27 @@ import java.util.List;
global = false,
defaultValue = CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5,
category = CoreProperties.CATEGORY_DIFFERENTIAL_VIEWS),
- @Property(key = CoreProperties.DRY_RUN, defaultValue = "false", name = "Dry Run", type = PropertyType.BOOLEAN, global = false, project = false),
- @Property(key = "sonar.dryRun.export.path", defaultValue = "dryRun.json", name = "Dry Run Results Export File", type = PropertyType.STRING, global = false, project = false),
+ @Property(
+ key = CoreProperties.DRY_RUN,
+ defaultValue = "false",
+ name = "Dry Run",
+ type = PropertyType.BOOLEAN,
+ global = false, project = false),
+ @Property(
+ key = CoreProperties.DRY_RUN_INCLUDE_PLUGINS,
+ name = "Plugins accepted for dry run",
+ global = true, project = false),
+ @Property(
+ key = CoreProperties.DRY_RUN_EXCLUDE_PLUGINS,
+ name = "Plugins excluded for dry run",
+ global = true, project = false,
+ defaultValue = "devcockpit,pdfreport,report,scmactivity,views"),
+ @Property(
+ key = "sonar.dryRun.export.path",
+ defaultValue = "dryRun.json",
+ name = "Dry Run Results Export File",
+ type = PropertyType.STRING,
+ global = false, project = false),
// SERVER-SIDE TECHNICAL PROPERTIES
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/IndexFactory.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/IndexFactory.java
index 21335c46d0a..ca3f7a4323d 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/IndexFactory.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/IndexFactory.java
@@ -56,7 +56,7 @@ public class IndexFactory implements BatchExtension {
boolean crossProject = false;
if (settings.getBoolean(CoreProperties.CPD_CROSS_RPOJECT)) {
- if (settings.getBoolean("sonar.dryRun")) {
+ if (settings.getBoolean(CoreProperties.DRY_RUN)) {
logger.info("Cross-project analysis disabled. Not supported on dry runs.");
} else if (StringUtils.isNotBlank(project.getBranch())) {
logger.info("Cross-project analysis disabled. Not supported on project branches.");
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/IndexFactoryTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/IndexFactoryTest.java
index e73bffa4acc..e59da4f6a4b 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/IndexFactoryTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/IndexFactoryTest.java
@@ -63,7 +63,7 @@ public class IndexFactoryTest {
@Test
public void cross_project_should_be_disabled_on_dry_run() {
settings.setProperty(CoreProperties.CPD_CROSS_RPOJECT, "true");
- settings.setProperty("sonar.dryRun", "true");
+ settings.setProperty(CoreProperties.DRY_RUN, "true");
assertThat(factory.verifyCrossProject(project, logger)).isFalse();
verify(logger).info("Cross-project analysis disabled. Not supported on dry runs.");
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
index 8f40cd8d07e..c0dddd09215 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java
@@ -64,17 +64,15 @@ public class BatchPluginRepository implements PluginRepository {
}
void doStart(List<RemotePlugin> remotePlugins) {
- Set<String> whiteList = initWhiteList();
- Set<String> blackList = initBlackList();
-
+ PluginFilter filter = new PluginFilter(settings);
PluginInstaller extractor = new PluginInstaller();
metadataByKey = Maps.newHashMap();
for (RemotePlugin remote : remotePlugins) {
- if (isAccepted(remote.getKey(), whiteList, blackList)) {
+ if (filter.accepts(remote.getKey())) {
List<File> pluginFiles = pluginDownloader.downloadPlugin(remote);
List<File> extensionFiles = pluginFiles.subList(1, pluginFiles.size());
PluginMetadata metadata = extractor.installInSameLocation(pluginFiles.get(0), remote.isCore(), extensionFiles);
- if (StringUtils.isBlank(metadata.getBasePlugin()) || isAccepted(metadata.getBasePlugin(), whiteList, blackList)) {
+ if (StringUtils.isBlank(metadata.getBasePlugin()) || filter.accepts(metadata.getBasePlugin())) {
LOG.debug("Excluded plugin: " + metadata.getKey());
metadataByKey.put(metadata.getKey(), metadata);
}
@@ -84,24 +82,6 @@ public class BatchPluginRepository implements PluginRepository {
pluginsByKey = classLoaders.init(metadataByKey.values());
}
- private Set<String> initBlackList() {
- Set<String> blackList = null;
- if (settings.hasKey(CoreProperties.BATCH_EXCLUDE_PLUGINS)) {
- blackList = Sets.newTreeSet(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_EXCLUDE_PLUGINS)));
- LOG.info("Exclude plugins: " + Joiner.on(", ").join(blackList));
- }
- return blackList;
- }
-
- private Set<String> initWhiteList() {
- Set<String> whiteList = null;
- if (settings.hasKey(CoreProperties.BATCH_INCLUDE_PLUGINS)) {
- whiteList = Sets.newTreeSet(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_INCLUDE_PLUGINS)));
- LOG.info("Include plugins: " + Joiner.on(", ").join(whiteList));
- }
- return whiteList;
- }
-
public void stop() {
if (classLoaders != null) {
classLoaders.clean();
@@ -121,16 +101,6 @@ public class BatchPluginRepository implements PluginRepository {
return metadataByKey.get(pluginKey);
}
- static boolean isAccepted(String pluginKey, Set<String> whiteList, Set<String> blackList) {
- if (CORE_PLUGIN.equals(pluginKey) || ENGLISH_PACK_PLUGIN.equals(pluginKey)) {
- return true;
- }
- if (whiteList != null) {
- return whiteList.contains(pluginKey);
- }
- return blackList == null || !blackList.contains(pluginKey);
- }
-
public Map<PluginMetadata, Plugin> getPluginsByMetadata() {
Map<PluginMetadata, Plugin> result = Maps.newHashMap();
for (Map.Entry<String, PluginMetadata> entry : metadataByKey.entrySet()) {
@@ -140,4 +110,37 @@ public class BatchPluginRepository implements PluginRepository {
}
return result;
}
+
+ static class PluginFilter {
+ Set<String> whites = Sets.newHashSet(), blacks = Sets.newHashSet();
+
+ PluginFilter(Settings settings) {
+ if (settings.hasKey(CoreProperties.BATCH_INCLUDE_PLUGINS)) {
+ whites.addAll(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_INCLUDE_PLUGINS)));
+ }
+ if (settings.hasKey(CoreProperties.BATCH_EXCLUDE_PLUGINS)) {
+ blacks.addAll(Arrays.asList(settings.getStringArray(CoreProperties.BATCH_EXCLUDE_PLUGINS)));
+ }
+ if (settings.getBoolean(CoreProperties.DRY_RUN)) {
+ whites.addAll(Arrays.asList(settings.getStringArray(CoreProperties.DRY_RUN_INCLUDE_PLUGINS)));
+ blacks.addAll(Arrays.asList(settings.getStringArray(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS)));
+ }
+ if (!whites.isEmpty()) {
+ LOG.info("Include plugins: " + Joiner.on(", ").join(whites));
+ }
+ if (!blacks.isEmpty()) {
+ LOG.info("Exclude plugins: " + Joiner.on(", ").join(blacks));
+ }
+ }
+
+ boolean accepts(String pluginKey) {
+ if (CORE_PLUGIN.equals(pluginKey) || ENGLISH_PACK_PLUGIN.equals(pluginKey)) {
+ return true;
+ }
+ if (!whites.isEmpty()) {
+ return whites.contains(pluginKey);
+ }
+ return blacks.isEmpty() || !blacks.contains(pluginKey);
+ }
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java
index d1b0e6ee753..609253a04d3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java
@@ -42,7 +42,7 @@ public class DatabaseCompatibility implements BatchComponent {
}
public void start() {
- if (!settings.getBoolean("sonar.dryRun")) {
+ if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
checkCorrectServerId();
checkDatabaseStatus();
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
index 4651bcb0db8..0f489826345 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
@@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
@@ -60,7 +61,7 @@ public class DryRunDatabase implements BatchComponent {
}
public void start() {
- if (settings.getBoolean("sonar.dryRun")) {
+ if (settings.getBoolean(CoreProperties.DRY_RUN)) {
LOG.info("Dry run");
File databaseFile = tempDirectories.getFile("", "dryrun.h2.db");
downloadDatabase(reactor.getRoot().getKey(), databaseFile);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
index 42dbd7a414e..b480a2447c7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java
@@ -20,6 +20,7 @@
package org.sonar.batch.bootstrap;
import org.sonar.api.BatchComponent;
+import org.sonar.api.CoreProperties;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.Plugin;
import org.sonar.api.batch.InstantiationStrategy;
@@ -47,7 +48,7 @@ public class ExtensionInstaller implements BatchComponent {
}
public void install(ComponentContainer container, String instantiationStrategy) {
- boolean dryRun = settings.getBoolean("sonar.dryRun");
+ boolean dryRun = settings.getBoolean(CoreProperties.DRY_RUN);
for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) {
PluginMetadata metadata = entry.getKey();
Plugin plugin = entry.getValue();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
index 74c091e4de3..80b4f8e1e43 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
@@ -22,6 +22,7 @@ package org.sonar.batch.bootstrap;
import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.SonarException;
@@ -54,7 +55,7 @@ public class JdbcDriverHolder {
}
public void start() {
- if (!settings.getBoolean("sonar.dryRun")) {
+ if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
LOG.info("Install JDBC driver");
File jdbcDriver = new File(tempDirectories.getRoot(), "jdbc-driver.jar");
serverClient.download("/deploy/jdbc-driver.jar", jdbcDriver);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
index e58d334c104..6da2f0192bf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
@@ -20,9 +20,7 @@
package org.sonar.batch.bootstrap;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
import org.codehaus.plexus.util.FileUtils;
-import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Test;
import org.sonar.api.CoreProperties;
@@ -34,11 +32,8 @@ import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
-import java.util.Set;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -64,10 +59,10 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle));
- assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
- assertThat(repository.getMetadata().size(), Matchers.is(1));
- assertThat(repository.getMetadata("checkstyle").getName(), Matchers.is("Checkstyle"));
- assertThat(repository.getMetadata("checkstyle").getDeployedFiles().size(), Matchers.is(4)); // plugin + 3 dependencies
+ assertThat(repository.getPlugin("checkstyle")).isNotNull();
+ assertThat(repository.getMetadata()).hasSize(1);
+ assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle");
+ assertThat(repository.getMetadata("checkstyle").getDeployedFiles()).hasSize(4); // plugin + 3 dependencies
}
@Test
@@ -83,11 +78,11 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
- assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
- assertThat(repository.getPlugin("checkstyleextensions"), not(nullValue()));
- assertThat(repository.getMetadata().size(), Matchers.is(2));
- assertThat(repository.getMetadata("checkstyle").getName(), Matchers.is("Checkstyle"));
- assertThat(repository.getMetadata("checkstyleextensions").getVersion(), Matchers.is("0.1-SNAPSHOT"));
+ assertThat(repository.getPlugin("checkstyle")).isNotNull();
+ assertThat(repository.getPlugin("checkstyleextensions")).isNotNull();
+ assertThat(repository.getMetadata()).hasSize(2);
+ assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle");
+ assertThat(repository.getMetadata("checkstyleextensions").getVersion()).isEqualTo("0.1-SNAPSHOT");
}
@Test
@@ -102,10 +97,10 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle));
- assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
- assertThat(repository.getMetadata().size(), Matchers.is(1));
- assertThat(repository.getMetadata("checkstyle").getName(), Matchers.is("Checkstyle"));
- assertThat(repository.getMetadata("checkstyle").getDeployedFiles().size(), Matchers.is(5)); // plugin + 3 dependencies + 1 deprecated
+ assertThat(repository.getPlugin("checkstyle")).isNotNull();
+ assertThat(repository.getMetadata()).hasSize(1);
+ assertThat(repository.getMetadata("checkstyle").getName()).isEqualTo("Checkstyle");
+ assertThat(repository.getMetadata("checkstyle").getDeployedFiles()).hasSize(5); // plugin + 3 dependencies + 1 deprecated
// extension
}
@@ -124,7 +119,7 @@ public class BatchPluginRepositoryTest {
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
- assertThat(repository.getMetadata().size(), Matchers.is(0));
+ assertThat(repository.getMetadata()).isEmpty();
}
private List<File> copyFiles(String... filenames) throws IOException {
@@ -141,58 +136,73 @@ public class BatchPluginRepositoryTest {
@Test
public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
- repository = new BatchPluginRepository(mock(PluginDownloader.class), new Settings());
- assertThat(repository.isAccepted("pmd", null, null), Matchers.is(true));
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings());
+ assertThat(filter.accepts("pmd")).isTrue();
}
@Test
public void whiteListShouldTakePrecedenceOverBlackList() {
- Set<String> whiteList = Sets.newHashSet("checkstyle", "pmd", "findbugs");
- Set<String> blackList = Sets.newHashSet("cobertura", "pmd");
- assertThat(BatchPluginRepository.isAccepted("pmd", whiteList, blackList), Matchers.is(true));
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura,pmd");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.accepts("pmd")).isTrue();
}
@Test
public void corePluginShouldAlwaysBeInWhiteList() {
- Set<String> whiteList = Sets.newHashSet("checkstyle", "pmd", "findbugs");
- Set<String> blackList = null;
-
- assertThat(BatchPluginRepository.isAccepted("core", whiteList, blackList), Matchers.is(true));
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.accepts("core")).isTrue();
}
@Test
public void corePluginShouldNeverBeInBlackList() {
- Set<String> whiteList = null;
- Set<String> blackList = Sets.newHashSet("core", "findbugs");
-
- assertThat(BatchPluginRepository.isAccepted("core", whiteList, blackList), Matchers.is(true));
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.accepts("core")).isTrue();
}
// English Pack plugin should never be blacklisted as it is mandatory for the I18nManager on batch side
@Test
public void englishPackPluginShouldNeverBeInBlackList() {
- Set<String> whiteList = null;
- Set<String> blackList = Sets.newHashSet("l10nen", "findbugs");
- assertThat(BatchPluginRepository.isAccepted("l10nen", whiteList, blackList), Matchers.is(true));
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "l10nen,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.accepts("l10nen")).isTrue();
}
@Test
public void shouldCheckWhitelist() {
- Set<String> whiteList = Sets.newHashSet("checkstyle", "pmd", "findbugs");
- Set<String> blackList = null;
-
- assertThat(BatchPluginRepository.isAccepted("checkstyle", whiteList, blackList), Matchers.is(true));
- assertThat(BatchPluginRepository.isAccepted("pmd", whiteList, blackList), Matchers.is(true));
- assertThat(BatchPluginRepository.isAccepted("cobertura", whiteList, blackList), Matchers.is(false));
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.accepts("checkstyle")).isTrue();
+ assertThat(filter.accepts("pmd")).isTrue();
+ assertThat(filter.accepts("cobertura")).isFalse();
}
@Test
public void shouldCheckBlackListIfNoWhiteList() {
- Set<String> whiteList = null;
- Set<String> blackList = Sets.newHashSet("checkstyle", "pmd", "findbugs");
- assertThat(BatchPluginRepository.isAccepted("checkstyle", whiteList, blackList), Matchers.is(false));
- assertThat(BatchPluginRepository.isAccepted("pmd", whiteList, blackList), Matchers.is(false));
- assertThat(BatchPluginRepository.isAccepted("cobertura", whiteList, blackList), Matchers.is(true));
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.accepts("checkstyle")).isFalse();
+ assertThat(filter.accepts("pmd")).isFalse();
+ assertThat(filter.accepts("cobertura")).isTrue();
}
+ @Test
+ public void should_concatenate_dry_run_filters() {
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.DRY_RUN, true)
+ .setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit")
+ .setProperty(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, "views")
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ assertThat(filter.whites).containsOnly("cockpit");
+ assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd");
+ }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java
index 5ed24eb4fb1..a99fab4d76a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java
@@ -51,7 +51,7 @@ public class DatabaseCompatibilityTest {
settings.setProperty(DatabaseProperties.PROP_URL, "jdbc:postgresql://localhost/foo");
settings.setProperty(DatabaseProperties.PROP_USER, "bar");
settings.setProperty(CoreProperties.SERVER_ID, "123456");
- settings.setProperty("sonar.dryRun", false);
+ settings.setProperty(CoreProperties.DRY_RUN, false);
databaseVersion = mock(DatabaseVersion.class);
}
@@ -119,7 +119,7 @@ public class DatabaseCompatibilityTest {
@Test
public void should_not_verify_compatibility_if_dry_run() {
settings.setProperty(CoreProperties.SERVER_ID, "11111111");
- settings.setProperty("sonar.dryRun", true);
+ settings.setProperty(CoreProperties.DRY_RUN, true);
new DatabaseCompatibility(databaseVersion, server, settings).start();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
index 55b4b936690..ae4f2826f01 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
@@ -56,13 +57,13 @@ public class DryRunDatabaseTest {
public void setUp() {
databaseFile = new File("/tmp/dryrun.h2.db");
when(tempDirectories.getFile("", "dryrun.h2.db")).thenReturn(databaseFile);
- settings.setProperty("sonar.dryRun", true);
+ settings.setProperty(CoreProperties.DRY_RUN, true);
dryRunDatabase = new DryRunDatabase(settings, server, tempDirectories, projectReactor, mock(ProjectReactorReady.class));
}
@Test
public void should_be_disabled_if_not_dry_run() {
- settings.setProperty("sonar.dryRun", false);
+ settings.setProperty(CoreProperties.DRY_RUN, false);
dryRunDatabase.start();
verifyZeroInteractions(tempDirectories, server);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
index 57a0fd417d2..20db293ba01 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
@@ -19,6 +19,9 @@
*/
package org.sonar.batch.bootstrap;
+import com.google.common.io.Files;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -33,20 +36,23 @@ import static org.fest.assertions.Assertions.assertThat;
public class TempDirectoriesTest {
- private TempDirectories tempDirectories;
-
@Rule
public TemporaryFolder folder = new TemporaryFolder();
+ TempDirectories tempDirectories;
+ File workDir;
+ ProjectReactor reactor;
+
@Before
public void before() throws IOException {
- ProjectDefinition project = ProjectDefinition.create().setKey("foo").setWorkDir(folder.newFolder());
- ProjectReactor reactor = new ProjectReactor(project);
- tempDirectories = new TempDirectories(reactor);
+ workDir = folder.newFolder();
+ ProjectDefinition project = ProjectDefinition.create().setKey("foo").setWorkDir(workDir);
+ reactor = new ProjectReactor(project);
}
@Test
- public void should_create_root_temp_dir() {
+ public void should_create_root_temp_dir() throws IOException {
+ tempDirectories = new TempDirectories(reactor);
assertThat(tempDirectories.getRoot()).isNotNull();
assertThat(tempDirectories.getRoot()).exists();
assertThat(tempDirectories.getRoot()).isDirectory();
@@ -54,12 +60,27 @@ public class TempDirectoriesTest {
}
@Test
- public void should_accept_empty_dirname() {
+ public void should_clean_root_temp_dir_at_startup() throws IOException {
+ File tempFile = new File(workDir, "_tmp/foo.txt");
+ FileUtils.touch(tempFile);
+ assertThat(tempFile).exists();
+
+ tempDirectories = new TempDirectories(reactor);
+ assertThat(tempDirectories.getRoot().getParentFile()).isEqualTo(workDir);
+ assertThat(tempDirectories.getRoot()).exists();
+ assertThat(tempFile).doesNotExist();
+ assertThat(FileUtils.listFiles(tempDirectories.getRoot(), new String[]{"txt"}, true)).isEmpty();
+ }
+
+ @Test
+ public void should_accept_empty_dirname() throws IOException {
+ tempDirectories = new TempDirectories(reactor);
assertThat(tempDirectories.getDir("")).isEqualTo(tempDirectories.getRoot());
}
@Test
- public void should_create_sub_directory() {
+ public void should_create_sub_directory() throws IOException {
+ tempDirectories = new TempDirectories(reactor);
File findbugsDir = tempDirectories.getDir("findbugs");
assertThat(findbugsDir).isNotNull();
assertThat(findbugsDir).exists();
@@ -68,7 +89,8 @@ public class TempDirectoriesTest {
}
@Test
- public void should_delete_temp_dir_on_shutdown() {
+ public void should_delete_temp_dir_on_shutdown() throws IOException {
+ tempDirectories = new TempDirectories(reactor);
File root = tempDirectories.getRoot();
File findbugsDir = tempDirectories.getDir("findbugs");
assertThat(findbugsDir).exists();
@@ -80,7 +102,8 @@ public class TempDirectoriesTest {
}
@Test
- public void should_create_parent_directory() {
+ public void should_create_parent_directory() throws IOException {
+ tempDirectories = new TempDirectories(reactor);
File file = tempDirectories.getFile("findbugs", "bcel.jar");
assertThat(file).isNotNull();
assertThat(file.getParentFile().getName()).isEqualTo("findbugs");
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
index 5f6c01e4429..0cf49601983 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java
@@ -26,6 +26,7 @@ import org.apache.commons.lang.StringUtils;
import org.hibernate.cfg.Environment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.core.persistence.dialect.Dialect;
@@ -101,7 +102,7 @@ public class DefaultDatabase implements Database {
if (dialect == null) {
throw new IllegalStateException("Can not guess the JDBC dialect. Please check the property sonar.jdbc.url.");
}
- if (H2.ID.equals(dialect.getId()) && !settings.getBoolean("sonar.dryRun")) {
+ if (H2.ID.equals(dialect.getId()) && !settings.getBoolean(CoreProperties.DRY_RUN)) {
LoggerFactory.getLogger(DefaultDatabase.class).warn("H2 database should be used for evaluation purpose only");
}
if (!properties.containsKey("sonar.jdbc.driverClassName")) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
index 88e87de5661..43a10d9338d 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
@@ -162,6 +162,16 @@ public interface CoreProperties {
String BATCH_EXCLUDE_PLUGINS = "sonar.excludePlugins";
/**
+ * @since 3.4
+ */
+ String DRY_RUN_INCLUDE_PLUGINS = "sonar.dryRun.includePlugins";
+
+ /**
+ * @since 3.4
+ */
+ String DRY_RUN_EXCLUDE_PLUGINS = "sonar.dryRun.excludePlugins";
+
+ /**
* @since 2.10
*/
String SERVER_BASE_URL = "sonar.core.serverBaseURL";