8149729: [jittester] Replace all 'path1 +"/" + path2' with Paths::get

Reviewed-by: kvn
This commit is contained in:
Igor Ignatyev 2018-06-28 16:45:15 -07:00
parent 2ddeb31e89
commit 6385038a37
5 changed files with 21 additions and 14 deletions

View File

@ -23,14 +23,14 @@
package jdk.test.lib.jittester;
import java.io.FileOutputStream;
import jdk.test.lib.jittester.visitors.ByteCodeVisitor;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.function.Function;
import jdk.test.lib.jittester.visitors.ByteCodeVisitor;
/**
* Generates class files from IRTree
@ -88,8 +88,8 @@ class ByteCodeGenerator extends TestsGenerator {
}
private void writeFile(String fileName, byte[] bytecode) {
try (FileOutputStream file = new FileOutputStream(generatorDir.resolve(fileName).toFile())) {
file.write(bytecode);
try {
Files.write(generatorDir.resolve(fileName), bytecode);
} catch (IOException ex) {
ex.printStackTrace();
}

View File

@ -23,7 +23,6 @@
package jdk.test.lib.jittester;
import java.io.File;
import java.io.IOException;
import java.util.function.Function;
import jdk.test.lib.jittester.visitors.JavaCodeVisitor;
@ -65,7 +64,9 @@ public class JavaCodeGenerator extends TestsGenerator {
}
private void compileJavaFile(String mainClassName) {
String classPath = getRoot() + File.pathSeparator + generatorDir;
String classPath = getRoot().resolve(generatorDir)
.toAbsolutePath()
.toString();
ProcessBuilder pb = new ProcessBuilder(JAVAC, "-cp", classPath,
generatorDir.resolve(mainClassName + ".java").toString());
try {

View File

@ -58,7 +58,9 @@ public abstract class TestsGenerator implements BiConsumer<IRNode, IRNode> {
}
protected void generateGoldenOut(String mainClassName) {
String classPath = getRoot() + File.pathSeparator + generatorDir;
String classPath = getRoot().resolve(generatorDir)
.toAbsolutePath()
.toString();
ProcessBuilder pb = new ProcessBuilder(JAVA, "-Xint", DISABLE_WARNINGS, "-Xverify",
"-cp", classPath, mainClassName);
String goldFile = mainClassName + ".gold";
@ -182,7 +184,10 @@ public abstract class TestsGenerator implements BiConsumer<IRNode, IRNode> {
for (String name : env) {
String path = System.getenv(name);
if (path != null) {
return path + "/bin/";
return Paths.get(path)
.resolve("bin")
.toAbsolutePath()
.toString();
}
}
return "";

View File

@ -31,6 +31,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -207,7 +208,7 @@ public class TypesParser {
Asserts.assertNotNull(klassesFileName, "Classes input file name is null");
Asserts.assertFalse(klassesFileName.isEmpty(), "Classes input file name is empty");
List<String> klassNamesList = new ArrayList<>();
Path klassesFilePath = (new File(klassesFileName)).toPath();
Path klassesFilePath = Paths.get(klassesFileName);
try {
Files.lines(klassesFilePath).forEach(line -> {
line = line.trim();
@ -223,7 +224,7 @@ public class TypesParser {
throw new Error("Error reading klasses file", ex);
}
List<Class<?>> klassesList = new ArrayList<>();
klassNamesList.stream().forEach(klassName -> {
klassNamesList.forEach(klassName -> {
try {
klassesList.add(Class.forName(klassName));
} catch (ClassNotFoundException ex) {
@ -237,7 +238,7 @@ public class TypesParser {
Asserts.assertNotNull(methodsFileName, "Methods exclude input file name is null");
Asserts.assertFalse(methodsFileName.isEmpty(), "Methods exclude input file name is empty");
LinkedList<String> methodNamesList = new LinkedList<>();
Path klassesFilePath = (new File(methodsFileName)).toPath();
Path klassesFilePath = Paths.get(methodsFileName);
try {
Files.lines(klassesFilePath).forEach(line -> {
line = line.trim();
@ -253,7 +254,7 @@ public class TypesParser {
throw new Error("Error reading exclude method file", ex);
}
Set<Executable> methodsList = new HashSet<>();
methodNamesList.stream().forEach(methodName -> {
methodNamesList.forEach(methodName -> {
String[] klassAndNameAndSig = methodName.split("::");
String klassName = klassAndNameAndSig[0].replaceAll("/", "\\.");
String[] nameAndSig = klassAndNameAndSig[1].split("[\\(\\)]");

View File

@ -24,15 +24,15 @@
package jdk.test.lib.jittester.jtreg;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.Utils;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;