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-core | |
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-core')
7 files changed, 39 insertions, 15 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java b/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java index 9df43699ec8..0914ecc37e0 100644 --- a/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java +++ b/sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; @@ -33,8 +34,6 @@ import org.codehaus.plexus.classworlds.realm.NoSuchRealmException; import org.sonar.api.utils.Logs; import org.sonar.api.utils.SonarException; -import com.google.common.collect.Lists; - /** * Encapsulates manipulations with ClassLoaders, such as creation and establishing dependencies. Current implementation based on * {@link ClassWorld}. @@ -108,13 +107,27 @@ public class ClassLoadersCollection { } } + public void extend(String baseKey, String key, Collection<URL> urls) { + try { + ClassRealm base = world.getRealm(baseKey); + base.createChildRealm(key); // we create new realm to be able to return it by key without conversion to baseKey + for (URL url : urls) { + base.addURL(url); + } + } catch (NoSuchRealmException e) { + throw new SonarException(e); + } catch (DuplicateRealmException e) { + throw new SonarException(e); + } + } + /** * Establishes dependencies among ClassLoaders. */ public void done() { for (Object o : world.getRealms()) { ClassRealm realm = (ClassRealm) o; - if ( !StringUtils.endsWith(realm.getId(), "-parent")) { + if (!StringUtils.endsWith(realm.getId(), "-parent")) { String[] packagesToExport = new String[PREFIXES_TO_EXPORT.length]; for (int i = 0; i < PREFIXES_TO_EXPORT.length; i++) { // important to have dot at the end of package name only for classworlds 1.1 @@ -132,7 +145,7 @@ public class ClassLoadersCollection { Logs.INFO.debug("Exporting " + Arrays.toString(packages) + " from " + realm.getId()); for (Object o : world.getRealms()) { ClassRealm dep = (ClassRealm) o; - if ( !StringUtils.equals(dep.getId(), realm.getId())) { + if (!StringUtils.equals(dep.getId(), realm.getId())) { try { for (String packageName : packages) { dep.importFrom(realm.getId(), packageName); diff --git a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java index a842173f3a2..2cc23e4afdf 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java +++ b/sonar-core/src/main/java/org/sonar/core/plugin/JpaPlugin.java @@ -78,16 +78,19 @@ public class JpaPlugin extends BaseIdentifiable { @Column(name = "core", updatable = true, nullable = true) private Boolean core; - + @Column(name = "child_first_classloader", updatable = true, nullable = true) private Boolean childFirstClassLoader = Boolean.FALSE; - @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, + @Column(name = "base_plugin", updatable = true, nullable = true) + private String basePlugin; + + @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE, org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.PERSIST, - org.hibernate.annotations.CascadeType.DELETE_ORPHAN}) - @OneToMany(mappedBy = "plugin", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER) + org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) + @OneToMany(mappedBy = "plugin", cascade = { CascadeType.ALL }, fetch = FetchType.EAGER) private List<JpaPluginFile> files = new ArrayList<JpaPluginFile>(); public JpaPlugin() { @@ -218,6 +221,14 @@ public class JpaPlugin extends BaseIdentifiable { return this; } + public String getBasePlugin() { + return basePlugin; + } + + public void setBasePlugin(String basePlugin) { + this.basePlugin = basePlugin; + } + public void createFile(String filename) { JpaPluginFile file = new JpaPluginFile(this, filename); this.files.add(file); diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java index f4c958a1452..7551bff7795 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java @@ -31,7 +31,7 @@ import javax.persistence.*; public class SchemaMigration { public final static int VERSION_UNKNOWN = -1; - public static final int LAST_VERSION = 180; + public static final int LAST_VERSION = 181; public final static String TABLE_NAME = "schema_migrations"; diff --git a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/removePreviousFilesWhenRegisteringPlugin-result.xml b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/removePreviousFilesWhenRegisteringPlugin-result.xml index 579a381a739..4ab85fcd109 100644 --- a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/removePreviousFilesWhenRegisteringPlugin-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/removePreviousFilesWhenRegisteringPlugin-result.xml @@ -1,6 +1,6 @@ <dataset> <plugins id="1" name="Checkstyle" plugin_key="checkstyle" organization="[null]" organization_url="[null]" license="[null]" homepage="[null]" - description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" version="2.2" /> + description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" base_plugin="[null]" version="2.2" /> <plugin_files id="3" plugin_id="1" filename="newfile.jar"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/saveDeprecatedPlugin-result.xml b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/saveDeprecatedPlugin-result.xml index 38f8e3d72d1..484d192dbb8 100644 --- a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/saveDeprecatedPlugin-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/saveDeprecatedPlugin-result.xml @@ -1,9 +1,9 @@ <dataset> <plugins id="1" name="Checkstyle" plugin_key="checkstyle" organization="[null]" organization_url="[null]" license="[null]" homepage="[null]" - description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" version="2.2"/> + description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" base_plugin="[null]" version="2.2"/> <plugins id="2" name="PMD" plugin_key="pmd" organization="[null]" organization_url="[null]" license="[null]" homepage="[null]" - description="[null]" installation_date="[null]" plugin_class="org.sonar.pmd.Main" core="false" child_first_classloader="false" version="[null]" /> + description="[null]" installation_date="[null]" plugin_class="org.sonar.pmd.Main" core="false" child_first_classloader="false" base_plugin="[null]" version="[null]" /> <plugin_files id="1" plugin_id="1" filename="checkstyle.jar"/> <plugin_files id="2" plugin_id="1" filename="checkstyle-extension.jar"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/savePluginAndFiles-result.xml b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/savePluginAndFiles-result.xml index 2ca3c309e6d..8bd8f817a45 100644 --- a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/savePluginAndFiles-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/savePluginAndFiles-result.xml @@ -1,9 +1,9 @@ <dataset> <plugins id="1" name="Checkstyle" plugin_key="checkstyle" organization="[null]" organization_url="[null]" license="[null]" homepage="[null]" - description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" version="2.2"/> + description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" base_plugin="[null]" version="2.2"/> <plugins id="2" name="PMD" plugin_key="pmd" organization="[null]" organization_url="[null]" license="[null]" homepage="[null]" - description="[null]" installation_date="[null]" plugin_class="org.sonar.pmd.Main" core="false" child_first_classloader="false" version="2.2" /> + description="[null]" installation_date="[null]" plugin_class="org.sonar.pmd.Main" core="false" child_first_classloader="false" base_plugin="[null]" version="2.2" /> <plugin_files id="1" plugin_id="1" filename="checkstyle.jar"/> <plugin_files id="2" plugin_id="1" filename="checkstyle-extension.jar"/> diff --git a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/shared.xml b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/shared.xml index 57dfd1358d7..f594347688f 100644 --- a/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/shared.xml +++ b/sonar-core/src/test/resources/org/sonar/core/plugin/JpaPluginDaoTest/shared.xml @@ -1,6 +1,6 @@ <dataset> <plugins id="1" name="Checkstyle" plugin_key="checkstyle" organization="[null]" organization_url="[null]" license="[null]" homepage="[null]" - description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" version="2.2" /> + description="[null]" installation_date="[null]" plugin_class="[null]" core="true" child_first_classloader="false" base_plugin="[null]" version="2.2" /> <plugin_files id="1" plugin_id="1" filename="checkstyle.jar"/> <plugin_files id="2" plugin_id="1" filename="checkstyle-extension.jar"/> |