diff options
author | 2017-02-14 17:40:20 +0000 | |
---|---|---|
committer | 2017-02-15 10:03:01 +0000 | |
commit | db5f2e413f8293b001a2de20e7c7d6d8b6970835 (patch) | |
tree | 1f0803c28b67e8401c73b079933839d8d7ef1092 /src/test/java/com/google/devtools/build/lib | |
parent | 59267f6642d9eb75115f32a53c6efe7f93326eab (diff) |
Search for Test classes within the classpath used by the current classloader, instead of the system classpath. (2nd Attempt)
Windows tests passed on Jenkins with this patch:
http://ci.bazel.io/job/Gerrit-bazel-tests/380/,
https://bazel-review.googlesource.com/c/8833
--
PiperOrigin-RevId: 147483103
MOS_MIGRATED_REVID=147483103
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/testutil/Classpath.java | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/Classpath.java b/src/test/java/com/google/devtools/build/lib/testutil/Classpath.java index 812951396d..059ef6f1c3 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/Classpath.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/Classpath.java @@ -18,6 +18,8 @@ import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Paths; import java.util.Enumeration; import java.util.LinkedHashSet; @@ -26,7 +28,6 @@ import java.util.TreeSet; import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -140,20 +141,23 @@ final class Classpath { } /** - * Gets the class path from the System Property "java.class.path" and splits it up into the - * individual elements. - * - * <p>Bazel creates a classpath jar when the class path length exceeds command line length limit, - * read the class path value from its manifest file if it's a classpath jar. + * Gets the classpath from current classloader. */ private static Set<String> getClassPath() { - String classPath = System.getProperty("java.class.path"); - String separator = System.getProperty("path.separator", ":"); - String[] classPaths = classPath.split(Pattern.quote(separator)); + ClassLoader classloader = Classpath.class.getClassLoader(); + if (!(classloader instanceof URLClassLoader)) { + throw new IllegalStateException("Unable to find classes to test, since Test Suite class is " + + "loaded by an unsupported Classloader."); + } + Set<String> completeClassPaths = new TreeSet<>(); - for (String entryName : classPaths) { + URL[] urls = ((URLClassLoader) classloader).getURLs(); + for (URL url : urls) { + String entryName = url.getPath(); completeClassPaths.add(entryName); if (entryName.endsWith("-classpath.jar")) { + // Bazel creates a classpath jar when the class path length exceeds command line length + // limit, read the class path value from its manifest file if it's a classpath jar. File classPathEntry = new File(entryName); if (classPathEntry.exists() && classPathEntry.isFile()) { try { |