author | lana |
Thu, 21 Jan 2016 09:46:01 -0800 | |
changeset 35340 | 38f7386ed942 |
parent 30730 | d3ce7619db2c |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
1261 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27850
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
1261 | 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 |
* |
|
5520 | 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. |
|
1261 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6728697 |
|
27 |
* @summary tools/javac/versionOpt.sh fails on OpenJDK builds |
|
28 |
* Test checks the version strings displayed by javac, using |
|
29 |
* strings that come out of the Java runtime. |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27850
diff
changeset
|
30 |
* @modules jdk.compiler |
1261 | 31 |
*/ |
32 |
||
33 |
import java.io.File; |
|
34 |
import java.io.PrintWriter; |
|
35 |
import java.io.StringWriter; |
|
36 |
import java.net.URL; |
|
37 |
||
38 |
public class VersionOpt { |
|
39 |
public static void main(String... args) throws Exception { |
|
40 |
new VersionOpt().run(); |
|
41 |
} |
|
42 |
||
43 |
void run() throws Exception { |
|
44 |
// Test functions by comparing the version string from javac against |
|
45 |
// a "golden" version generated automatically from the underlying JVM. |
|
46 |
// As such, it is only effective in testing the "standard" compiler, |
|
47 |
// and not any development version being tested via -Xbootclasspath. |
|
48 |
// Check the version of the compiler being used, and let the test pass |
|
49 |
// automatically if is is a development version. |
|
50 |
Class<?> javacClass = com.sun.tools.javac.Main.class; |
|
51 |
URL javacURL = getClass().getClassLoader().getResource(javacClass.getName().replace(".", "/") + ".class"); |
|
52 |
if (!javacURL.getProtocol().equals("jar") || !javacURL.getFile().contains("!")) { |
|
53 |
System.err.println("javac not found in tools.jar: " + javacURL); |
|
54 |
System.err.println("rest of test skipped"); |
|
55 |
return; |
|
56 |
} |
|
57 |
String javacHome = javacURL.getFile().substring(0, javacURL.getFile().indexOf("!")); |
|
58 |
||
59 |
File javaHome = new File(System.getProperty("java.home")); |
|
60 |
if (javaHome.getName().equals("jre")) |
|
61 |
javaHome = javaHome.getParentFile(); |
|
62 |
File toolsJar = new File(new File(javaHome, "lib"), "tools.jar"); |
|
63 |
||
18385
3d41b3b9f305
7113519: test/tools/javac/VersionOpt.java passes on windows
vromero
parents:
5520
diff
changeset
|
64 |
if (!javacHome.equalsIgnoreCase(toolsJar.toURI().toString())) { |
1261 | 65 |
System.err.println("javac not found in tools.jar: " + javacHome); |
66 |
System.err.println("rest of test skipped"); |
|
67 |
return; |
|
68 |
} |
|
69 |
||
70 |
System.out.println("javac found in " + toolsJar); |
|
71 |
||
72 |
String javaVersion = System.getProperty("java.version"); |
|
73 |
String javaRuntimeVersion = System.getProperty("java.runtime.version"); |
|
74 |
System.out.println("java.version: " + javaVersion); |
|
75 |
System.out.println("java.runtime.version: " + javaRuntimeVersion); |
|
76 |
||
77 |
StringWriter sw = new StringWriter(); |
|
78 |
com.sun.tools.javac.Main.compile(new String[] { "-version" }, new PrintWriter(sw)); |
|
79 |
String javacVersion = sw.toString().trim(); |
|
80 |
||
81 |
sw = new StringWriter(); |
|
82 |
com.sun.tools.javac.Main.compile(new String[] { "-fullversion" }, new PrintWriter(sw)); |
|
83 |
String javacFullVersion = sw.toString().trim(); |
|
84 |
System.out.println("javac -version: " + javacVersion); |
|
85 |
System.out.println("javac -fullversion: " + javacFullVersion); |
|
86 |
||
87 |
checkEqual("javac -version", javacVersion, "javac " + javaVersion); |
|
88 |
checkEqual("javac -fullversion", javacFullVersion, "javac full version \"" + javaRuntimeVersion + "\""); |
|
89 |
||
90 |
if (errors > 0) |
|
91 |
throw new Exception(errors + " errors found"); |
|
92 |
} |
|
93 |
||
94 |
void checkEqual(String kind, String found, String expect) { |
|
95 |
if (!found.equals(expect)) { |
|
96 |
System.err.println("error: unexpected value for " + kind); |
|
97 |
System.err.println("expect: >>" + expect + "<<"); |
|
98 |
System.err.println(" found: >>" + found + "<<"); |
|
99 |
errors++; |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
int errors; |
|
104 |
} |