test/tools/jdeps/Basic.java

changeset 2172
aa91bc6e8480
parent 2139
defadd528513
child 2525
2eb010b6cb22
child 2538
1e39ae45d8ac
equal deleted inserted replaced
2171:44e3ba40e00c 2172:aa91bc6e8480
1 /* 1 /*
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
21 * questions. 21 * questions.
22 */ 22 */
23 23
24 /* 24 /*
25 * @test 25 * @test
26 * @bug 8003562 8005428 8015912 26 * @bug 8003562 8005428 8015912 8027481
27 * @summary Basic tests for jdeps tool 27 * @summary Basic tests for jdeps tool
28 * @build Test p.Foo 28 * @build Test p.Foo p.Bar javax.activity.NotCompactProfile
29 * @run main Basic 29 * @run main Basic
30 */ 30 */
31 31
32 import java.io.File; 32 import java.io.File;
33 import java.io.IOException; 33 import java.io.IOException;
34 import java.io.PrintWriter; 34 import java.io.PrintWriter;
35 import java.io.StringWriter; 35 import java.io.StringWriter;
36 import java.nio.file.Files;
36 import java.nio.file.Path; 37 import java.nio.file.Path;
37 import java.nio.file.Paths; 38 import java.nio.file.Paths;
38 import java.util.*; 39 import java.util.*;
39 import java.util.regex.*; 40 import java.util.regex.*;
41 import static java.nio.file.StandardCopyOption.*;
40 42
41 public class Basic { 43 public class Basic {
42 private static boolean symbolFileExist = initProfiles(); 44 private static boolean symbolFileExist = initProfiles();
43 private static boolean initProfiles() { 45 private static boolean initProfiles() {
44 // check if ct.sym exists; if not use the profiles.properties file 46 // check if ct.sym exists; if not use the profiles.properties file
72 // test a .class file 74 // test a .class file
73 test(new File(testDir, "Test.class"), 75 test(new File(testDir, "Test.class"),
74 new String[] {"java.lang", "p"}, 76 new String[] {"java.lang", "p"},
75 new String[] {"compact1", "not found"}); 77 new String[] {"compact1", "not found"});
76 // test a directory 78 // test a directory
79 // also test non-SE javax.activity class dependency
77 test(new File(testDir, "p"), 80 test(new File(testDir, "p"),
78 new String[] {"java.lang", "java.util", "java.lang.management"}, 81 new String[] {"java.lang", "java.util", "java.lang.management", "javax.activity", "javax.crypto"},
79 new String[] {"compact1", "compact1", "compact3"}); 82 new String[] {"compact1", "compact1", "compact3", testDir.getName(), "compact1"},
83 new String[] {"-classpath", testDir.getPath()});
80 // test class-level dependency output 84 // test class-level dependency output
81 test(new File(testDir, "Test.class"), 85 test(new File(testDir, "Test.class"),
82 new String[] {"java.lang.Object", "java.lang.String", "p.Foo"}, 86 new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
83 new String[] {"compact1", "compact1", "not found"}, 87 new String[] {"compact1", "compact1", "not found", "not found"},
84 new String[] {"-verbose:class"}); 88 new String[] {"-verbose:class"});
85 // test -p option 89 // test -p option
86 test(new File(testDir, "Test.class"), 90 test(new File(testDir, "Test.class"),
87 new String[] {"p.Foo"}, 91 new String[] {"p.Foo", "p.Bar"},
88 new String[] {"not found"}, 92 new String[] {"not found", "not found"},
89 new String[] {"-verbose:class", "-p", "p"}); 93 new String[] {"-verbose:class", "-p", "p"});
90 // test -e option 94 // test -e option
91 test(new File(testDir, "Test.class"), 95 test(new File(testDir, "Test.class"),
92 new String[] {"p.Foo"}, 96 new String[] {"p.Foo", "p.Bar"},
93 new String[] {"not found"}, 97 new String[] {"not found", "not found"},
94 new String[] {"-verbose:class", "-e", "p\\..*"}); 98 new String[] {"-verbose:class", "-e", "p\\..*"});
95 test(new File(testDir, "Test.class"), 99 test(new File(testDir, "Test.class"),
96 new String[] {"java.lang"}, 100 new String[] {"java.lang"},
97 new String[] {"compact1"}, 101 new String[] {"compact1"},
98 new String[] {"-verbose:package", "-e", "java\\.lang\\..*"}); 102 new String[] {"-verbose:package", "-e", "java\\.lang\\..*"});
99 // test -classpath and -include options 103 // test -classpath and -include options
100 test(null, 104 test(null,
101 new String[] {"java.lang", "java.util", 105 new String[] {"java.lang", "java.util",
102 "java.lang.management"}, 106 "java.lang.management", "javax.crypto"},
103 new String[] {"compact1", "compact1", "compact3"}, 107 new String[] {"compact1", "compact1", "compact3", "compact1"},
104 new String[] {"-classpath", testDir.getPath(), "-include", "p.+|Test.class"}); 108 new String[] {"-classpath", testDir.getPath(), "-include", "p.+|Test.class"});
105 test(new File(testDir, "Test.class"), 109 test(new File(testDir, "Test.class"),
106 new String[] {"java.lang.Object", "java.lang.String", "p.Foo"}, 110 new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
107 new String[] {"compact1", "compact1", testDir.getName()}, 111 new String[] {"compact1", "compact1", testDir.getName(), testDir.getName()},
108 new String[] {"-v", "-classpath", testDir.getPath(), "Test.class"}); 112 new String[] {"-v", "-classpath", testDir.getPath(), "Test.class"});
113
114 // split package p - move p/Foo.class to dir1 and p/Bar.class to dir2
115 Path testClassPath = testDir.toPath();
116 Path dirP = testClassPath.resolve("p");
117 Path dir1 = testClassPath.resolve("dir1");
118 Path subdir1P = dir1.resolve("p");
119 Path dir2 = testClassPath.resolve("dir2");
120 Path subdir2P = dir2.resolve("p");
121 if (!Files.exists(subdir1P))
122 Files.createDirectories(subdir1P);
123 if (!Files.exists(subdir2P))
124 Files.createDirectories(subdir2P);
125 Files.move(dirP.resolve("Foo.class"), subdir1P.resolve("Foo.class"), REPLACE_EXISTING);
126 Files.move(dirP.resolve("Bar.class"), subdir2P.resolve("Bar.class"), REPLACE_EXISTING);
127 StringBuilder cpath = new StringBuilder(testDir.toString());
128 cpath.append(File.pathSeparator).append(dir1.toString());
129 cpath.append(File.pathSeparator).append(dir2.toString());
130 test(new File(testDir, "Test.class"),
131 new String[] {"java.lang.Object", "java.lang.String", "p.Foo", "p.Bar"},
132 new String[] {"compact1", "compact1", dir1.toFile().getName(), dir2.toFile().getName()},
133 new String[] {"-v", "-classpath", cpath.toString(), "Test.class"});
109 return errors; 134 return errors;
110 } 135 }
111 136
112 void test(File file, String[] expect, String[] profiles) { 137 void test(File file, String[] expect, String[] profiles) {
113 test(file, expect, profiles, new String[0]); 138 test(file, expect, profiles, new String[0]);
146 private static Pattern pattern = Pattern.compile("\\s+ -> (\\S+) +(.*)"); 171 private static Pattern pattern = Pattern.compile("\\s+ -> (\\S+) +(.*)");
147 172
148 // Use the linePattern to break the given String into lines, applying 173 // Use the linePattern to break the given String into lines, applying
149 // the pattern to each line to see if we have a match 174 // the pattern to each line to see if we have a match
150 private static Map<String,String> findDeps(String out) { 175 private static Map<String,String> findDeps(String out) {
151 Map<String,String> result = new HashMap<>(); 176 Map<String,String> result = new LinkedHashMap<>();
152 Matcher lm = linePattern.matcher(out); // Line matcher 177 Matcher lm = linePattern.matcher(out); // Line matcher
153 Matcher pm = null; // Pattern matcher 178 Matcher pm = null; // Pattern matcher
154 int lines = 0; 179 int lines = 0;
155 while (lm.find()) { 180 while (lm.find()) {
156 lines++; 181 lines++;

mercurial