Sort the jar files from the war before adding to classpath.
Currently, the order they are inserted onto the classpath depends on
directory iteration order of the WEB-INF directory at war-file
building time. On some filesystems that is alphabetical, and on some
filesystems, it is completely arbitrary. On the second kind of
filesystem, gerrit-patch-jgit can randomly end up on the classpath
*after* jgit itself, thus causing it to not be loaded.
Change-Id: I4ee9b22cbb93405e033f6f6bda9da1dd87b3419f
diff --git a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java
index d9ea7d3..7f2007e 100644
--- a/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java
+++ b/gerrit-launcher/src/main/java/com/google/gerrit/launcher/GerritLauncher.java
@@ -31,6 +31,8 @@
import java.net.URLClassLoader;
import java.security.CodeSource;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@@ -235,6 +237,12 @@
if (jars.isEmpty()) {
return GerritLauncher.class.getClassLoader();
}
+ Collections.sort(jars, new Comparator<URL>() {
+ public int compare(URL o1, URL o2) {
+ return o1.toString().compareTo(o2.toString());
+ }
+ });
+
return new URLClassLoader(jars.toArray(new URL[jars.size()]));
}