Skip to content
Permalink
Browse files
8286571: java source launcher from a minimal jdk image containing jdk…
….compiler fails with --enable-preview option

Reviewed-by: jlahoda
  • Loading branch information
asotona committed Jun 7, 2022
1 parent 8d28734 commit 905bcbe34eb9750f6f7f12a577733c71a31d7972
Showing 3 changed files with 39 additions and 47 deletions.
@@ -78,6 +78,7 @@
*/
module jdk.compiler {
requires transitive java.compiler;
requires jdk.zipfs;

exports com.sun.source.doctree;
exports com.sun.source.tree;
@@ -23,7 +23,7 @@

/**
* @test
* @bug 8192920 8204588 8210275
* @bug 8192920 8204588 8210275 8286571
* @summary Test source mode
* @modules jdk.compiler jdk.jlink
* @run main SourceMode
@@ -32,6 +32,7 @@

import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -106,6 +107,33 @@ void testSimpleJava() throws IOException {
show(tr);
}

// java --source N --enable-preview Simple.java hello
// on minimal jdk image containing jdk.compiler
@Test
void test8286571() throws IOException {
starting("test8286571");
var pw = new PrintWriter(System.out);
int rc = ToolProvider.findFirst("jlink").orElseThrow().run(
pw, pw,
"--add-modules",
"jdk.compiler",
"--output",
"comp_only");
if (rc != 0)
throw new AssertionError("Jlink failed: rc = " + rc);
Path file = getSimpleFile("Simple.java", false);
TestResult tr = doExec(
Path.of("comp_only", "bin", isWindows ? "java.exe" : "java").toString(),
"--source", thisVersion,
"--enable-preview",
file.toString(), "hello");
if (!tr.isOK())
error(tr, "Bad exit code: " + tr.exitValue);
if (!tr.contains("[hello]"))
error(tr, "Expected output not found");
show(tr);
}

// java --source N simple 1 2 3
@Test
void testSimple() throws IOException {
@@ -24,7 +24,7 @@
/**
* @test
* @bug 8153391
* @summary Verify javac behaves properly in absence of zip/jar FileSystemProvider
* @summary Verify javac behaves properly in JDK image limited to jdk.compiler module
* @library /tools/lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@@ -34,14 +34,11 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

import toolbox.JavacTask;
import toolbox.JarTask;
import toolbox.Task.Expect;
import toolbox.Task.Mode;
import toolbox.Task.OutputKind;
import toolbox.ToolBox;

public class LimitedImage {
@@ -68,73 +65,39 @@ public static void main(String... args) throws IOException {

new JarTask(tb, testJar).run();

List<String> actualOutput;
List<String> expectedOutput = Arrays.asList(
"- compiler.err.no.zipfs.for.archive: " + testJar.toString()
);

//check proper diagnostics when zip/jar FS not present:
System.err.println("Test " + testJar + " on classpath");
actualOutput = new JavacTask(tb, Mode.CMDLINE)
new JavacTask(tb, Mode.CMDLINE)
.classpath(testJar)
.options("-XDrawDiagnostics")
.files(testSource)
.outdir(".")
.run(Expect.FAIL)
.writeAll()
.getOutputLines(OutputKind.DIRECT);

if (!expectedOutput.equals(actualOutput)) {
throw new AssertionError("Unexpected output");
}
.run(Expect.SUCCESS);

System.err.println("Test " + testJar + " on sourcepath");
actualOutput = new JavacTask(tb, Mode.CMDLINE)
new JavacTask(tb, Mode.CMDLINE)
.sourcepath(testJar)
.options("-XDrawDiagnostics")
.files(testSource)
.outdir(".")
.run(Expect.FAIL)
.writeAll()
.getOutputLines(OutputKind.DIRECT);

if (!expectedOutput.equals(actualOutput)) {
throw new AssertionError("Unexpected output");
}
.run(Expect.SUCCESS);

System.err.println("Test " + testJar + " on modulepath");
actualOutput = new JavacTask(tb, Mode.CMDLINE)
new JavacTask(tb, Mode.CMDLINE)
.options("-XDrawDiagnostics",
"--module-path", testJar.toString())
.files(testSource)
.outdir(".")
.run(Expect.FAIL)
.writeAll()
.getOutputLines(OutputKind.DIRECT);

if (!expectedOutput.equals(actualOutput)) {
throw new AssertionError("Unexpected output");
}

expectedOutput = Arrays.asList(
"- compiler.err.no.zipfs.for.archive: " + testJar.toString(),
"1 error"
);
.run(Expect.SUCCESS);

System.err.println("Test directory containing " + testJar + " on modulepath");
actualOutput = new JavacTask(tb, Mode.CMDLINE)
new JavacTask(tb, Mode.CMDLINE)
.classpath()
.options("-XDrawDiagnostics",
"--module-path", testJar.getParent().toString())
.files(testSource)
.outdir(".")
.run(Expect.FAIL)
.writeAll()
.getOutputLines(OutputKind.DIRECT);

if (!expectedOutput.equals(actualOutput)) {
throw new AssertionError("Unexpected output");
}
.run(Expect.SUCCESS);
}

}

1 comment on commit 905bcbe

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 905bcbe Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.