author | bobv |
Tue, 07 Nov 2017 10:30:53 -0500 | |
changeset 47801 | c7b50c23ea71 |
parent 47216 | 71c04702a3d5 |
child 48081 | 89829dd3cc54 |
permissions | -rw-r--r-- |
25448 | 1 |
/* |
43646 | 2 |
* Copyright (c) 2014, 2017, 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 |
|
43646 | 26 |
* @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961 8030610 8028546 |
25448 | 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 TC = ""; |
|
65 |
System.out.println("Version.java: Starting"); |
|
66 |
||
37940 | 67 |
check("53.0"); |
68 |
check("53.0", "-source 1.6"); |
|
69 |
check("53.0", "-source 1.7"); |
|
70 |
check("53.0", "-source 1.8"); |
|
71 |
check("53.0", "-source 1.9"); |
|
43646 | 72 |
check("53.0", "-source 1.10"); |
25448 | 73 |
|
74 |
check_source_target("50.0", "6", "6"); |
|
75 |
check_source_target("51.0", "6", "7"); |
|
76 |
check_source_target("51.0", "7", "7"); |
|
77 |
check_source_target("52.0", "6", "8"); |
|
78 |
check_source_target("52.0", "7", "8"); |
|
79 |
check_source_target("52.0", "8", "8"); |
|
37940 | 80 |
check_source_target("53.0", "6", "9"); |
81 |
check_source_target("53.0", "7", "9"); |
|
82 |
check_source_target("53.0", "8", "9"); |
|
83 |
check_source_target("53.0", "9", "9"); |
|
43646 | 84 |
check_source_target("53.0", "10", "10"); |
25448 | 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("-source 1.9"); |
|
99 |
checksrc19("-source 9"); |
|
100 |
checksrc19("-source 1.9", "-target 1.9"); |
|
101 |
checksrc19("-source 9", "-target 9"); |
|
43646 | 102 |
|
103 |
checksrc110(); |
|
104 |
checksrc110("-source 1.10"); |
|
105 |
checksrc110("-source 10"); |
|
106 |
checksrc110("-source 1.10", "-target 1.10"); |
|
107 |
checksrc110("-source 10", "-target 10"); |
|
108 |
checksrc110("-target 1.10"); |
|
109 |
checksrc110("-target 10"); |
|
25448 | 110 |
|
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
fail("-source 9", "-target 1.8", "Base.java"); |
43646 | 116 |
fail("-source 10", "-target 1.7", "Base.java"); |
117 |
fail("-source 10", "-target 1.8", "Base.java"); |
|
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
|
118 |
|
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
fail("-source 1.2", "-target 1.2", "Base.java"); |
25448 | 123 |
|
124 |
if (failedCases > 0) { |
|
125 |
System.err.println("failedCases = " + String.valueOf(failedCases)); |
|
126 |
throw new Error("Test failed"); |
|
127 |
} |
|
128 |
||
129 |
} |
|
130 |
||
131 |
protected void printargs(String fname,String... args) { |
|
132 |
System.out.printf("test: %s", fname); |
|
133 |
for (String onearg : args) { |
|
134 |
System.out.printf(" %s", onearg); |
|
135 |
} |
|
136 |
System.out.printf("\n", fname); |
|
137 |
} |
|
138 |
||
139 |
protected void check_source_target(String... args) { |
|
140 |
printargs("check_source_target", args); |
|
141 |
check_target(args[0], args[1], args[2]); |
|
142 |
check_target(args[0], "1." + args[1], args[2]); |
|
143 |
} |
|
144 |
||
145 |
protected void check_target(String... args) { |
|
146 |
check(args[0], "-source " + args[1], "-target " + args[2]); |
|
147 |
check(args[0], "-source " + args[1], "-target 1." + args[2]); |
|
148 |
} |
|
149 |
||
150 |
protected void check(String major, String... args) { |
|
151 |
printargs("check", args); |
|
152 |
List<String> jcargs = new ArrayList<String>(); |
|
153 |
jcargs.add("-Xlint:-options"); |
|
154 |
||
155 |
// add in args conforming to List requrements of JavaCompiler |
|
156 |
for (String onearg : args) { |
|
157 |
String[] fields = onearg.split(" "); |
|
158 |
for (String onefield : fields) { |
|
159 |
jcargs.add(onefield); |
|
160 |
} |
|
161 |
} |
|
162 |
||
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
|
163 |
boolean creturn = compile("Base.java", jcargs); |
25448 | 164 |
if (!creturn) { |
165 |
// compilation errors note and return.. assume no class file |
|
166 |
System.err.println("check: Compilation Failed"); |
|
167 |
System.err.println("\t classVersion:\t" + major); |
|
168 |
System.err.println("\t arguments:\t" + jcargs); |
|
169 |
failedCases++; |
|
170 |
||
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
|
171 |
} else if (!checkClassFileVersion("Base.class", major)) { |
25448 | 172 |
failedCases++; |
173 |
} |
|
174 |
} |
|
175 |
||
176 |
protected void checksrc16(String... args) { |
|
177 |
printargs("checksrc16", args); |
|
178 |
int asize = args.length; |
|
179 |
String[] newargs = new String[asize + 1]; |
|
180 |
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
|
181 |
newargs[asize] = "Base.java"; |
25448 | 182 |
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
|
183 |
newargs[asize] = "New17.java"; |
25448 | 184 |
fail(newargs); |
185 |
} |
|
186 |
||
187 |
protected void checksrc17(String... args) { |
|
188 |
printargs("checksrc17", args); |
|
189 |
int asize = args.length; |
|
190 |
String[] newargs = new String[asize+1]; |
|
191 |
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
|
192 |
newargs[asize] = "New17.java"; |
25448 | 193 |
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
|
194 |
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
|
195 |
fail(newargs); |
25448 | 196 |
} |
197 |
||
198 |
protected void checksrc18(String... args) { |
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
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
|
206 |
pass(newargs); |
25448 | 207 |
} |
208 |
||
209 |
protected void checksrc19(String... args) { |
|
210 |
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
|
211 |
checksrc18(args); |
25448 | 212 |
} |
213 |
||
43646 | 214 |
protected void checksrc110(String... args) { |
215 |
printargs("checksrc110", args); |
|
216 |
checksrc19(args); |
|
217 |
} |
|
218 |
||
25448 | 219 |
protected void pass(String... args) { |
220 |
printargs("pass", args); |
|
221 |
||
222 |
List<String> jcargs = new ArrayList<String>(); |
|
223 |
jcargs.add("-Xlint:-options"); |
|
224 |
||
225 |
// add in args conforming to List requrements of JavaCompiler |
|
226 |
for (String onearg : args) { |
|
227 |
String[] fields = onearg.split(" "); |
|
228 |
for (String onefield : fields) { |
|
229 |
jcargs.add(onefield); |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
// empty list is error |
|
234 |
if (jcargs.isEmpty()) { |
|
235 |
System.err.println("error: test error in pass() - No arguments"); |
|
236 |
System.err.println("\t arguments:\t" + jcargs); |
|
237 |
failedCases++; |
|
238 |
return; |
|
239 |
} |
|
240 |
||
241 |
// the last argument is the filename *.java |
|
242 |
String filename = jcargs.get(jcargs.size() - 1); |
|
243 |
jcargs.remove(jcargs.size() - 1); |
|
244 |
||
245 |
boolean creturn = compile(filename, jcargs); |
|
246 |
// expect a compilation failure, failure if otherwise |
|
247 |
if (!creturn) { |
|
248 |
System.err.println("pass: Compilation erroneously failed"); |
|
249 |
System.err.println("\t arguments:\t" + jcargs); |
|
250 |
System.err.println("\t file :\t" + filename); |
|
251 |
failedCases++; |
|
252 |
||
253 |
} |
|
254 |
||
255 |
} |
|
256 |
||
257 |
protected void fail(String... args) { |
|
258 |
printargs("fail", args); |
|
259 |
||
260 |
List<String> jcargs = new ArrayList<String>(); |
|
261 |
jcargs.add("-Xlint:-options"); |
|
262 |
||
263 |
// add in args conforming to List requrements of JavaCompiler |
|
264 |
for (String onearg : args) { |
|
265 |
String[] fields = onearg.split(" "); |
|
266 |
for (String onefield : fields) { |
|
267 |
jcargs.add(onefield); |
|
268 |
} |
|
269 |
} |
|
270 |
||
271 |
// empty list is error |
|
272 |
if (jcargs.isEmpty()) { |
|
273 |
System.err.println("error: test error in fail()- No arguments"); |
|
274 |
System.err.println("\t arguments:\t" + jcargs); |
|
275 |
failedCases++; |
|
276 |
return; |
|
277 |
} |
|
278 |
||
279 |
// the last argument is the filename *.java |
|
280 |
String filename = jcargs.get(jcargs.size() - 1); |
|
281 |
jcargs.remove(jcargs.size() - 1); |
|
282 |
||
283 |
boolean creturn = compile(filename, jcargs); |
|
284 |
// expect a compilation failure, failure if otherwise |
|
285 |
if (creturn) { |
|
286 |
System.err.println("fail: Compilation erroneously succeeded"); |
|
287 |
System.err.println("\t arguments:\t" + jcargs); |
|
288 |
System.err.println("\t file :\t" + filename); |
|
289 |
failedCases++; |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
protected boolean compile(String sourceFile, List<String>options) { |
|
294 |
JavaCompiler.CompilationTask jctask; |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
295 |
try (StandardJavaFileManager fm = javacompiler.getStandardFileManager(null, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
296 |
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(sourceFile); |
25448 | 297 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
298 |
jctask = javacompiler.getTask( |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
299 |
null, // Writer |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
300 |
fm, // JavaFileManager |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
301 |
null, // DiagnosticListener |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
302 |
options, // Iterable<String> |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
303 |
null, // Iterable<String> classes |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
304 |
files); // Iterable<? extends JavaFileObject> |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25448
diff
changeset
|
305 |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
306 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
307 |
return jctask.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
308 |
} catch (IllegalStateException e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
309 |
System.err.println(e); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
310 |
return false; |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
311 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
312 |
} catch (IOException e) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
26782
diff
changeset
|
313 |
throw new Error(e); |
26264
a09fedde76be
8044859: javac duplicates option processing when using Compiler API
jjg
parents:
25448
diff
changeset
|
314 |
} |
25448 | 315 |
} |
316 |
||
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
|
317 |
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
|
318 |
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
|
319 |
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
|
320 |
} |
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 |
} |
25448 | 322 |
|
323 |
protected void genSourceFiles() throws IOException{ |
|
324 |
/* 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
|
325 |
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
|
326 |
|
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 |
/* |
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 |
* 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
|
329 |
*/ |
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 |
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
|
331 |
"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
|
332 |
"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
|
333 |
"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
|
334 |
); |
25448 | 335 |
|
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
|
336 |
/* |
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
|
337 |
* Create a file with a new feature in 1.8, not in 1.7 : lambda |
25448 | 338 |
*/ |
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
|
339 |
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
|
340 |
"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
|
341 |
" 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
|
342 |
" 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
|
343 |
" } \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
|
344 |
"} \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
|
345 |
); |
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
|
346 |
|
25448 | 347 |
} |
348 |
||
349 |
protected boolean checkClassFileVersion |
|
350 |
(String filename,String classVersionNumber) { |
|
351 |
ByteBuffer bb = ByteBuffer.allocate(1024); |
|
352 |
try (FileChannel fc = new FileInputStream(filename).getChannel()) { |
|
353 |
bb.clear(); |
|
354 |
if (fc.read(bb) < 0) |
|
355 |
throw new IOException("Could not read from file : " + filename); |
|
356 |
bb.flip(); |
|
357 |
int minor = bb.getShort(4); |
|
358 |
int major = bb.getShort(6); |
|
359 |
String fileVersion = major + "." + minor; |
|
360 |
if (fileVersion.equals(classVersionNumber)) { |
|
361 |
return true; |
|
362 |
} else { |
|
363 |
System.err.println("checkClassFileVersion : Failed"); |
|
364 |
System.err.println("\tclassfile version mismatch"); |
|
365 |
System.err.println("\texpected : " + classVersionNumber); |
|
366 |
System.err.println("\tfound : " + fileVersion); |
|
367 |
return false; |
|
368 |
} |
|
369 |
} |
|
370 |
catch (IOException e) { |
|
371 |
System.err.println("checkClassFileVersion : Failed"); |
|
372 |
System.err.println("\terror :\t" + e.getMessage()); |
|
373 |
System.err.println("\tfile:\tfilename"); |
|
374 |
} |
|
375 |
return false; |
|
376 |
} |
|
377 |
} |
|
378 |