author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 45156 | langtools/test/tools/javac/options/release/ReleaseOptionClashes.java@001f73134346 |
permissions | -rw-r--r-- |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
1 |
/* |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40763
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
4 |
* |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
8 |
* |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
13 |
* accompanied this code). |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
14 |
* |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
18 |
* |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
21 |
* questions. |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
22 |
*/ |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
23 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
24 |
/** |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
25 |
* @test |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
26 |
* @bug 8072480 |
40763
209113892b0d
8165109: langtools/test switches to use new CLI options
mchung
parents:
35359
diff
changeset
|
27 |
* @summary Verify option clash between --release and -source is reported correctly. |
42407
f3702cff2933
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40763
diff
changeset
|
28 |
* @modules jdk.compiler/com.sun.tools.javac.util:open |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
29 |
*/ |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
30 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
31 |
import java.io.ByteArrayOutputStream; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
32 |
import java.io.File; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
33 |
import java.lang.reflect.Field; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
34 |
import java.util.ArrayList; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
35 |
import java.util.Arrays; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
36 |
import java.util.List; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
37 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
38 |
import javax.tools.Tool; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
39 |
import javax.tools.ToolProvider; |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
40 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
41 |
public class ReleaseOptionClashes { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
42 |
public static void main(String... args) throws Exception { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
43 |
new ReleaseOptionClashes().run(); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
44 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
45 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
46 |
void run() throws Exception { |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
47 |
doRunTest("7", "-bootclasspath", "any"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
48 |
doRunTest("7", "-Xbootclasspath:any"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
49 |
doRunTest("7", "-Xbootclasspath/a:any"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
50 |
doRunTest("7", "-Xbootclasspath/p:any"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
51 |
doRunTest("7", "-endorseddirs", "any"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
52 |
doRunTest("7", "-extdirs", "any"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
53 |
doRunTest("7", "-source", "8"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
54 |
doRunTest("7", "-target", "8"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
55 |
doRunTest("9", "--system", "none"); |
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
56 |
doRunTest("9", "--upgrade-module-path", "any"); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
57 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
58 |
|
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
59 |
void doRunTest(String release, String... args) throws Exception { |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
60 |
System.out.println("Testing clashes for arguments: " + Arrays.asList(args)); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
61 |
Class<?> log = Class.forName("com.sun.tools.javac.util.Log", true, cl); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
62 |
Field useRawMessages = log.getDeclaredField("useRawMessages"); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
63 |
useRawMessages.setAccessible(true); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
64 |
useRawMessages.setBoolean(null, true); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
65 |
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
66 |
List<String> options = new ArrayList<>(); |
45156
001f73134346
8178152: Handling of incubating modules, the jdk.unsupported module and --add-exports with --release <current>
jlahoda
parents:
42408
diff
changeset
|
67 |
options.addAll(Arrays.asList("--release", release)); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
68 |
options.addAll(Arrays.asList(args)); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
69 |
options.add(System.getProperty("test.src") + File.separator + "ReleaseOptionClashes.java"); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
70 |
compiler.run(null, null, out, options.toArray(new String[0])); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
71 |
useRawMessages.setBoolean(null, false); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
72 |
if (!out.toString().equals(String.format("%s%n%s%n", |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
73 |
"javac: javac.err.release.bootclasspath.conflict", |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
74 |
"javac.msg.usage")) && |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
75 |
//-Xbootclasspath:any produces two warnings: one for -bootclasspath and one for -Xbootclasspath: |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
76 |
!out.toString().equals(String.format("%s%n%s%n%s%n%s%n", |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
77 |
"javac: javac.err.release.bootclasspath.conflict", |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
78 |
"javac.msg.usage", |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
79 |
"javac: javac.err.release.bootclasspath.conflict", |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
80 |
"javac.msg.usage"))) { |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
81 |
throw new AssertionError(out); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
82 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
83 |
System.out.println("Test PASSED. Running javac again to see localized output:"); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
84 |
compiler.run(null, null, System.out, options.toArray(new String[0])); |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
85 |
} |
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
86 |
|
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
87 |
Tool compiler = ToolProvider.getSystemJavaCompiler(); |
42270
3bd3e7e378b5
8155765: javax.tools.ToolProvider::getSystemToolClassLoader returns app class loader even if no tool is available
jjg
parents:
40763
diff
changeset
|
88 |
ClassLoader cl = compiler.getClass().getClassLoader(); |
31506
4e07f827a794
8072480: javac should support compilation for a specific platform version
jlahoda
parents:
diff
changeset
|
89 |
} |