Don't put plugins into system classpath
Plugin code is often loaded into the workspace in Eclipse, and is therefore part of the default project path. Detect this at startup time by looking for gerrit.buck-out system property and building a new classpath consisting only of the primary classes and JARs. The GWT compiler, tests and plugins are excluded from the classpath, preventing weird collisions with the dynamically loaded plugins from $site_path/plugins. PluginLoader recognizes the split output directory used by Eclipse and loads the latest classes files ahead of anything from the JAR in $site_path/plugins. This makes development of most code changes quick by hiding the staleness of the installed JAR. Change-Id: I4b879eebbcb332384c4e747d3f0c4b5c948c5fed
This commit is contained in:
@@ -29,6 +29,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.security.CodeSource;
|
||||
@@ -192,10 +193,7 @@ public final class GerritLauncher {
|
||||
path = getDistributionArchive();
|
||||
} catch (FileNotFoundException e) {
|
||||
if (NOT_ARCHIVED.equals(e.getMessage())) {
|
||||
// Assume the CLASSPATH was made complete by the calling process,
|
||||
// as we are likely being run from within a developer's IDE.
|
||||
//
|
||||
return GerritLauncher.class.getClassLoader();
|
||||
return useDevClasspath();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@@ -600,6 +598,29 @@ public final class GerritLauncher {
|
||||
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||
}
|
||||
|
||||
private static ClassLoader useDevClasspath()
|
||||
throws MalformedURLException, FileNotFoundException {
|
||||
File out = getDeveloperBuckOut();
|
||||
List<URL> dirs = new ArrayList<URL>();
|
||||
dirs.add(new File(new File(out, "eclipse"), "classes").toURI().toURL());
|
||||
ClassLoader cl = GerritLauncher.class.getClassLoader();
|
||||
for (URL u : ((URLClassLoader) cl).getURLs()) {
|
||||
if (includeJar(u)) {
|
||||
dirs.add(u);
|
||||
}
|
||||
}
|
||||
return new URLClassLoader(
|
||||
dirs.toArray(new URL[dirs.size()]),
|
||||
ClassLoader.getSystemClassLoader().getParent());
|
||||
}
|
||||
|
||||
private static boolean includeJar(URL u) {
|
||||
String path = u.getPath();
|
||||
return path.endsWith(".jar")
|
||||
&& !path.endsWith("-src.jar")
|
||||
&& !path.contains("/buck-out/gen/lib/gwt/");
|
||||
}
|
||||
|
||||
private GerritLauncher() {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user