Rollback of commit
*** Reason for rollback ***
Breaks "classpath from classpath.jar"
Fixes
*** Original change description ***
Search for Test classes within the classpath used by the current classloader, instead of the system classpath.
MOS_MIGRATED_REVID=147328429
@@ -18,8 +18,6 @@ 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;
@@ -28,6 +26,7 @@ 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;
@@ -141,18 +140,30 @@ final class Classpath {
}
/**
- * Gets the classpath from current classloader.
+ * 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.
*/
private static Set<String> getClassPath() {
- 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.");
- }
+ String classPath = System.getProperty("java.class.path");
+ String separator = System.getProperty("path.separator", ":");
+ String[] classPaths = classPath.split(Pattern.quote(separator));
Set<String> completeClassPaths = new TreeSet<>();
- URL[] urls = ((URLClassLoader) classloader).getURLs();
- for (URL url : urls) {
- completeClassPaths.add(url.getPath());
+ 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());
+ }
+ }
+ }
}
return completeClassPaths;
}
