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 */
23
24 /*
25 * @test
26 * @bug 8004182
27 * @summary Add support for profiles in javac
28 */
29
30 import java.io.PrintWriter;
31 import java.io.StringWriter;
32 import java.lang.annotation.Annotation;
33 import java.lang.annotation.Retention;
34 import java.lang.annotation.RetentionPolicy;
35 import java.lang.reflect.InvocationTargetException;
36 import java.lang.reflect.Method;
37 import java.net.URI;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collections;
41 import java.util.EnumMap;
42 import java.util.List;
43 import java.util.Map;
44
45 import javax.tools.Diagnostic;
46 import javax.tools.DiagnosticCollector;
93 // the diag listener
94 String out = sw.toString();
95 if (!out.isEmpty())
96 System.err.println(out.trim());
97
98 if (!out.contains("invalid profile: " + badName)) {
99 error("expected message not found");
100 }
101 }
102
103 @Test
104 void testTargetProfileCombinations() throws Exception {
105 JavaFileObject fo = new StringJavaFileObject("Test.java", "class Test { }");
106 for (Target t: Target.values()) {
107 switch (t) {
108 case JDK1_1: case JDK1_2: // no equivalent -source
109 continue;
110 }
111
112 for (Profile p: Profile.values()) {
113 List<String> opts = new ArrayList<String>();
114 opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
115 opts.add("-Xlint:-options"); // dont warn about no -bootclasspath
116 if (p != Profile.DEFAULT)
117 opts.addAll(Arrays.asList("-profile", p.name));
118 StringWriter sw = new StringWriter();
119 JavacTask task = (JavacTask) javac.getTask(sw, fm, null, opts, null,
120 Arrays.asList(fo));
121 task.analyze();
122
123 // sadly, command line errors are not (yet?) reported to
124 // the diag listener
125 String out = sw.toString();
126 if (!out.isEmpty())
127 System.err.println(out.trim());
128
129 switch (t) {
130 case JDK1_8:
131 if (!out.isEmpty())
132 error("unexpected output from compiler");
133 break;
134 default:
135 if (p != Profile.DEFAULT
136 && !out.contains("profile " + p.name
137 + " is not valid for target release " + t.name)) {
138 error("expected message not found");
139 }
140 }
141 }
142 }
143 }
144
145 @Test
146 void testClassesInProfiles() throws Exception {
147 for (Profile p: Profile.values()) {
148 for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
149 for (JavaFileObject fo: e.getValue()) {
150 DiagnosticCollector<JavaFileObject> dl =
|
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 */
23
24 /*
25 * @test
26 * @bug 8004182 8028545
27 * @summary Add support for profiles in javac
28 */
29
30 import java.io.PrintWriter;
31 import java.io.StringWriter;
32 import java.lang.annotation.Annotation;
33 import java.lang.annotation.Retention;
34 import java.lang.annotation.RetentionPolicy;
35 import java.lang.reflect.InvocationTargetException;
36 import java.lang.reflect.Method;
37 import java.net.URI;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Collections;
41 import java.util.EnumMap;
42 import java.util.List;
43 import java.util.Map;
44
45 import javax.tools.Diagnostic;
46 import javax.tools.DiagnosticCollector;
93 // the diag listener
94 String out = sw.toString();
95 if (!out.isEmpty())
96 System.err.println(out.trim());
97
98 if (!out.contains("invalid profile: " + badName)) {
99 error("expected message not found");
100 }
101 }
102
103 @Test
104 void testTargetProfileCombinations() throws Exception {
105 JavaFileObject fo = new StringJavaFileObject("Test.java", "class Test { }");
106 for (Target t: Target.values()) {
107 switch (t) {
108 case JDK1_1: case JDK1_2: // no equivalent -source
109 continue;
110 }
111
112 for (Profile p: Profile.values()) {
113 List<String> opts = new ArrayList<>();
114 opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
115 opts.add("-Xlint:-options"); // dont warn about no -bootclasspath
116 if (p != Profile.DEFAULT)
117 opts.addAll(Arrays.asList("-profile", p.name));
118 StringWriter sw = new StringWriter();
119 JavacTask task = (JavacTask) javac.getTask(sw, fm, null, opts, null,
120 Arrays.asList(fo));
121 task.analyze();
122
123 // sadly, command line errors are not (yet?) reported to
124 // the diag listener
125 String out = sw.toString();
126 if (!out.isEmpty())
127 System.err.println(out.trim());
128
129 switch (t) {
130 case JDK1_8:
131 case JDK1_9:
132 if (!out.isEmpty())
133 error("unexpected output from compiler");
134 break;
135 default:
136 if (p != Profile.DEFAULT
137 && !out.contains("profile " + p.name
138 + " is not valid for target release " + t.name)) {
139 error("expected message not found");
140 }
141 }
142 }
143 }
144 }
145
146 @Test
147 void testClassesInProfiles() throws Exception {
148 for (Profile p: Profile.values()) {
149 for (Map.Entry<Profile, List<JavaFileObject>> e: testClasses.entrySet()) {
150 for (JavaFileObject fo: e.getValue()) {
151 DiagnosticCollector<JavaFileObject> dl =
|