]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1814 remove the API to find a plugin from an extension :
authorsimonbrandhof <simon.brandhof@gmail.com>
Tue, 28 Sep 2010 12:10:05 +0000 (12:10 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Tue, 28 Sep 2010 12:10:05 +0000 (12:10 +0000)
 * 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

17 files changed:
sonar-batch/src/main/java/org/sonar/batch/BatchPluginRepository.java
sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java [new file with mode: 0644]
sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java [new file with mode: 0644]
sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java [new file with mode: 0644]
sonar-deprecated/src/main/java/org/sonar/api/rules/DefaultRulesManager.java
sonar-deprecated/src/main/java/org/sonar/api/rules/RulesManager.java
sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java [deleted file]
sonar-plugin-api/src/main/java/org/sonar/api/ExtensionProvider.java
sonar-plugin-api/src/main/java/org/sonar/api/Plugins.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCoverageExtension.java
sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractCoverageExtensionTest.java
sonar-server/src/main/java/org/sonar/server/platform/Platform.java
sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterMetrics.java
sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java [new file with mode: 0644]
sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java

index 105686834e449f9e0f403eb12dabb0e9e171a6f0..5544762ad7a450a8577a5d8effd3dee9a91007b6 100644 (file)
 package org.sonar.batch;
 
 import com.google.common.collect.HashMultimap;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.lang.ArrayUtils;
 import org.picocontainer.MutablePicoContainer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.BatchExtension;
 import org.sonar.api.Plugin;
-import org.sonar.api.platform.PluginRepository;
+import org.sonar.api.batch.AbstractCoverageExtension;
+import org.sonar.api.utils.SonarException;
+import org.sonar.core.plugin.AbstractPluginRepository;
 import org.sonar.core.plugin.JpaPlugin;
 import org.sonar.core.plugin.JpaPluginDao;
 import org.sonar.core.plugin.JpaPluginFile;
@@ -36,15 +40,26 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-public class BatchPluginRepository extends PluginRepository {
+public class BatchPluginRepository extends AbstractPluginRepository {
+
+  private static final Logger LOG = LoggerFactory.getLogger(BatchPluginRepository.class);
 
   private Map<String, ClassLoader> classloaders;
   private String baseUrl;
   private JpaPluginDao dao;
+  private Configuration configuration;
 
-  public BatchPluginRepository(JpaPluginDao dao, ServerMetadata server) {
-    this.dao= dao;
+  public BatchPluginRepository(JpaPluginDao dao, ServerMetadata server, Configuration configuration) {
+    this.dao = dao;
     this.baseUrl = server.getUrl() + "/deploy/plugins/";
+    this.configuration = configuration;
+  }
+
+  /**
+   * only for unit tests
+   */
+  BatchPluginRepository(Configuration configuration) {
+    this.configuration = configuration;
   }
 
   public void start() {
@@ -56,7 +71,7 @@ public class BatchPluginRepository extends PluginRepository {
         urlsByKey.put(key, url);
 
       } catch (MalformedURLException e) {
-        throw new RuntimeException("Can not build the classloader of the plugin " + pluginFile.getPluginKey(), e);
+        throw new SonarException("Can not build the classloader of the plugin " + pluginFile.getPluginKey(), e);
       }
     }
 
@@ -64,11 +79,10 @@ public class BatchPluginRepository extends PluginRepository {
     for (String key : urlsByKey.keySet()) {
       Set<URL> urls = urlsByKey.get(key);
 
-      Logger logger = LoggerFactory.getLogger(getClass());
-      if (logger.isDebugEnabled()) {
-        logger.debug("Classloader of plugin " + key + ":");
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Classloader of plugin " + key + ":");
         for (URL url : urls) {
-          logger.debug("   -> " + url);
+          LOG.debug("   -> " + url);
         }
       }
       classloaders.put(key, new RemoteClassLoader(urls, Thread.currentThread().getContextClassLoader()).getClassLoader());
@@ -80,16 +94,36 @@ public class BatchPluginRepository extends PluginRepository {
   }
 
   public void registerPlugins(MutablePicoContainer pico) {
-    try {
-      for (JpaPlugin pluginMetadata : dao.getPlugins()) {
+    for (JpaPlugin pluginMetadata : dao.getPlugins()) {
+      try {
         String classloaderKey = getClassloaderKey(pluginMetadata.getKey());
         Class claz = classloaders.get(classloaderKey).loadClass(pluginMetadata.getPluginClass());
         Plugin plugin = (Plugin) claz.newInstance();
-        registerPlugin(pico, plugin, BatchExtension.class);
+        registerPlugin(pico, plugin, pluginMetadata.getKey());
+
+      } catch (Exception e) {
+        throw new SonarException("Fail to load extensions from plugin " + pluginMetadata.getKey(), e);
       }
+    }
+  }
 
-    } catch (Exception e) {
-      throw new RuntimeException(e);
+  boolean shouldRegisterCoverageExtension(String pluginKey) {
+    String[] selectedPluginKeys = configuration.getStringArray(AbstractCoverageExtension.PARAM_PLUGIN);
+    if (ArrayUtils.isEmpty(selectedPluginKeys)) {
+      selectedPluginKeys = new String[]{AbstractCoverageExtension.DEFAULT_PLUGIN};
+    }
+    return ArrayUtils.contains(selectedPluginKeys, pluginKey);
+  }
+
+  @Override
+  protected boolean shouldRegisterExtension(String pluginKey, Object extension) {
+    boolean ok = isType(extension, BatchExtension.class);
+    if (ok && isType(extension, AbstractCoverageExtension.class)) {
+      ok = shouldRegisterCoverageExtension(pluginKey);
+      if (!ok) {
+        LOG.debug("The following extension is ignored: " + extension + ". See the parameter " + AbstractCoverageExtension.PARAM_PLUGIN);
+      }
     }
+    return ok;
   }
 }
diff --git a/sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/BatchPluginRepositoryTest.java
new file mode 100644 (file)
index 0000000..1f7696e
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.batch;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.batch.AbstractCoverageExtension;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class BatchPluginRepositoryTest {
+
+  @Test
+  public void shouldRegisterBatchExtension() {
+    BatchPluginRepository repository = new BatchPluginRepository(new PropertiesConfiguration());
+
+    // check classes
+    assertThat(repository.shouldRegisterExtension("foo", FakeBatchExtension.class), is(true));
+    assertThat(repository.shouldRegisterExtension("foo", FakeServerExtension.class), is(false));
+    assertThat(repository.shouldRegisterExtension("foo", String.class), is(false));
+
+    // check objects
+    assertThat(repository.shouldRegisterExtension("foo", new FakeBatchExtension()), is(true));
+    assertThat(repository.shouldRegisterExtension("foo", new FakeServerExtension()), is(false));
+    assertThat(repository.shouldRegisterExtension("foo", "bar"), is(false));
+  }
+
+  @Test
+  public void shouldRegisterOnlyCoberturaExtensionByDefault() {
+    Configuration conf = new PropertiesConfiguration();
+    BatchPluginRepository repository = new BatchPluginRepository(conf);
+    assertThat(repository.shouldRegisterCoverageExtension("cobertura"), is(true));
+    assertThat(repository.shouldRegisterCoverageExtension("clover"), is(false));
+  }
+
+  @Test
+  public void shouldRegisterCustomCoverageExtension() {
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty(AbstractCoverageExtension.PARAM_PLUGIN, "clover,phpunit");
+    BatchPluginRepository repository = new BatchPluginRepository(conf);
+    assertThat(repository.shouldRegisterCoverageExtension("cobertura"), is(false));
+    assertThat(repository.shouldRegisterCoverageExtension("clover"), is(true));
+    assertThat(repository.shouldRegisterCoverageExtension("phpunit"), is(true));
+    assertThat(repository.shouldRegisterCoverageExtension("other"), is(false));
+  }
+
+
+  public static class FakeBatchExtension implements BatchExtension {
+
+  }
+
+  public static class FakeServerExtension implements ServerExtension {
+
+  }
+}
diff --git a/sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java b/sonar-core/src/main/java/org/sonar/core/plugin/AbstractPluginRepository.java
new file mode 100644 (file)
index 0000000..24a40d9
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * 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.core.plugin;
+
+import com.google.common.collect.Maps;
+import org.picocontainer.Characteristics;
+import org.picocontainer.MutablePicoContainer;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.*;
+import org.sonar.api.platform.PluginRepository;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @since 2.2
+ */
+public abstract class AbstractPluginRepository implements PluginRepository {
+
+  private static final Logger LOG = LoggerFactory.getLogger(AbstractPluginRepository.class);
+
+  private Map<String, Plugin> pluginByKey = Maps.newHashMap();
+  private Map<Object, Plugin> pluginByExtension = Maps.newIdentityHashMap();
+
+  protected void registerPlugin(MutablePicoContainer container, Plugin plugin, String pluginKey) {
+    LOG.debug("Register the plugin {}", pluginKey);
+    pluginByKey.put(pluginKey, plugin);
+    for (Object extension : plugin.getExtensions()) {
+      registerExtension(container, plugin, pluginKey, extension);
+    }
+  }
+
+  private void registerExtension(MutablePicoContainer container, Plugin plugin, String pluginKey, Object extension) {
+    if (shouldRegisterExtension(pluginKey, extension)) {
+      LOG.debug("Register the extension: {}", extension);
+      container.as(Characteristics.CACHE).addComponent(getExtensionKey(extension), extension);
+      pluginByExtension.put(extension, plugin);
+    }
+    if (isExtensionProvider(extension)) {
+      LOG.debug("Register the extension provider: {}", extension);
+      container.as(Characteristics.CACHE).addAdapter(new ExtensionProviderAdapter(extension));
+    }
+  }
+
+  protected abstract boolean shouldRegisterExtension(String pluginKey, Object extension);
+
+  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;
+  }
+
+  protected static boolean isType(Object extension, Class<? extends Extension> extensionClass) {
+    Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
+    return extensionClass.isAssignableFrom(clazz);
+  }
+
+  protected static boolean isExtensionProvider(Object extension) {
+    return extension instanceof ExtensionProvider;
+  }
+
+  protected static Object getExtensionKey(Object component) {
+    if (component instanceof Class) {
+      return component;
+    }
+    return component.getClass().getCanonicalName() + "-" + component.toString();
+  }
+
+  public static class ExtensionProviderAdapter extends ProviderAdapter {
+    public ExtensionProviderAdapter(Object provider) {
+      super(provider);
+    }
+  }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java b/sonar-core/src/test/java/org/sonar/core/plugin/AbstractPluginRepositoryTest.java
new file mode 100644 (file)
index 0000000..319150c
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * 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.core.plugin;
+
+import org.junit.Test;
+import org.picocontainer.MutablePicoContainer;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.ExtensionProvider;
+import org.sonar.api.Plugin;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.utils.IocContainer;
+
+import java.util.Arrays;
+
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AbstractPluginRepositoryTest {
+
+  @Test
+  public void testIsType() {
+    assertThat(AbstractPluginRepository.isType(FakeServerExtension.class, ServerExtension.class), is(true));
+    assertThat(AbstractPluginRepository.isType(new FakeServerExtension(), ServerExtension.class), is(true));
+
+    assertThat(AbstractPluginRepository.isType(FakeBatchExtension.class, ServerExtension.class), is(false));
+    assertThat(AbstractPluginRepository.isType(new FakeBatchExtension(), ServerExtension.class), is(false));
+    assertThat(AbstractPluginRepository.isType(String.class, ServerExtension.class), is(false));
+    assertThat(AbstractPluginRepository.isType("foo", ServerExtension.class), is(false));
+  }
+
+  @Test
+  public void extensionKeyshouldBeClassNameIfClass() {
+    assertEquals(AbstractPluginRepository.getExtensionKey(FakeServerExtension.class), FakeServerExtension.class);
+  }
+
+  @Test
+  public void extensionKeyshouldBeUniqueIfObject() {
+    assertThat((String) AbstractPluginRepository.getExtensionKey(new FakeServerExtension()), endsWith("FakeServerExtension-instance"));
+  }
+
+  @Test
+  public void extensionProviderIsAnObjectButNotAClass() {
+    assertThat(AbstractPluginRepository.isExtensionProvider(BProvider.class), is(false));
+    assertThat(AbstractPluginRepository.isExtensionProvider(new BProvider()), is(true));
+  }
+
+  @Test
+  public void shouldRegisterExtensionProviders() {
+    MutablePicoContainer pico = IocContainer.buildPicoContainer();
+    AbstractPluginRepository repository = new AbstractPluginRepository() {
+      @Override
+      protected boolean shouldRegisterExtension(String pluginKey, Object extension) {
+        return isType(extension, ServerExtension.class);
+      }
+    };
+
+    Plugin plugin = mock(Plugin.class);
+    BProvider bProvider = new BProvider();
+    when(plugin.getExtensions()).thenReturn(Arrays.asList(A.class, bProvider, C.class, D.class));
+    repository.registerPlugin(pico, plugin, "foo");
+    pico.start();
+
+    assertThat(pico.getComponent(A.class), is(A.class));
+    assertThat(pico.getComponent(C.class), is(C.class));
+    assertThat(pico.getComponent(D.class), is(D.class));
+    assertThat(pico.getComponent(C.class).getBees().length, is(2));
+    assertThat(pico.getComponent(D.class).getBees().length, is(2));
+    assertThat(bProvider.calls, is(1)); // do not create B instances two times (C and D dependencies)
+
+    // Picocontainer question: why components created by providers are not registered in the container ?
+    //assertThat(pico.getComponents(B.class).size(), is(2)); // created by the ExtensionProvider
+  }
+
+  public static class FakeServerExtension implements ServerExtension {
+    @Override
+    public String toString() {
+      return "instance";
+    }
+  }
+
+  public static class FakeBatchExtension implements BatchExtension {
+
+  }
+
+  public static class A implements ServerExtension {
+  }
+
+  public static class B implements ServerExtension {
+    private A a;
+
+    public B(A a) {
+      this.a = a;
+    }
+  }
+
+  public static class C implements ServerExtension {
+    private B[] bees;
+
+    public C(B[] bees) {
+      this.bees = bees;
+    }
+
+    public B[] getBees() {
+      return bees;
+    }
+  }
+
+  public static class D implements ServerExtension {
+    private B[] bees;
+
+    public D(B[] bees) {
+      this.bees = bees;
+    }
+
+    public B[] getBees() {
+      return bees;
+    }
+  }
+
+  public static class BProvider extends ExtensionProvider {
+
+    private int calls = 0;
+    public B[] provide(A a) {
+      calls++;
+      return new B[]{new B(a), new B(a)};
+    }
+  }
+
+
+}
index 26b917b9329dd4ae85336f3f05a4978d924c4ec2..37345cead6ad447e9005fc817307160d11931457 100644 (file)
  */
 package org.sonar.api.rules;
 
-import org.apache.commons.collections.CollectionUtils;
-import org.sonar.api.Plugin;
-import org.sonar.api.Plugins;
+import com.google.common.collect.Maps;
 import org.sonar.jpa.dao.RulesDao;
-import org.sonar.api.resources.Language;
 
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * A class to manage and access rules defined in Sonar.
  *
- *  @deprecated UGLY CLASS - WILL BE COMPLETELY REFACTORED IN SONAR 2.3 
+ * @deprecated UGLY CLASS 
  */
 @Deprecated
 public class DefaultRulesManager extends RulesManager {
 
-  private final Set<Language> languages;
-  private final RulesRepository<?>[] repositories;
-  private final Map<Language, List<RulesRepository<?>>> rulesByLanguage;
-  private final Map<Language, List<Plugin>> pluginsByLanguage;
-  private final Map<String, Map<String, Rule>> rulesByPluginAndKey = new HashMap<String, Map<String, Rule>>();
+  private final Map<String, Map<String, Rule>> rulesByPluginAndKey = Maps.newHashMap();
   private final RulesDao rulesDao;
-  private final Plugins plugins;
 
-  /**
-   * Creates a RuleManager
-   * @param plugins the plugins dictionnary
-   * @param repositories the repositories of rules
-   * @param dao the dao object
-   */
-  public DefaultRulesManager(Plugins plugins, RulesRepository[] repositories, RulesDao dao) {
-    this.plugins = plugins;
+  public DefaultRulesManager(RulesDao dao) {
     this.rulesDao = dao;
-
-    languages = new HashSet<Language>();
-    rulesByLanguage = new HashMap<Language, List<RulesRepository<?>>>();
-    pluginsByLanguage = new HashMap<Language, List<Plugin>>();
-    this.repositories = repositories;
-
-    for (RulesRepository<?> repository : repositories) {
-      languages.add(repository.getLanguage());
-
-      List<RulesRepository<?>> list = rulesByLanguage.get(repository.getLanguage());
-      if (list == null) {
-        list = new ArrayList<RulesRepository<?>>();
-        rulesByLanguage.put(repository.getLanguage(), list);
-      }
-      list.add(repository);
-
-      List<Plugin> languagePlugins = pluginsByLanguage.get(repository.getLanguage());
-      if (languagePlugins == null) {
-        languagePlugins = new ArrayList<Plugin>();
-        pluginsByLanguage.put(repository.getLanguage(), languagePlugins);
-      }
-      languagePlugins.add(plugins.getPluginByExtension(repository));
-    }
-  }
-
-  /**
-   * Constructor for tests only
-   *
-   * @param dao the dao
-   */
-  protected DefaultRulesManager(RulesDao dao, Plugins plugins) {
-    this.rulesDao = dao;
-    this.plugins = plugins;
-    languages = new HashSet<Language>();
-    rulesByLanguage = new HashMap<Language, List<RulesRepository<?>>>();
-    pluginsByLanguage = new HashMap<Language, List<Plugin>>();
-    repositories = null;
-
-  }
-
-  /**
-   * Returns the list of languages for which there is a rule repository
-   *
-   * @return a Set of languages
-   */
-  public Set<Language> getLanguages() {
-    return languages;
-  }
-
-  /**
-   * Gets the list of Rules Repositories available for a language
-   *
-   * @param language the language
-   * @return the list of rules repositories
-   */
-  public List<RulesRepository<?>> getRulesRepositories(Language language) {
-    List<RulesRepository<?>> rulesRepositories = rulesByLanguage.get(language);
-    if (CollectionUtils.isNotEmpty(rulesRepositories)) {
-      return rulesRepositories;
-    }
-    return Collections.emptyList();
-  }
-
-  /**
-   * Gets the complete list of Rules Repositories in the Sonar instance
-   *
-   * @return the list of rules repositories
-   */
-  public List<RulesRepository<?>> getRulesRepositories() {
-    return Arrays.asList(repositories);
-  }
-
-  /**
-   * Gets the list of rules plugins for a given language
-   * @param language  the language
-   * @return the list of plugins
-   */
-  public List<Plugin> getPlugins(Language language) {
-    List<Plugin> result = pluginsByLanguage.get(language);
-    if (!CollectionUtils.isEmpty(result)) {
-      return result;
-    }
-    return Collections.emptyList();
-  }
-
-
-  /**
-   * Get the list of rules plugin that implement a mechanism of import for a given language
-   *
-   * @param language the language
-   * @return the list of plugins
-   */
-  public List<Plugin> getImportablePlugins(Language language) {
-    List<Plugin> targets = new ArrayList<Plugin>();
-    for (RulesRepository<?> repository : getRulesRepositories(language)) {
-      if (repository instanceof ConfigurationImportable) {
-        targets.add(plugins.getPluginByExtension(repository));
-      }
-    }
-    return targets;
   }
 
   /**
    * Gets a list of rules indexed by their key for a given plugin
+   *
    * @param pluginKey the plugin key
    * @return a Map with the rule key and the rule
    */
@@ -174,22 +62,11 @@ public class DefaultRulesManager extends RulesManager {
     return rulesByKey;
   }
 
-  /**
-   * Gets a collection of rules belonging to a plugin
-   *
-   * @param pluginKey the plugin key
-   * @return the collection of rules
-   */
-  public Collection<Rule> getPluginRules(String pluginKey) {
-    Map<String, Rule> rulesByKey = getPluginRulesIndexedByKey(pluginKey);
-    return rulesByKey.values();
-  }
-
   /**
    * Gets a rule belonging to a defined plugin based on its key
    *
    * @param pluginKey the plugin key
-   * @param ruleKey the rule key
+   * @param ruleKey   the rule key
    * @return the rule
    */
   public Rule getPluginRule(String pluginKey, String ruleKey) {
index 374f2241cf37a05b0a75a55b72bee5eb95bc734a..2cf6a8723074dcddf6e6ab69f77848d7762b2c04 100644 (file)
@@ -33,58 +33,6 @@ import java.util.Set;
 @Deprecated
 public abstract class RulesManager {
 
-  /**
-   * Returns the list of languages for which there is a rule repository
-   *
-   * @return a Set of languages
-   */
-  public abstract Set<Language> getLanguages();
-
-  /**
-   * Gets the list of Rules Repositories available for a language
-   *
-   * @param language the language
-   * @return the list of rules repositories
-   */
-  public abstract List<RulesRepository<?>> getRulesRepositories(Language language);
-
-  /**
-   * Gets the complete list of Rules Repositories in the Sonar instance
-   *
-   * @return the list of rules repositories
-   */
-  public abstract List<RulesRepository<?>> getRulesRepositories();
-
-  /**
-   * Gets the list of rules plugins for a given language
-   * @param language  the language
-   * @return the list of plugins
-   */
-  public abstract List<Plugin> getPlugins(Language language);
-
-  /**
-   * Get the list of rules plugin that implement a mechanism of import for a given language
-   *
-   * @param language the language
-   * @return the list of plugins
-   */
-  public abstract List<Plugin> getImportablePlugins(Language language);
-
-  /**
-   * Gets a list of rules indexed by their key for a given plugin
-   * @param pluginKey the plugin key
-   * @return a Map with the rule key and the rule
-   */
-  public abstract Map<String, Rule> getPluginRulesIndexedByKey(String pluginKey);
-
-  /**
-   * Gets a collection of rules belonging to a plugin
-   *
-   * @param pluginKey the plugin key
-   * @return the collection of rules
-   */
-  public abstract Collection<Rule> getPluginRules(String pluginKey);
-
   /**
    * Gets a rule belonging to a defined plugin based on its key
    *
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java b/sonar-deprecated/src/test/java/org/sonar/api/rules/DefaultRulesManagerTest.java
deleted file mode 100644 (file)
index 7aec32d..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/*\r
- * Sonar, open source software quality management tool.\r
- * Copyright (C) 2009 SonarSource SA\r
- * mailto:contact AT sonarsource DOT com\r
- *\r
- * Sonar is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Lesser General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 3 of the License, or (at your option) any later version.\r
- *\r
- * Sonar is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- * Lesser General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Lesser General Public\r
- * License along with Sonar; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02\r
- */\r
-package org.sonar.api.rules;\r
-\r
-import org.junit.Test;\r
-import org.sonar.api.Plugin;\r
-import org.sonar.api.Plugins;\r
-import org.sonar.jpa.dao.RulesDao;\r
-import org.sonar.api.resources.Language;\r
-import org.sonar.jpa.dao.DaoFacade;\r
-\r
-import java.util.Collections;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import static org.hamcrest.CoreMatchers.is;\r
-import static org.hamcrest.MatcherAssert.assertThat;\r
-import static org.mockito.Mockito.mock;\r
-import static org.mockito.Mockito.when;\r
-\r
-public class DefaultRulesManagerTest {\r
-\r
-  @Test\r
-  public void shouldReturnsZeroImportablePluginsWhenLanguageHasNoRulesPlugin() {\r
-    DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();\r
-\r
-    Language language = mock(Language.class);\r
-    List<Plugin> result = rulesManager.getImportablePlugins(language);\r
-    assertThat(result.size(), is(0));\r
-  }\r
-\r
-  @Test\r
-  public void shouldReturnZeroPluginWhenLanguageHasNoRulesPlugin() {\r
-    DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();\r
-    Language language = mock(Language.class);\r
-    List<Plugin> result = rulesManager.getPlugins(language);\r
-    assertThat(result.size(), is(0));\r
-  }\r
-\r
-  @Test\r
-  public void shouldReturnZeroRulesRepositoryWhenLanguageHasNoRulesRepository() {\r
-    DefaultRulesManager rulesManager = createRulesManagerForAlanguageWithNoPlugins();\r
-    Language language = mock(Language.class);\r
-    List<RulesRepository<?>> result = rulesManager.getRulesRepositories(language);\r
-    assertThat(result.size(), is(0));\r
-  }\r
-\r
-  private DefaultRulesManager createRulesManagerForAlanguageWithNoPlugins() {\r
-    DaoFacade dao = mock(DaoFacade.class);\r
-    RulesDao rulesDao = mock(RulesDao.class);\r
-    when(rulesDao.getCategories()).thenReturn(Collections.<RulesCategory>emptyList());\r
-    DefaultRulesManager rulesManager = new DefaultRulesManager(rulesDao, new Plugins(null));\r
-    return rulesManager;\r
-  }\r
-}\r
index bc5b61544a6777b8ab94affe524dae2536868f4d..615c57a6631f4d00391df869656d10566ea1f77e 100644 (file)
  */
 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 {
 
 }
index eca185e492001d43db072331a941eebb764bc3c8..82fa9606c365c7ce9aa2a53a86f0a9233e41dc2b 100644 (file)
@@ -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
    */
index 330e1d4e79c46d531c1a1fe9eb791e4acdd3182a..02869c36a5bfe6b1b95ebfdd8b3b376919e34dfd 100644 (file)
@@ -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);
   }
 }
index 611c3eeca28d295d887dd2e32a2bbaaf1c823a0e..8529642a9f16c2129599db7066c3c3df190f6955 100644 (file)
  */
 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);
 }
index bfa556fabd069ed9e0cc72c4cf03514ef527e8ca..036b8647878dec970313155676699b1cdce04891 100644 (file)
  */
 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);
-    }
+
   }
 }
index bf8b923b6b989f19f6710c3d00cd1e1797b4dbd3..145ba28e3f43097cc7301d6752023a56d7c56c4e 100644 (file)
@@ -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));
index 980898bc0eb1f0ca64f599902ee5f0e52bd6e5d1..cfb1191fc11ad6eb1d9be270be2bc02be767e41e 100644 (file)
@@ -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);
+  }
 }
index 4b66047e7d2e21f931308ef128bd49930990e0ab..4e9ea3d96cadea11082519422a902cdaee85fd45 100644 (file)
@@ -36,35 +36,30 @@ import com.google.common.collect.Maps;
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.List;\r
+import java.util.Map;\r
 \r
 import javax.persistence.Query;\r
 \r
 public class RegisterMetrics {\r
 \r
-  private PluginRepository pluginRepository;\r
   private MeasuresDao measuresDao;\r
   private Metrics[] metricsRepositories = null;\r
   private DatabaseSession session;\r
 \r
-  public RegisterMetrics(DatabaseSession session, MeasuresDao measuresDao, PluginRepository pluginRepository, Metrics[] metricsRepositories) {\r
+  public RegisterMetrics(DatabaseSession session, MeasuresDao measuresDao, Metrics[] metricsRepositories) {\r
     this.session = session;\r
     this.measuresDao = measuresDao;\r
-    this.pluginRepository = pluginRepository;\r
     this.metricsRepositories = metricsRepositories;\r
   }\r
 \r
-  public RegisterMetrics(MeasuresDao measuresDao) {\r
-    this.measuresDao = measuresDao;\r
-  }\r
-\r
   public void start() {\r
     TimeProfiler profiler = new TimeProfiler().start("Load metrics");\r
     measuresDao.disableAutomaticMetrics();\r
 \r
-    ArrayList<Metric> metricsToRegister = Lists.newArrayList();\r
+    List<Metric> metricsToRegister = Lists.newArrayList();\r
     metricsToRegister.addAll(CoreMetrics.getMetrics());\r
 \r
-    HashMap<String, Metrics> metricsByRepository = Maps.newHashMap();\r
+    Map<String, Metrics> metricsByRepository = Maps.newHashMap();\r
     if (metricsRepositories != null) {\r
       for (Metrics metrics : metricsRepositories) {\r
         checkMetrics(metricsByRepository, metrics);\r
@@ -76,17 +71,15 @@ public class RegisterMetrics {
     profiler.stop();\r
   }\r
 \r
-  private void checkMetrics(HashMap<String, Metrics> metricsByRepository, Metrics metrics) {\r
+  private void checkMetrics(Map<String, Metrics> metricsByRepository, Metrics metrics) {\r
     for (Metric metric : metrics.getMetrics()) {\r
       String metricKey = metric.getKey();\r
       if (CoreMetrics.metrics.contains(metric)) {\r
-        throw new ServerStartException("Found plugin, which contains metric '" + metricKey + "' from core: " + pluginRepository.getPluginKeyForExtension(metrics));\r
+        throw new ServerStartException("The following metric is already defined in sonar: " + metricKey);\r
       }\r
       Metrics anotherRepository = metricsByRepository.get(metricKey);\r
       if (anotherRepository != null) {\r
-        String firstPlugin = pluginRepository.getPluginKeyForExtension(anotherRepository);\r
-        String secondPlugin = pluginRepository.getPluginKeyForExtension(metrics);\r
-        throw new ServerStartException("Found two plugins with the same metric '" + metricKey + "': " + firstPlugin + " and " + secondPlugin);\r
+        throw new ServerStartException("The metric '" + metricKey + "' is already defined in the extension: " + anotherRepository);\r
       }\r
       metricsByRepository.put(metricKey, metrics);\r
     }\r
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 (file)
index 0000000..d6d3115
--- /dev/null
@@ -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 {
+
+  }
+}
index 2f2244e938a39fe6fde1dd02f0d9159da4f05d44..49670f559cabb0f66857fb90a8624edaa19711a6 100644 (file)
@@ -41,7 +41,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
 \r
     Metric metric1 = new Metric("new1", "short1", "desc1", Metric.ValueType.FLOAT, 1, true, "domain1", false);\r
     Metric metric2 = new Metric("new2", "short2", "desc2", Metric.ValueType.FLOAT, 1, true, "domain2", false);\r
-    RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);\r
+    RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);\r
     synchronizer.register(Arrays.asList(metric1, metric2));\r
     checkTables("shouldSaveIfNew", "metrics");\r
   }\r
@@ -52,7 +52,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
 \r
     final List<Metric> metrics = new ArrayList<Metric>();\r
     metrics.add(new Metric("key", "new short name", "new description", Metric.ValueType.FLOAT, -1, true, "new domain", false));\r
-    RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);\r
+    RegisterMetrics synchronizer = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);\r
     synchronizer.register(metrics);\r
 \r
     checkTables("shouldUpdateIfAlreadyExists", "metrics");\r
@@ -62,7 +62,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
   public void enableOnlyLoadedMetrics() throws SQLException {\r
     setupData("enableOnlyLoadedMetrics");\r
 \r
-    RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);\r
+    RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);\r
     loader.start();\r
 \r
     assertFalse(getDao().getMeasuresDao().getMetric("deprecated").getEnabled());\r
@@ -73,7 +73,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
   public void cleanAlerts() throws SQLException {\r
     setupData("cleanAlerts");\r
 \r
-    RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null, null);\r
+    RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);\r
     loader.cleanAlerts();\r
 \r
     checkTables("cleanAlerts", "metrics", "alerts");\r