summaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-23 15:29:12 +0000
committerGodin <mandrikov@gmail.com>2010-10-23 15:29:12 +0000
commitd3840113923f94c33c4ed1f92b137e20f20707a5 (patch)
treeab382b245d0f31cb8db1f389197f39f432b342e7 /sonar-core
parente54133d5887b6c92c17084fde9c9f245da67260e (diff)
downloadsonarqube-d3840113923f94c33c4ed1f92b137e20f20707a5.tar.gz
sonarqube-d3840113923f94c33c4ed1f92b137e20f20707a5.zip
SONAR-1861: Don't create ResourcesClassLoader if no resources
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/classloaders/ClassLoadersCollection.java32
-rw-r--r--sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java10
2 files changed, 28 insertions, 14 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 852649a49c6..c9d3afa25b0 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
@@ -8,7 +8,10 @@ import org.codehaus.classworlds.NoSuchRealmException;
import org.sonar.api.utils.Logs;
import org.sonar.api.utils.SonarException;
+import com.google.common.collect.Lists;
+
import java.net.URL;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -54,16 +57,30 @@ public class ClassLoadersCollection {
*/
public ClassLoader createClassLoader(String key, Collection<URL> urls, boolean childFirst) {
try {
- ClassLoader resourcesClassLoader = new ResourcesClassLoader(urls, baseClassLoader);
+ ArrayList<URL> resources = Lists.newArrayList();
+ ArrayList<URL> others = Lists.newArrayList();
+ for (URL url : urls) {
+ if (isResource(url)) {
+ resources.add(url);
+ } else {
+ others.add(url);
+ }
+ }
+ ClassLoader parent;
+ if (resources.isEmpty()) {
+ parent = baseClassLoader;
+ } else {
+ parent = new ResourcesClassLoader(resources, baseClassLoader);
+ }
final ClassRealm realm;
if (childFirst) {
- ClassRealm parentRealm = world.newRealm(key + "-parent", resourcesClassLoader);
+ ClassRealm parentRealm = world.newRealm(key + "-parent", parent);
realm = parentRealm.createChildRealm(key);
} else {
- realm = world.newRealm(key, resourcesClassLoader);
+ realm = world.newRealm(key, parent);
}
- for (URL constituent : urls) {
- realm.addConstituent(constituent);
+ for (URL url : others) {
+ realm.addConstituent(url);
}
return realm.getClassLoader();
} catch (DuplicateRealmException e) {
@@ -119,4 +136,9 @@ public class ClassLoadersCollection {
}
}
+ private boolean isResource(URL url) {
+ String path = url.getPath();
+ return !StringUtils.endsWith(path, ".jar") && !StringUtils.endsWith(path, "/");
+ }
+
}
diff --git a/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java b/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java
index e2298f42602..dcf243808d5 100644
--- a/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java
+++ b/sonar-core/src/main/java/org/sonar/core/classloaders/ResourcesClassLoader.java
@@ -7,7 +7,6 @@ import com.google.common.collect.Lists;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
-import java.util.List;
/**
* This class loader is used to load resources from a list of URLs - see SONAR-1861.
@@ -17,14 +16,7 @@ public class ResourcesClassLoader extends URLClassLoader {
public ResourcesClassLoader(Collection<URL> urls, ClassLoader parent) {
super(new URL[] {}, parent);
- List<URL> filtered = Lists.newArrayList();
- for (URL url : urls) {
- String path = url.getPath();
- if ( !StringUtils.endsWith(path, ".jar") && !StringUtils.endsWith(path, "/")) {
- filtered.add(url);
- }
- }
- this.urls = filtered;
+ this.urls = Lists.newArrayList(urls);
}
@Override