aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-09-28 12:10:05 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-09-28 12:10:05 +0000
commitd2f25e344d5db20b68339d52ad940e7f17edfc4d (patch)
tree08764c4c16267bf9265f885859d65831c5d25332 /sonar-plugin-api/src
parent51f793f7e9f643e12d148a9fac9a2ac79ef3da49 (diff)
downloadsonarqube-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-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/Plugins.java15
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java20
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java95
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractCoverageExtensionTest.java37
5 files changed, 23 insertions, 150 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java
index bc5b61544a6..615c57a6631 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java
@@ -19,13 +19,11 @@
*/
package org.sonar.api;
-import java.util.Collection;
+import org.picocontainer.injectors.Provider;
/**
* @since 2.3
*/
-public interface ExtensionProvider {
-
- Collection provide();
+public abstract class ExtensionProvider implements Extension, Provider {
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/Plugins.java b/sonar-plugin-api/src/main/java/org/sonar/api/Plugins.java
index eca185e4920..82fa9606c36 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/Plugins.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/Plugins.java
@@ -54,21 +54,6 @@ public class Plugins {
return pluginProvider.getPlugin(key);
}
-
- /**
- * Returns a plugin based on its extension
- */
- public Plugin getPluginByExtension(Class<? extends Extension> clazz) {
- return pluginProvider.getPluginForExtension(clazz);
- }
-
- /**
- * Returns a plugin key based on its extension
- */
- public String getPluginKeyByExtension(Class<? extends Extension> clazz) {
- return pluginProvider.getPluginKeyForExtension(clazz);
- }
-
/**
* Returns a plugin based on its extension
*/
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java
index 330e1d4e79c..02869c36a5b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.batch;
-import org.apache.commons.lang.ArrayUtils;
import org.sonar.api.BatchExtension;
import org.sonar.api.Plugins;
import org.sonar.api.resources.Project;
@@ -42,29 +41,22 @@ public abstract class AbstractCoverageExtension implements BatchExtension {
*/
public static final String DEFAULT_PLUGIN = "cobertura";
- private final Plugins plugins;
-
/**
* Default constructor
+ *
* @param plugins the list of plugins available
+ * @deprecated since 2.3. Use the default constructor
*/
public AbstractCoverageExtension(Plugins plugins) {
- this.plugins = plugins;
+ }
+
+ public AbstractCoverageExtension() {
}
/**
* Whether to implement the extension on the project
*/
public boolean shouldExecuteOnProject(Project project) {
- return project.getAnalysisType().isDynamic(true) && isSelectedPlugin(project);
- }
-
- protected boolean isSelectedPlugin(Project project) {
- String[] selectedPluginKeys = project.getConfiguration().getStringArray(PARAM_PLUGIN);
- if (selectedPluginKeys.length == 0) {
- selectedPluginKeys = new String[]{DEFAULT_PLUGIN};
- }
- String pluginKey = plugins.getPluginKeyByExtension(getClass());
- return ArrayUtils.contains(selectedPluginKeys, pluginKey);
+ return project.getAnalysisType().isDynamic(true);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java
index 611c3eeca28..8529642a9f1 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java
@@ -19,95 +19,20 @@
*/
package org.sonar.api.platform;
-import org.picocontainer.Characteristics;
-import org.picocontainer.MutablePicoContainer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.*;
+import org.sonar.api.BatchComponent;
+import org.sonar.api.Plugin;
+import org.sonar.api.Property;
+import org.sonar.api.ServerComponent;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.IdentityHashMap;
-import java.util.Map;
-/**
- * @since 2.2
- */
-public abstract class PluginRepository implements BatchComponent, ServerComponent {
-
- private static final Logger LOG = LoggerFactory.getLogger(PluginRepository.class);
-
- private Map<String, Plugin> pluginByKey = new HashMap<String, Plugin>();
- private Map<Object, Plugin> pluginByExtension = new IdentityHashMap<Object, Plugin>();
-
- public void registerPlugin(MutablePicoContainer container, Plugin plugin, Class<? extends Extension> extensionClass) {
- LOG.debug("Registering the plugin {}", plugin.getKey());
- pluginByKey.put(plugin.getKey(), plugin);
- for (Object extension : plugin.getExtensions()) {
- if (isExtension(extension, extensionClass)) {
- LOG.debug("Registering the extension: {}", extension);
- container.as(Characteristics.CACHE).addComponent(getExtensionKey(extension), extension);
- pluginByExtension.put(extension, plugin);
- }
- }
- }
-
- public Collection<Plugin> getPlugins() {
- return pluginByKey.values();
- }
-
- public Plugin getPlugin(String key) {
- return pluginByKey.get(key);
- }
-
- /**
- * Returns the list of properties of a plugin
- */
- public Property[] getProperties(Plugin plugin) {
- if (plugin != null) {
- Class<? extends Plugin> classInstance = plugin.getClass();
- if (classInstance.isAnnotationPresent(Properties.class)) {
- return classInstance.getAnnotation(Properties.class).value();
- }
- }
- return new Property[0];
- }
-
- public Property[] getProperties(String pluginKey) {
- return getProperties(pluginByKey.get(pluginKey));
- }
-
- public Plugin getPluginForExtension(Object extension) {
- Plugin plugin = pluginByExtension.get(extension);
- if (plugin == null && !(extension instanceof Class)) {
- plugin = pluginByExtension.get(extension.getClass());
- }
- return plugin;
- }
-
- public String getPluginKeyForExtension(Object extension) {
- Plugin plugin = getPluginForExtension(extension);
- if (plugin != null) {
- return plugin.getKey();
- }
- return null;
- }
-
- private boolean isExtension(Object extension, Class<? extends Extension> extensionClass) {
- Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
- return extensionClass.isAssignableFrom(clazz);
- }
+public interface PluginRepository extends BatchComponent, ServerComponent {
+ Collection<Plugin> getPlugins();
- public void registerExtension(MutablePicoContainer container, Plugin plugin, Object extension) {
- container.as(Characteristics.CACHE).addComponent(getExtensionKey(extension), extension);
- pluginByExtension.put(extension, plugin);
- }
+ Plugin getPlugin(String key);
- protected Object getExtensionKey(Object component) {
- if (component instanceof Class) {
- return component;
- }
- return component.getClass().getCanonicalName() + "-" + component.toString();
- }
+ @Deprecated
+ Plugin getPluginForExtension(Object extension);
+ Property[] getProperties(Plugin plugin);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractCoverageExtensionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractCoverageExtensionTest.java
index bfa556fabd0..036b8647878 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractCoverageExtensionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractCoverageExtensionTest.java
@@ -19,53 +19,26 @@
*/
package org.sonar.api.batch;
-import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+import org.sonar.api.resources.Project;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import org.sonar.api.Plugins;
-import org.sonar.api.resources.Project;
public class AbstractCoverageExtensionTest {
@Test
- public void defaultPluginIsCobertura() {
- Plugins plugins = mock(Plugins.class);
- when(plugins.getPluginKeyByExtension(FakeCoverageSensor.class)).thenReturn("cobertura");
-
- Project project = mock(Project.class);
- when(project.getConfiguration()).thenReturn(new PropertiesConfiguration());
-
- assertThat(new FakeCoverageSensor(plugins).isSelectedPlugin(project), is(true));
- }
-
- @Test
- public void doNotExecuteIfNotSelectedPlugin() {
- Plugins plugins = mock(Plugins.class);
- when(plugins.getPluginKeyByExtension(FakeCoverageSensor.class)).thenReturn("fake");
-
- Project project = mock(Project.class);
- PropertiesConfiguration config = new PropertiesConfiguration();
- when(project.getConfiguration()).thenReturn(config);
- config.setProperty(AbstractCoverageExtension.PARAM_PLUGIN, "cobertura");
-
- assertThat(new FakeCoverageSensor(plugins).isSelectedPlugin(project), is(false));
- }
-
- @Test
public void doNotExecuteIfStaticAnalysis() {
Project project = mock(Project.class);
when(project.getAnalysisType()).thenReturn(Project.AnalysisType.STATIC);
- FakeCoverageSensor sensor = new FakeCoverageSensor(null);
+ FakeCoverageSensor sensor = new FakeCoverageSensor();
assertThat(sensor.shouldExecuteOnProject(project), is(false));
}
protected static class FakeCoverageSensor extends AbstractCoverageExtension {
- public FakeCoverageSensor(Plugins plugins) {
- super(plugins);
- }
+
}
}