Path: blob/master/test/langtools/jdk/javadoc/tool/MultiReleaseJar/TestMultiRelease.java
40971 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 820826926* @summary Verify module-infos are read from the correct place in multi-release jars27* @library /tools/lib28* @modules jdk.compiler/com.sun.tools.javac.api29* jdk.compiler/com.sun.tools.javac.main30* jdk.javadoc/jdk.javadoc.internal.api31* jdk.javadoc/jdk.javadoc.internal.tool32* @build toolbox.JavacTask toolbox.JavadocTask toolbox.TestRunner toolbox.ToolBox33* @run main TestMultiRelease34*/3536import java.io.IOException;37import java.nio.file.Files;38import java.nio.file.Path;39import java.nio.file.Paths;40import java.util.Arrays;4142import toolbox.JarTask;43import toolbox.JavacTask;44import toolbox.JavadocTask;45import toolbox.Task.Expect;46import toolbox.TestRunner;47import toolbox.ToolBox;4849public class TestMultiRelease extends TestRunner {5051public static void main(String... args) throws Exception {52TestMultiRelease t = new TestMultiRelease();53t.runTests(m -> new Object[] { Paths.get(m.getName()) });54}5556private final ToolBox tb = new ToolBox();5758TestMultiRelease() throws IOException {59super(System.err);60}6162@Test63public void testMultiReleaseModule(Path base) throws Exception {64Files.createDirectory(base);6566Path module = base.resolve("module");67Path moduleSrc = module.resolve("src");68Path moduleCls = module.resolve("classes");6970tb.writeJavaFiles(moduleSrc, "module test.module { }");7172Files.createDirectories(moduleCls);7374new JavacTask(tb)75.outdir(moduleCls)76.files(tb.findJavaFiles(moduleSrc))77.run()78.writeAll();7980Path moduleJarDir = module.resolve("jar-dir");81Path versions = moduleJarDir.resolve("META-INF/versions/10");8283Files.createDirectories(versions);8485Files.copy(moduleCls.resolve("module-info.class"),86versions.resolve("module-info.class"));8788Path moduleJar = module.resolve("module.jar");8990new JarTask(tb, moduleJar)91.baseDir(moduleJarDir)92.files(Arrays.stream(tb.findFiles("class", moduleJarDir))93.map(p -> moduleJarDir.relativize(p).toString())94.toArray(s -> new String[s]))95.manifest("Multi-Release: true\n\n")96.run();9798Path src = base.resolve("src");99100tb.writeJavaFiles(src,101"module m { requires test.module; exports api; }",102"package api; public class Api { }");103Path out = base.resolve("out");104Files.createDirectory(out);105106JavadocTask task = new JavadocTask(tb);107task.outdir(out)108.options("--module-path", moduleJar.toString(),109"-source", "10")110.files(tb.findJavaFiles(src))111.run(Expect.SUCCESS);112113task.outdir(out)114.options("--module-path", moduleJar.toString(),115"-source", "9")116.files(tb.findJavaFiles(src))117.run(Expect.FAIL);118}119}120121122