Path: blob/master/test/langtools/tools/jdeps/modules/SplitPackage.java
41152 views
/*1* Copyright (c) 2017, 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* @summary Tests split packages26* @library ../lib27* @build CompilerUtils28* @modules jdk.jdeps/com.sun.tools.jdeps29* @run testng SplitPackage30*/3132import java.nio.file.Path;33import java.nio.file.Paths;34import java.util.Arrays;35import java.util.Collections;36import java.util.Map;37import java.util.Set;38import java.util.stream.Collectors;3940import com.sun.tools.jdeps.DepsAnalyzer;41import com.sun.tools.jdeps.JdepsConfiguration;42import org.testng.annotations.BeforeTest;43import org.testng.annotations.Test;4445import static org.testng.Assert.assertTrue;4647public class SplitPackage {48private static final String TEST_SRC = System.getProperty("test.src");4950private static final Path CLASSES_DIR = Paths.get("classes");51private static final Path PATCHES_DIR = Paths.get(TEST_SRC, "patches");5253private static final String SPLIT_PKG_NAME = "java.sql";54private static final String MODULE_NAME = "java.sql";55/**56* Compiles classes used by the test57*/58@BeforeTest59public void compileAll() throws Exception {60CompilerUtils.cleanDir(CLASSES_DIR);61assertTrue(CompilerUtils.compile(PATCHES_DIR, CLASSES_DIR, "--patch-module", "java.sql=" + PATCHES_DIR));62}6364@Test65public void runTest() throws Exception {66// split package detected because of java.sql is in the root set67runTest(MODULE_NAME, SPLIT_PKG_NAME);68runTest("ALL-SYSTEM", SPLIT_PKG_NAME);69// default70runTest(null, SPLIT_PKG_NAME);7172// Test jdeps classes73runTest("ALL-DEFAULT", SPLIT_PKG_NAME);7475}7677private void runTest(String root, String... splitPackages) throws Exception {78String cmd = String.format("jdeps -verbose:class --add-modules %s %s%n",79root, CLASSES_DIR);8081try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {82jdeps.verbose("-verbose:class")83.addRoot(CLASSES_DIR);84if (root != null)85jdeps.addmods(Set.of(root));8687JdepsConfiguration config = jdeps.configuration();88Map<String, Set<String>> pkgs = config.splitPackages();8990final Set<String> expected;91if (splitPackages != null) {92expected = Arrays.stream(splitPackages).collect(Collectors.toSet());93} else {94expected = Collections.emptySet();95}9697if (!pkgs.keySet().equals(expected)) {98throw new RuntimeException(splitPackages.toString());99}100101DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();102103assertTrue(analyzer.run());104105jdeps.dumpOutput(System.err);106}107}108}109110111