diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-02-08 00:51:56 +0300 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-02-08 12:05:17 +0300 |
commit | 1639e4fba1bd2203f39104076d85d69bd0228c8b (patch) | |
tree | ca8a6ef1af2e79aba281194dd37fec7c7151b729 /sonar-batch/src | |
parent | 54a6901006ec1ec7f498cbb968c47a05e4075937 (diff) | |
download | sonarqube-1639e4fba1bd2203f39104076d85d69bd0228c8b.tar.gz sonarqube-1639e4fba1bd2203f39104076d85d69bd0228c8b.zip |
SONAR-2075: Add the ability for a plugin to extend an other plugin
Diffstat (limited to 'sonar-batch/src')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java index 5ec8ac920ae..c883998d927 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginRepository.java @@ -57,6 +57,7 @@ public class BatchPluginRepository extends AbstractPluginRepository { private ClassLoadersCollection classLoaders; private ExtensionDownloader extensionDownloader; private EnvironmentInformation environment; + private List<JpaPlugin> register; public BatchPluginRepository(JpaPluginDao dao, ExtensionDownloader extensionDownloader, EnvironmentInformation environment) { this.dao = dao; @@ -69,36 +70,59 @@ public class BatchPluginRepository extends AbstractPluginRepository { * for unit tests only */ BatchPluginRepository() { + } + + private List<URL> download(JpaPlugin pluginMetadata) { + List<URL> urls = Lists.newArrayList(); + for (JpaPluginFile pluginFile : pluginMetadata.getFiles()) { + File file = extensionDownloader.downloadExtension(pluginFile); + try { + urls.add(file.toURI().toURL()); + } catch (MalformedURLException e) { + throw new SonarException("Can not get the URL of: " + file, e); + } + } + return urls; } public void start() { + register = Lists.newArrayList(); classLoaders = new ClassLoadersCollection(Thread.currentThread().getContextClassLoader()); - for (JpaPlugin pluginMetadata : dao.getPlugins()) { - String key = pluginMetadata.getKey(); - List<URL> urls = Lists.newArrayList(); - for (JpaPluginFile pluginFile : pluginMetadata.getFiles()) { - File file = extensionDownloader.downloadExtension(pluginFile); - try { - urls.add(file.toURI().toURL()); - - } catch (MalformedURLException e) { - throw new SonarException("Can not get the URL of: " + file, e); - } + + List<JpaPlugin> jpaPlugins = dao.getPlugins(); + + for (JpaPlugin pluginMetadata : jpaPlugins) { + if (StringUtils.isEmpty(pluginMetadata.getBasePlugin())) { + String key = pluginMetadata.getKey(); + List<URL> urls = download(pluginMetadata); + classLoaders.createClassLoader(key, urls, pluginMetadata.isUseChildFirstClassLoader() == Boolean.TRUE); + register.add(pluginMetadata); } - if (LOG.isDebugEnabled()) { - LOG.debug("Classloader of plugin " + key + ":"); - for (URL url : urls) { - LOG.debug(" -> " + url); + } + + // Extend plugins by other plugins + for (JpaPlugin pluginMetadata : jpaPlugins) { + String pluginKey = pluginMetadata.getKey(); + String basePluginKey = pluginMetadata.getBasePlugin(); + if (StringUtils.isNotEmpty(basePluginKey)) { + if (classLoaders.get(basePluginKey) != null) { + LOG.debug("Plugin {} extends {}", pluginKey, basePluginKey); + List<URL> urls = download(pluginMetadata); + classLoaders.extend(basePluginKey, pluginKey, urls); + register.add(pluginMetadata); + } else { + // Ignored, because base plugin doesn't exists + LOG.warn("Plugin {} extends nonexistent plugin {}", pluginKey, basePluginKey); } } - classLoaders.createClassLoader(key, urls, pluginMetadata.isUseChildFirstClassLoader() == Boolean.TRUE); } + classLoaders.done(); } public void registerPlugins(MutablePicoContainer pico) { - for (JpaPlugin pluginMetadata : dao.getPlugins()) { + for (JpaPlugin pluginMetadata : register) { try { Class claz = classLoaders.get(pluginMetadata.getKey()).loadClass(pluginMetadata.getPluginClass()); Plugin plugin = (Plugin) claz.newInstance(); |