Path: blob/master/test/langtools/tools/jdeps/modules/GenOpenModule.java
41149 views
/*1* Copyright (c) 2016, 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* @summary Tests jdeps --generate-open-module option26* @library ../lib27* @build CompilerUtils JdepsUtil JdepsRunner28* @modules jdk.jdeps/com.sun.tools.jdeps29* @run testng GenOpenModule30*/3132import java.io.IOException;33import java.io.InputStream;34import java.lang.module.ModuleDescriptor;3536import java.nio.file.Files;37import java.nio.file.Path;38import java.nio.file.Paths;3940import java.util.stream.Stream;4142import org.testng.annotations.BeforeTest;43import org.testng.annotations.Test;4445import static org.testng.Assert.assertEquals;46import static org.testng.Assert.assertTrue;4748public class GenOpenModule extends GenModuleInfo {49private static final String MODULE_INFO = "module-info.class";5051private static final Path MODS_DIR = Paths.get("mods");52private static final Path LIBS_DIR = Paths.get("libs");53private static final Path DEST_DIR = Paths.get("moduleinfosrc");54private static final Path NEW_MODS_DIR = Paths.get("new_mods");5556@BeforeTest57public void setup() throws Exception {58compileAndCreateJars();59}6061@Test62public void test() throws IOException {63Path dest = DEST_DIR.resolve("open");64Path classes = NEW_MODS_DIR.resolve("open");65Files.createDirectories(dest);66Files.createDirectories(classes);6768Stream<String> files = MODULES.stream()69.map(mn -> LIBS_DIR.resolve(mn + ".jar"))70.map(Path::toString);7172Stream<String> options = Stream.concat(73Stream.of("--generate-open-module", dest.toString()), files);74JdepsRunner.run(options.toArray(String[]::new));7576// check file exists77MODULES.stream()78.map(mn -> dest.resolve(mn).resolve("module-info.java"))79.forEach(f -> assertTrue(Files.exists(f)));8081// copy classes to a temporary directory82// and then compile new module-info.java83copyClasses(MODS_DIR, classes);84compileNewGenModuleInfo(dest, classes);8586for (String mn : MODULES) {87Path p1 = classes.resolve(mn).resolve(MODULE_INFO);88Path p2 = MODS_DIR.resolve(mn).resolve(MODULE_INFO);89try (InputStream in1 = Files.newInputStream(p1);90InputStream in2 = Files.newInputStream(p2)) {91verify(ModuleDescriptor.read(in1),92ModuleDescriptor.read(in2));93}94}95}9697/*98* Verify the dependences99*/100private void verify(ModuleDescriptor openModule, ModuleDescriptor md) {101System.out.println("verifying: " + openModule.name());102assertTrue(openModule.isOpen());103assertTrue(!md.isOpen());104assertEquals(openModule.name(), md.name());105assertEquals(openModule.requires(), md.requires());106assertTrue(openModule.exports().isEmpty());107assertEquals(openModule.provides(), md.provides());108}109}110111112