mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8014363: javac test class ToolTester handles classpath incorrectly
Reviewed-by: ksrini
This commit is contained in:
parent
8ea0284b13
commit
c037757e7b
23 changed files with 82 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -24,7 +24,7 @@
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
import javax.tools.*;
|
||||
|
||||
import static javax.tools.StandardLocation.CLASS_PATH;
|
||||
|
@ -34,6 +34,8 @@ import static javax.tools.StandardLocation.CLASS_OUTPUT;
|
|||
public class ToolTester {
|
||||
public final File test_src = new File(System.getProperty("test.src", "."));
|
||||
public final File test_classes = new File(System.getProperty("test.classes", "."));
|
||||
public final List<File> test_class_path = pathToFiles(System.getProperty("test.class.path"),
|
||||
Arrays.asList(test_classes));
|
||||
public final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
|
||||
public final StandardJavaFileManager fm = getFileManager(tool, null, null);
|
||||
public JavaCompiler.CompilationTask task = null;
|
||||
|
@ -43,11 +45,36 @@ public class ToolTester {
|
|||
StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, encoding);
|
||||
try {
|
||||
fm.setLocation(SOURCE_PATH, Arrays.asList(test_src));
|
||||
fm.setLocation(CLASS_PATH, Arrays.asList(test_classes));
|
||||
fm.setLocation(CLASS_PATH, test_class_path);
|
||||
fm.setLocation(CLASS_OUTPUT, Arrays.asList(test_classes));
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return fm;
|
||||
}
|
||||
|
||||
protected List<File> pathToFiles(String path, List<File> defaultPath) {
|
||||
List<File> files = new ArrayList<>();
|
||||
for (String f: path.split(File.pathSeparator)) {
|
||||
if (f.isEmpty())
|
||||
continue;
|
||||
File file = new File(f);
|
||||
if (file.exists())
|
||||
files.add(file);
|
||||
}
|
||||
if (files.isEmpty())
|
||||
files.addAll(defaultPath);
|
||||
return files;
|
||||
}
|
||||
|
||||
protected <T> List<T> join(List<T> a, List<T> b) {
|
||||
if (a.isEmpty())
|
||||
return b;
|
||||
if (b.isEmpty())
|
||||
return a;
|
||||
List<T> result = new ArrayList<>();
|
||||
result.addAll(a);
|
||||
result.addAll(b);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue