aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/java_tools/junitrunner/java/com/google/testing/junit
diff options
context:
space:
mode:
authorGravatar Kush Chakraborty <kush@google.com>2017-03-28 13:04:36 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2017-03-28 19:51:20 +0000
commitc2cc768cb1d891f2f2f942feb007d5508e04f585 (patch)
tree7bd99d2962163dff4530444d5fbc29307d15217c /src/java_tools/junitrunner/java/com/google/testing/junit
parentc82a16186dd5c1291c1b6609a9d0762ad6183ca9 (diff)
Dump the classpaths in a separate file and read the classpaths from that file, so that each test run can have the latest version of the Classpaths.
This does not tackle the case where runfiles are not present, such as windows. -- PiperOrigin-RevId: 151440999 MOS_MIGRATED_REVID=151440999
Diffstat (limited to 'src/java_tools/junitrunner/java/com/google/testing/junit')
-rw-r--r--src/java_tools/junitrunner/java/com/google/testing/junit/runner/ExperimentalTestRunner.java40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/ExperimentalTestRunner.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/ExperimentalTestRunner.java
index a2eb17b9cd..37c3e336fc 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/ExperimentalTestRunner.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/ExperimentalTestRunner.java
@@ -26,6 +26,10 @@ import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -216,7 +220,7 @@ public class ExperimentalTestRunner {
"Running test suites for class: %s, created by classLoader: %s%n",
targetSuiteClass, targetSuiteClass.getClassLoader());
return targetSuiteClass;
- } catch (ClassNotFoundException | MalformedURLException e) {
+ } catch (ClassNotFoundException | IOException e) {
System.err.println("Exception in loading class:" + e.getMessage());
return null;
}
@@ -228,23 +232,37 @@ public class ExperimentalTestRunner {
* @throws MalformedURLException when we are unable to create a given classpath.
* @return array of URLs containing the classpaths or null if classpaths could not be located.
*/
- private static URL[] getClasspaths() throws MalformedURLException {
- // TODO(kush): WARNING THIS DOES NOT RELOAD CLASSPATHS FOR EVERY TEST RUN. b/34712039
+ private static URL[] getClasspaths() throws IOException {
if (classpaths != null) {
return classpaths;
}
- String testTargetsClaspaths = System.getenv("TEST_TARGET_CLASSPATH");
- if (testTargetsClaspaths == null || testTargetsClaspaths.isEmpty()) {
- throw new IllegalStateException(
- "Target's classpath not present in TEST_TARGET_CLASSPATH environment variable");
- }
- String[] targetClassPaths = testTargetsClaspaths.split(":");
+ String selfLocation = System.getenv("SELF_LOCATION");
+ // TODO(kush): Get this to work for windows style paths.
+ String classpathFileLocation = selfLocation + "_classpaths_file";
+ Path file = Paths.get(classpathFileLocation);
+ byte[] classPathFileBytes = null;
+ try {
+ classPathFileBytes = Files.readAllBytes(file);
+ } catch (IOException e) {
+ System.err.println("exception in reading file:" + e.getMessage());
+ throw e;
+ }
- classpaths = new URL[targetClassPaths.length];
+ String classloaderPrefixPath = System.getenv("CLASSLOADER_PREFIX_PATH");
String workingDir = System.getProperty("user.dir");
+ String[] targetClassPaths = new String(classPathFileBytes, StandardCharsets.UTF_8).split(":");
+ classpaths = new URL[targetClassPaths.length];
+
+ String locationPrefix = "file://" + workingDir + "/" + classloaderPrefixPath;
+
for (int index = 0; index < targetClassPaths.length; index++) {
- classpaths[index] = new URL("file://" + workingDir + "/" + targetClassPaths[index]);
+ try {
+ classpaths[index] = new URL(locationPrefix + targetClassPaths[index]);
+ } catch (MalformedURLException e) {
+ System.err.println("Unable to create URL for:" + targetClassPaths[index]);
+ throw e;
+ }
}
return classpaths;
}