author | sogoel |
Thu, 05 Jun 2014 10:57:10 -0700 | |
changeset 24797 | 850ebd4d80a7 |
parent 19653 | e49999626675 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
19653
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
1 |
/* |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
4 |
* |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
8 |
* |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
14 |
* |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
18 |
* |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
21 |
* questions. |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
22 |
*/ |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
23 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
24 |
/* |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
25 |
* @test |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
26 |
* @bug 8022287 |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
27 |
* @summary javac.sym.Profiles uses a static Map when it should not |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
28 |
*/ |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
29 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
30 |
import java.io.File; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
31 |
import java.io.FileWriter; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
32 |
import java.io.IOException; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
33 |
import java.io.PrintWriter; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
34 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.sym.Profiles; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
36 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
37 |
public class ProfileTest { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
38 |
public static void main(String... args) throws Exception { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
39 |
new ProfileTest().run(); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
40 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
41 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
42 |
public void run() throws Exception { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
43 |
test("A"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
44 |
test("B"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
45 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
46 |
if (errors > 0) |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
47 |
throw new Exception(errors + " occurred"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
48 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
49 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
50 |
void test(String base) throws IOException { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
51 |
System.err.println("test " + base); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
52 |
File profileDesc = createFiles(base); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
53 |
checkProfile(profileDesc, base); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
54 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
55 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
56 |
void checkProfile(File profileDesc, String base) throws IOException { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
57 |
Profiles p = Profiles.read(profileDesc); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
58 |
for (int i = 0; i < p.getProfileCount(); i++) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
59 |
System.err.println(p.getPackages(i)); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
60 |
for (String pkg: p.getPackages(i)) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
61 |
if (!pkg.endsWith(base)) |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
62 |
error("unexpected package " + pkg + " for profile " + i); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
63 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
64 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
65 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
66 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
67 |
File createFiles(String base) throws IOException { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
68 |
File baseDir = new File(base); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
69 |
baseDir.mkdirs(); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
70 |
for (int p = 1; p <= 4; p++) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
71 |
String pkg = "pkg" + p + base; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
72 |
File pkgDir = new File(baseDir, pkg); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
73 |
pkgDir.mkdirs(); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
74 |
File clssFile = new File(pkgDir, pkg + "Class.java"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
75 |
try (PrintWriter out = new PrintWriter(new FileWriter(clssFile))) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
76 |
out.println("package " + pkgDir.getName() + ";"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
77 |
out.println("class " + clssFile.getName().replace(".java", "")); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
78 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
79 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
80 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
81 |
File profileDesc = new File(baseDir, "profiles" + base + ".txt"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
82 |
try (PrintWriter out = new PrintWriter(new FileWriter(profileDesc))) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
83 |
for (int p = 1; p <= 4; p++) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
84 |
String pkg = "pkg" + p + base; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
85 |
createPackage(baseDir, pkg, "Pkg" + p + base + "Class"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
86 |
out.println("PROFILE_" + p + "_RTJAR_INCLUDE_PACKAGES := " + pkg); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
87 |
out.println("PROFILE_" + p + "_RTJAR_INCLUDE_TYPES :="); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
88 |
out.println("PROFILE_" + p + "_RTJAR_EXCLUDE_TYPES :="); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
89 |
out.println("PROFILE_" + p + "_INCLUDE_METAINF_SERVICES := "); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
90 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
91 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
92 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
93 |
return profileDesc; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
94 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
95 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
96 |
void createPackage(File baseDir, String pkg, String... classNames) throws IOException { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
97 |
File pkgDir = new File(baseDir, pkg); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
98 |
pkgDir.mkdirs(); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
99 |
for (String className: classNames) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
100 |
File clssFile = new File(pkgDir, className + ".java"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
101 |
try (PrintWriter out = new PrintWriter(new FileWriter(clssFile))) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
102 |
out.println("package " + pkg + ";"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
103 |
out.println("public class " + className + " { }"); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
104 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
105 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
106 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
107 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
108 |
void error(String msg) { |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
109 |
System.err.println("Error: " + msg); |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
110 |
errors++; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
111 |
} |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
112 |
|
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
113 |
int errors; |
e49999626675
8022287: javac.sym.Profiles uses a static Map when it should not
jjg
parents:
diff
changeset
|
114 |
} |