aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-17 15:08:04 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-17 16:27:11 +0200
commit51cc491410147364a9c81e870d40880189f62fd9 (patch)
treed652d1b1aa72e80153ef30874ba01aaf31d3ace4 /sonar-batch/src
parente5531f07ac51ace0dc6d957c9960fcec37c28783 (diff)
downloadsonarqube-51cc491410147364a9c81e870d40880189f62fd9.tar.gz
sonarqube-51cc491410147364a9c81e870d40880189f62fd9.zip
SONAR-5417 Initial version of batch protocol + refactoring of settings
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java (renamed from sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java)51
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java8
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java10
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java2
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java95
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.java47
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalSettingsTest.java65
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ModuleSettingsTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java14
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java (renamed from sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java)53
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/ScanTaskTest.java2
13 files changed, 210 insertions, 149 deletions
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 5d7e836786b..e0f8e64c090 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
@@ -98,7 +98,7 @@ public class BootstrapContainer extends ComponentContainer {
AnalysisMode.class,
BatchPluginRepository.class,
BatchPluginJarInstaller.class,
- BatchSettings.class,
+ GlobalSettings.class,
ServerClient.class,
ExtensionInstaller.class,
Logback.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java
index b818a602361..baeb2706ad1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalSettings.java
@@ -20,11 +20,9 @@
package org.sonar.batch.bootstrap;
import org.apache.commons.configuration.Configuration;
-import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
@@ -32,20 +30,17 @@ import org.sonar.batch.settings.SettingsReferential;
import javax.annotation.Nullable;
-import java.util.Map;
+public class GlobalSettings extends Settings {
-public class BatchSettings extends Settings {
-
- private static final Logger LOG = LoggerFactory.getLogger(BatchSettings.class);
+ private static final Logger LOG = LoggerFactory.getLogger(GlobalSettings.class);
private Configuration deprecatedConfiguration;
private final BootstrapProperties bootstrapProps;
private final SettingsReferential settingsReferential;
private final AnalysisMode mode;
- private Map<String, String> savedProperties;
- public BatchSettings(BootstrapProperties bootstrapProps, PropertyDefinitions propertyDefinitions,
+ public GlobalSettings(BootstrapProperties bootstrapProps, PropertyDefinitions propertyDefinitions,
SettingsReferential settingsReferential, Configuration deprecatedConfiguration, AnalysisMode mode) {
super(propertyDefinitions);
@@ -54,45 +49,13 @@ public class BatchSettings extends Settings {
this.bootstrapProps = bootstrapProps;
this.settingsReferential = settingsReferential;
this.deprecatedConfiguration = deprecatedConfiguration;
- init(null);
+ init();
}
- public void init(@Nullable ProjectReactor reactor) {
- savedProperties = this.getProperties();
-
- if (reactor != null) {
- LOG.info("Load project settings");
-
- String branch = reactor.getRoot().getProperties().getProperty(CoreProperties.PROJECT_BRANCH_PROPERTY);
- String projectKey = reactor.getRoot().getKey();
- if (StringUtils.isNotBlank(branch)) {
- projectKey = String.format("%s:%s", projectKey, branch);
- }
- downloadSettings(projectKey);
- } else {
- LOG.info("Load global settings");
- downloadSettings(null);
- }
-
+ private void init() {
+ LOG.info("Load global settings");
+ addProperties(settingsReferential.globalSettings());
addProperties(bootstrapProps.properties());
- if (reactor != null) {
- addProperties(reactor.getRoot().getProperties());
- }
- }
-
- /**
- * Restore properties like they were before call of the {@link #init(org.sonar.api.batch.bootstrap.ProjectReactor)} method
- */
- public void restore() {
- this.setProperties(savedProperties);
- }
-
- private void downloadSettings(@Nullable String projectKey) {
- if (StringUtils.isNotBlank(projectKey)) {
- addProperties(settingsReferential.projectSettings(projectKey));
- } else {
- addProperties(settingsReferential.globalSettings());
- }
}
@Override
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 da469b8bb89..b1fc05905c5 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,7 +28,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.bootstrap.AnalysisMode;
-import org.sonar.batch.bootstrap.BatchSettings;
+import org.sonar.batch.bootstrap.GlobalSettings;
import org.sonar.batch.settings.SettingsReferential;
import javax.annotation.Nullable;
@@ -44,7 +44,7 @@ public class ModuleSettings extends Settings {
private final SettingsReferential settingsReferential;
private AnalysisMode analysisMode;
- public ModuleSettings(BatchSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, SettingsReferential settingsReferential,
+ public ModuleSettings(GlobalSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf, SettingsReferential settingsReferential,
AnalysisMode analysisMode) {
super(batchSettings.getDefinitions());
this.settingsReferential = settingsReferential;
@@ -56,13 +56,13 @@ public class ModuleSettings extends Settings {
init(project, batchSettings);
}
- private ModuleSettings init(ProjectDefinition project, BatchSettings batchSettings) {
+ private ModuleSettings init(ProjectDefinition project, GlobalSettings batchSettings) {
addProjectProperties(project, batchSettings);
addBuildProperties(project);
return this;
}
- private void addProjectProperties(ProjectDefinition project, BatchSettings batchSettings) {
+ private void addProjectProperties(ProjectDefinition project, GlobalSettings batchSettings) {
String branch = batchSettings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY);
String projectKey = project.getKey();
if (StringUtils.isNotBlank(branch)) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java
index 9ae79832e12..c1333e0ad47 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectExclusions.java
@@ -45,16 +45,14 @@ public class ProjectExclusions implements TaskComponent {
private ProjectReactor reactor;
public ProjectExclusions(Settings settings, ProjectReactor reactor,
- // exclusions are applied when settings are loaded from Sonar DB
- ProjectSettingsReady settingsReady,
- // exclusions are applied when the project is completely defined by extensions
- @Nullable ProjectBuilder[] projectBuilders) {
+ // exclusions are applied when the project is completely defined by extensions
+ @Nullable ProjectBuilder[] projectBuilders) {
this.settings = settings;
this.reactor = reactor;
}
- public ProjectExclusions(Settings settings, ProjectReactor reactor, ProjectSettingsReady settingsReady) {
- this(settings, reactor, settingsReady, new ProjectBuilder[0]);
+ public ProjectExclusions(Settings settings, ProjectReactor reactor) {
+ this(settings, reactor, new ProjectBuilder[0]);
}
public void apply() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
index 12eaf5aa378..588fb02fb77 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
@@ -186,7 +186,7 @@ public class ProjectScanContainer extends ComponentContainer {
// Measures
MeasureCache.class,
- ProjectSettingsReady.class);
+ ProjectSettings.class);
}
private void fixMavenExecutor() {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java
new file mode 100644
index 00000000000..7ad8745ef79
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettings.java
@@ -0,0 +1,95 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.scan;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.MessageException;
+import org.sonar.batch.bootstrap.AnalysisMode;
+import org.sonar.batch.bootstrap.GlobalSettings;
+import org.sonar.batch.settings.SettingsReferential;
+
+import javax.annotation.Nullable;
+
+public class ProjectSettings extends Settings {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ProjectSettings.class);
+
+ private Configuration deprecatedConfiguration;
+
+ private final GlobalSettings globalSettings;
+ private final SettingsReferential settingsReferential;
+ private final AnalysisMode mode;
+
+ public ProjectSettings(ProjectReactor reactor, GlobalSettings globalSettings, PropertyDefinitions propertyDefinitions,
+ SettingsReferential settingsReferential, Configuration deprecatedConfiguration, AnalysisMode mode) {
+ super(propertyDefinitions);
+ this.mode = mode;
+ getEncryption().setPathToSecretKey(globalSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH));
+ this.globalSettings = globalSettings;
+ this.settingsReferential = settingsReferential;
+ this.deprecatedConfiguration = deprecatedConfiguration;
+ init(reactor);
+ }
+
+ private void init(ProjectReactor reactor) {
+ LOG.info("Load project settings");
+
+ addProperties(globalSettings.getProperties());
+
+ String branch = reactor.getRoot().getProperties().getProperty(CoreProperties.PROJECT_BRANCH_PROPERTY);
+ String projectKey = reactor.getRoot().getKey();
+ if (StringUtils.isNotBlank(branch)) {
+ projectKey = String.format("%s:%s", projectKey, branch);
+ }
+ addProperties(settingsReferential.projectSettings(projectKey));
+
+ addProperties(reactor.getRoot().getProperties());
+ }
+
+ @Override
+ protected void doOnSetProperty(String key, @Nullable String value) {
+ deprecatedConfiguration.setProperty(key, value);
+ }
+
+ @Override
+ protected void doOnRemoveProperty(String key) {
+ deprecatedConfiguration.clearProperty(key);
+ }
+
+ @Override
+ protected void doOnClearProperties() {
+ deprecatedConfiguration.clear();
+ }
+
+ @Override
+ protected void doOnGetProperties(String key) {
+ if (mode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
+ throw MessageException.of("Access to the secured property '" + key
+ + "' 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/ProjectSettingsReady.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.java
deleted file mode 100644
index 462de9e61b7..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.scan;
-
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.batch.bootstrap.BatchSettings;
-
-/**
- * Barrier to control the project settings are loaded from Sonar DB before applying project exclusions
- * </ul>
- */
-public class ProjectSettingsReady {
-
- private final ProjectReactor reactor;
- private final BatchSettings settings;
-
- public ProjectSettingsReady(ProjectReactor reactor, BatchSettings settings) {
- this.reactor = reactor;
- this.settings = settings;
- }
-
- public void start() {
- settings.init(reactor);
- }
-
- public void stop() {
- // Remove project specific settings
- settings.restore();
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java
index 28c5df4f765..b306a0ba35f 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java
@@ -35,6 +35,7 @@ import org.sonar.batch.bootstrap.ExtensionUtils;
import org.sonar.batch.index.Caches;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
import org.sonar.batch.scan.ProjectReactorBuilder;
+import org.sonar.batch.scan.ProjectSettings;
import org.sonar.batch.scan.filesystem.InputFileCache;
import org.sonar.batch.scan.maven.FakeMavenPluginExecutor;
import org.sonar.batch.scan.maven.MavenPluginExecutor;
@@ -77,6 +78,7 @@ public class ProjectScanContainer extends ComponentContainer {
private void addBatchComponents() {
add(
+ ProjectSettings.class,
Caches.class,
// Measures
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalSettingsTest.java
new file mode 100644
index 00000000000..b7b367dea46
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalSettingsTest.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.batch.settings.SettingsReferential;
+
+import java.util.Collections;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class GlobalSettingsTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ SettingsReferential settingsRef = mock(SettingsReferential.class);
+ ProjectDefinition project = ProjectDefinition.create().setKey("struts");
+ Configuration deprecatedConf = new BaseConfiguration();
+ BootstrapProperties bootstrapProps;
+
+ private AnalysisMode mode;
+
+ @Before
+ public void prepare() {
+ bootstrapProps = new BootstrapProperties(Collections.<String, String>emptyMap());
+ mode = mock(AnalysisMode.class);
+ }
+
+ @Test
+ public void should_load_global_settings() {
+ when(settingsRef.globalSettings()).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
+
+ GlobalSettings batchSettings = new GlobalSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
+
+ assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
+ }
+}
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 0140f39a7d2..20e593585ab 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
@@ -30,7 +30,7 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.bootstrap.AnalysisMode;
-import org.sonar.batch.bootstrap.BatchSettings;
+import org.sonar.batch.bootstrap.GlobalSettings;
import org.sonar.batch.settings.SettingsReferential;
import java.util.List;
@@ -68,7 +68,7 @@ public class ModuleSettingsTest {
@Test
public void test_loading_of_module_settings() {
- BatchSettings batchSettings = mock(BatchSettings.class);
+ GlobalSettings batchSettings = mock(GlobalSettings.class);
when(batchSettings.getDefinitions()).thenReturn(new PropertyDefinitions());
when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
"overridding", "batch",
@@ -92,7 +92,7 @@ public class ModuleSettingsTest {
@Test
public void should_not_fail_when_accessing_secured_properties() {
- BatchSettings batchSettings = mock(BatchSettings.class);
+ GlobalSettings batchSettings = mock(GlobalSettings.class);
when(batchSettings.getDefinitions()).thenReturn(new PropertyDefinitions());
when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
"sonar.foo.secured", "bar"
@@ -110,7 +110,7 @@ public class ModuleSettingsTest {
@Test
public void should_fail_when_accessing_secured_properties_in_preview() {
- BatchSettings batchSettings = mock(BatchSettings.class);
+ GlobalSettings batchSettings = mock(GlobalSettings.class);
when(batchSettings.getDefinitions()).thenReturn(new PropertyDefinitions());
when(batchSettings.getProperties()).thenReturn(ImmutableMap.of(
"sonar.foo.secured", "bar"
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java
index 7f01b5fb55d..6afe7bc1b68 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectScanContainerTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.scan;
+import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.BatchExtension;
@@ -32,9 +33,14 @@ import org.sonar.api.config.Settings;
import org.sonar.api.platform.ComponentContainer;
import org.sonar.api.task.TaskExtension;
import org.sonar.api.utils.System2;
+import org.sonar.batch.bootstrap.AnalysisMode;
+import org.sonar.batch.bootstrap.BootstrapProperties;
import org.sonar.batch.bootstrap.ExtensionInstaller;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
import org.sonar.batch.scan.maven.MavenPluginExecutor;
+import org.sonar.batch.settings.SettingsReferential;
+
+import java.util.Collections;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -46,6 +52,7 @@ public class ProjectScanContainerTest {
private ProjectScanContainer container;
private Settings settings;
private ComponentContainer parentContainer;
+ private BootstrapProperties bootstrapProperties;
@Before
public void prepare() {
@@ -55,6 +62,11 @@ public class ProjectScanContainerTest {
parentContainer = new ComponentContainer();
parentContainer.add(settings);
parentContainer.add(System2.INSTANCE);
+ bootstrapProperties = new BootstrapProperties(Collections.<String, String>emptyMap());
+ parentContainer.add(bootstrapProperties);
+ parentContainer.add(new AnalysisMode(bootstrapProperties));
+ parentContainer.add(new PropertiesConfiguration());
+ parentContainer.add(mock(SettingsReferential.class));
container = new ProjectScanContainer(parentContainer);
}
@@ -84,7 +96,7 @@ public class ProjectScanContainerTest {
assertThat(container.getComponentsByType(PhasesSumUpTimeProfiler.class)).hasSize(0);
- settings.setProperty(CoreProperties.PROFILING_LOG_PROPERTY, "true");
+ bootstrapProperties.properties().put(CoreProperties.PROFILING_LOG_PROPERTY, "true");
container = new ProjectScanContainer(parentContainer);
container.add(mock(ExtensionInstaller.class), projectBootstrapper);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java
index 1b507af9c7f..2d318ee628e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchSettingsTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ProjectSettingsTest.java
@@ -17,7 +17,7 @@
* 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;
+package org.sonar.batch.scan;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.configuration.BaseConfiguration;
@@ -31,6 +31,9 @@ import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.utils.MessageException;
+import org.sonar.batch.bootstrap.AnalysisMode;
+import org.sonar.batch.bootstrap.BootstrapProperties;
+import org.sonar.batch.bootstrap.GlobalSettings;
import org.sonar.batch.settings.SettingsReferential;
import java.util.Collections;
@@ -39,58 +42,38 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public class BatchSettingsTest {
+public class ProjectSettingsTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private static final String JSON_RESPONSE = "[{\"k\":\"sonar.cpd.cross\",\"v\":\"true\"}]";
- private static final String JSON_RESPONSE_WITH_SECURED = "[{\"k\":\"sonar.foo.secured\",\"v\":\"bar\"},{\"k\":\"sonar.foo.license.secured\",\"v\":\"bar2\"}]";
-
- private static final String REACTOR_JSON_RESPONSE = "[{\"k\":\"sonar.cpd.cross\",\"v\":\"true\"}," +
- "{\"k\":\"sonar.java.coveragePlugin\",\"v\":\"jacoco\"}]";
-
- private static final String BRANCH_REACTOR_JSON_RESPONSE = "[{\"k\":\"sonar.cpd.cross\",\"v\":\"true\"}," +
- "{\"k\":\"sonar.java.coveragePlugin\",\"v\":\"jacoco\"}]";
-
SettingsReferential settingsRef = mock(SettingsReferential.class);
ProjectDefinition project = ProjectDefinition.create().setKey("struts");
Configuration deprecatedConf = new BaseConfiguration();
- BootstrapProperties bootstrapProps;
+ GlobalSettings bootstrapProps;
private AnalysisMode mode;
@Before
public void prepare() {
- bootstrapProps = new BootstrapProperties(Collections.<String, String>emptyMap());
mode = mock(AnalysisMode.class);
+ bootstrapProps = new GlobalSettings(new BootstrapProperties(Collections.<String, String>emptyMap()), new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
}
@Test
public void should_load_project_props() {
project.setProperty("project.prop", "project");
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- batchSettings.init(new ProjectReactor(project));
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
assertThat(batchSettings.getString("project.prop")).isEqualTo("project");
}
@Test
- public void should_load_global_settings() {
- when(settingsRef.globalSettings()).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
-
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
-
- assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
- }
-
- @Test
public void should_load_project_root_settings() {
when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- batchSettings.init(new ProjectReactor(project));
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
}
@@ -101,8 +84,7 @@ public class BatchSettingsTest {
when(settingsRef.projectSettings("struts:mybranch")).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- batchSettings.init(new ProjectReactor(project));
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
assertThat(batchSettings.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
}
@@ -111,8 +93,7 @@ public class BatchSettingsTest {
public void should_not_fail_when_accessing_secured_properties() {
when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.foo.secured", "bar", "sonar.foo.license.secured", "bar2"));
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- batchSettings.init(new ProjectReactor(project));
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
assertThat(batchSettings.getString("sonar.foo.secured")).isEqualTo("bar");
@@ -124,8 +105,7 @@ public class BatchSettingsTest {
when(mode.isPreview()).thenReturn(true);
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- batchSettings.init(new ProjectReactor(project));
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
assertThat(batchSettings.getString("sonar.foo.license.secured")).isEqualTo("bar2");
thrown.expect(MessageException.class);
@@ -138,8 +118,7 @@ public class BatchSettingsTest {
public void should_forward_to_deprecated_commons_configuration() {
when(settingsRef.projectSettings("struts")).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true", "sonar.java.coveragePlugin", "jacoco"));
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- batchSettings.init(new ProjectReactor(project));
+ ProjectSettings batchSettings = new ProjectSettings(new ProjectReactor(project), bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
assertThat(deprecatedConf.getString("sonar.cpd.cross")).isEqualTo("true");
assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isEqualTo("jacoco");
@@ -153,10 +132,4 @@ public class BatchSettingsTest {
assertThat(deprecatedConf.getString("sonar.java.coveragePlugin")).isNull();
}
- @Test
- public void project_should_be_optional() {
- when(settingsRef.globalSettings()).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true"));
- BatchSettings batchSettings = new BatchSettings(bootstrapProps, new PropertyDefinitions(), settingsRef, deprecatedConf, mode);
- assertThat(batchSettings.getProperties()).isNotEmpty();
- }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/ScanTaskTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/ScanTaskTest.java
index a392a8050f3..602f3ea641b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/ScanTaskTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/ScanTaskTest.java
@@ -45,7 +45,7 @@ public class ScanTaskTest {
ScanTask task = new ScanTask(mock(TaskContainer.class));
ComponentContainer projectScanContainer = new ComponentContainer();
projectScanContainer.add(mock(ProjectConfigurator.class), new ProjectReactor(ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo")),
- mock(Settings.class), mock(ProjectSettingsReady.class),
+ mock(Settings.class),
mock(ResourceDao.class));
task.scan(projectScanContainer);