diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-28 12:10:05 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-09-28 12:10:05 +0000 |
commit | d2f25e344d5db20b68339d52ad940e7f17edfc4d (patch) | |
tree | 08764c4c16267bf9265f885859d65831c5d25332 /sonar-server | |
parent | 51f793f7e9f643e12d148a9fac9a2ac79ef3da49 (diff) | |
download | sonarqube-d2f25e344d5db20b68339d52ad940e7f17edfc4d.tar.gz sonarqube-d2f25e344d5db20b68339d52ad940e7f17edfc4d.zip |
SONAR-1814 remove the API to find a plugin from an extension :
* do register coverage extensions in picocontainer only when the plugin is selected (see parameter sonar.core.codeCoveragePlugin)
* do not display plugin names when detecting a duplication of metrics
* remove unused methods from the deprecated component RulesManager
Diffstat (limited to 'sonar-server')
5 files changed, 79 insertions, 23 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index bf8b923b6b9..145ba28e3f4 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -133,7 +133,7 @@ public final class Platform { coreContainer.as(Characteristics.CACHE).addComponent(UpdateFinderFactory.class); coreContainer.as(Characteristics.CACHE).addComponent(PluginDownloader.class); coreContainer.as(Characteristics.NO_CACHE).addComponent(FilterExecutor.class); - coreContainer.addAdapter(new DatabaseSessionProvider()); + coreContainer.as(Characteristics.NO_CACHE).addAdapter(new DatabaseSessionProvider()); coreContainer.start(); DatabaseConfiguration dbConfiguration = new DatabaseConfiguration(coreContainer.getComponent(DatabaseSessionFactory.class)); diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java b/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java index 980898bc0eb..cfb1191fc11 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java @@ -23,15 +23,15 @@ import org.picocontainer.Characteristics; import org.picocontainer.MutablePicoContainer; import org.sonar.api.Plugin; import org.sonar.api.ServerExtension; -import org.sonar.api.platform.PluginRepository; import org.sonar.api.utils.SonarException; +import org.sonar.core.plugin.AbstractPluginRepository; import org.sonar.core.plugin.JpaPlugin; import org.sonar.core.plugin.JpaPluginDao; /** * @since 2.2 */ -public class ServerPluginRepository extends PluginRepository { +public class ServerPluginRepository extends AbstractPluginRepository { private JpaPluginDao dao; private PluginClassLoaders classloaders; @@ -41,18 +41,29 @@ public class ServerPluginRepository extends PluginRepository { this.classloaders = classloaders; } + /** + * Only for unit tests + */ + ServerPluginRepository() { + } + public void registerPlugins(MutablePicoContainer pico) { for (JpaPlugin jpaPlugin : dao.getPlugins()) { try { Class pluginClass = classloaders.getClassLoader(jpaPlugin.getKey()).loadClass(jpaPlugin.getPluginClass()); pico.as(Characteristics.CACHE).addComponent(pluginClass); Plugin plugin = (Plugin) pico.getComponent(pluginClass); - registerPlugin(pico, plugin, ServerExtension.class); - + registerPlugin(pico, plugin, jpaPlugin.getKey()); + + } catch (ClassNotFoundException e) { throw new SonarException("Please check the plugin manifest. The main plugin class does not exist: " + jpaPlugin.getPluginClass(), e); } } } + @Override + protected boolean shouldRegisterExtension(String pluginKey, Object extension) { + return isType(extension, ServerExtension.class); + } } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java index 4b66047e7d2..4e9ea3d96ca 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java @@ -36,35 +36,30 @@ import com.google.common.collect.Maps; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.persistence.Query;
public class RegisterMetrics {
- private PluginRepository pluginRepository;
private MeasuresDao measuresDao;
private Metrics[] metricsRepositories = null;
private DatabaseSession session;
- public RegisterMetrics(DatabaseSession session, MeasuresDao measuresDao, PluginRepository pluginRepository, Metrics[] metricsRepositories) {
+ public RegisterMetrics(DatabaseSession session, MeasuresDao measuresDao, Metrics[] metricsRepositories) {
this.session = session;
this.measuresDao = measuresDao;
- this.pluginRepository = pluginRepository;
this.metricsRepositories = metricsRepositories;
}
- public RegisterMetrics(MeasuresDao measuresDao) {
- this.measuresDao = measuresDao;
- }
-
public void start() {
TimeProfiler profiler = new TimeProfiler().start("Load metrics");
measuresDao.disableAutomaticMetrics();
- ArrayList<Metric> metricsToRegister = Lists.newArrayList();
+ List<Metric> metricsToRegister = Lists.newArrayList();
metricsToRegister.addAll(CoreMetrics.getMetrics());
- HashMap<String, Metrics> metricsByRepository = Maps.newHashMap();
+ Map<String, Metrics> metricsByRepository = Maps.newHashMap();
if (metricsRepositories != null) {
for (Metrics metrics : metricsRepositories) {
checkMetrics(metricsByRepository, metrics);
@@ -76,17 +71,15 @@ public class RegisterMetrics { profiler.stop();
}
- private void checkMetrics(HashMap<String, Metrics> metricsByRepository, Metrics metrics) {
+ private void checkMetrics(Map<String, Metrics> metricsByRepository, Metrics metrics) {
for (Metric metric : metrics.getMetrics()) {
String metricKey = metric.getKey();
if (CoreMetrics.metrics.contains(metric)) {
- throw new ServerStartException("Found plugin, which contains metric '" + metricKey + "' from core: " + pluginRepository.getPluginKeyForExtension(metrics));
+ throw new ServerStartException("The following metric is already defined in sonar: " + metricKey);
}
Metrics anotherRepository = metricsByRepository.get(metricKey);
if (anotherRepository != null) {
- String firstPlugin = pluginRepository.getPluginKeyForExtension(anotherRepository);
- String secondPlugin = pluginRepository.getPluginKeyForExtension(metrics);
- throw new ServerStartException("Found two plugins with the same metric '" + metricKey + "': " + firstPlugin + " and " + secondPlugin);
+ throw new ServerStartException("The metric '" + metricKey + "' is already defined in the extension: " + anotherRepository);
}
metricsByRepository.put(metricKey, metrics);
}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java new file mode 100644 index 00000000000..d6d3115e806 --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java @@ -0,0 +1,52 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.server.plugins; + +import org.junit.Test; +import org.sonar.api.BatchExtension; +import org.sonar.api.ServerExtension; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class ServerPluginRepositoryTest { + @Test + public void shouldRegisterServerExtensions() { + ServerPluginRepository repository = new ServerPluginRepository(); + + // check classes + assertThat(repository.shouldRegisterExtension("foo", FakeBatchExtension.class), is(false)); + assertThat(repository.shouldRegisterExtension("foo", FakeServerExtension.class), is(true)); + assertThat(repository.shouldRegisterExtension("foo", String.class), is(false)); + + // check objects + assertThat(repository.shouldRegisterExtension("foo", new FakeBatchExtension()), is(false)); + assertThat(repository.shouldRegisterExtension("foo", new FakeServerExtension()), is(true)); + assertThat(repository.shouldRegisterExtension("foo", "foo"), is(false)); + } + + public static class FakeBatchExtension implements BatchExtension { + + } + + public static class FakeServerExtension implements ServerExtension { + + } +} diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java index 2f2244e938a..49670f559ca 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java @@ -41,7 +41,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase { Metric metric1 = new Metric("new1", "short1", "desc1", Metric.ValueType.FLOAT, 1, true, "domain1", false);
Metric metric2 = new Metric("new2", "short2", "desc2", Metric.ValueType.FLOAT, 1, true, "domain2", false);
- RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);
+ RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);
synchronizer.register(Arrays.asList(metric1, metric2));
checkTables("shouldSaveIfNew", "metrics");
}
@@ -52,7 +52,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase { final List<Metric> metrics = new ArrayList<Metric>();
metrics.add(new Metric("key", "new short name", "new description", Metric.ValueType.FLOAT, -1, true, "new domain", false));
- RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);
+ RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);
synchronizer.register(metrics);
checkTables("shouldUpdateIfAlreadyExists", "metrics");
@@ -62,7 +62,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase { public void enableOnlyLoadedMetrics() throws SQLException {
setupData("enableOnlyLoadedMetrics");
- RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);
+ RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);
loader.start();
assertFalse(getDao().getMeasuresDao().getMetric("deprecated").getEnabled());
@@ -73,7 +73,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase { public void cleanAlerts() throws SQLException {
setupData("cleanAlerts");
- RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);
+ RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);
loader.cleanAlerts();
checkTables("cleanAlerts", "metrics", "alerts");
|