Skip to content

Commit

Permalink
8216539: tools/jar/modularJar/Basic.java times out
Browse files Browse the repository at this point in the history
Reviewed-by: mchung, alanb, bchristi, bpb
  • Loading branch information
Lance Andersen committed Apr 3, 2019
1 parent 5c06e0a commit 518e3a8
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions test/jdk/tools/jar/modularJar/Basic.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, 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
Expand All @@ -24,14 +24,17 @@
import java.io.*;
import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Method;
import java.nio.file.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.function.Consumer;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import java.util.regex.Pattern;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -59,6 +62,16 @@
*/

public class Basic {

private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
.orElseThrow(()
-> new RuntimeException("jar tool not found")
);
private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac")
.orElseThrow(()
-> new RuntimeException("javac tool not found")
);

static final Path TEST_SRC = Paths.get(System.getProperty("test.src", "."));
static final Path TEST_CLASSES = Paths.get(System.getProperty("test.classes", "."));
static final Path MODULE_CLASSES = TEST_CLASSES.resolve("build");
Expand Down Expand Up @@ -977,13 +990,14 @@ static Result jarWithStdin(File stdinSource, String... args) {
}
Stream.of(args).forEach(commands::add);
ProcessBuilder p = new ProcessBuilder(commands);
if (stdinSource != null)
if (stdinSource != null) {
p.redirectInput(stdinSource);
}
return run(p);
}

static Result jar(String... args) {
return jarWithStdin(null, args);
return run(JAR_TOOL, args);
}

static Path compileModule(String mn) throws IOException {
Expand Down Expand Up @@ -1071,10 +1085,8 @@ static void javac(Path dest, Path... sourceFiles) throws IOException {
static void javac(Path dest, Path modulePath, Path... sourceFiles)
throws IOException
{
String javac = getJDKTool("javac");

List<String> commands = new ArrayList<>();
commands.add(javac);
if (!TOOL_VM_OPTIONS.isEmpty()) {
commands.addAll(Arrays.asList(TOOL_VM_OPTIONS.split("\\s+", -1)));
}
Expand All @@ -1092,7 +1104,13 @@ static void javac(Path dest, Path modulePath, Path... sourceFiles)
}
Stream.of(sourceFiles).map(Object::toString).forEach(x -> commands.add(x));

quickFail(run(new ProcessBuilder(commands)));
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
int rc = JAVAC_TOOL.run(pw, pw, commands.toArray(new String[0]));
if(rc != 0) {
throw new RuntimeException(sw.toString());
}
}
}

static Result java(Path modulePath, String entryPoint, String... args) {
Expand Down Expand Up @@ -1138,9 +1156,13 @@ static boolean jarContains(JarInputStream jis, String entryName)
return false;
}

static void quickFail(Result r) {
if (r.ec != 0)
throw new RuntimeException(r.output);
static Result run(ToolProvider tp, String[] commands) {
int rc = 0;
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
rc = tp.run(pw, pw, commands);
}
return new Result(rc, sw.toString());
}

static Result run(ProcessBuilder pb) {
Expand Down

0 comments on commit 518e3a8

Please sign in to comment.