SplitPackage.java revision 3946:31f3cfd70930
1280364Sandrew/* 2280364Sandrew * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3280364Sandrew * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4280364Sandrew * 5280364Sandrew * This code is free software; you can redistribute it and/or modify it 6280364Sandrew * under the terms of the GNU General Public License version 2 only, as 7280364Sandrew * published by the Free Software Foundation. 8280364Sandrew * 9280364Sandrew * This code is distributed in the hope that it will be useful, but WITHOUT 10280364Sandrew * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11280364Sandrew * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12280364Sandrew * version 2 for more details (a copy is included in the LICENSE file that 13280364Sandrew * accompanied this code). 14280364Sandrew * 15280364Sandrew * You should have received a copy of the GNU General Public License version 16280364Sandrew * 2 along with this work; if not, write to the Free Software Foundation, 17280364Sandrew * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18280364Sandrew * 19280364Sandrew * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20280364Sandrew * or visit www.oracle.com if you need additional information or have any 21280364Sandrew * questions. 22280364Sandrew */ 23280364Sandrew 24280364Sandrew/* 25280364Sandrew * @test 26280364Sandrew * @summary Tests split packages 27280364Sandrew * @library ../lib 28280364Sandrew * @build CompilerUtils 29280364Sandrew * @modules jdk.jdeps/com.sun.tools.jdeps 30280364Sandrew * @run testng SplitPackage 31280364Sandrew */ 32280364Sandrew 33280364Sandrewimport java.nio.file.Path; 34280364Sandrewimport java.nio.file.Paths; 35280364Sandrewimport java.util.Arrays; 36280364Sandrewimport java.util.Collections; 37280364Sandrewimport java.util.Map; 38280364Sandrewimport java.util.Set; 39280364Sandrewimport java.util.stream.Collectors; 40280364Sandrew 41280364Sandrewimport com.sun.tools.jdeps.DepsAnalyzer; 42280364Sandrewimport com.sun.tools.jdeps.JdepsConfiguration; 43280364Sandrewimport org.testng.annotations.BeforeTest; 44280364Sandrewimport org.testng.annotations.Test; 45280364Sandrew 46280364Sandrewimport static org.testng.Assert.assertTrue; 47280364Sandrew 48280364Sandrewpublic class SplitPackage { 49280364Sandrew private static final String TEST_SRC = System.getProperty("test.src"); 50280364Sandrew 51280364Sandrew private static final Path CLASSES_DIR = Paths.get("classes"); 52280364Sandrew 53280364Sandrew private static final String SPLIT_PKG_NAME = "javax.annotation"; 54280364Sandrew private static final String JAVA_XML_WS_ANNOTATION = "java.xml.ws.annotation"; 55280364Sandrew /** 56280364Sandrew * Compiles classes used by the test 57280364Sandrew */ 58280364Sandrew @BeforeTest 59280364Sandrew public void compileAll() throws Exception { 60280364Sandrew CompilerUtils.cleanDir(CLASSES_DIR); 61280364Sandrew assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "patches"), CLASSES_DIR)); 62280364Sandrew } 63280364Sandrew 64280364Sandrew @Test 65280364Sandrew public void runTest() throws Exception { 66280364Sandrew // split package detected if java.annotation.common is in the root set 67280364Sandrew runTest(JAVA_XML_WS_ANNOTATION, SPLIT_PKG_NAME); 68280364Sandrew runTest("ALL-SYSTEM", SPLIT_PKG_NAME); 69280364Sandrew // default 70280364Sandrew runTest(null, SPLIT_PKG_NAME); 71280364Sandrew 72280364Sandrew // Test jdeps classes 73280364Sandrew runTest("ALL-DEFAULT"); 74280364Sandrew 75280364Sandrew } 76280364Sandrew 77280364Sandrew private void runTest(String root, String... splitPackages) throws Exception { 78280364Sandrew String cmd = String.format("jdeps -verbose:class --add-modules %s %s%n", 79280364Sandrew root, CLASSES_DIR); 80280364Sandrew 81280364Sandrew try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) { 82280364Sandrew jdeps.verbose("-verbose:class") 83280364Sandrew .addRoot(CLASSES_DIR); 84280364Sandrew if (root != null) 85280364Sandrew jdeps.addmods(Set.of(root)); 86 87 JdepsConfiguration config = jdeps.configuration(); 88 Map<String, Set<String>> pkgs = config.splitPackages(); 89 90 final Set<String> expected; 91 if (splitPackages != null) { 92 expected = Arrays.stream(splitPackages).collect(Collectors.toSet()); 93 } else { 94 expected = Collections.emptySet(); 95 } 96 97 if (!pkgs.keySet().equals(expected)) { 98 throw new RuntimeException(splitPackages.toString()); 99 } 100 101 // java.xml.ws.annotation is not observable 102 DepsAnalyzer analyzer = jdeps.getDepsAnalyzer(); 103 104 assertTrue(analyzer.run()); 105 106 jdeps.dumpOutput(System.err); 107 } 108 } 109} 110