1 /*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
32
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.Map;
38 import java.util.Set;
39 import java.util.stream.Collectors;
40
41 import com.sun.tools.jdeps.DepsAnalyzer;
42 import com.sun.tools.jdeps.JdepsConfiguration;
43 import org.testng.annotations.BeforeTest;
44 import org.testng.annotations.Test;
45
46 import static org.testng.Assert.assertTrue;
47
48 public class SplitPackage {
49 private static final String TEST_SRC = System.getProperty("test.src");
50
51 private static final Path CLASSES_DIR = Paths.get("classes");
52
53 private static final String SPLIT_PKG_NAME = "javax.annotation";
54 private static final String JAVA_XML_WS_ANNOTATION = "java.xml.ws.annotation";
55 /**
56 * Compiles classes used by the test
57 */
58 @BeforeTest
59 public void compileAll() throws Exception {
60 CompilerUtils.cleanDir(CLASSES_DIR);
61 assertTrue(CompilerUtils.compile(Paths.get(TEST_SRC, "patches"), CLASSES_DIR));
62 }
63
64 @Test
65 public void runTest() throws Exception {
66 // split package detected if java.annotation.common is in the root set
67 runTest(JAVA_XML_WS_ANNOTATION, SPLIT_PKG_NAME);
68 runTest("ALL-SYSTEM", SPLIT_PKG_NAME);
69 // default
70 runTest(null, SPLIT_PKG_NAME);
71
72 // Test jdeps classes
73 runTest("ALL-DEFAULT");
74
75 }
76
77 private void runTest(String root, String... splitPackages) throws Exception {
78 String cmd = String.format("jdeps -verbose:class --add-modules %s %s%n",
79 root, CLASSES_DIR);
80
81 try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
82 jdeps.verbose("-verbose:class")
83 .addRoot(CLASSES_DIR);
84 if (root != null)
85 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 }
|
1 /*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
32
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.Map;
38 import java.util.Set;
39 import java.util.stream.Collectors;
40
41 import com.sun.tools.jdeps.DepsAnalyzer;
42 import com.sun.tools.jdeps.JdepsConfiguration;
43 import org.testng.annotations.BeforeTest;
44 import org.testng.annotations.Test;
45
46 import static org.testng.Assert.assertTrue;
47
48 public class SplitPackage {
49 private static final String TEST_SRC = System.getProperty("test.src");
50
51 private static final Path CLASSES_DIR = Paths.get("classes");
52 private static final Path PATCHES_DIR = Paths.get(TEST_SRC, "patches");
53
54 private static final String SPLIT_PKG_NAME = "java.sql";
55 private static final String MODULE_NAME = "java.sql";
56 /**
57 * Compiles classes used by the test
58 */
59 @BeforeTest
60 public void compileAll() throws Exception {
61 CompilerUtils.cleanDir(CLASSES_DIR);
62 assertTrue(CompilerUtils.compile(PATCHES_DIR, CLASSES_DIR, "--patch-module", "java.sql=" + PATCHES_DIR));
63 }
64
65 @Test
66 public void runTest() throws Exception {
67 // split package detected because of java.sql is in the root set
68 runTest(MODULE_NAME, SPLIT_PKG_NAME);
69 runTest("ALL-SYSTEM", SPLIT_PKG_NAME);
70 // default
71 runTest(null, SPLIT_PKG_NAME);
72
73 // Test jdeps classes
74 runTest("ALL-DEFAULT", SPLIT_PKG_NAME);
75
76 }
77
78 private void runTest(String root, String... splitPackages) throws Exception {
79 String cmd = String.format("jdeps -verbose:class --add-modules %s %s%n",
80 root, CLASSES_DIR);
81
82 try (JdepsUtil.Command jdeps = JdepsUtil.newCommand(cmd)) {
83 jdeps.verbose("-verbose:class")
84 .addRoot(CLASSES_DIR);
85 if (root != null)
86 jdeps.addmods(Set.of(root));
87
88 JdepsConfiguration config = jdeps.configuration();
89 Map<String, Set<String>> pkgs = config.splitPackages();
90
91 final Set<String> expected;
92 if (splitPackages != null) {
93 expected = Arrays.stream(splitPackages).collect(Collectors.toSet());
94 } else {
95 expected = Collections.emptySet();
96 }
97
98 if (!pkgs.keySet().equals(expected)) {
99 throw new RuntimeException(splitPackages.toString());
100 }
101
102 DepsAnalyzer analyzer = jdeps.getDepsAnalyzer();
103
104 assertTrue(analyzer.run());
105
106 jdeps.dumpOutput(System.err);
107 }
108 }
109 }
|