]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6517 use thread context classloader as base classloader on batch side
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 13 May 2015 14:20:23 +0000 (16:20 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 13 May 2015 14:20:35 +0000 (16:20 +0200)
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginLoader.java [new file with mode: 0644]
sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalContainer.java
sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java

diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginLoader.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginLoader.java
new file mode 100644 (file)
index 0000000..5831491
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.bootstrap;
+
+import org.sonar.api.BatchSide;
+import org.sonar.core.platform.PluginExploder;
+import org.sonar.core.platform.PluginLoader;
+
+/**
+ * The {@link PluginLoader} on batch side requires to use thread context
+ * classloader as base classloader in order to support plugins like Groovy
+ * (at least its version 1.1).
+ */
+@BatchSide
+public class BatchPluginLoader extends PluginLoader {
+  public BatchPluginLoader(PluginExploder exploder) {
+    super(exploder);
+  }
+
+  @Override
+  protected ClassLoader baseClassloader() {
+    return Thread.currentThread().getContextClassLoader();
+  }
+}
index 2b84c018c17fc4912d3ba87e26d14e5d0b23584d..f24fe52fbe84742246a67bd957a6e1c3cf3e5fd7 100644 (file)
@@ -55,7 +55,6 @@ import org.sonar.core.persistence.SemaphoreUpdater;
 import org.sonar.core.persistence.SemaphoresImpl;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.core.platform.PluginInfo;
-import org.sonar.core.platform.PluginLoader;
 import org.sonar.core.platform.PluginRepository;
 import org.sonar.core.purge.PurgeProfiler;
 import org.sonar.core.rule.CacheRuleFinder;
@@ -99,7 +98,7 @@ public class GlobalContainer extends ComponentContainer {
     add(
       // plugins
       BatchPluginRepository.class,
-      PluginLoader.class,
+      BatchPluginLoader.class,
       BatchPluginExploder.class,
       BatchPluginPredicate.class,
       ExtensionInstaller.class,
index ecede3063a6618af3f46a85ade762887e5cbbda5..1e602c1e55637e6452bdc219a282d731f0e09228 100644 (file)
@@ -55,7 +55,7 @@ import static org.sonar.classloader.ClassloaderBuilder.LoadingOrder.SELF_FIRST;
  * <p/>
  * This class is stateless. It does not keep classloaders and {@link Plugin} in memory.
  */
-public class PluginLoader implements BatchComponent, ServerComponent {
+public class PluginLoader {
 
   private static final String[] DEFAULT_SHARED_RESOURCES = {"org/sonar/plugins", "com/sonar/plugins", "com/sonarsource/plugins"};
 
@@ -179,7 +179,10 @@ public class PluginLoader implements BatchComponent, ServerComponent {
     }
   }
 
-  private ClassLoader baseClassloader() {
+  /**
+   * This method can be overridden to change the base classloader.
+   */
+  protected ClassLoader baseClassloader() {
     return getClass().getClassLoader();
   }