aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-22 09:51:55 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-22 09:56:29 +0200
commitd34d7b471485298abc3c268b171882c73fbd778d (patch)
tree60e5e98ff34455ea7e3e8b9262dea8a95fea4853
parentd2a6cb9963b8c6dd89620a7c50fcdc5b5645ec75 (diff)
downloadsonarqube-d34d7b471485298abc3c268b171882c73fbd778d.tar.gz
sonarqube-d34d7b471485298abc3c268b171882c73fbd778d.zip
SONAR-5477 Load global referentials earlier
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java64
-rw-r--r--sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/ProjectReferentials.java7
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java65
-rw-r--r--sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/ProjectReferentialsTest.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapContainer.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java42
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java67
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsLoader.java28
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsProvider.java30
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java2
15 files changed, 314 insertions, 67 deletions
diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.java
new file mode 100644
index 00000000000..a1ad9e31a5a
--- /dev/null
+++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/input/GlobalReferentials.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;
+
+/**
+ * Container for all global data going from server to batch.
+ * This is not an API since server and batch always share the same version.
+ */
+public class GlobalReferentials {
+
+ private long timestamp;
+ private Collection<Metric> metrics = new ArrayList<Metric>();
+ private Map<String, String> globalSettings = new HashMap<String, String>();
+
+ public Map<String, String> globalSettings() {
+ return globalSettings;
+ }
+
+ public Collection<Metric> metrics() {
+ return metrics;
+ }
+
+ public long timestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(long timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public String toJson() {
+ return new Gson().toJson(this);
+ }
+
+ public static GlobalReferentials fromJson(Reader input) {
+ return new Gson().fromJson(input, GlobalReferentials.class);
+ }
+
+}
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
index 7a4231802e3..a386a0eeac7 100644
--- 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
@@ -28,13 +28,12 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Container for all data going from server to batch.
+ * Container for all project data going from server to batch.
* This is not an API since server and batch always share the same version.
*/
public class ProjectReferentials {
private long timestamp;
- private Collection<Metric> metrics = new ArrayList<Metric>();
private Map<String, QProfile> qprofilesByLanguage = new HashMap<String, QProfile>();
private Collection<ActiveRule> activeRules = new ArrayList<ActiveRule>();
private Map<String, Map<String, String>> settingsByModule = new HashMap<String, Map<String, String>>();
@@ -48,10 +47,6 @@ public class ProjectReferentials {
return this;
}
- public Collection<Metric> metrics() {
- return metrics;
- }
-
public Collection<QProfile> qProfiles() {
return qprofilesByLanguage.values();
}
diff --git a/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.java
new file mode 100644
index 00000000000..3afd7662fc0
--- /dev/null
+++ b/sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalReferentialsTest.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.protocol.input;
+
+import org.fest.assertions.MapAssert;
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import java.io.StringReader;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class GlobalReferentialsTest {
+
+ @Test
+ public void testToJson() throws Exception {
+ GlobalReferentials ref = new GlobalReferentials();
+ ref.metrics().add(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 1.0, true));
+ ref.globalSettings().put("prop", "value");
+ ref.setTimestamp(10);
+
+ System.out.println(ref.toJson());
+ JSONAssert
+ .assertEquals(
+ "{timestamp:10,"
+ + "metrics:[{id:1,key:ncloc,valueType:INT,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+ + "globalSettings:{prop:value}}",
+ ref.toJson(), true);
+ }
+
+ @Test
+ public void testFromJson() throws JSONException {
+ GlobalReferentials ref = GlobalReferentials
+ .fromJson(new StringReader(
+ "{timestamp:1,"
+ + "metrics:[{id:1,key:ncloc,valueType:DATA,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+ + "globalSettings:{prop:value}}"));
+
+ assertThat(ref.timestamp()).isEqualTo(1);
+ Metric metric = ref.metrics().iterator().next();
+ assertThat(metric.id()).isEqualTo(1);
+ assertThat(metric.key()).isEqualTo("ncloc");
+ assertThat(metric.valueType()).isEqualTo("DATA");
+
+ assertThat(ref.globalSettings()).includes(MapAssert.entry("prop", "value"));
+ }
+}
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
index deeca583cb5..831f5e12cef 100644
--- 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
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.protocol.input;
+import org.fest.assertions.MapAssert;
import org.json.JSONException;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
@@ -34,7 +35,6 @@ public class ProjectReferentialsTest {
@Test
public void testToJson() throws Exception {
ProjectReferentials ref = new ProjectReferentials();
- ref.metrics().add(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 1.0, true));
ref.addQProfile(new QProfile("squid-java", "Java", "java", new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984")));
ref.addSettings("foo", new HashMap<String, String>());
ref.settings("foo").put("prop", "value");
@@ -44,7 +44,7 @@ public class ProjectReferentialsTest {
System.out.println(ref.toJson());
JSONAssert
.assertEquals(
- "{timestamp:10,metrics:[{id:1,key:ncloc,valueType:INT,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+ "{timestamp:10,"
+ "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,severity:MAJOR,internalKey:rule,language:java,params:{}}],"
+ "settingsByModule:{foo:{prop:value}}}",
@@ -53,18 +53,15 @@ public class ProjectReferentialsTest {
@Test
public void testFromJson() throws JSONException {
- ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,metrics:[{id:1,key:ncloc,valueType:DATA}],"
+ ProjectReferentials ref = ProjectReferentials.fromJson(new StringReader("{timestamp:1,"
+ "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,severity:MAJOR,internalKey:rule,language:java,params:{}}],"
+ "settingsByModule:{foo:{prop:value}}}"));
assertThat(ref.timestamp()).isEqualTo(1);
- Metric metric = ref.metrics().iterator().next();
- assertThat(metric.id()).isEqualTo(1);
- assertThat(metric.key()).isEqualTo("ncloc");
- assertThat(metric.valueType()).isEqualTo("DATA");
assertThat(ref.activeRules().iterator().next().ruleKey()).isEqualTo("rule");
assertThat(ref.qProfiles().iterator().next().name()).isEqualTo("Java");
+ assertThat(ref.settings("foo")).includes(MapAssert.entry("prop", "value"));
}
}
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 daa6210cd1f..d7d866f3d79 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
@@ -36,7 +36,10 @@ import org.sonar.batch.components.PastSnapshotFinderByDays;
import org.sonar.batch.components.PastSnapshotFinderByPreviousAnalysis;
import org.sonar.batch.components.PastSnapshotFinderByPreviousVersion;
import org.sonar.batch.components.PastSnapshotFinderByVersion;
+import org.sonar.batch.referential.DefaultGlobalReferentialsLoader;
import org.sonar.batch.referential.DefaultProjectReferentialsLoader;
+import org.sonar.batch.referential.GlobalReferentialsLoader;
+import org.sonar.batch.referential.GlobalReferentialsProvider;
import org.sonar.batch.referential.ProjectReferentialsLoader;
import org.sonar.batch.settings.DefaultSettingsReferential;
import org.sonar.batch.settings.SettingsReferential;
@@ -103,13 +106,17 @@ public class BootstrapContainer extends ComponentContainer {
HttpDownloader.class,
UriReader.class,
new FileCacheProvider(),
- System2.INSTANCE);
+ System2.INSTANCE,
+ new GlobalReferentialsProvider());
if (getComponentByType(SettingsReferential.class) == null) {
add(DefaultSettingsReferential.class);
}
if (getComponentByType(PluginsReferential.class) == null) {
add(DefaultPluginsReferential.class);
}
+ if (getComponentByType(GlobalReferentialsLoader.class) == null) {
+ add(DefaultGlobalReferentialsLoader.class);
+ }
if (getComponentByType(ProjectReferentialsLoader.class) == null) {
add(DefaultProjectReferentialsLoader.class);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java
index e7fd8427a2d..c29b5aa98bc 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/TaskContainer.java
@@ -31,6 +31,8 @@ import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.batch.scan.DeprecatedProjectReactorBuilder;
import org.sonar.batch.scan.ProjectReactorBuilder;
import org.sonar.batch.scan.ScanTask;
+import org.sonar.batch.scan.measure.DefaultMetricFinder;
+import org.sonar.batch.scan.measure.DeprecatedMetricFinder;
import org.sonar.batch.tasks.ListTask;
import org.sonar.batch.tasks.Tasks;
import org.sonar.core.permission.PermissionFacade;
@@ -54,11 +56,21 @@ public class TaskContainer extends ComponentContainer {
installCoreTasks();
installTaskExtensions();
installComponentsUsingTaskExtensions();
+ addCoreComponents();
for (Object component : components) {
add(component);
}
}
+ private void addCoreComponents() {
+ // Metrics
+ if (!getParent().getComponentByType(AnalysisMode.class).isSensorMode()) {
+ add(DeprecatedMetricFinder.class);
+ }
+ add(DefaultMetricFinder.class);
+
+ }
+
void installCoreTasks() {
add(new TaskProperties(taskProperties, getParent().getComponentByType(BootstrapProperties.class).property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)));
add(
diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
index 70a509bb22f..5eaa1ee13a4 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
@@ -35,7 +35,9 @@ import org.sonar.batch.bootstrap.PluginsReferential;
import org.sonar.batch.bootstrapper.Batch;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.batch.protocol.input.GlobalReferentials;
import org.sonar.batch.protocol.input.ProjectReferentials;
+import org.sonar.batch.referential.GlobalReferentialsLoader;
import org.sonar.batch.referential.ProjectReferentialsLoader;
import org.sonar.batch.scan.filesystem.InputFileCache;
import org.sonar.batch.scan2.AnalyzerIssueCache;
@@ -65,7 +67,8 @@ public class BatchMediumTester {
}
public static class BatchMediumTesterBuilder {
- private final FakeProjectReferentialsLoader refProvider = new FakeProjectReferentialsLoader();
+ private final FakeGlobalReferentialsLoader globalRefProvider = new FakeGlobalReferentialsLoader();
+ private final FakeProjectReferentialsLoader projectRefProvider = new FakeProjectReferentialsLoader();
private final FakeSettingsReferential settingsReferential = new FakeSettingsReferential();
private final FackPluginsReferential pluginsReferential = new FackPluginsReferential();
private final Map<String, String> bootstrapProperties = new HashMap<String, String>();
@@ -92,12 +95,12 @@ public class BatchMediumTester {
}
public BatchMediumTesterBuilder registerMetric(Metric<?> metric) {
- refProvider.add(metric);
+ globalRefProvider.add(metric);
return this;
}
public BatchMediumTesterBuilder addQProfile(String language, String name) {
- refProvider.addQProfile(language, name);
+ projectRefProvider.addQProfile(language, name);
return this;
}
@@ -113,7 +116,7 @@ public class BatchMediumTester {
}
public BatchMediumTesterBuilder activateRule(ActiveRule activeRule) {
- refProvider.addActiveRule(activeRule);
+ projectRefProvider.addActiveRule(activeRule);
return this;
}
@@ -134,7 +137,8 @@ public class BatchMediumTester {
new EnvironmentInformation("mediumTest", "1.0"),
builder.settingsReferential,
builder.pluginsReferential,
- builder.refProvider,
+ builder.globalRefProvider,
+ builder.projectRefProvider,
new DefaultDebtModel())
.setBootstrapProperties(builder.bootstrapProperties)
.build();
@@ -228,23 +232,18 @@ public class BatchMediumTester {
}
- private static class FakeProjectReferentialsLoader implements ProjectReferentialsLoader {
+ private static class FakeGlobalReferentialsLoader implements GlobalReferentialsLoader {
private int metricId = 1;
- private ProjectReferentials ref = new ProjectReferentials();
+ private GlobalReferentials ref = new GlobalReferentials();
@Override
- public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
+ public GlobalReferentials load() {
return ref;
}
- public FakeProjectReferentialsLoader addQProfile(String language, String name) {
- ref.addQProfile(new org.sonar.batch.protocol.input.QProfile(name, name, language, new Date()));
- return this;
- }
-
- public FakeProjectReferentialsLoader add(Metric metric) {
+ public FakeGlobalReferentialsLoader add(Metric metric) {
ref.metrics().add(new org.sonar.batch.protocol.input.Metric(metricId,
metric.key(),
metric.getType().name(),
@@ -259,6 +258,21 @@ public class BatchMediumTester {
metricId++;
return this;
}
+ }
+
+ private static class FakeProjectReferentialsLoader implements ProjectReferentialsLoader {
+
+ private ProjectReferentials ref = new ProjectReferentials();
+
+ @Override
+ public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
+ return ref;
+ }
+
+ public FakeProjectReferentialsLoader addQProfile(String language, String name) {
+ ref.addQProfile(new org.sonar.batch.protocol.input.QProfile(name, name, language, new Date()));
+ return this;
+ }
public FakeProjectReferentialsLoader addActiveRule(ActiveRule activeRule) {
ref.addActiveRule(activeRule);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java
new file mode 100644
index 00000000000..ec7e93382eb
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java
@@ -0,0 +1,67 @@
+/*
+ * 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.referential;
+
+import org.sonar.api.measures.Metric;
+import org.sonar.batch.protocol.input.GlobalReferentials;
+import org.sonar.jpa.session.DatabaseSessionFactory;
+
+import java.util.Collection;
+
+/**
+ * TODO This is currently implemented by accessing DB but should be replaced by WS call
+ */
+public class DefaultGlobalReferentialsLoader implements GlobalReferentialsLoader {
+
+ private static final String ENABLED = "enabled";
+
+ private final DatabaseSessionFactory sessionFactory;
+
+ public DefaultGlobalReferentialsLoader(DatabaseSessionFactory sessionFactory) {
+ this.sessionFactory = sessionFactory;
+ }
+
+ @Override
+ public GlobalReferentials load() {
+ GlobalReferentials ref = new GlobalReferentials();
+ for (Metric m : sessionFactory.getSession().getResults(Metric.class, ENABLED, true)) {
+ Boolean optimizedBestValue = m.isOptimizedBestValue();
+ Boolean qualitative = m.getQualitative();
+ Boolean userManaged = m.getUserManaged();
+ ref.metrics().add(
+ new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(),
+ m.getType().name(),
+ m.getDescription(),
+ m.getDirection(),
+ m.getName(),
+ qualitative != null ? m.getQualitative() : false,
+ userManaged != null ? m.getUserManaged() : false,
+ m.getWorstValue(),
+ m.getBestValue(),
+ optimizedBestValue != null ? optimizedBestValue : false));
+ }
+
+ return ref;
+ }
+
+ private Collection<Metric> doFindAll() {
+ return sessionFactory.getSession().getResults(Metric.class, ENABLED, true);
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
index 558308bb8cb..3ca6ff97634 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
@@ -24,7 +24,6 @@ import com.google.common.collect.ListMultimap;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
-import org.sonar.api.measures.Metric;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Languages;
import org.sonar.api.rules.Rule;
@@ -41,12 +40,9 @@ import org.sonar.core.qualityprofile.db.ActiveRuleDto;
import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
import org.sonar.core.qualityprofile.db.QualityProfileDao;
import org.sonar.core.qualityprofile.db.QualityProfileDto;
-import org.sonar.jpa.session.DatabaseSessionFactory;
import javax.annotation.CheckForNull;
-import java.util.Collection;
-
/**
* TODO This is currently implemented by accessing DB but should be replaced by WS call
*/
@@ -54,14 +50,12 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad
private static final String ENABLED = "enabled";
- private final DatabaseSessionFactory sessionFactory;
private final QualityProfileDao qualityProfileDao;
private final ActiveRuleDao activeRuleDao;
private final RuleFinder ruleFinder;
- public DefaultProjectReferentialsLoader(DatabaseSessionFactory sessionFactory, QualityProfileDao qualityProfileDao,
+ public DefaultProjectReferentialsLoader(QualityProfileDao qualityProfileDao,
ActiveRuleDao activeRuleDao, RuleFinder ruleFinder) {
- this.sessionFactory = sessionFactory;
this.qualityProfileDao = qualityProfileDao;
this.activeRuleDao = activeRuleDao;
this.ruleFinder = ruleFinder;
@@ -70,22 +64,6 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad
@Override
public ProjectReferentials load(ProjectReactor reactor, Settings settings, Languages languages) {
ProjectReferentials ref = new ProjectReferentials();
- for (Metric m : sessionFactory.getSession().getResults(Metric.class, ENABLED, true)) {
- Boolean optimizedBestValue = m.isOptimizedBestValue();
- Boolean qualitative = m.getQualitative();
- Boolean userManaged = m.getUserManaged();
- ref.metrics().add(
- new org.sonar.batch.protocol.input.Metric(m.getId(), m.getKey(),
- m.getType().name(),
- m.getDescription(),
- m.getDirection(),
- m.getName(),
- qualitative != null ? m.getQualitative() : false,
- userManaged != null ? m.getUserManaged() : false,
- m.getWorstValue(),
- m.getBestValue(),
- optimizedBestValue != null ? optimizedBestValue : false));
- }
String defaultName = settings.getString(ModuleQProfiles.SONAR_PROFILE_PROP);
@@ -158,10 +136,6 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad
return get(language, profileName);
}
- protected Collection<Metric> doFindAll() {
- return sessionFactory.getSession().getResults(Metric.class, ENABLED, true);
- }
-
public QProfile get(String language, String name) {
QualityProfileDto dto = qualityProfileDao.getByNameAndLanguage(name, language);
if (dto == null) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsLoader.java
new file mode 100644
index 00000000000..d355867d433
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsLoader.java
@@ -0,0 +1,28 @@
+/*
+ * 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.referential;
+
+import org.sonar.batch.protocol.input.GlobalReferentials;
+
+public interface GlobalReferentialsLoader {
+
+ GlobalReferentials load();
+
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsProvider.java b/sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsProvider.java
new file mode 100644
index 00000000000..87da7f92d65
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/referential/GlobalReferentialsProvider.java
@@ -0,0 +1,30 @@
+/*
+ * 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.referential;
+
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.batch.protocol.input.GlobalReferentials;
+
+public class GlobalReferentialsProvider extends ProviderAdapter {
+
+ public GlobalReferentials provide(GlobalReferentialsLoader loader) {
+ return loader.load();
+ }
+}
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 911aede44cc..9c2b46bf9b8 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
@@ -70,8 +70,6 @@ import org.sonar.batch.rule.RulesProvider;
import org.sonar.batch.scan.filesystem.InputFileCache;
import org.sonar.batch.scan.maven.FakeMavenPluginExecutor;
import org.sonar.batch.scan.maven.MavenPluginExecutor;
-import org.sonar.batch.scan.measure.DefaultMetricFinder;
-import org.sonar.batch.scan.measure.DeprecatedMetricFinder;
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.source.HighlightableBuilder;
import org.sonar.batch.source.SymbolizableBuilder;
@@ -192,8 +190,6 @@ public class ProjectScanContainer extends ComponentContainer {
// Measures
MeasureCache.class,
- DeprecatedMetricFinder.class,
- DefaultMetricFinder.class,
PastMeasuresLoader.class,
// Rules
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java
index 4881bf8a6cd..aac335178f5 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DefaultMetricFinder.java
@@ -24,7 +24,7 @@ import com.google.common.collect.Maps;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.measures.Metric.ValueType;
-import org.sonar.batch.protocol.input.ProjectReferentials;
+import org.sonar.batch.protocol.input.GlobalReferentials;
import java.util.Collection;
import java.util.List;
@@ -34,8 +34,8 @@ public class DefaultMetricFinder implements MetricFinder {
private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
- public DefaultMetricFinder(ProjectReferentials projectReferentials) {
- for (org.sonar.batch.protocol.input.Metric metric : projectReferentials.metrics()) {
+ public DefaultMetricFinder(GlobalReferentials globalReferentials) {
+ for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) {
metricsByKey.put(metric.key(), new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType())).create());
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java
index 3f1ab39668d..7242f61c8ad 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/measure/DeprecatedMetricFinder.java
@@ -24,7 +24,7 @@ import com.google.common.collect.Maps;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.api.measures.MetricFinder;
-import org.sonar.batch.protocol.input.ProjectReferentials;
+import org.sonar.batch.protocol.input.GlobalReferentials;
import java.util.Collection;
import java.util.List;
@@ -35,8 +35,8 @@ public final class DeprecatedMetricFinder implements MetricFinder {
private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
private Map<Integer, Metric> metricsById = Maps.newLinkedHashMap();
- public DeprecatedMetricFinder(ProjectReferentials projectReferentials) {
- for (org.sonar.batch.protocol.input.Metric metric : projectReferentials.metrics()) {
+ public DeprecatedMetricFinder(GlobalReferentials globalReferentials) {
+ for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) {
Metric hibernateMetric = new org.sonar.api.measures.Metric.Builder(metric.key(), metric.key(), ValueType.valueOf(metric.valueType()))
.create()
.setDirection(metric.direction())
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 a2b602f166a..91b11ce80da 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
@@ -44,7 +44,6 @@ 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;
-import org.sonar.batch.scan.measure.DefaultMetricFinder;
public class ProjectScanContainer extends ComponentContainer {
public ProjectScanContainer(ComponentContainer taskContainer) {
@@ -96,7 +95,6 @@ public class ProjectScanContainer extends ComponentContainer {
DefaultLanguagesReferential.class,
// Measures
- DefaultMetricFinder.class,
AnalyzerMeasureCache.class,
// file system