author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 27319 | 030080f03e4f |
child 37940 | ead113a2f92e |
permissions | -rw-r--r-- |
25448 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
25448 | 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 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610 |
|
27 |
* @summary Check interpretation of -target and -source options |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* jdk.compiler |
25448 | 30 |
* @run main Versions |
31 |
*/ |
|
32 |
||
33 |
import java.io.*; |
|
34 |
import java.nio.*; |
|
35 |
import java.nio.channels.*; |
|
36 |
||
37 |
import javax.tools.JavaCompiler; |
|
38 |
import javax.tools.ToolProvider; |
|
39 |
import javax.tools.JavaFileObject; |
|
40 |
import javax.tools.StandardJavaFileManager; |
|
41 |
import java.util.List; |
|
42 |
import java.util.ArrayList; |
|
43 |
import java.util.Arrays; |
|
44 |
||
45 |
||
46 |
public class Versions { |
|
47 |
||
48 |
protected JavaCompiler javacompiler; |
|
49 |
protected int failedCases; |
|
50 |
||
51 |
public Versions() throws IOException { |
|
52 |
javacompiler = ToolProvider.getSystemJavaCompiler(); |
|
53 |
genSourceFiles(); |
|
54 |
failedCases = 0; |
|
55 |
} |
|
56 |
||
57 |
public static void main(String... args) throws IOException { |
|
58 |
Versions versions = new Versions(); |
|
59 |
versions.run(); |
|
60 |
} |
|
61 |
||
62 |
void run() { |
|
63 |
||
64 |
String jdk9cv = "52.0"; // class version.change when ./dev pushed to 53 |
|
65 |
||
66 |
String TC = ""; |
|
67 |
System.out.println("Version.java: Starting"); |
|
68 |
||
69 |
check("52.0"); |
|
70 |
check("52.0", "-source 1.6"); |
|
71 |
check("52.0", "-source 1.7"); |
|
72 |
check("52.0", "-source 1.8"); |
|
73 |
check(jdk9cv, "-source 1.9"); |
|
74 |
||
75 |
check_source_target("50.0", "6", "6"); |
|
76 |
check_source_target("51.0", "6", "7"); |
|
77 |
check_source_target("51.0", "7", "7"); |
|
78 |
check_source_target("52.0", "6", "8"); |
|
79 |
check_source_target("52.0", "7", "8"); |
|
80 |
check_source_target("52.0", "8", "8"); |
|
81 |
check_source_target(jdk9cv, "6", "9"); |
|
82 |
check_source_target(jdk9cv, "7", "9"); |
|
83 |
check_source_target(jdk9cv, "8", "9"); |
|
84 |
check_source_target(jdk9cv, "9", "9"); |
|
85 |
||
86 |
checksrc16("-source 1.6"); |
|
87 |
checksrc16("-source 6"); |
|
88 |
checksrc16("-source 1.6", "-target 1.6"); |
|
89 |
checksrc16("-source 6", "-target 6"); |
|
90 |
checksrc17("-source 1.7"); |
|
91 |
checksrc17("-source 7"); |
|
92 |
checksrc17("-source 1.7", "-target 1.7"); |
|
93 |
checksrc17("-source 7", "-target 7"); |
|
94 |
checksrc18("-source 1.8"); |
|
95 |
checksrc18("-source 8"); |
|
96 |
checksrc18("-source 1.8", "-target 1.8"); |
|
97 |
checksrc18("-source 8", "-target 8"); |
|
98 |
checksrc19(); |
|
99 |
checksrc19("-source 1.9"); |
|
100 |
checksrc19("-source 9"); |
|
101 |
checksrc19("-source 1.9", "-target 1.9"); |
|
102 |
checksrc19("-source 9", "-target 9"); |
|
103 |
checksrc19("-target 1.9"); |
|
104 |
checksrc19("-target 9"); |
|
105 |
||
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
106 |
fail("-source 7", "-target 1.6", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
107 |
fail("-source 8", "-target 1.6", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
108 |
fail("-source 8", "-target 1.7", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
109 |
fail("-source 9", "-target 1.7", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
110 |
fail("-source 9", "-target 1.8", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
111 |
|
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
112 |
fail("-source 1.5", "-target 1.5", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
113 |
fail("-source 1.4", "-target 1.4", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
114 |
fail("-source 1.3", "-target 1.3", "Base.java"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
115 |
fail("-source 1.2", "-target 1.2", "Base.java"); |
25448 | 116 |
|
117 |
if (failedCases > 0) { |
|
118 |
System.err.println("failedCases = " + String.valueOf(failedCases)); |
|
119 |
throw new Error("Test failed"); |
|
120 |
} |
|
121 |
||
122 |
} |
|
123 |
||
124 |
protected void printargs(String fname,String... args) { |
|
125 |
System.out.printf("test: %s", fname); |
|
126 |
for (String onearg : args) { |
|
127 |
System.out.printf(" %s", onearg); |
|
128 |
} |
|
129 |
System.out.printf("\n", fname); |
|
130 |
} |
|
131 |
||
132 |
protected void check_source_target(String... args) { |
|
133 |
printargs("check_source_target", args); |
|
134 |
check_target(args[0], args[1], args[2]); |
|
135 |
check_target(args[0], "1." + args[1], args[2]); |
|
136 |
} |
|
137 |
||
138 |
protected void check_target(String... args) { |
|
139 |
check(args[0], "-source " + args[1], "-target " + args[2]); |
|
140 |
check(args[0], "-source " + args[1], "-target 1." + args[2]); |
|
141 |
} |
|
142 |
||
143 |
protected void check(String major, String... args) { |
|
144 |
printargs("check", args); |
|
145 |
List<String> jcargs = new ArrayList<String>(); |
|
146 |
jcargs.add("-Xlint:-options"); |
|
147 |
||
148 |
// add in args conforming to List requrements of JavaCompiler |
|
149 |
for (String onearg : args) { |
|
150 |
String[] fields = onearg.split(" "); |
|
151 |
for (String onefield : fields) { |
|
152 |
jcargs.add(onefield); |
|
153 |
} |
|
154 |
} |
|
155 |
||
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
156 |
boolean creturn = compile("Base.java", jcargs); |
25448 | 157 |
if (!creturn) { |
158 |
// compilation errors note and return.. assume no class file |
|
159 |
System.err.println("check: Compilation Failed"); |
|
160 |
System.err.println("\t classVersion:\t" + major); |
|
161 |
System.err.println("\t arguments:\t" + jcargs); |
|
162 |
failedCases++; |
|
163 |
||
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
164 |
} else if (!checkClassFileVersion("Base.class", major)) { |
25448 | 165 |
failedCases++; |
166 |
} |
|
167 |
} |
|
168 |
||
169 |
protected void checksrc16(String... args) { |
|
170 |
printargs("checksrc16", args); |
|
171 |
int asize = args.length; |
|
172 |
String[] newargs = new String[asize + 1]; |
|
173 |
System.arraycopy(args, 0, newargs, 0, asize); |
|
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
174 |
newargs[asize] = "Base.java"; |
25448 | 175 |
pass(newargs); |
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
176 |
newargs[asize] = "New17.java"; |
25448 | 177 |
fail(newargs); |
178 |
} |
|
179 |
||
180 |
protected void checksrc17(String... args) { |
|
181 |
printargs("checksrc17", args); |
|
182 |
int asize = args.length; |
|
183 |
String[] newargs = new String[asize+1]; |
|
184 |
System.arraycopy(args, 0, newargs,0 , asize); |
|
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
185 |
newargs[asize] = "New17.java"; |
25448 | 186 |
pass(newargs); |
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
187 |
newargs[asize] = "New18.java"; |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
188 |
fail(newargs); |
25448 | 189 |
} |
190 |
||
191 |
protected void checksrc18(String... args) { |
|
192 |
printargs("checksrc18", args); |
|
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
193 |
int asize = args.length; |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
194 |
String[] newargs = new String[asize+1]; |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
195 |
System.arraycopy(args, 0, newargs,0 , asize); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
196 |
newargs[asize] = "New17.java"; |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
197 |
pass(newargs); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
198 |
newargs[asize] = "New18.java"; |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
199 |
pass(newargs); |
25448 | 200 |
} |
201 |
||
202 |
protected void checksrc19(String... args) { |
|
203 |
printargs("checksrc19", args); |
|
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
204 |
checksrc18(args); |
25448 | 205 |
} |
206 |
||
207 |
protected void pass(String... args) { |
|
208 |
printargs("pass", args); |
|
209 |
||
210 |
List<String> jcargs = new ArrayList<String>(); |
|
211 |
jcargs.add("-Xlint:-options"); |
|
212 |
||
213 |
// add in args conforming to List requrements of JavaCompiler |
|
214 |
for (String onearg : args) { |
|
215 |
String[] fields = onearg.split(" "); |
|
216 |
for (String onefield : fields) { |
|
217 |
jcargs.add(onefield); |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
// empty list is error |
|
222 |
if (jcargs.isEmpty()) { |
|
223 |
System.err.println("error: test error in pass() - No arguments"); |
|
224 |
System.err.println("\t arguments:\t" + jcargs); |
|
225 |
failedCases++; |
|
226 |
return; |
|
227 |
} |
|
228 |
||
229 |
// the last argument is the filename *.java |
|
230 |
String filename = jcargs.get(jcargs.size() - 1); |
|
231 |
jcargs.remove(jcargs.size() - 1); |
|
232 |
||
233 |
boolean creturn = compile(filename, jcargs); |
|
234 |
// expect a compilation failure, failure if otherwise |
|
235 |
if (!creturn) { |
|
236 |
System.err.println("pass: Compilation erroneously failed"); |
|
237 |
System.err.println("\t arguments:\t" + jcargs); |
|
238 |
System.err.println("\t file :\t" + filename); |
|
239 |
failedCases++; |
|
240 |
||
241 |
} |
|
242 |
||
243 |
} |
|
244 |
||
245 |
protected void fail(String... args) { |
|
246 |
printargs("fail", args); |
|
247 |
||
248 |
List<String> jcargs = new ArrayList<String>(); |
|
249 |
jcargs.add("-Xlint:-options"); |
|
250 |
||
251 |
// add in args conforming to List requrements of JavaCompiler |
|
252 |
for (String onearg : args) { |
|
253 |
String[] fields = onearg.split(" "); |
|
254 |
for (String onefield : fields) { |
|
255 |
jcargs.add(onefield); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
// empty list is error |
|
260 |
if (jcargs.isEmpty()) { |
|
261 |
System.err.println("error: test error in fail()- No arguments"); |
|
262 |
System.err.println("\t arguments:\t" + jcargs); |
|
263 |
failedCases++; |
|
264 |
return; |
|
265 |
} |
|
266 |
||
267 |
// the last argument is the filename *.java |
|
268 |
String filename = jcargs.get(jcargs.size() - 1); |
|
269 |
jcargs.remove(jcargs.size() - 1); |
|
270 |
||
271 |
boolean creturn = compile(filename, jcargs); |
|
272 |
// expect a compilation failure, failure if otherwise |
|
273 |
if (creturn) { |
|
274 |
System.err.println("fail: Compilation erroneously succeeded"); |
|
275 |
System.err.println("\t arguments:\t" + jcargs); |
|
276 |
System.err.println("\t file :\t" + filename); |
|
277 |
failedCases++; |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
protected boolean compile(String sourceFile, List<String>options) { |
|
282 |
JavaCompiler.CompilationTask jctask; |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
283 |
try (StandardJavaFileManager fm = javacompiler.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
284 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(sourceFile); |
25448 | 285 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
286 |
jctask = javacompiler.getTask( |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
287 |
null, // Writer |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
288 |
fm, // JavaFileManager |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
289 |
null, // DiagnosticListener |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
290 |
options, // Iterable<String> |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
291 |
null, // Iterable<String> classes |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
292 |
files); // Iterable<? extends JavaFileObject> |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25448
diff
changeset
|
293 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
294 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
295 |
return jctask.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
296 |
} catch (IllegalStateException e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
297 |
System.err.println(e); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
298 |
return false; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
299 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
300 |
} catch (IOException e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
301 |
throw new Error(e); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25448
diff
changeset
|
302 |
} |
25448 | 303 |
} |
304 |
||
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
305 |
protected void writeSourceFile(String fileName, String body) throws IOException{ |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
306 |
try (Writer fw = new FileWriter(fileName)) { |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
307 |
fw.write(body); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
308 |
} |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
309 |
} |
25448 | 310 |
|
311 |
protected void genSourceFiles() throws IOException{ |
|
312 |
/* Create a file that executes with all supported versions. */ |
|
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
313 |
writeSourceFile("Base.java","public class Base { }\n"); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
314 |
|
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
315 |
/* |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
316 |
* Create a file with a new feature in 1.7, not in 1.6 : "<>" |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
317 |
*/ |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
318 |
writeSourceFile("New17.java", |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
319 |
"import java.util.List;\n" + |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
320 |
"import java.util.ArrayList;\n" + |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
321 |
"class New17 { List<String> s = new ArrayList<>(); }\n" |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
322 |
); |
25448 | 323 |
|
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
324 |
/* |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
325 |
* Create a file with a new feature in 1.8, not in 1.7 : lambda |
25448 | 326 |
*/ |
26782
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
327 |
writeSourceFile("New18.java", |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
328 |
"public class New18 { \n" + |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
329 |
" void m() { \n" + |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
330 |
" new Thread(() -> { }); \n" + |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
331 |
" } \n" + |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
332 |
"} \n" |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
333 |
); |
6c1bac8138d8
8050117: add to javac test Versions.java tests that show correct operation for source/target options pre 1.9
ntoda
parents:
26264
diff
changeset
|
334 |
|
25448 | 335 |
} |
336 |
||
337 |
protected boolean checkClassFileVersion |
|
338 |
(String filename,String classVersionNumber) { |
|
339 |
ByteBuffer bb = ByteBuffer.allocate(1024); |
|
340 |
try (FileChannel fc = new FileInputStream(filename).getChannel()) { |
|
341 |
bb.clear(); |
|
342 |
if (fc.read(bb) < 0) |
|
343 |
throw new IOException("Could not read from file : " + filename); |
|
344 |
bb.flip(); |
|
345 |
int minor = bb.getShort(4); |
|
346 |
int major = bb.getShort(6); |
|
347 |
String fileVersion = major + "." + minor; |
|
348 |
if (fileVersion.equals(classVersionNumber)) { |
|
349 |
return true; |
|
350 |
} else { |
|
351 |
System.err.println("checkClassFileVersion : Failed"); |
|
352 |
System.err.println("\tclassfile version mismatch"); |
|
353 |
System.err.println("\texpected : " + classVersionNumber); |
|
354 |
System.err.println("\tfound : " + fileVersion); |
|
355 |
return false; |
|
356 |
} |
|
357 |
} |
|
358 |
catch (IOException e) { |
|
359 |
System.err.println("checkClassFileVersion : Failed"); |
|
360 |
System.err.println("\terror :\t" + e.getMessage()); |
|
361 |
System.err.println("\tfile:\tfilename"); |
|
362 |
} |
|
363 |
return false; |
|
364 |
} |
|
365 |
} |
|
366 |