8231850: BasicTest test fails in jcov build
Submitted-by: asemenyuk
Reviewed-by: almatvee, herrick
--- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java Thu Oct 03 11:04:51 2019 -0400
+++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Executor.java Fri Oct 04 14:53:39 2019 -0400
@@ -30,12 +30,7 @@
import java.io.PrintStream;
import java.io.StringReader;
import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
import java.util.regex.Pattern;
import java.util.spi.ToolProvider;
import java.util.stream.Collectors;
@@ -53,19 +48,14 @@
}
public Executor setExecutable(Path v) {
- executable = v;
- if (executable != null) {
- toolProvider = null;
- }
+ executable = Objects.requireNonNull(v);
+ toolProvider = null;
return this;
}
public Executor setToolProvider(ToolProvider v) {
- toolProvider = v;
- filterOutJcovOutput = true;
- if (toolProvider != null) {
- executable = null;
- }
+ toolProvider = Objects.requireNonNull(v);
+ executable = null;
return this;
}
@@ -75,7 +65,6 @@
}
public Executor setExecutable(JavaTool v) {
- filterOutJcovOutput = true;
return setExecutable(v.getPath());
}
@@ -233,8 +222,8 @@
if (withSavedOutput()) {
try (BufferedReader outReader = new BufferedReader(
new InputStreamReader(process.getInputStream()))) {
- if (saveOutputType.contains(SaveOutputType.DUMP) || saveOutputType.contains(
- SaveOutputType.FULL)) {
+ if (saveOutputType.contains(SaveOutputType.DUMP)
+ || saveOutputType.contains(SaveOutputType.FULL)) {
outputLines = outReader.lines().collect(Collectors.toList());
} else {
outputLines = Arrays.asList(
@@ -294,13 +283,12 @@
try (BufferedReader bufReader = new BufferedReader(new StringReader(
buf.toString()))) {
if (saveOutputType.contains(SaveOutputType.FIRST_LINE)) {
- String firstLine = filterJcovOutput(bufReader.lines()).findFirst().orElse(
- null);
+ String firstLine = bufReader.lines().findFirst().orElse(null);
if (firstLine != null) {
reply.output = List.of(firstLine);
}
} else if (saveOutputType.contains(SaveOutputType.FULL)) {
- reply.output = filterJcovOutput(bufReader.lines()).collect(
+ reply.output = bufReader.lines().collect(
Collectors.toUnmodifiableList());
}
@@ -343,18 +331,10 @@
Collectors.joining(" "));
}
- private Stream<String> filterJcovOutput(Stream<String> lines) {
- if (filterOutJcovOutput) {
- return lines.filter(line -> !line.startsWith("Picked up"));
- }
- return lines;
- }
-
private ToolProvider toolProvider;
private Path executable;
private Set<SaveOutputType> saveOutputType;
private Path directory;
- private boolean filterOutJcovOutput;
private static enum SaveOutputType {
NONE, FULL, FIRST_LINE, DUMP
--- a/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java Thu Oct 03 11:04:51 2019 -0400
+++ b/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java Fri Oct 04 14:53:39 2019 -0400
@@ -28,6 +28,7 @@
import java.nio.file.Path;
import java.util.List;
import java.util.ArrayList;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jdk.jpackage.test.Executor;
import jdk.jpackage.test.JPackageCommand;
@@ -51,7 +52,7 @@
@Test
public void testNoArgs() {
List<String> output = JPackageCommand.filterOutput(
- createVanillaJPackageCommand().executeAndGetOutput());
+ getJPackageToolProvider().executeAndGetOutput());
TKit.assertStringListEquals(List.of("Usage: jpackage <mode> <options>",
"Use jpackage --help (or -h) for a list of possible options"),
output, "Check jpackage output");
@@ -60,7 +61,7 @@
@Test
public void testVersion() {
List<String> output = JPackageCommand.filterOutput(
- createVanillaJPackageCommand()
+ getJPackageToolProvider()
.addArgument("--version")
.executeAndGetOutput());
TKit.assertStringListEquals(List.of(System.getProperty("java.version")),
@@ -159,7 +160,7 @@
// Instead of running jpackage command through configured
// JPackageCommand instance, run vanilla jpackage command with @ file.
- createVanillaJPackageCommand()
+ getJPackageToolProvider()
.addArgument(String.format("@%s", optionsFile))
.execute().assertExitCodeIsZero();
@@ -172,7 +173,7 @@
@Parameter("com.foo/com.foo.main.Aloha")
@Test
public void testJLinkRuntime(String javaAppDesc) {
- JPackageCommand cmd = new JPackageCommand().helloAppImage(javaAppDesc);
+ JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc);
// If `--module` parameter was set on jpackage command line, get its
// value and extract module name.
@@ -189,7 +190,7 @@
TKit.withTempDirectory("runtime", runtimeDir -> {
TKit.deleteDirectoryRecursive(runtimeDir, String.format(
"Delete [%s] output directory for jlink command", runtimeDir));
- Executor jlink = createJavaToolCommand(JavaTool.JLINK)
+ Executor jlink = getToolProvider(JavaTool.JLINK)
.saveOutput(false)
.addArguments(
"--add-modules", "java.base",
@@ -212,14 +213,21 @@
final Path appImageRuntimePath = cmd.appImage().resolve(
cmd.appRuntimeDirectoryInAppImage());
+ //
// This is an overkill to list modules in jlink output as we have
// already verified that Java app is functional and thus app's runtime
// is likely to be OK, but let's double check.
+ //
+ // Filter out all first strings with whitespace. They are java
+ // launcher output like `Picked up ...` unrelated to module names.
+ //
+ Pattern whitespaceChar = Pattern.compile("\\s");
List<String> moduleList = new Executor().dumpOutput().setExecutable(
appImageRuntimePath.resolve(
JPackageCommand.relativePathInRuntime(JavaTool.JAVA))).addArguments(
- "--list-modules").executeAndGetOutput().stream().sorted().collect(
- Collectors.toList());
+ "--list-modules").executeAndGetOutput().stream().dropWhile(
+ s -> whitespaceChar.matcher(s).find()).sorted().collect(
+ Collectors.toList());
List<String> expectedModules = new ArrayList<>();
expectedModules.add(String.format("java.base@%s",
@@ -237,18 +245,13 @@
});
}
- private static Executor createVanillaJPackageCommand() {
- return createJavaToolCommand(JavaTool.JPACKAGE);
+ private static Executor getJPackageToolProvider() {
+ return getToolProvider(JavaTool.JPACKAGE);
}
- private static Executor createJavaToolCommand(JavaTool tool) {
- Executor exec = new Executor().dumpOutput().saveOutput();
- if (new JPackageCommand().isWithToolProvider()) {
- exec.setToolProvider(tool.asToolProvider());
- } else {
- exec.setExecutable(tool);
- }
-
- return exec;
+ private static Executor getToolProvider(JavaTool tool) {
+ return new Executor()
+ .dumpOutput().saveOutput()
+ .setToolProvider(tool.asToolProvider());
}
}