Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8216539: tools/jar/modularJar/Basic.java timed out #2981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -933,13 +946,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 @@ -1027,10 +1041,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 @@ -1048,7 +1060,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 @@ -1094,9 +1112,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