8286571: java source launcher from a minimal jdk image containing jdk.compiler fails with --enable-preview option

Reviewed-by: jlahoda
This commit is contained in:
Adam Sotona 2022-06-07 13:38:56 +00:00
parent 8d28734ede
commit 905bcbe34e
3 changed files with 39 additions and 47 deletions

View File

@ -78,6 +78,7 @@
*/
module jdk.compiler {
requires transitive java.compiler;
requires jdk.zipfs;
exports com.sun.source.doctree;
exports com.sun.source.tree;

View File

@ -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 @@ public class SourceMode extends TestHelper {
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 {

View File

@ -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 class LimitedImage {
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);
}
}