aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kush Chakraborty <kush@google.com>2017-02-09 17:53:20 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2017-02-09 19:27:43 +0000
commit48e7fe262aacd6602331435e22247ced260c87ec (patch)
treecc6b3d1d8030cec2f259c67473b37d0b5438463c
parent1b9bcca0b30899e1df501bffa53777ce8f4f7f99 (diff)
Search for Test classes within the classpath used by the current classloader, instead of the system classpath.
-- PiperOrigin-RevId: 147045814 MOS_MIGRATED_REVID=147045814
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/Classpath.java33
1 files changed, 11 insertions, 22 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..0e43c2bd50 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,30 +141,18 @@ 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) {
- completeClassPaths.add(entryName);
- if (entryName.endsWith("-classpath.jar")) {
- File classPathEntry = new File(entryName);
- if (classPathEntry.exists() && classPathEntry.isFile()) {
- try {
- getClassPathsFromClasspathJar(classPathEntry, completeClassPaths);
- } catch (IOException e) {
- throw new AssertionError(
- "Can't read classpath entry " + entryName + ": " + e.getMessage());
- }
- }
- }
+ URL[] urls = ((URLClassLoader) classloader).getURLs();
+ for (URL url : urls) {
+ completeClassPaths.add(url.getPath());
}
return completeClassPaths;
}