summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-10-14 18:20:07 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-10-14 18:20:49 +0200
commit9e5187e9431abe59c832be81a230e8b957e85573 (patch)
tree0c5521254366f88d57ab48fa04bb24b94fec9b79 /sonar-batch
parent12c638ba9652a7ff7209484dc3ea66c7f565c567 (diff)
downloadsonarqube-9e5187e9431abe59c832be81a230e8b957e85573.tar.gz
sonarqube-9e5187e9431abe59c832be81a230e8b957e85573.zip
SONAR-3677 Rename dryRun -> preview and introduce sonar.analysis.mode
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/AnalysisMode.java71
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java31
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java31
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseCompatibility.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionInstaller.java21
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/PreviewDatabase.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java)52
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java19
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java17
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/UnsupportedProperties.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java13
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java62
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java67
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java31
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseCompatibilityTest.java23
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java26
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java12
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/PreviewDatabaseTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java)45
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java12
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java34
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java40
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java23
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/UnsupportedPropertiesTest.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java32
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileQueryFilterTest.java29
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java66
37 files changed, 544 insertions, 380 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AnalysisMode.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AnalysisMode.java
new file mode 100644
index 00000000000..f0872de55b2
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/AnalysisMode.java
@@ -0,0 +1,71 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.CoreProperties;
+
+import java.text.MessageFormat;
+
+/**
+ * @since 4.0
+ */
+public class AnalysisMode implements BatchComponent {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AnalysisMode.class);
+
+ private boolean preview;
+ private boolean incremental;
+
+ public AnalysisMode(BootstrapSettings bootstrapSettings) {
+ init(bootstrapSettings);
+ }
+
+ public boolean isPreview() {
+ return preview || incremental;
+ }
+
+ public boolean isIncremental() {
+ return incremental;
+ }
+
+ private void init(BootstrapSettings bootstrapSettings) {
+ if (bootstrapSettings.properties().containsKey(CoreProperties.DRY_RUN)) {
+ LOG.warn(MessageFormat.format("Property {0} is deprecated. Please use {1} instead", CoreProperties.DRY_RUN, CoreProperties.ANALYSIS_MODE));
+ preview = "true".equals(bootstrapSettings.property(CoreProperties.DRY_RUN));
+ incremental = false;
+ } else {
+ String mode = bootstrapSettings.property(CoreProperties.ANALYSIS_MODE);
+ preview = CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode);
+ incremental = CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(mode);
+ }
+ if (incremental) {
+ LOG.info("Incremental mode");
+ } else if (preview) {
+ LOG.info("Preview mode");
+ }
+ // To stay compatible with plugins that use the old property to check mode
+ if (incremental || preview) {
+ bootstrapSettings.properties().put(CoreProperties.DRY_RUN, "true");
+ }
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
index 8f58a39a4d9..0282d43e178 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchDatabase.java
@@ -29,22 +29,28 @@ import java.util.Properties;
*/
public class BatchDatabase extends DefaultDatabase {
+ private final AnalysisMode analysisMode;
+
public BatchDatabase(Settings settings,
- // The dependency on JdbcDriverHolder is required to be sure that the JDBC driver
- // has been downloaded and injected into classloader
- JdbcDriverHolder jdbcDriverHolder,
+ AnalysisMode analysisMode,
+ // The dependency on JdbcDriverHolder is required to be sure that the JDBC driver
+ // has been downloaded and injected into classloader
+ JdbcDriverHolder jdbcDriverHolder,
- // The dependency on DryRunDatabase is required to be sure that the dryRun mode
- // changed settings
- DryRunDatabase dryRun) {
+ // The dependency on DryRunDatabase is required to be sure that the dryRun mode
+ // changed settings
+ PreviewDatabase dryRun) {
super(settings);
+ this.analysisMode = analysisMode;
}
public BatchDatabase(Settings settings,
- // The dependency on JdbcDriverHolder is required to be sure that the JDBC driver
- // has been downloaded and injected into classloader
- JdbcDriverHolder jdbcDriverHolder) {
+ AnalysisMode analysisMode,
+ // The dependency on JdbcDriverHolder is required to be sure that the JDBC driver
+ // has been downloaded and injected into classloader
+ JdbcDriverHolder jdbcDriverHolder) {
super(settings);
+ this.analysisMode = analysisMode;
}
@Override
@@ -57,4 +63,11 @@ public class BatchDatabase extends DefaultDatabase {
// SONAR-2965
properties.setProperty("sonar.jdbc.defaultAutoCommit", "false");
}
+
+ @Override
+ protected void checkH2Database() {
+ if (!analysisMode.isPreview()) {
+ super.checkH2Database();
+ }
+ }
}
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 755d2a46b97..49603d683d7 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
@@ -35,6 +35,7 @@ import org.sonar.core.plugins.PluginInstaller;
import org.sonar.core.plugins.RemotePlugin;
import java.io.File;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -53,11 +54,13 @@ public class BatchPluginRepository implements PluginRepository {
private Settings settings;
private PluginClassloaders classLoaders;
private TempDirectories workingDirectories;
+ private final AnalysisMode analysisMode;
- public BatchPluginRepository(PluginDownloader pluginDownloader, TempDirectories workingDirectories, Settings settings) {
+ public BatchPluginRepository(PluginDownloader pluginDownloader, TempDirectories workingDirectories, Settings settings, AnalysisMode analysisMode) {
this.pluginDownloader = pluginDownloader;
this.workingDirectories = workingDirectories;
this.settings = settings;
+ this.analysisMode = analysisMode;
}
public void start() {
@@ -66,7 +69,7 @@ public class BatchPluginRepository implements PluginRepository {
}
void doStart(List<RemotePlugin> remotePlugins) {
- PluginFilter filter = new PluginFilter(settings);
+ PluginFilter filter = new PluginFilter(settings, analysisMode);
PluginInstaller extractor = new PluginInstaller();
metadataByKey = Maps.newHashMap();
for (RemotePlugin remote : remotePlugins) {
@@ -119,20 +122,32 @@ public class BatchPluginRepository implements PluginRepository {
static class PluginFilter {
Set<String> whites = Sets.newHashSet(), blacks = Sets.newHashSet();
- PluginFilter(Settings settings) {
+ PluginFilter(Settings settings, AnalysisMode mode) {
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)) {
+ if (mode.isPreview()) {
// These default values are not supported by Settings because the class CorePlugin
// is not loaded yet.
- whites.addAll(propertyValues(settings,
- CoreProperties.DRY_RUN_INCLUDE_PLUGINS, CoreProperties.DRY_RUN_INCLUDE_PLUGINS_DEFAULT_VALUE));
- blacks.addAll(propertyValues(settings,
- CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, CoreProperties.DRY_RUN_EXCLUDE_PLUGINS_DEFAULT_VALUE));
+ if (settings.hasKey(CoreProperties.DRY_RUN_INCLUDE_PLUGINS)) {
+ LOG.warn(MessageFormat.format("Property {0} is deprecated. Please use {1} instead", 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 {0} is deprecated. Please use {1} instead", 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));
+ }
}
if (!whites.isEmpty()) {
LOG.info("Include plugins: " + Joiner.on(", ").join(whites));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java
index 163f9dc232c..e06c8c9c433 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java
@@ -37,15 +37,17 @@ import java.util.Map;
public class BatchSettings extends Settings {
public static final String BATCH_BOOTSTRAP_PROPERTIES_URL = "/batch_bootstrap/properties";
private Configuration deprecatedConfiguration;
- private boolean dryRun;
+ private boolean preview;
private final BootstrapSettings bootstrapSettings;
private final ServerClient client;
+ private final AnalysisMode mode;
private Map<String, String> savedProperties;
public BatchSettings(BootstrapSettings bootstrapSettings, PropertyDefinitions propertyDefinitions,
- ServerClient client, Configuration deprecatedConfiguration) {
+ ServerClient client, Configuration deprecatedConfiguration, AnalysisMode mode) {
super(propertyDefinitions);
+ this.mode = mode;
getEncryption().setPathToSecretKey(bootstrapSettings.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
this.bootstrapSettings = bootstrapSettings;
this.client = client;
@@ -56,8 +58,7 @@ public class BatchSettings extends Settings {
public void init(@Nullable ProjectReactor reactor) {
savedProperties = this.getProperties();
- // Do not use getBoolean to avoid recursion
- this.dryRun = "true".equals(bootstrapSettings.property(CoreProperties.DRY_RUN));
+ this.preview = mode.isPreview();
if (reactor != null) {
LoggerFactory.getLogger(BatchSettings.class).info("Load project settings");
String branch = bootstrapSettings.property(CoreProperties.PROJECT_BRANCH_PROPERTY);
@@ -89,9 +90,9 @@ public class BatchSettings extends Settings {
private void downloadSettings(@Nullable String projectKey) {
String url;
if (StringUtils.isNotBlank(projectKey)) {
- url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?project=" + projectKey + "&dryRun=" + dryRun;
+ url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?project=" + projectKey + "&dryRun=" + preview;
} else {
- url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?dryRun=" + dryRun;
+ url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?dryRun=" + preview;
}
String jsonText = client.request(url);
List<Map<String, String>> json = (List<Map<String, String>>) JSONValue.parse(jsonText);
@@ -119,9 +120,9 @@ public class BatchSettings extends Settings {
@Override
protected void doOnGetProperties(String key) {
- if (dryRun && key.endsWith(".secured") && !key.contains(".license")) {
+ if (preview && key.endsWith(".secured") && !key.contains(".license")) {
throw new SonarException("Access to the secured property '" + key
- + "' is not possible in local (dry run) SonarQube analysis. The SonarQube plugin which requires this property must be deactivated in dry run mode.");
+ + "' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode.");
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
index 2913aad74d8..6aa2b6b31b5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java
@@ -19,8 +19,6 @@
*/
package org.sonar.batch.bootstrap;
-import org.sonar.core.purge.PurgeProfiler;
-
import org.apache.commons.configuration.PropertiesConfiguration;
import org.sonar.api.Plugin;
import org.sonar.api.config.EmailSettings;
@@ -44,6 +42,7 @@ import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.persistence.SemaphoreUpdater;
import org.sonar.core.persistence.SemaphoresImpl;
+import org.sonar.core.purge.PurgeProfiler;
import org.sonar.core.qualitymodel.DefaultModelFinder;
import org.sonar.core.rule.CacheRuleFinder;
import org.sonar.core.user.HibernateUserFinder;
@@ -79,6 +78,7 @@ public class BootstrapContainer extends ComponentContainer {
add(
new PropertiesConfiguration(),
BootstrapSettings.class,
+ AnalysisMode.class,
PluginDownloader.class,
BatchPluginRepository.class,
BatchSettings.class,
@@ -90,25 +90,23 @@ public class BootstrapContainer extends ComponentContainer {
TempDirectories.class,
HttpDownloader.class,
UriReader.class,
- new FileCacheProvider()
- );
+ new FileCacheProvider());
}
private void addDatabaseComponents() {
add(
- DryRunDatabase.class,
+ PreviewDatabase.class,
JdbcDriverHolder.class,
BatchDatabase.class,
MyBatis.class,
DatabaseVersion.class,
- //TODO check that it still works (see @Freddy)
+ // TODO check that it still works (see @Freddy)
DatabaseCompatibility.class,
DefaultDatabaseConnector.class,
JpaDatabaseSession.class,
BatchDatabaseSessionFactory.class,
DaoUtils.getDaoClasses(),
- PurgeProfiler.class
- );
+ PurgeProfiler.class);
}
/**
@@ -134,8 +132,7 @@ public class BootstrapContainer extends ComponentContainer {
PastSnapshotFinderByPreviousVersion.class,
PastMeasuresLoader.class,
PastSnapshotFinder.class,
- DefaultModelFinder.class
- );
+ DefaultModelFinder.class);
}
@Override
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 6fe7394e040..965ce42ae7f 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
@@ -34,15 +34,17 @@ public class DatabaseCompatibility implements BatchComponent {
private DatabaseVersion version;
private Settings settings;
private ServerMetadata server;
+ private AnalysisMode analysisMode;
- public DatabaseCompatibility(DatabaseVersion version, ServerMetadata server, Settings settings) {
+ public DatabaseCompatibility(DatabaseVersion version, ServerMetadata server, Settings settings, AnalysisMode mode) {
this.version = version;
this.server = server;
this.settings = settings;
+ this.analysisMode = mode;
}
public void start() {
- if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
+ if (!analysisMode.isPreview()) {
checkCorrectServerId();
checkDatabaseStatus();
}
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 8c396056f76..d51421d084c 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
@@ -19,10 +19,8 @@
*/
package org.sonar.batch.bootstrap;
-import org.sonar.api.CoreProperties;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.Plugin;
-import org.sonar.api.config.Settings;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
@@ -36,21 +34,21 @@ public class ExtensionInstaller {
private final BatchPluginRepository pluginRepository;
private final EnvironmentInformation env;
- private final Settings settings;
+ private final AnalysisMode analysisMode;
- public ExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation env, Settings settings) {
+ public ExtensionInstaller(BatchPluginRepository pluginRepository, EnvironmentInformation env, AnalysisMode analysisMode) {
this.pluginRepository = pluginRepository;
this.env = env;
- this.settings = settings;
+ this.analysisMode = analysisMode;
}
public ExtensionInstaller install(ComponentContainer container, ExtensionMatcher matcher) {
- boolean dryRun = isDryRun();
+ boolean preview = analysisMode.isPreview();
for (Map.Entry<PluginMetadata, Plugin> entry : pluginRepository.getPluginsByMetadata().entrySet()) {
PluginMetadata metadata = entry.getKey();
Plugin plugin = entry.getValue();
for (Object extension : plugin.getExtensions()) {
- doInstall(container, matcher, metadata, dryRun, extension);
+ doInstall(container, matcher, metadata, preview, extension);
}
}
List<ExtensionProvider> providers = container.getComponentsByType(ExtensionProvider.class);
@@ -58,10 +56,10 @@ public class ExtensionInstaller {
Object object = provider.provide();
if (object instanceof Iterable) {
for (Object extension : (Iterable) object) {
- doInstall(container, matcher, null, dryRun, extension);
+ doInstall(container, matcher, null, preview, extension);
}
} else {
- doInstall(container, matcher, null, dryRun, object);
+ doInstall(container, matcher, null, preview, object);
}
}
return this;
@@ -69,7 +67,7 @@ public class ExtensionInstaller {
private void doInstall(ComponentContainer container, ExtensionMatcher matcher, @Nullable PluginMetadata metadata, boolean dryRun, Object extension) {
if (ExtensionUtils.supportsEnvironment(extension, env)
- && (!dryRun || ExtensionUtils.supportsDryRun(extension))
+ && (!dryRun || ExtensionUtils.supportsPreview(extension))
&& matcher.accept(extension)) {
container.addExtension(metadata, extension);
} else {
@@ -77,7 +75,4 @@ public class ExtensionInstaller {
}
}
- private boolean isDryRun() {
- return settings.getBoolean(CoreProperties.DRY_RUN);
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
index 1111e7fbfd2..89cdaa59845 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ExtensionUtils.java
@@ -58,7 +58,7 @@ public class ExtensionUtils {
return false;
}
- public static boolean supportsDryRun(Object extension) {
+ public static boolean supportsPreview(Object extension) {
return AnnotationUtils.getAnnotation(extension, DryRunIncompatible.class) == null;
}
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 0ebd74fee9f..85777901b5c 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,8 +22,6 @@ 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;
import org.sonar.home.cache.FileCache;
@@ -43,20 +41,20 @@ public class JdbcDriverHolder {
private static final Logger LOG = LoggerFactory.getLogger(JdbcDriverHolder.class);
private ServerClient serverClient;
- private Settings settings;
+ private AnalysisMode analysisMode;
private FileCache fileCache;
// initialized in start()
private JdbcDriverClassLoader classLoader = null;
- public JdbcDriverHolder(FileCache fileCache, Settings settings, ServerClient serverClient) {
+ public JdbcDriverHolder(FileCache fileCache, AnalysisMode analysisMode, ServerClient serverClient) {
this.serverClient = serverClient;
- this.settings = settings;
+ this.analysisMode = analysisMode;
this.fileCache = fileCache;
}
public void start() {
- if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
+ if (!analysisMode.isPreview()) {
try {
LOG.info("Install JDBC driver");
String[] nameAndHash = downloadJdbcDriverIndex();
@@ -150,7 +148,7 @@ public class JdbcDriverHolder {
static class JdbcDriverClassLoader extends URLClassLoader {
public JdbcDriverClassLoader(URL jdbcDriver, ClassLoader parent) {
- super(new URL[]{jdbcDriver}, parent);
+ super(new URL[] {jdbcDriver}, parent);
}
public void clearReferencesJdbc() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/PreviewDatabase.java
index f4847877247..222a40fad01 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/PreviewDatabase.java
@@ -37,8 +37,8 @@ import java.net.SocketTimeoutException;
/**
* @since 3.4
*/
-public class DryRunDatabase implements BatchComponent {
- private static final Logger LOG = LoggerFactory.getLogger(DryRunDatabase.class);
+public class PreviewDatabase implements BatchComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(PreviewDatabase.class);
private static final String DIALECT = "h2";
private static final String DRIVER = "org.h2.Driver";
@@ -46,27 +46,25 @@ public class DryRunDatabase implements BatchComponent {
private static final String USER = "sonar";
private static final String PASSWORD = USER;
- private static final int DEFAULT_DRY_RUN_READ_TIMEOUT_SEC = 60;
+ private static final int DEFAULT_PREVIEW_READ_TIMEOUT_SEC = 60;
private final Settings settings;
private final ServerClient server;
private final TempDirectories tempDirectories;
+ private final AnalysisMode mode;
- public DryRunDatabase(Settings settings, ServerClient server, TempDirectories tempDirectories) {
+ public PreviewDatabase(Settings settings, ServerClient server, TempDirectories tempDirectories, AnalysisMode mode) {
this.settings = settings;
this.server = server;
this.tempDirectories = tempDirectories;
+ this.mode = mode;
}
public void start() {
- if (settings.getBoolean(CoreProperties.DRY_RUN)) {
- LOG.info("Preview");
- File databaseFile = tempDirectories.getFile("", "dryrun.h2.db");
-
- // SONAR-4488 Allow to increase dryRun timeout
- int readTimeoutSec = settings.getInt(CoreProperties.DRY_RUN_READ_TIMEOUT_SEC);
- readTimeoutSec = (readTimeoutSec == 0) ? DEFAULT_DRY_RUN_READ_TIMEOUT_SEC : readTimeoutSec;
+ if (mode.isPreview()) {
+ File databaseFile = tempDirectories.getFile("", "preview.h2.db");
+ int readTimeoutSec = getReadTimeout();
downloadDatabase(databaseFile, readTimeoutSec * 1000);
String databasePath = StringUtils.removeEnd(databaseFile.getAbsolutePath(), ".h2.db");
@@ -74,6 +72,20 @@ public class DryRunDatabase implements BatchComponent {
}
}
+ // SONAR-4488 Allow to increase dryRun timeout
+ private int getReadTimeout() {
+ int readTimeoutSec;
+ if (settings.hasKey(CoreProperties.DRY_RUN_READ_TIMEOUT_SEC)) {
+ LOG.warn(String.format("Property {0} is deprecated. Please use {1} instead.", CoreProperties.DRY_RUN_READ_TIMEOUT_SEC, CoreProperties.PREVIEW_READ_TIMEOUT_SEC));
+ readTimeoutSec = settings.getInt(CoreProperties.DRY_RUN_READ_TIMEOUT_SEC);
+ } else if (settings.hasKey(CoreProperties.PREVIEW_READ_TIMEOUT_SEC)) {
+ readTimeoutSec = settings.getInt(CoreProperties.PREVIEW_READ_TIMEOUT_SEC);
+ } else {
+ readTimeoutSec = DEFAULT_PREVIEW_READ_TIMEOUT_SEC;
+ }
+ return readTimeoutSec;
+ }
+
private void downloadDatabase(File toFile, int readTimeout) {
String projectKey = null;
try {
@@ -98,9 +110,9 @@ public class DryRunDatabase implements BatchComponent {
Throwable rootCause = Throwables.getRootCause(e);
if (rootCause instanceof SocketTimeoutException) {
// Pico will unwrap the first runtime exception
- throw new SonarException(new SonarException(String.format("DryRun database read timed out after %s ms. You can try to increase read timeout with property -D"
- + CoreProperties.DRY_RUN_READ_TIMEOUT_SEC + " (in seconds)",
- readTimeout), e));
+ throw new SonarException(new SonarException(String.format("Preview database read timed out after %s ms. You can try to increase read timeout with property -D"
+ + CoreProperties.PREVIEW_READ_TIMEOUT_SEC + " (in seconds)",
+ readTimeout), e));
}
if (projectKey != null && (rootCause instanceof HttpException) && (((HttpException) rootCause).getResponseCode() == 401)) {
// Pico will unwrap the first runtime exception
@@ -110,11 +122,11 @@ public class DryRunDatabase implements BatchComponent {
private void replaceSettings(String databasePath) {
settings
- .removeProperty("sonar.jdbc.schema")
- .setProperty(DatabaseProperties.PROP_DIALECT, DIALECT)
- .setProperty(DatabaseProperties.PROP_DRIVER, DRIVER)
- .setProperty(DatabaseProperties.PROP_USER, USER)
- .setProperty(DatabaseProperties.PROP_PASSWORD, PASSWORD)
- .setProperty(DatabaseProperties.PROP_URL, URL + databasePath);
+ .removeProperty("sonar.jdbc.schema")
+ .setProperty(DatabaseProperties.PROP_DIALECT, DIALECT)
+ .setProperty(DatabaseProperties.PROP_DRIVER, DRIVER)
+ .setProperty(DatabaseProperties.PROP_USER, USER)
+ .setProperty(DatabaseProperties.PROP_PASSWORD, PASSWORD)
+ .setProperty(DatabaseProperties.PROP_URL, URL + databasePath);
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java
index 6668001f9b7..183bbae1e0c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuePersister.java
@@ -21,9 +21,8 @@ package org.sonar.batch.issue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.api.issue.internal.DefaultIssue;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.index.ScanPersister;
/**
@@ -35,18 +34,18 @@ public class IssuePersister implements ScanPersister {
private final IssueCache issueCache;
private final ScanIssueStorage storage;
- private Settings settings;
+ private AnalysisMode analysisMode;
- public IssuePersister(IssueCache issueCache, ScanIssueStorage storage, Settings settings) {
+ public IssuePersister(IssueCache issueCache, ScanIssueStorage storage, AnalysisMode analysisMode) {
this.issueCache = issueCache;
this.storage = storage;
- this.settings = settings;
+ this.analysisMode = analysisMode;
}
@Override
public void persist() {
- if (settings.getBoolean(CoreProperties.DRY_RUN)) {
- LOG.debug("IssuePersister skipped in dryRun");
+ if (analysisMode.isPreview()) {
+ LOG.debug("IssuePersister skipped in preview mode");
return;
}
Iterable<DefaultIssue> issues = issueCache.all();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
index dc338ddd360..bbc78302893 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
@@ -30,6 +30,7 @@ import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.index.ResourcePersister;
@@ -48,35 +49,37 @@ public class UpdateStatusJob implements BatchComponent {
private ResourcePersister resourcePersister;
private Settings settings;
private Project project;
+ private AnalysisMode analysisMode;
public UpdateStatusJob(Settings settings, ServerClient server, DatabaseSession session,
- ResourcePersister resourcePersister, Project project, Snapshot snapshot) {
+ ResourcePersister resourcePersister, Project project, Snapshot snapshot, AnalysisMode analysisMode) {
this.session = session;
this.server = server;
this.resourcePersister = resourcePersister;
this.project = project;
this.snapshot = snapshot;
this.settings = settings;
+ this.analysisMode = analysisMode;
}
public void execute() {
disablePreviousSnapshot();
enableCurrentSnapshot();
- evictDryRunDB();
+ evictPreviewDB();
}
@VisibleForTesting
- void evictDryRunDB() {
- if (settings.getBoolean(CoreProperties.DRY_RUN)) {
- // If this is a dryRun analysis then we should not evict dryRun database
+ void evictPreviewDB() {
+ if (analysisMode.isPreview()) {
+ // If this is a preview analysis then we should not evict remote preview database
return;
}
String url = "/batch_bootstrap/evict?project=" + project.getId();
try {
- LOG.debug("Evict dryRun database");
+ LOG.debug("Evict preview database");
server.request(url);
} catch (Exception e) {
- throw new SonarException("Unable to evict dryRun database: " + url, e);
+ throw new SonarException("Unable to evict preview database: " + url, e);
}
}
@@ -103,7 +106,7 @@ public class UpdateStatusJob implements BatchComponent {
@VisibleForTesting
void logSuccess(Logger logger) {
- if (settings.getBoolean(CoreProperties.DRY_RUN)) {
+ if (analysisMode.isPreview()) {
logger.info("ANALYSIS SUCCESSFUL");
} else {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
index eeb39aa6cdb..226a3d6751a 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
@@ -20,8 +20,6 @@
package org.sonar.batch.scan;
import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
@@ -29,18 +27,19 @@ import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.ResourceUtils;
import org.sonar.api.utils.HttpDownloader;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
import javax.persistence.Query;
public class LastSnapshots implements BatchComponent {
- private final Settings settings;
+ private final AnalysisMode analysisMode;
private final DatabaseSession session;
private final ServerClient server;
- public LastSnapshots(Settings settings, DatabaseSession session, ServerClient server) {
- this.settings = settings;
+ public LastSnapshots(AnalysisMode analysisMode, DatabaseSession session, ServerClient server) {
+ this.analysisMode = analysisMode;
this.session = session;
this.server = server;
}
@@ -48,7 +47,7 @@ public class LastSnapshots implements BatchComponent {
public String getSource(Resource resource) {
String source = "";
if (ResourceUtils.isFile(resource)) {
- if (settings.getBoolean(CoreProperties.DRY_RUN)) {
+ if (analysisMode.isPreview()) {
source = loadSourceFromWs(resource);
} else {
source = loadSourceFromDb(resource);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
index 956711a1d70..996fb1e60a7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java
@@ -28,6 +28,7 @@ import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.BatchSettings;
import org.sonar.batch.bootstrap.ServerClient;
@@ -44,14 +45,14 @@ import static org.sonar.batch.bootstrap.BatchSettings.BATCH_BOOTSTRAP_PROPERTIES
public class ModuleSettings extends Settings {
private final Configuration deprecatedCommonsConf;
- private boolean dryRun;
private final ServerClient client;
+ private AnalysisMode analysisMode;
- public ModuleSettings(BatchSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, ServerClient client) {
+ public ModuleSettings(BatchSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, ServerClient client, AnalysisMode analysisMode) {
super(batchSettings.getDefinitions());
this.client = client;
+ this.analysisMode = analysisMode;
getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
- this.dryRun = "true".equals(batchSettings.getString(CoreProperties.DRY_RUN));
LoggerFactory.getLogger(ModuleSettings.class).info("Load module settings");
this.deprecatedCommonsConf = deprecatedCommonsConf;
@@ -77,7 +78,7 @@ public class ModuleSettings extends Settings {
}
private void downloadSettings(String moduleKey) {
- String url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?project=" + moduleKey + "&dryRun=" + dryRun;
+ String url = BATCH_BOOTSTRAP_PROPERTIES_URL + "?project=" + moduleKey + "&dryRun=" + analysisMode.isPreview();
String jsonText = client.request(url);
List<Map<String, String>> json = (List<Map<String, String>>) JSONValue.parse(jsonText);
for (Map<String, String> jsonProperty : json) {
@@ -124,9 +125,9 @@ public class ModuleSettings extends Settings {
@Override
protected void doOnGetProperties(String key) {
- if (this.dryRun && key.endsWith(".secured") && !key.contains(".license")) {
+ if (analysisMode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
throw new SonarException("Access to the secured property '" + key
- + "' is not possible in local (dry run) SonarQube analysis. The SonarQube plugin which requires this property must be deactivated in dry run mode.");
+ + "' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode.");
}
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java
index 2f51d525153..a21b1bbd93b 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectLock.java
@@ -22,12 +22,11 @@ package org.sonar.batch.scan;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.Semaphores;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.ProjectTree;
+import org.sonar.batch.bootstrap.AnalysisMode;
public class ProjectLock {
@@ -35,16 +34,16 @@ public class ProjectLock {
private final Semaphores semaphores;
private final ProjectTree projectTree;
- private final Settings settings;
+ private final AnalysisMode analysisMode;
- public ProjectLock(Semaphores semaphores, ProjectTree projectTree, Settings settings) {
+ public ProjectLock(Semaphores semaphores, ProjectTree projectTree, AnalysisMode analysisMode) {
this.semaphores = semaphores;
this.projectTree = projectTree;
- this.settings = settings;
+ this.analysisMode = analysisMode;
}
public void start() {
- if (!isInDryRunMode() && StringUtils.isNotBlank(getProject().getKey())) {
+ if (!analysisMode.isPreview() && StringUtils.isNotBlank(getProject().getKey())) {
Semaphores.Semaphore semaphore = acquire();
if (!semaphore.isLocked()) {
LOG.error(getErrorMessage(semaphore));
@@ -62,7 +61,7 @@ public class ProjectLock {
}
public void stop() {
- if (!isInDryRunMode()) {
+ if (!analysisMode.isPreview()) {
release();
}
}
@@ -84,8 +83,4 @@ public class ProjectLock {
private Project getProject() {
return projectTree.getRootProject();
}
-
- private boolean isInDryRunMode() {
- return settings.getBoolean(CoreProperties.DRY_RUN);
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/UnsupportedProperties.java b/sonar-batch/src/main/java/org/sonar/batch/scan/UnsupportedProperties.java
index cce1d037c06..c521f261d9c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/UnsupportedProperties.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/UnsupportedProperties.java
@@ -20,7 +20,6 @@
package org.sonar.batch.scan;
import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
@@ -33,7 +32,6 @@ public class UnsupportedProperties implements BatchComponent {
public void start() {
verify("sonar.light", "The property 'sonar.light' is no longer supported. Please use 'sonar.dynamicAnalysis'");
- verifyIncrementalPreviewMode();
}
private void verify(String key, String message) {
@@ -41,10 +39,4 @@ public class UnsupportedProperties implements BatchComponent {
throw MessageException.of(message);
}
}
-
- private void verifyIncrementalPreviewMode() {
- if (settings.getBoolean(CoreProperties.INCREMENTAL_PREVIEW) && !settings.getBoolean(CoreProperties.DRY_RUN)) {
- throw MessageException.of("Incremental mode is only supported with preview mode");
- }
- }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index 571088ac7cb..f37c3021b66 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -32,8 +32,10 @@ import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.InputFiles;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
+import org.sonar.batch.bootstrap.AnalysisMode;
import javax.annotation.CheckForNull;
+
import java.io.File;
import java.nio.charset.Charset;
import java.util.List;
@@ -55,16 +57,18 @@ public class DefaultModuleFileSystem implements ModuleFileSystem, Startable {
private List<File> binaryDirs = Lists.newArrayList();
private List<File> sourceFiles = Lists.newArrayList();
private List<File> testFiles = Lists.newArrayList();
+ private AnalysisMode analysisMode;
- public DefaultModuleFileSystem(ProjectDefinition module, Settings settings, FileIndex index, ModuleFileSystemInitializer initializer) {
- this(module.getKey(), settings, index, initializer);
+ public DefaultModuleFileSystem(ProjectDefinition module, Settings settings, FileIndex index, ModuleFileSystemInitializer initializer, AnalysisMode analysisMode) {
+ this(module.getKey(), settings, index, initializer, analysisMode);
}
@VisibleForTesting
- DefaultModuleFileSystem(String moduleKey, Settings settings, FileIndex index, ModuleFileSystemInitializer initializer) {
+ DefaultModuleFileSystem(String moduleKey, Settings settings, FileIndex index, ModuleFileSystemInitializer initializer, AnalysisMode analysisMode) {
this.moduleKey = moduleKey;
this.settings = settings;
this.index = index;
+ this.analysisMode = analysisMode;
this.baseDir = initializer.baseDir();
this.workingDir = initializer.workingDir();
this.buildDir = initializer.buildDir();
@@ -141,7 +145,7 @@ public class DefaultModuleFileSystem implements ModuleFileSystem, Startable {
@Override
public Iterable<InputFile> inputFiles(FileQuery query) {
List<InputFile> result = Lists.newArrayList();
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(analysisMode, query);
for (InputFile input : index.inputFiles(moduleKey)) {
if (filter.accept(input)) {
result.add(input);
@@ -189,7 +193,6 @@ public class DefaultModuleFileSystem implements ModuleFileSystem, Startable {
return builder.build();
}
-
@Override
public boolean equals(Object o) {
if (this == o) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java
index a273903d3cb..82f831eac1f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/FileQueryFilter.java
@@ -21,11 +21,10 @@ package org.sonar.batch.scan.filesystem;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.InputFileFilter;
+import org.sonar.batch.bootstrap.AnalysisMode;
import java.util.Collection;
import java.util.List;
@@ -35,7 +34,7 @@ class FileQueryFilter {
private final List<InputFileFilter> filters;
- FileQueryFilter(Settings settings, FileQuery query) {
+ FileQueryFilter(AnalysisMode analysisMode, FileQuery query) {
filters = Lists.newArrayList();
for (String pattern : query.inclusions()) {
filters.add(new InclusionFilter(pattern));
@@ -48,7 +47,7 @@ class FileQueryFilter {
}
// TODO speed-up the following algorithm. Cache ?
- if (settings.getBoolean(CoreProperties.INCREMENTAL_PREVIEW)) {
+ if (analysisMode.isIncremental()) {
Collection<String> status = query.attributes().get(InputFile.ATTRIBUTE_STATUS);
if (status == null || status.isEmpty()) {
// TODO should be not(SAME) instead of is(ADDED, CHANGED)
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java
index 81c9f8d4a1e..b384130468c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ComponentSelectorFactory.java
@@ -20,22 +20,21 @@
package org.sonar.batch.scan.report;
import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.scan.filesystem.InputFileCache;
public class ComponentSelectorFactory implements BatchComponent {
private final InputFileCache fileCache;
- private final Settings settings;
+ private final AnalysisMode mode;
- public ComponentSelectorFactory(InputFileCache fileCache, Settings settings) {
+ public ComponentSelectorFactory(InputFileCache fileCache, AnalysisMode mode) {
this.fileCache = fileCache;
- this.settings = settings;
+ this.mode = mode;
}
public ComponentSelector create() {
- if (settings.getBoolean(CoreProperties.INCREMENTAL_PREVIEW)) {
+ if (mode.isIncremental()) {
return new IncrementalComponentSelector(fileCache);
}
return new DefaultComponentSelector();
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
index 049cff49360..e43dd40be50 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JsonReport.java
@@ -25,7 +25,6 @@ import com.google.gson.stream.JsonWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.platform.Server;
@@ -33,12 +32,17 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.events.BatchStepEvent;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.issue.IssueCache;
import org.sonar.core.i18n.RuleI18nManager;
-import java.io.*;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
import java.util.Locale;
import java.util.Set;
@@ -58,15 +62,16 @@ public class JsonReport implements BatchComponent {
private final IssueCache issueCache;
private final EventBus eventBus;
private final ComponentSelector componentSelector;
+ private AnalysisMode analysisMode;
public JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleI18nManager ruleI18nManager, IssueCache issueCache,
- EventBus eventBus, ComponentSelectorFactory componentSelectorFactory) {
- this(settings, fileSystem, server, ruleI18nManager, issueCache, eventBus, componentSelectorFactory.create());
+ EventBus eventBus, ComponentSelectorFactory componentSelectorFactory, AnalysisMode mode) {
+ this(settings, fileSystem, server, ruleI18nManager, issueCache, eventBus, componentSelectorFactory.create(), mode);
}
@VisibleForTesting
JsonReport(Settings settings, ModuleFileSystem fileSystem, Server server, RuleI18nManager ruleI18nManager, IssueCache issueCache,
- EventBus eventBus, ComponentSelector componentSelector) {
+ EventBus eventBus, ComponentSelector componentSelector, AnalysisMode analysisMode) {
this.settings = settings;
this.fileSystem = fileSystem;
this.server = server;
@@ -74,10 +79,11 @@ public class JsonReport implements BatchComponent {
this.issueCache = issueCache;
this.eventBus = eventBus;
this.componentSelector = componentSelector;
+ this.analysisMode = analysisMode;
}
public void execute() {
- if (settings.getBoolean(CoreProperties.DRY_RUN)) {
+ if (analysisMode.isPreview()) {
eventBus.fireEvent(new BatchStepEvent("JSON report", true));
exportResults();
eventBus.fireEvent(new BatchStepEvent("JSON report", false));
@@ -128,19 +134,19 @@ public class JsonReport implements BatchComponent {
for (DefaultIssue issue : getIssues()) {
if (issue.resolution() == null && componentSelector.register(issue)) {
json
- .beginObject()
- .name("key").value(issue.key())
- .name("component").value(issue.componentKey())
- .name("line").value(issue.line())
- .name("message").value(issue.message())
- .name("severity").value(issue.severity())
- .name("rule").value(issue.ruleKey().toString())
- .name("status").value(issue.status())
- .name("resolution").value(issue.resolution())
- .name("isNew").value(issue.isNew())
- .name("reporter").value(issue.reporter())
- .name("assignee").value(issue.assignee())
- .name("effortToFix").value(issue.effortToFix());
+ .beginObject()
+ .name("key").value(issue.key())
+ .name("component").value(issue.componentKey())
+ .name("line").value(issue.line())
+ .name("message").value(issue.message())
+ .name("severity").value(issue.severity())
+ .name("rule").value(issue.ruleKey().toString())
+ .name("status").value(issue.status())
+ .name("resolution").value(issue.resolution())
+ .name("isNew").value(issue.isNew())
+ .name("reporter").value(issue.reporter())
+ .name("assignee").value(issue.assignee())
+ .name("effortToFix").value(issue.effortToFix());
if (issue.creationDate() != null) {
json.name("creationDate").value(DateUtils.formatDateTime(issue.creationDate()));
}
@@ -161,9 +167,9 @@ public class JsonReport implements BatchComponent {
json.name("components").beginArray();
for (String componentKey : componentSelector.componentKeys()) {
json
- .beginObject()
- .name("key").value(componentKey)
- .endObject();
+ .beginObject()
+ .name("key").value(componentKey)
+ .endObject();
}
json.endArray();
}
@@ -172,12 +178,12 @@ public class JsonReport implements BatchComponent {
json.name("rules").beginArray();
for (RuleKey ruleKey : ruleKeys) {
json
- .beginObject()
- .name("key").value(ruleKey.toString())
- .name("rule").value(ruleKey.rule())
- .name("repository").value(ruleKey.repository())
- .name("name").value(getRuleName(ruleKey))
- .endObject();
+ .beginObject()
+ .name("key").value(ruleKey.toString())
+ .name("rule").value(ruleKey.rule())
+ .name("repository").value(ruleKey.repository())
+ .name("name").value(getRuleName(ruleKey))
+ .endObject();
}
json.endArray();
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java
index 042c2d98bd6..06e1b72b5e0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchDatabaseTest.java
@@ -30,7 +30,7 @@ import static org.mockito.Mockito.mock;
public class BatchDatabaseTest {
@Test
public void should_init_at_least_two_connections() {
- BatchDatabase db = new BatchDatabase(new Settings(), mock(JdbcDriverHolder.class), mock(DryRunDatabase.class));
+ BatchDatabase db = new BatchDatabase(new Settings(), mock(AnalysisMode.class), mock(JdbcDriverHolder.class), mock(PreviewDatabase.class));
Properties props = new Properties();
db.doCompleteProperties(props);
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 04ac097df7a..56cdc053f3c 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
@@ -22,6 +22,7 @@ package org.sonar.batch.bootstrap;
import com.google.common.collect.Lists;
import org.codehaus.plexus.util.FileUtils;
import org.junit.After;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -46,6 +47,12 @@ public class BatchPluginRepositoryTest {
public TemporaryFolder temp = new TemporaryFolder();
private BatchPluginRepository repository;
+ private AnalysisMode mode;
+
+ @Before
+ public void before() {
+ mode = mock(AnalysisMode.class);
+ }
@After
public void tearDown() {
@@ -64,7 +71,7 @@ public class BatchPluginRepositoryTest {
PluginDownloader downloader = mock(PluginDownloader.class);
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar"));
- repository = new BatchPluginRepository(downloader, tempDirs, new Settings());
+ repository = new BatchPluginRepository(downloader, tempDirs, new Settings(), mode);
repository.doStart(Arrays.asList(checkstyle));
@@ -88,7 +95,7 @@ public class BatchPluginRepositoryTest {
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar"));
when(downloader.downloadPlugin(checkstyleExt)).thenReturn(copyFiles("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
- repository = new BatchPluginRepository(downloader, tempDirs, new Settings());
+ repository = new BatchPluginRepository(downloader, tempDirs, new Settings(), mode);
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
@@ -110,7 +117,7 @@ public class BatchPluginRepositoryTest {
PluginDownloader downloader = mock(PluginDownloader.class);
when(downloader.downloadPlugin(checkstyle)).thenReturn(copyFiles("sonar-checkstyle-plugin-2.8.jar", "checkstyle-ext.xml"));
- repository = new BatchPluginRepository(downloader, tempDirs, new Settings());
+ repository = new BatchPluginRepository(downloader, tempDirs, new Settings(), mode);
repository.doStart(Arrays.asList(checkstyle));
@@ -137,7 +144,7 @@ public class BatchPluginRepositoryTest {
Settings settings = new Settings();
settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle");
- repository = new BatchPluginRepository(downloader, tempDirs, settings);
+ repository = new BatchPluginRepository(downloader, tempDirs, settings, mode);
repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
@@ -158,32 +165,32 @@ public class BatchPluginRepositoryTest {
@Test
public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
- BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings());
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(new Settings(), mode);
assertThat(filter.accepts("pmd")).isTrue();
}
@Test
public void whiteListShouldTakePrecedenceOverBlackList() {
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);
+ .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs")
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "cobertura,pmd");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.accepts("pmd")).isTrue();
}
@Test
public void corePluginShouldAlwaysBeInWhiteList() {
Settings settings = new Settings()
- .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.accepts("core")).isTrue();
}
@Test
public void corePluginShouldNeverBeInBlackList() {
Settings settings = new Settings()
- .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
- BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "core,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.accepts("core")).isTrue();
}
@@ -191,16 +198,16 @@ public class BatchPluginRepositoryTest {
@Test
public void englishPackPluginShouldNeverBeInBlackList() {
Settings settings = new Settings()
- .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "l10nen,findbugs");
- BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "l10nen,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.accepts("l10nen")).isTrue();
}
@Test
public void shouldCheckWhitelist() {
Settings settings = new Settings()
- .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ .setProperty(CoreProperties.BATCH_INCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.accepts("checkstyle")).isTrue();
assertThat(filter.accepts("pmd")).isTrue();
assertThat(filter.accepts("cobertura")).isFalse();
@@ -209,21 +216,33 @@ public class BatchPluginRepositoryTest {
@Test
public void shouldCheckBlackListIfNoWhiteList() {
Settings settings = new Settings()
- .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
- BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings);
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd,findbugs");
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.accepts("checkstyle")).isFalse();
assertThat(filter.accepts("pmd")).isFalse();
assertThat(filter.accepts("cobertura")).isTrue();
}
@Test
- public void should_concatenate_dry_run_filters() {
+ public void should_concatenate_preview_filters() {
+ Settings settings = new Settings()
+ .setProperty(CoreProperties.PREVIEW_INCLUDE_PLUGINS, "cockpit")
+ .setProperty(CoreProperties.PREVIEW_EXCLUDE_PLUGINS, "views")
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd");
+ when(mode.isPreview()).thenReturn(true);
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
+ assertThat(filter.whites).containsOnly("cockpit");
+ assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd");
+ }
+
+ @Test
+ public void should_concatenate_deprecated_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);
+ .setProperty(CoreProperties.DRY_RUN_INCLUDE_PLUGINS, "cockpit")
+ .setProperty(CoreProperties.DRY_RUN_EXCLUDE_PLUGINS, "views")
+ .setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle,pmd");
+ when(mode.isPreview()).thenReturn(true);
+ BatchPluginRepository.PluginFilter filter = new BatchPluginRepository.PluginFilter(settings, mode);
assertThat(filter.whites).containsOnly("cockpit");
assertThat(filter.blacks).containsOnly("views", "checkstyle", "pmd");
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java
index 396b2d4be3a..0c67862db73 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java
@@ -56,9 +56,12 @@ public class BatchSettingsTest {
Configuration deprecatedConf = new BaseConfiguration();
BootstrapSettings bootstrapSettings;
+ private AnalysisMode mode;
+
@Before
public void prepare() {
- bootstrapSettings = new BootstrapSettings(new BootstrapProperties(Collections.<String, String> emptyMap()));
+ bootstrapSettings = new BootstrapSettings(new BootstrapProperties(Collections.<String, String>emptyMap()));
+ mode = mock(AnalysisMode.class);
}
@Test
@@ -66,9 +69,9 @@ public class BatchSettingsTest {
when(client.request("/batch_bootstrap/properties?dryRun=false")).thenReturn(JSON_RESPONSE);
System.setProperty("BatchSettingsTest.testSystemProp", "system");
// Reconstruct bootstrap settings to get system property
- bootstrapSettings = new BootstrapSettings(new BootstrapProperties(Collections.<String, String> emptyMap()));
+ bootstrapSettings = new BootstrapSettings(new BootstrapProperties(Collections.<String, String>emptyMap()));
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
assertThat(batchSettings.getString("BatchSettingsTest.testSystemProp")).isEqualTo("system");
}
@@ -79,7 +82,7 @@ public class BatchSettingsTest {
when(client.request("/batch_bootstrap/properties?project=struts&dryRun=false")).thenReturn(REACTOR_JSON_RESPONSE);
project.setProperty("project.prop", "project");
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
batchSettings.init(new ProjectReactor(project));
assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
@@ -89,7 +92,7 @@ public class BatchSettingsTest {
public void should_load_global_settings() {
when(client.request("/batch_bootstrap/properties?dryRun=false")).thenReturn(JSON_RESPONSE);
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
}
@@ -99,7 +102,7 @@ public class BatchSettingsTest {
when(client.request("/batch_bootstrap/properties?dryRun=false")).thenReturn(JSON_RESPONSE);
when(client.request("/batch_bootstrap/properties?project=struts&dryRun=false")).thenReturn(REACTOR_JSON_RESPONSE);
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
batchSettings.init(new ProjectReactor(project));
assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
@@ -112,7 +115,7 @@ public class BatchSettingsTest {
bootstrapSettings.properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "mybranch");
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
batchSettings.init(new ProjectReactor(project));
assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
@@ -123,7 +126,7 @@ public class BatchSettingsTest {
when(client.request("/batch_bootstrap/properties?dryRun=false")).thenReturn(JSON_RESPONSE_WITH_SECURED);
when(client.request("/batch_bootstrap/properties?project=struts&dryRun=false")).thenReturn(REACTOR_JSON_RESPONSE);
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
batchSettings.init(new ProjectReactor(project));
assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
@@ -135,15 +138,15 @@ public class BatchSettingsTest {
when(client.request("/batch_bootstrap/properties?dryRun=true")).thenReturn(JSON_RESPONSE_WITH_SECURED);
when(client.request("/batch_bootstrap/properties?project=struts&dryRun=true")).thenReturn(REACTOR_JSON_RESPONSE);
- bootstrapSettings.properties().put(CoreProperties.DRY_RUN, "true");
+ when(mode.isPreview()).thenReturn(true);
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
batchSettings.init(new ProjectReactor(project));
assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
thrown.expect(SonarException.class);
thrown
- .expectMessage("Access to the secured property 'sonar.foo.secured' is not possible in local (dry run) SonarQube analysis. The SonarQube plugin which requires this property must be deactivated in dry run mode.");
+ .expectMessage("Access to the secured property 'sonar.foo.secured' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode.");
batchSettings.getString("sonar.foo.secured");
}
@@ -153,7 +156,7 @@ public class BatchSettingsTest {
System.setProperty("BatchSettingsTest.testSystemProp", "system");
project.setProperty("BatchSettingsTest.testSystemProp", "build");
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
assertThat(batchSettings.getString("BatchSettingsTest.testSystemProp")).isEqualTo("system");
}
@@ -163,7 +166,7 @@ public class BatchSettingsTest {
when(client.request("/batch_bootstrap/properties?dryRun=false")).thenReturn(JSON_RESPONSE);
when(client.request("/batch_bootstrap/properties?project=struts&dryRun=false")).thenReturn(REACTOR_JSON_RESPONSE);
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
batchSettings.init(new ProjectReactor(project));
assertThat(deprecatedConf.getString("sonar.cpd.cross")).isEqualTo("true");
@@ -181,7 +184,7 @@ public class BatchSettingsTest {
@Test
public void project_should_be_optional() {
when(client.request("/batch_bootstrap/properties?dryRun=false")).thenReturn(JSON_RESPONSE);
- BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf);
+ BatchSettings batchSettings = new BatchSettings(bootstrapSettings, new PropertyDefinitions(), client, deprecatedConf, mode);
assertThat(batchSettings.getProperties()).isNotEmpty();
}
}
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 673d422affe..aa166f78195 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
@@ -41,6 +41,8 @@ public class DatabaseCompatibilityTest {
ServerMetadata server;
Settings settings;
+ private AnalysisMode mode;
+
@Before
public void init() {
server = mock(ServerMetadata.class);
@@ -51,7 +53,8 @@ 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(CoreProperties.DRY_RUN, false);
+
+ mode = mock(AnalysisMode.class);
databaseVersion = mock(DatabaseVersion.class);
}
@@ -63,7 +66,7 @@ public class DatabaseCompatibilityTest {
thrown.expect(MessageException.class);
thrown.expectMessage("Database relates to a more recent version of SonarQube. Please check your settings (JDBC settings, version of Maven plugin)");
- new DatabaseCompatibility(databaseVersion, server, settings).start();
+ new DatabaseCompatibility(databaseVersion, server, settings, mode).start();
}
@Test
@@ -73,7 +76,7 @@ public class DatabaseCompatibilityTest {
thrown.expect(MessageException.class);
thrown.expectMessage("Database must be upgraded.");
- new DatabaseCompatibility(databaseVersion, server, settings).start();
+ new DatabaseCompatibility(databaseVersion, server, settings, mode).start();
}
@Test
@@ -85,7 +88,7 @@ public class DatabaseCompatibilityTest {
thrown.expectMessage("- Batch side: jdbc:postgresql://localhost/foo (bar / *****)");
thrown.expectMessage("- Server side: check the configuration at http://localhost:9000/system");
- new DatabaseCompatibility(databaseVersion, server, settings).start();
+ new DatabaseCompatibility(databaseVersion, server, settings, mode).start();
}
@Test
@@ -97,7 +100,7 @@ public class DatabaseCompatibilityTest {
thrown.expect(MessageException.class);
thrown.expectMessage("- Batch side: jdbc:postgresql://localhost/foo (sonar / *****)");
- new DatabaseCompatibility(databaseVersion, server, settings).start();
+ new DatabaseCompatibility(databaseVersion, server, settings, mode).start();
}
@Test
@@ -106,22 +109,22 @@ public class DatabaseCompatibilityTest {
thrown.expect(IllegalStateException.class);
- new DatabaseCompatibility(mock(DatabaseVersion.class), server, settings).start();
+ new DatabaseCompatibility(mock(DatabaseVersion.class), server, settings, mode).start();
}
@Test
public void shouldDoNothingIfUpToDate() {
when(databaseVersion.getStatus()).thenReturn(DatabaseVersion.Status.UP_TO_DATE);
- new DatabaseCompatibility(databaseVersion, server, settings).start();
+ new DatabaseCompatibility(databaseVersion, server, settings, mode).start();
// no error
}
@Test
- public void should_not_verify_compatibility_if_dry_run() {
+ public void should_not_verify_compatibility_if_preview() {
settings.setProperty(CoreProperties.SERVER_ID, "11111111");
- settings.setProperty(CoreProperties.DRY_RUN, true);
+ when(mode.isPreview()).thenReturn(true);
- new DatabaseCompatibility(databaseVersion, server, settings).start();
+ new DatabaseCompatibility(databaseVersion, server, settings, mode).start();
// no failure
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java
index cb02a9657dd..d3c5b7c095d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionInstallerTest.java
@@ -21,13 +21,13 @@ package org.sonar.batch.bootstrap;
import com.google.common.collect.Maps;
import org.apache.commons.lang.ClassUtils;
+import org.junit.Before;
import org.junit.Test;
import org.sonar.api.BatchExtension;
import org.sonar.api.ExtensionProvider;
import org.sonar.api.Plugin;
import org.sonar.api.SonarPlugin;
import org.sonar.api.batch.SupportedEnvironment;
-import org.sonar.api.config.Settings;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
@@ -42,26 +42,32 @@ import static org.mockito.Mockito.when;
public class ExtensionInstallerTest {
+ private AnalysisMode mode;
PluginMetadata metadata = mock(PluginMetadata.class);
Map<PluginMetadata, Plugin> newPlugin(final Object... extensions) {
Map<PluginMetadata, Plugin> result = Maps.newHashMap();
result.put(metadata,
- new SonarPlugin() {
- public List<?> getExtensions() {
- return Arrays.asList(extensions);
- }
+ new SonarPlugin() {
+ public List<?> getExtensions() {
+ return Arrays.asList(extensions);
}
- );
+ }
+ );
return result;
}
+ @Before
+ public void setUp() throws Exception {
+ mode = mock(AnalysisMode.class);
+ }
+
@Test
public void should_filter_extensions_to_install() {
BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(Foo.class, Bar.class));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode);
installer.install(container, new FooMatcher());
assertThat(container.getComponentByType(Foo.class)).isNotNull();
@@ -73,7 +79,7 @@ public class ExtensionInstallerTest {
BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(new FooProvider(), new BarProvider()));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode);
installer.install(container, new FooMatcher());
@@ -86,7 +92,7 @@ public class ExtensionInstallerTest {
BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(new FooBarProvider()));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode);
installer.install(container, new TrueMatcher());
@@ -100,7 +106,7 @@ public class ExtensionInstallerTest {
when(pluginRepository.getPluginsByMetadata()).thenReturn(newPlugin(Foo.class, MavenExtension.class, AntExtension.class, new BarProvider()));
ComponentContainer container = new ComponentContainer();
- ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), new Settings());
+ ExtensionInstaller installer = new ExtensionInstaller(pluginRepository, new EnvironmentInformation("ant", "1.7"), mode);
installer.install(container, new TrueMatcher());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
index d5809081505..7825e2592d9 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ExtensionUtilsTest.java
@@ -81,10 +81,10 @@ public class ExtensionUtilsTest {
@Test
public void shouldSupportDryRun() {
- assertThat(ExtensionUtils.supportsDryRun(BatchService.class)).isTrue();
- assertThat(ExtensionUtils.supportsDryRun(new BatchService())).isTrue();
- assertThat(ExtensionUtils.supportsDryRun(PersistentService.class)).isFalse();
- assertThat(ExtensionUtils.supportsDryRun(new PersistentService())).isFalse();
+ assertThat(ExtensionUtils.supportsPreview(BatchService.class)).isTrue();
+ assertThat(ExtensionUtils.supportsPreview(new BatchService())).isTrue();
+ assertThat(ExtensionUtils.supportsPreview(PersistentService.class)).isFalse();
+ assertThat(ExtensionUtils.supportsPreview(new PersistentService())).isFalse();
}
@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
index f54e45b464c..3e36a9b103d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/JdbcDriverHolderTest.java
@@ -25,8 +25,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.home.cache.FileCache;
import java.io.File;
@@ -47,10 +45,12 @@ public class JdbcDriverHolderTest {
public ExpectedException thrown = ExpectedException.none();
ClassLoader initialThreadClassloader;
+ private AnalysisMode mode;
@Before
public void before() {
initialThreadClassloader = Thread.currentThread().getContextClassLoader();
+ mode = mock(AnalysisMode.class);
}
@After
@@ -72,7 +72,7 @@ public class JdbcDriverHolderTest {
when(server.request("/deploy/jdbc-driver.txt")).thenReturn("ojdbc14.jar|fakemd5");
when(server.request("/deploy/ojdbc14.jar")).thenReturn("fakecontent");
- JdbcDriverHolder holder = new JdbcDriverHolder(cache, new Settings(), server);
+ JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server);
holder.start();
assertThat(holder.getClassLoader().getResource("foo/foo.txt")).isNotNull();
@@ -85,11 +85,11 @@ public class JdbcDriverHolderTest {
}
@Test
- public void should_be_disabled_if_dry_run() {
+ public void should_be_disabled_if_preview() {
FileCache cache = mock(FileCache.class);
- Settings settings = new Settings().setProperty(CoreProperties.DRY_RUN, true);
+ when(mode.isPreview()).thenReturn(true);
ServerClient server = mock(ServerClient.class);
- JdbcDriverHolder holder = new JdbcDriverHolder(cache, settings, server);
+ JdbcDriverHolder holder = new JdbcDriverHolder(cache, mode, server);
holder.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/PreviewDatabaseTest.java
index 94935e8fa20..cd41618236d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/PreviewDatabaseTest.java
@@ -41,11 +41,12 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
-public class DryRunDatabaseTest {
+public class PreviewDatabaseTest {
Settings settings;
ServerClient server = mock(ServerClient.class);
TempDirectories tempDirectories = mock(TempDirectories.class);
File databaseFile;
+ private AnalysisMode mode;
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -55,32 +56,42 @@ public class DryRunDatabaseTest {
@Before
public void setUp() throws Exception {
- databaseFile = temp.newFile("dryrun.h2.db");
- when(tempDirectories.getFile("", "dryrun.h2.db")).thenReturn(databaseFile);
+ databaseFile = temp.newFile("preview.h2.db");
+ when(tempDirectories.getFile("", "preview.h2.db")).thenReturn(databaseFile);
settings = new Settings();
- settings.setProperty(CoreProperties.DRY_RUN, true);
settings.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "group:project");
+
+ mode = mock(AnalysisMode.class);
+ when(mode.isPreview()).thenReturn(true);
}
@Test
- public void should_be_disabled_if_not_dry_run() {
- settings.setProperty(CoreProperties.DRY_RUN, false);
- new DryRunDatabase(settings, server, tempDirectories).start();
+ public void should_be_disabled_if_not_preview() {
+ when(mode.isPreview()).thenReturn(false);
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
verifyZeroInteractions(tempDirectories, server);
}
@Test
public void should_download_database() {
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
verify(server).download("/batch_bootstrap/db?project=group:project", databaseFile, 60000);
}
@Test
- public void should_download_database_with_overriden_timeout() {
+ public void should_download_database_with_deprecated_overriden_timeout() {
settings.setProperty(CoreProperties.DRY_RUN_READ_TIMEOUT_SEC, 80);
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
+
+ verify(server).download("/batch_bootstrap/db?project=group:project", databaseFile, 80000);
+ }
+
+ @Test
+ public void should_download_database_with_overriden_timeout() {
+ settings.setProperty(CoreProperties.PREVIEW_READ_TIMEOUT_SEC, 80);
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
verify(server).download("/batch_bootstrap/db?project=group:project", databaseFile, 80000);
}
@@ -88,14 +99,14 @@ public class DryRunDatabaseTest {
@Test
public void should_download_database_on_branch() {
settings.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "mybranch");
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
verify(server).download("/batch_bootstrap/db?project=group:project:mybranch", databaseFile, 60000);
}
@Test
public void should_replace_database_settings() {
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
assertThat(settings.getString(DatabaseProperties.PROP_DIALECT)).isEqualTo("h2");
assertThat(settings.getString(DatabaseProperties.PROP_DRIVER)).isEqualTo("org.h2.Driver");
@@ -111,7 +122,7 @@ public class DryRunDatabaseTest {
thrown.expect(SonarException.class);
thrown.expectMessage("You don't have access rights to project [group:project]");
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
}
@Test
@@ -119,9 +130,9 @@ public class DryRunDatabaseTest {
doThrow(new SonarException(new SocketTimeoutException())).when(server).download("/batch_bootstrap/db?project=group:project", databaseFile, 60000);
thrown.expect(SonarException.class);
- thrown.expectMessage("DryRun database read timed out after 60000 ms. You can try to increase read timeout with property -Dsonar.dryRun.readTimeout (in seconds)");
+ thrown.expectMessage("Preview database read timed out after 60000 ms. You can try to increase read timeout with property -Dsonar.preview.readTimeout (in seconds)");
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
}
@Test
@@ -131,14 +142,14 @@ public class DryRunDatabaseTest {
thrown.expect(SonarException.class);
thrown.expectMessage("BUG");
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
}
@Test
public void project_should_be_optional() {
// on non-scan tasks
settings.removeProperty(CoreProperties.PROJECT_KEY_PROPERTY);
- new DryRunDatabase(settings, server, tempDirectories).start();
+ new PreviewDatabase(settings, server, tempDirectories, mode).start();
verify(server).download("/batch_bootstrap/db", databaseFile, 60000);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java
index 0a30195aa1f..baa08006d3c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuePersisterTest.java
@@ -21,8 +21,8 @@ package org.sonar.batch.issue;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.api.issue.internal.DefaultIssue;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Arrays;
@@ -39,7 +39,7 @@ public class IssuePersisterTest extends AbstractDaoTestCase {
IssuePersister persister;
private ScanIssueStorage storage;
private List<DefaultIssue> issues;
- private Settings settings;
+ private AnalysisMode mode;
@Before
public void prepare() {
@@ -48,8 +48,8 @@ public class IssuePersisterTest extends AbstractDaoTestCase {
when(issueCache.all()).thenReturn(issues);
storage = mock(ScanIssueStorage.class);
- settings = new Settings();
- persister = new IssuePersister(issueCache, storage, settings);
+ mode = mock(AnalysisMode.class);
+ persister = new IssuePersister(issueCache, storage, mode);
}
@Test
@@ -60,8 +60,8 @@ public class IssuePersisterTest extends AbstractDaoTestCase {
}
@Test
- public void should_not_persist_issues_in_dry_run() throws Exception {
- settings.setProperty("sonar.dryRun", true);
+ public void should_not_persist_issues_in_preview_mode() throws Exception {
+ when(mode.isPreview()).thenReturn(true);
persister.persist();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
index fd975e034de..88e21cc4a36 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.phases;
+import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.sonar.api.CoreProperties;
@@ -27,6 +28,8 @@ import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Project;
import org.sonar.api.security.ResourcePermissions;
+import org.sonar.batch.bootstrap.AnalysisMode;
+import org.sonar.batch.bootstrap.BootstrapSettings;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.index.DefaultResourcePersister;
import org.sonar.batch.index.ResourceCache;
@@ -41,9 +44,18 @@ import static org.mockito.Matchers.contains;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
+ private AnalysisMode mode;
+ private BootstrapSettings bootstrapSettings;
+
+ @Before
+ public void setUp() {
+ mode = mock(AnalysisMode.class);
+ }
+
@Test
public void shouldUnflagPenultimateLastSnapshot() {
assertAnalysis(11, "shouldUnflagPenultimateLastSnapshot");
@@ -67,7 +79,7 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
project.setId(1);
UpdateStatusJob job = new UpdateStatusJob(new Settings().appendProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/"), mock(ServerClient.class), session,
new DefaultResourcePersister(session, mock(ResourcePermissions.class), mock(SnapshotCache.class), mock(ResourceCache.class)),
- project, loadSnapshot(snapshotId));
+ project, loadSnapshot(snapshotId), mode);
job.execute();
checkTables(fixture, "snapshots");
@@ -85,7 +97,7 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/");
Project project = new Project("struts");
UpdateStatusJob job = new UpdateStatusJob(settings, mock(ServerClient.class), mock(DatabaseSession.class),
- mock(ResourcePersister.class), project, mock(Snapshot.class));
+ mock(ResourcePersister.class), project, mock(Snapshot.class), mode);
Logger logger = mock(Logger.class);
job.logSuccess(logger);
@@ -94,12 +106,12 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
}
@Test
- public void should_log_successful_dry_run_analysis() throws Exception {
+ public void should_log_successful_preview_analysis() throws Exception {
Settings settings = new Settings();
- settings.setProperty("sonar.dryRun", true);
+ when(mode.isPreview()).thenReturn(true);
Project project = new Project("struts");
UpdateStatusJob job = new UpdateStatusJob(settings, mock(ServerClient.class), mock(DatabaseSession.class),
- mock(ResourcePersister.class), project, mock(Snapshot.class));
+ mock(ResourcePersister.class), project, mock(Snapshot.class), mode);
Logger logger = mock(Logger.class);
job.logSuccess(logger);
@@ -113,22 +125,22 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
Project project = new Project("struts");
ServerClient serverClient = mock(ServerClient.class);
UpdateStatusJob job = new UpdateStatusJob(settings, serverClient, mock(DatabaseSession.class),
- mock(ResourcePersister.class), project, mock(Snapshot.class));
+ mock(ResourcePersister.class), project, mock(Snapshot.class), mode);
- job.evictDryRunDB();
+ job.evictPreviewDB();
verify(serverClient).request(contains("/batch_bootstrap/evict"));
}
@Test
- public void should_not_evict_cache_for_dry_run_analysis() throws Exception {
+ public void should_not_evict_cache_for_preview_analysis() throws Exception {
Settings settings = new Settings();
- settings.setProperty("sonar.dryRun", true);
+ when(mode.isPreview()).thenReturn(true);
Project project = new Project("struts");
ServerClient serverClient = mock(ServerClient.class);
UpdateStatusJob job = new UpdateStatusJob(settings, serverClient, mock(DatabaseSession.class),
- mock(ResourcePersister.class), project, mock(Snapshot.class));
+ mock(ResourcePersister.class), project, mock(Snapshot.class), mode);
- job.evictDryRunDB();
+ job.evictPreviewDB();
verify(serverClient, never()).request(anyString());
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
index fe2a78750de..d712ee66245 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LastSnapshotsTest.java
@@ -19,14 +19,14 @@
*/
package org.sonar.batch.scan;
+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.config.Settings;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.HttpDownloader;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@@ -36,19 +36,28 @@ import java.net.URISyntaxException;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class LastSnapshotsTest extends AbstractDbUnitTestCase {
@Rule
public ExpectedException thrown = ExpectedException.none();
+ private AnalysisMode mode;
+
+ @Before
+ public void before() {
+ mode = mock(AnalysisMode.class);
+ }
@Test
public void should_get_source_of_last_snapshot() {
setupData("last_snapshot");
ServerClient server = mock(ServerClient.class);
- LastSnapshots lastSnapshots = new LastSnapshots(new Settings(), getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
assertThat(lastSnapshots.getSource(newFile())).isEqualTo("this is bar");
verifyZeroInteractions(server);
@@ -59,21 +68,20 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
setupData("no_last_snapshot");
ServerClient server = mock(ServerClient.class);
- LastSnapshots lastSnapshots = new LastSnapshots(new Settings(), getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
assertThat(lastSnapshots.getSource(newFile())).isEqualTo("");
verifyZeroInteractions(server);
}
@Test
- public void should_download_source_from_ws_if_dry_run() {
+ public void should_download_source_from_ws_if_preview_mode() {
setupData("last_snapshot");
ServerClient server = mock(ServerClient.class);
when(server.request(anyString(), eq(false))).thenReturn("downloaded source of Bar.c");
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.DRY_RUN, true);
- LastSnapshots lastSnapshots = new LastSnapshots(settings, getSession(), server);
+ when(mode.isPreview()).thenReturn(true);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
String source = lastSnapshots.getSource(newFile());
assertThat(source).isEqualTo("downloaded source of Bar.c");
@@ -86,23 +94,21 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
ServerClient server = mock(ServerClient.class);
when(server.request(anyString(), eq(false))).thenThrow(new HttpDownloader.HttpException(new URI(""), 500));
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.DRY_RUN, true);
- LastSnapshots lastSnapshots = new LastSnapshots(settings, getSession(), server);
+ when(mode.isPreview()).thenReturn(true);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
thrown.expect(HttpDownloader.HttpException.class);
lastSnapshots.getSource(newFile());
}
@Test
- public void should_return_empty_source_if_dry_run_and_no_last_snapshot() throws URISyntaxException {
+ public void should_return_empty_source_if_preview_mode_and_no_last_snapshot() throws URISyntaxException {
setupData("last_snapshot");
ServerClient server = mock(ServerClient.class);
when(server.request(anyString(), eq(false))).thenThrow(new HttpDownloader.HttpException(new URI(""), 404));
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.DRY_RUN, true);
- LastSnapshots lastSnapshots = new LastSnapshots(settings, getSession(), server);
+ when(mode.isPreview()).thenReturn(true);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
String source = lastSnapshots.getSource(newFile());
assertThat(source).isEqualTo("");
@@ -114,7 +120,7 @@ public class LastSnapshotsTest extends AbstractDbUnitTestCase {
setupData("last_snapshot");
ServerClient server = mock(ServerClient.class);
- LastSnapshots lastSnapshots = new LastSnapshots(new Settings(), getSession(), server);
+ LastSnapshots lastSnapshots = new LastSnapshots(mode, getSession(), server);
String source = lastSnapshots.getSource(new Project("my-project"));
assertThat(source).isEqualTo("");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java
index 9df1e2aace3..61f2a5c8043 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java
@@ -22,13 +22,14 @@ package org.sonar.batch.scan;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
+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.config.PropertyDefinitions;
import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.BatchSettings;
import org.sonar.batch.bootstrap.ServerClient;
@@ -44,6 +45,12 @@ public class ModuleSettingsTest {
public ExpectedException thrown = ExpectedException.none();
ServerClient client = mock(ServerClient.class);
+ private AnalysisMode mode;
+
+ @Before
+ public void before() {
+ mode = mock(AnalysisMode.class);
+ }
@Test
public void testOrderedProjects() {
@@ -74,7 +81,7 @@ public class ModuleSettingsTest {
ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
Configuration deprecatedConf = new PropertiesConfiguration();
- ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, client);
+ ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, client, mode);
assertThat(moduleSettings.getString("overridding")).isEqualTo("module");
assertThat(moduleSettings.getString("on-batch")).isEqualTo("true");
@@ -98,33 +105,35 @@ public class ModuleSettingsTest {
ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
Configuration deprecatedConf = new PropertiesConfiguration();
- ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, client);
+ ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, client, mode);
assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
assertThat(moduleSettings.getString("sonar.foo.secured")).isEqualTo("bar");
}
@Test
- public void should_fail_when_accessing_secured_properties_in_dryrun() {
+ public void should_fail_when_accessing_secured_properties_in_preview() {
BatchSettings batchSettings = mock(BatchSettings.class);
when(batchSettings.getDefinitions()).thenReturn(new PropertyDefinitions());
- when(batchSettings.getString(CoreProperties.DRY_RUN)).thenReturn("true");
when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
"sonar.foo.secured", "bar"
));
+
+ when(mode.isPreview()).thenReturn(true);
+
when(client.request("/batch_bootstrap/properties?project=struts-core&dryRun=true"))
.thenReturn("[{\"k\":\"sonar.foo.license.secured\",\"v\":\"bar2\"}]");
ProjectDefinition module = ProjectDefinition.create().setKey("struts-core");
Configuration deprecatedConf = new PropertiesConfiguration();
- ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, client);
+ ModuleSettings moduleSettings = new ModuleSettings(batchSettings, module, deprecatedConf, client, mode);
assertThat(moduleSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
thrown.expect(SonarException.class);
thrown
- .expectMessage("Access to the secured property 'sonar.foo.secured' is not possible in local (dry run) SonarQube analysis. The SonarQube plugin which requires this property must be deactivated in dry run mode.");
+ .expectMessage("Access to the secured property 'sonar.foo.secured' is not possible in preview mode. The SonarQube plugin which requires this property must be deactivated in preview mode.");
moduleSettings.getString("sonar.foo.secured");
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java
index c32829a13fc..30a5c367ef8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectLockTest.java
@@ -21,12 +21,12 @@ package org.sonar.batch.scan;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.Semaphores;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.ProjectTree;
+import org.sonar.batch.bootstrap.AnalysisMode;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
@@ -42,15 +42,16 @@ public class ProjectLockTest {
ProjectTree projectTree = mock(ProjectTree.class);
Settings settings;
Project project;
+ private AnalysisMode mode;
@Before
public void setUp() {
- settings = new Settings();
- setDryRunMode(false);
+ mode = mock(AnalysisMode.class);
+
project = new Project("my-project-key");
when(projectTree.getRootProject()).thenReturn(project);
- projectLock = new ProjectLock(semaphores, projectTree, settings);
+ projectLock = new ProjectLock(semaphores, projectTree, mode);
}
@Test
@@ -69,8 +70,7 @@ public class ProjectLockTest {
@Test
public void shouldNotAcquireSemaphoreInDryRunMode() {
- setDryRunMode(true);
- settings = new Settings().setProperty(CoreProperties.DRY_RUN, true);
+ when(mode.isPreview()).thenReturn(true);
projectLock.start();
verifyZeroInteractions(semaphores);
}
@@ -82,14 +82,10 @@ public class ProjectLockTest {
}
@Test
- public void shouldNotReleaseSemaphoreInDryRunMode() {
- setDryRunMode(true);
+ public void shouldNotReleaseSemaphoreInPreviewMode() {
+ when(mode.isPreview()).thenReturn(true);
projectLock.stop();
verifyZeroInteractions(semaphores);
}
- private void setDryRunMode(boolean isInDryRunMode) {
- settings.setProperty(CoreProperties.DRY_RUN, isInDryRunMode);
- }
-
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/UnsupportedPropertiesTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/UnsupportedPropertiesTest.java
index f5246e64099..1e61091991c 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/UnsupportedPropertiesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/UnsupportedPropertiesTest.java
@@ -22,7 +22,6 @@ package org.sonar.batch.scan;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
@@ -46,23 +45,4 @@ public class UnsupportedPropertiesTest {
Settings settings = new Settings();
new UnsupportedProperties(settings).start();
}
-
- @Test
- public void should_fail_if_incremental_but_not_preview_mode() {
- thrown.expect(MessageException.class);
- thrown.expectMessage("Incremental mode is only supported with preview mode");
-
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.INCREMENTAL_PREVIEW, true);
- settings.setProperty(CoreProperties.DRY_RUN, false);
- new UnsupportedProperties(settings).start();
- }
-
- @Test
- public void should_not_fail_if_incremental_preview_mode() {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.INCREMENTAL_PREVIEW, true);
- settings.setProperty(CoreProperties.DRY_RUN, true);
- new UnsupportedProperties(settings).start();
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
index b7948e7f5bd..eeded167a46 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
@@ -21,6 +21,7 @@ package org.sonar.batch.scan.filesystem;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -31,6 +32,7 @@ import org.sonar.api.config.Settings;
import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
+import org.sonar.batch.bootstrap.AnalysisMode;
import java.io.File;
import java.io.IOException;
@@ -39,7 +41,10 @@ import java.util.Arrays;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class DefaultModuleFileSystemTest {
@@ -52,12 +57,18 @@ public class DefaultModuleFileSystemTest {
Settings settings = new Settings();
FileIndex fileIndex = mock(FileIndex.class);
ModuleFileSystemInitializer initializer = mock(ModuleFileSystemInitializer.class, Mockito.RETURNS_DEEP_STUBS);
+ private AnalysisMode mode;
+
+ @Before
+ public void before() {
+ mode = mock(AnalysisMode.class);
+ }
@Test
public void test_equals_and_hashCode() throws Exception {
- DefaultModuleFileSystem foo1 = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
- DefaultModuleFileSystem foo2 = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
- DefaultModuleFileSystem bar = new DefaultModuleFileSystem("bar", settings, fileIndex, initializer);
+ DefaultModuleFileSystem foo1 = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
+ DefaultModuleFileSystem foo2 = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
+ DefaultModuleFileSystem bar = new DefaultModuleFileSystem("bar", settings, fileIndex, initializer, mode);
assertThat(foo1.moduleKey()).isEqualTo("foo");
assertThat(foo1.equals(foo1)).isTrue();
@@ -70,7 +81,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void default_source_encoding() {
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
assertThat(fs.sourceCharset()).isEqualTo(Charset.defaultCharset());
assertThat(fs.isDefaultSourceCharset()).isTrue();
@@ -79,7 +90,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void source_encoding_is_set() {
settings.setProperty(CoreProperties.ENCODING_PROPERTY, "Cp1124");
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
assertThat(fs.sourceCharset()).isEqualTo(Charset.forName("Cp1124"));
@@ -103,8 +114,7 @@ public class DefaultModuleFileSystemTest {
when(initializer.additionalSourceFiles()).thenReturn(Arrays.asList(additionalFile));
when(initializer.additionalTestFiles()).thenReturn(Arrays.asList(additionalTest));
-
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
assertThat(fs.baseDir().getCanonicalPath()).isEqualTo(basedir.getCanonicalPath());
assertThat(fs.workingDir().getCanonicalPath()).isEqualTo(workingDir.getCanonicalPath());
@@ -123,7 +133,7 @@ public class DefaultModuleFileSystemTest {
when(initializer.workingDir()).thenReturn(basedir);
when(initializer.sourceDirs()).thenReturn(Arrays.asList(new File(basedir, "src/main/java")));
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
File existingDir = temp.newFolder("new_folder");
File notExistingDir = new File(existingDir, "not_exist");
@@ -144,7 +154,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void should_search_input_files() throws Exception {
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
File mainFile = temp.newFile();
InputFile mainInput = DefaultInputFile.create(mainFile, "Main.java", ImmutableMap.of(InputFile.ATTRIBUTE_TYPE, InputFile.TYPE_SOURCE));
@@ -161,7 +171,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void should_index() throws Exception {
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer);
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem("foo", settings, fileIndex, initializer, mode);
verifyZeroInteractions(fileIndex);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileQueryFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileQueryFilterTest.java
index b149bbf4576..49cdd51ba14 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileQueryFilterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/FileQueryFilterTest.java
@@ -19,23 +19,30 @@
*/
package org.sonar.batch.scan.filesystem;
+import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
import org.sonar.api.scan.filesystem.FileQuery;
import org.sonar.api.scan.filesystem.InputFile;
import org.sonar.api.scan.filesystem.InputFileFilter;
+import org.sonar.batch.bootstrap.AnalysisMode;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class FileQueryFilterTest {
- Settings settings = new Settings();
+ private AnalysisMode mode;
+
+ @Before
+ public void before() {
+ mode = mock(AnalysisMode.class);
+ }
@Test
public void wrap_query_on_attributes() throws Exception {
FileQuery query = FileQuery.onSource();
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(mode, query);
assertThat(filter.filters()).hasSize(1);
InputFileFilter typeFilter = filter.filters().get(0);
@@ -47,7 +54,7 @@ public class FileQueryFilterTest {
@Test
public void wrap_query_on_inclusions() throws Exception {
FileQuery query = FileQuery.on().withInclusions("Foo*.java");
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(mode, query);
assertThat(filter.filters()).hasSize(1);
InputFileFilter inclusionFilter = filter.filters().get(0);
@@ -58,7 +65,7 @@ public class FileQueryFilterTest {
@Test
public void wrap_query_on_exclusions() throws Exception {
FileQuery query = FileQuery.on().withExclusions("Foo*.java");
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(mode, query);
assertThat(filter.filters()).hasSize(1);
InputFileFilter exclusionFilter = filter.filters().get(0);
@@ -69,16 +76,16 @@ public class FileQueryFilterTest {
@Test
public void all_files_by_default() throws Exception {
FileQuery query = FileQuery.on();
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(mode, query);
assertThat(filter.filters()).isEmpty();
}
@Test
public void only_changed_files_by_default_if_incremental_mode() throws Exception {
- settings.setProperty(CoreProperties.INCREMENTAL_PREVIEW, true);
+ when(mode.isIncremental()).thenReturn(true);
FileQuery query = FileQuery.on();
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(mode, query);
assertThat(filter.filters()).hasSize(1);
AttributeFilter statusFilter = (AttributeFilter) filter.filters().get(0);
@@ -88,10 +95,10 @@ public class FileQueryFilterTest {
@Test
public void get_all_files_even_if_incremental_mode() throws Exception {
- settings.setProperty(CoreProperties.INCREMENTAL_PREVIEW, true);
+ when(mode.isIncremental()).thenReturn(true);
FileQuery query = FileQuery.on().on(InputFile.ATTRIBUTE_STATUS, InputFile.STATUS_SAME);
- FileQueryFilter filter = new FileQueryFilter(settings, query);
+ FileQueryFilter filter = new FileQueryFilter(mode, query);
assertThat(filter.filters()).hasSize(1);
AttributeFilter statusFilter = (AttributeFilter) filter.filters().get(0);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
index 74d6b6ce413..2c8d070c97d 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
@@ -25,7 +25,6 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.skyscreamer.jsonassert.JSONAssert;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
@@ -34,6 +33,7 @@ import org.sonar.api.resources.Resource;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.scan.filesystem.ModuleFileSystem;
+import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.events.EventBus;
import org.sonar.batch.issue.IssueCache;
import org.sonar.core.i18n.RuleI18nManager;
@@ -62,6 +62,7 @@ public class JsonReportTest {
RuleI18nManager ruleI18nManager = mock(RuleI18nManager.class);
Settings settings;
IssueCache issueCache = mock(IssueCache.class);
+ private AnalysisMode mode;
@Before
public void setUp() {
@@ -69,62 +70,63 @@ public class JsonReportTest {
when(server.getVersion()).thenReturn("3.6");
settings = new Settings();
- settings.setProperty(CoreProperties.DRY_RUN, true);
- jsonReport = new JsonReport(settings, fileSystem, server, ruleI18nManager, issueCache, mock(EventBus.class), new DefaultComponentSelector());
+ mode = mock(AnalysisMode.class);
+ when(mode.isPreview()).thenReturn(true);
+ jsonReport = new JsonReport(settings, fileSystem, server, ruleI18nManager, issueCache, mock(EventBus.class), new DefaultComponentSelector(), mode);
}
@Test
public void should_write_json() throws Exception {
DefaultIssue issue = new DefaultIssue()
- .setKey("200")
- .setComponentKey("struts:org.apache.struts.Action")
- .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
- .setMessage("There are 2 cycles")
- .setSeverity("MINOR")
- .setStatus(Issue.STATUS_OPEN)
- .setResolution(null)
- .setLine(1)
- .setEffortToFix(3.14)
- .setReporter("julien")
- .setAssignee("simon")
- .setCreationDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-24"))
- .setUpdateDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-25"))
- .setNew(false);
+ .setKey("200")
+ .setComponentKey("struts:org.apache.struts.Action")
+ .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
+ .setMessage("There are 2 cycles")
+ .setSeverity("MINOR")
+ .setStatus(Issue.STATUS_OPEN)
+ .setResolution(null)
+ .setLine(1)
+ .setEffortToFix(3.14)
+ .setReporter("julien")
+ .setAssignee("simon")
+ .setCreationDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-24"))
+ .setUpdateDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-25"))
+ .setNew(false);
when(ruleI18nManager.getName("squid", "AvoidCycles", Locale.getDefault())).thenReturn("Avoid Cycles");
- when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue> newArrayList(issue));
+ when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/report/JsonReportTest/report.json"),
- writer.toString(), false);
+ writer.toString(), false);
}
@Test
public void should_exclude_resolved_issues() throws Exception {
DefaultIssue issue = new DefaultIssue()
- .setKey("200")
- .setComponentKey("struts:org.apache.struts.Action")
- .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
- .setStatus(Issue.STATUS_CLOSED)
- .setResolution(Issue.RESOLUTION_FIXED)
- .setCreationDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-24"))
- .setUpdateDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-25"))
- .setCloseDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-26"))
- .setNew(false);
+ .setKey("200")
+ .setComponentKey("struts:org.apache.struts.Action")
+ .setRuleKey(RuleKey.of("squid", "AvoidCycles"))
+ .setStatus(Issue.STATUS_CLOSED)
+ .setResolution(Issue.RESOLUTION_FIXED)
+ .setCreationDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-24"))
+ .setUpdateDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-25"))
+ .setCloseDate(new SimpleDateFormat("yyyy-MM-dd").parse("2013-04-26"))
+ .setNew(false);
when(ruleI18nManager.getName("squid", "AvoidCycles", Locale.getDefault())).thenReturn("Avoid Cycles");
- when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue> newArrayList(issue));
+ when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"),
- writer.toString(), false);
+ writer.toString(), false);
}
@Test
public void should_ignore_components_without_issue() throws JSONException {
- when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue> emptyList());
+ when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
@@ -138,7 +140,7 @@ public class JsonReportTest {
Rule rule = Rule.create("squid", "AvoidCycles");
when(ruleI18nManager.getName(rule, Locale.getDefault())).thenReturn("Avoid Cycles");
- when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue> emptyList());
+ when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
settings.setProperty("sonar.report.export.path", "output.json");
when(fileSystem.workingDir()).thenReturn(sonarDirectory);