1 /*
2 * Copyright (c) 2011, 2012, 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 */
89 PrintWriter pw = new PrintWriter(sw);
90 int rc = com.sun.tools.javac.Main.compile(opts, pw);
91
92 // sadly, command line errors are not (yet?) reported to
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 case JDK1_4_1: case JDK1_4_2: case JSR14: // transitional values
110 continue;
111 }
112
113 for (Profile p: Profile.values()) {
114 List<String> opts = new ArrayList<String>();
115 opts.addAll(Arrays.asList("-source", t.name, "-target", t.name));
116 opts.add("-Xlint:-options"); // dont warn about no -bootclasspath
117 if (p != Profile.DEFAULT)
118 opts.addAll(Arrays.asList("-profile", p.name));
119 StringWriter sw = new StringWriter();
120 JavacTask task = (JavacTask) javac.getTask(sw, fm, null, opts, null,
121 Arrays.asList(fo));
122 task.analyze();
123
124 // sadly, command line errors are not (yet?) reported to
125 // the diag listener
126 String out = sw.toString();
127 if (!out.isEmpty())
128 System.err.println(out.trim());
129
|
1 /*
2 * Copyright (c) 2011, 2013, 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 */
89 PrintWriter pw = new PrintWriter(sw);
90 int rc = com.sun.tools.javac.Main.compile(opts, pw);
91
92 // sadly, command line errors are not (yet?) reported to
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
|