aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pom.xml8
-rw-r--r--sonar-batch-protocol/pom.xml42
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java (renamed from sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.java)31
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java64
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java33
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java49
-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/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
18 files changed, 412 insertions, 127 deletions
diff --git a/pom.xml b/pom.xml
index 50f20902ee7..c787e9aa4dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1043,7 +1043,7 @@
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
- <version>1.2.2</version>
+ <version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
@@ -1054,12 +1054,6 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
- <exclusions>
- <exclusion>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-core</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
diff --git a/sonar-batch-protocol/pom.xml b/sonar-batch-protocol/pom.xml
new file mode 100644
index 00000000000..b57fa36fb4f
--- /dev/null
+++ b/sonar-batch-protocol/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar</artifactId>
+ <version>4.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sonar-batch-protocol</artifactId>
+ <name>SonarQube :: Batch :: Protocol</name>
+
+ <description>Classes used for communication between batch and server</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.esotericsoftware.kryo</groupId>
+ <artifactId>kryo</artifactId>
+ <version>2.24.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+
+ <!-- unit tests -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.easytesting</groupId>
+ <artifactId>fest-assert</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.skyscreamer</groupId>
+ <artifactId>jsonassert</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java
index 462de9e61b7..8e1bd467226 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectSettingsReady.java
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/Language.java
@@ -17,31 +17,26 @@
* 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;
+package org.sonar.batch.protocol.input;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.batch.bootstrap.BatchSettings;
+public class Language {
-/**
- * Barrier to control the project settings are loaded from Sonar DB before applying project exclusions
- * </ul>
- */
-public class ProjectSettingsReady {
+ private String key;
+
+ private String name;
- private final ProjectReactor reactor;
- private final BatchSettings settings;
+ private String[] suffixes;
- public ProjectSettingsReady(ProjectReactor reactor, BatchSettings settings) {
- this.reactor = reactor;
- this.settings = settings;
+ public String key() {
+ return key;
}
- public void start() {
- settings.init(reactor);
+ public String name() {
+ return name;
}
- public void stop() {
- // Remove project specific settings
- settings.restore();
+ public String[] suffixes() {
+ return suffixes;
}
+
}
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
new file mode 100644
index 00000000000..5e672051a10
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java
@@ -0,0 +1,64 @@
+/*
+ * 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.protocol.input;
+
+import com.google.gson.Gson;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ProjectReferentials {
+
+ private long timestamp;
+ private Collection<Language> languages = new ArrayList<Language>();
+ private Map<String, Map<String, String>> projectSettings = new HashMap<String, Map<String, String>>();
+
+ public Map<String, String> projectSettings(String projectOrSubProjectKey) {
+ return projectSettings.get(projectOrSubProjectKey);
+ }
+
+ public void setProjectSettings(String projectOrSubProjectKey, Map<String, String> projectSettings) {
+ this.projectSettings.put(projectOrSubProjectKey, projectSettings);
+ }
+
+ public Collection<Language> languages() {
+ return languages;
+ }
+
+ public long timestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String toJson() {
+ return new Gson().toJson(this);
+ }
+
+ public static ProjectReferentials fromJson(Reader input) {
+ return new Gson().fromJson(input, ProjectReferentials.class);
+ }
+
+}
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java
new file mode 100644
index 00000000000..66f4edf9e0a
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/QProfiles.java
@@ -0,0 +1,33 @@
+/*
+ * 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.protocol.input;
+
+import java.util.Map;
+
+public class QProfiles {
+
+ public static class QProfile {
+
+ private String key, name, language;
+ }
+
+ private Map<String, QProfile> byLanguage;
+
+}
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
new file mode 100644
index 00000000000..037517958b4
--- /dev/null
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java
@@ -0,0 +1,49 @@
+/*
+ * 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.protocol.input;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import java.io.StringReader;
+import java.util.HashMap;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ProjectReferentialsTest {
+
+ @Test
+ public void testToJson() throws JSONException {
+ ProjectReferentials ref = new ProjectReferentials();
+ HashMap<String, String> projectSettings = new HashMap<String, String>();
+ projectSettings.put("sonar.foo", "bar");
+ ref.setProjectSettings("foo", projectSettings);
+
+ JSONAssert.assertEquals("{languages: [], projectSettings: {foo: {'sonar.foo': 'bar'}}, timestamp: 0}", ref.toJson(), true);
+ }
+
+ @Test
+ public void testFromJson() throws JSONException {
+ ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{languages: [], projectSettings: {foo: {'sonar.foo': 'bar'}}, timestamp: 1}"));
+
+ assertThat(ref.timestamp()).isEqualTo(1);
+ }
+}
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/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);