Skip to content

Commit 1fafc5d

Browse files
author
SendaoYan
committed
8216539: tools/jar/modularJar/Basic.java timed out
Backport-of: 518e3a8
1 parent 9ee1571 commit 1fafc5d

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

test/jdk/tools/jar/modularJar/Basic.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,14 +24,17 @@
2424
import java.io.*;
2525
import java.lang.module.ModuleDescriptor;
2626
import java.lang.reflect.Method;
27-
import java.nio.file.*;
27+
import java.nio.file.Files;
28+
import java.nio.file.Path;
29+
import java.nio.file.Paths;
2830
import java.util.*;
2931
import java.util.function.Consumer;
3032
import java.util.jar.JarEntry;
3133
import java.util.jar.JarFile;
3234
import java.util.jar.JarInputStream;
3335
import java.util.jar.Manifest;
3436
import java.util.regex.Pattern;
37+
import java.util.spi.ToolProvider;
3538
import java.util.stream.Collectors;
3639
import java.util.stream.Stream;
3740

@@ -59,6 +62,16 @@
5962
*/
6063

6164
public class Basic {
65+
66+
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
67+
.orElseThrow(()
68+
-> new RuntimeException("jar tool not found")
69+
);
70+
private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac")
71+
.orElseThrow(()
72+
-> new RuntimeException("javac tool not found")
73+
);
74+
6275
static final Path TEST_SRC = Paths.get(System.getProperty("test.src", "."));
6376
static final Path TEST_CLASSES = Paths.get(System.getProperty("test.classes", "."));
6477
static final Path MODULE_CLASSES = TEST_CLASSES.resolve("build");
@@ -933,13 +946,14 @@ static Result jarWithStdin(File stdinSource, String... args) {
933946
}
934947
Stream.of(args).forEach(commands::add);
935948
ProcessBuilder p = new ProcessBuilder(commands);
936-
if (stdinSource != null)
949+
if (stdinSource != null) {
937950
p.redirectInput(stdinSource);
951+
}
938952
return run(p);
939953
}
940954

941955
static Result jar(String... args) {
942-
return jarWithStdin(null, args);
956+
return run(JAR_TOOL, args);
943957
}
944958

945959
static Path compileModule(String mn) throws IOException {
@@ -1027,10 +1041,8 @@ static void javac(Path dest, Path... sourceFiles) throws IOException {
10271041
static void javac(Path dest, Path modulePath, Path... sourceFiles)
10281042
throws IOException
10291043
{
1030-
String javac = getJDKTool("javac");
10311044

10321045
List<String> commands = new ArrayList<>();
1033-
commands.add(javac);
10341046
if (!TOOL_VM_OPTIONS.isEmpty()) {
10351047
commands.addAll(Arrays.asList(TOOL_VM_OPTIONS.split("\\s+", -1)));
10361048
}
@@ -1048,7 +1060,13 @@ static void javac(Path dest, Path modulePath, Path... sourceFiles)
10481060
}
10491061
Stream.of(sourceFiles).map(Object::toString).forEach(x -> commands.add(x));
10501062

1051-
quickFail(run(new ProcessBuilder(commands)));
1063+
StringWriter sw = new StringWriter();
1064+
try (PrintWriter pw = new PrintWriter(sw)) {
1065+
int rc = JAVAC_TOOL.run(pw, pw, commands.toArray(new String[0]));
1066+
if(rc != 0) {
1067+
throw new RuntimeException(sw.toString());
1068+
}
1069+
}
10521070
}
10531071

10541072
static Result java(Path modulePath, String entryPoint, String... args) {
@@ -1094,9 +1112,13 @@ static boolean jarContains(JarInputStream jis, String entryName)
10941112
return false;
10951113
}
10961114

1097-
static void quickFail(Result r) {
1098-
if (r.ec != 0)
1099-
throw new RuntimeException(r.output);
1115+
static Result run(ToolProvider tp, String[] commands) {
1116+
int rc = 0;
1117+
StringWriter sw = new StringWriter();
1118+
try (PrintWriter pw = new PrintWriter(sw)) {
1119+
rc = tp.run(pw, pw, commands);
1120+
}
1121+
return new Result(rc, sw.toString());
11001122
}
11011123

11021124
static Result run(ProcessBuilder pb) {

0 commit comments

Comments
 (0)