Path: blob/master/test/langtools/jdk/javadoc/tool/modules/MissingSourceModules.java
40974 views
/*1* Copyright (c) 2017, 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 8176481 824670526* @summary Tests behavior of the tool, when modules are present as27* binaries.28* @modules29* jdk.javadoc/jdk.javadoc.internal.api30* jdk.javadoc/jdk.javadoc.internal.tool31* jdk.compiler/com.sun.tools.javac.api32* jdk.compiler/com.sun.tools.javac.main33* @library /tools/lib34* @build toolbox.ToolBox toolbox.TestRunner35* @run main MissingSourceModules36*/3738import java.nio.file.Path;39import java.nio.file.Paths;4041import toolbox.*;4243public class MissingSourceModules extends ModuleTestBase {4445public static void main(String... args) throws Exception {46new MissingSourceModules().runTests();47}4849@Test50public void testExplicitBinaryModuleOnModulePath(Path base) throws Exception {51Path modulePath = base.resolve("modules");5253ModuleBuilder ma = new ModuleBuilder(tb, "ma");54ma.comment("Module ma.")55.exports("pkg1")56.classes("package pkg1; /** Class A */ public class A { }")57.classes("package pkg1.pkg2; /** Class B */ public class B { }")58.build(modulePath);5960execNegativeTask("--module-path", modulePath.toString(),61"--module", "ma");62assertMessagePresent("module ma not found");63}6465@Test66public void testExplicitBinaryModuleOnLegacyPaths(Path base) throws Exception {67Path modulePath = base.resolve("modules");6869ModuleBuilder ma = new ModuleBuilder(tb, "ma");70ma.comment("Module ma.")71.exports("pkg1")72.classes("package pkg1; /** Class A */ public class A { }")73.classes("package pkg1.pkg2; /** Class B */ public class B { }")74.build(modulePath);7576Path mPath = Paths.get(modulePath.toString(), "ma");77execNegativeTask("--source-path", mPath.toString(),78"--module", "ma");79assertMessagePresent("module ma not found on source path");8081execNegativeTask("--class-path", mPath.toString(),82"--module", "ma");83assertMessagePresent("module ma not found");84}8586@Test87public void testImplicitBinaryRequiresModule(Path base) throws Exception {88Path src = base.resolve("src");89Path modulePath = base.resolve("modules");9091ModuleBuilder mb = new ModuleBuilder(tb, "mb");92mb.comment("Module mb.")93.exports("pkgb")94.classes("package pkgb; /** Class A */ public class A { }")95.build(modulePath);9697ModuleBuilder ma = new ModuleBuilder(tb, "ma");98ma.comment("Module ma.")99.exports("pkga")100.requires("mb", modulePath)101.classes("package pkga; /** Class A */ public class A { }")102.write(src);103104execTask("--module-path", modulePath.toString(),105"--module-source-path", src.toString(),106"--expand-requires", "all",107"--module", "ma");108assertMessagePresent("source files for module mb not found");109}110111@Test112public void testImplicitBinaryTransitiveModule(Path base) throws Exception {113Path src = base.resolve("src");114Path modulePath = base.resolve("modules");115116ModuleBuilder mb = new ModuleBuilder(tb, "mb");117mb.comment("Module mb.")118.exports("pkgb")119.classes("package pkgb; /** Class A */ public class A { }")120.build(modulePath);121122ModuleBuilder ma = new ModuleBuilder(tb, "ma");123ma.comment("Module ma.")124.exports("pkga")125.requiresTransitive("mb", modulePath)126.classes("package pkga; /** Class A */ public class A { }")127.write(src);128129execTask("--module-path", modulePath.toString(),130"--module-source-path", src.toString(),131"--expand-requires", "transitive",132"--module", "ma");133assertMessagePresent("source files for module mb not found");134}135}136137138