author | avstepan |
Tue, 19 May 2015 16:04:14 +0400 | |
changeset 30655 | d83f50188ca9 |
parent 27319 | 030080f03e4f |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
10 | 1 |
/* |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6306137 |
|
27 |
* @summary JSR 199: encoding option doesn't affect standard file manager |
|
15708
fbf749010eba
8007698: jtreg test T6306137.java won't compile with ASCII encoding
jjh
parents:
15569
diff
changeset
|
28 |
* @compile -encoding utf-8 T6306137.java |
fbf749010eba
8007698: jtreg test T6306137.java won't compile with ASCII encoding
jjh
parents:
15569
diff
changeset
|
29 |
* @run main T6306137 |
18390 | 30 |
* @author Peter von der Ah\u00e9 |
10 | 31 |
*/ |
32 |
||
33 |
import java.io.File; |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
34 |
import java.io.IOException; |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
35 |
import java.nio.charset.Charset; |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
36 |
import java.nio.file.Files; |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
37 |
import java.util.ArrayList; |
10 | 38 |
import java.util.Arrays; |
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
39 |
import java.util.List; |
10 | 40 |
import javax.tools.*; |
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
41 |
import static java.nio.file.StandardOpenOption.*; |
10 | 42 |
|
43 |
public class T6306137 { |
|
44 |
boolean error; |
|
45 |
final StandardJavaFileManager fm; |
|
46 |
final JavaCompiler compiler; |
|
47 |
Iterable<? extends JavaFileObject> files; |
|
48 |
DiagnosticListener<JavaFileObject> dl; |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
49 |
final File testFile = new File("Utf8.java"); |
10 | 50 |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
51 |
T6306137() throws IOException { |
10 | 52 |
dl = new DiagnosticListener<JavaFileObject>() { |
53 |
public void report(Diagnostic<? extends JavaFileObject> message) { |
|
54 |
if (message.getKind() == Diagnostic.Kind.ERROR) |
|
55 |
error = true; |
|
56 |
System.out.println(message.getSource() |
|
57 |
+":"+message.getStartPosition()+":" |
|
58 |
+message.getStartPosition()+":"+message.getPosition()); |
|
59 |
System.out.println(message.toString()); |
|
60 |
System.out.format("Found problem: %s%n", message.getCode()); |
|
61 |
System.out.flush(); |
|
62 |
} |
|
63 |
}; |
|
64 |
compiler = ToolProvider.getSystemJavaCompiler(); |
|
65 |
fm = compiler.getStandardFileManager(dl, null, null); |
|
66 |
files = |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
67 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(testFile)); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
68 |
createTestFile(); |
10 | 69 |
} |
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
70 |
final void createTestFile() throws IOException { |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
71 |
List<String> scratch = new ArrayList<>(); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
72 |
scratch.add("// @author Peter von der Ah" + (char)0xe9); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
73 |
scratch.add("class Utf8{}"); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
74 |
Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"), |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
75 |
CREATE, TRUNCATE_EXISTING); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
76 |
} |
10 | 77 |
void test(String encoding, boolean good) { |
78 |
error = false; |
|
22444
c79ee1e6742f
8031745: Remove unneeded/obsolete -source/-target options in javac tests, part 1
darcy
parents:
18648
diff
changeset
|
79 |
Iterable<String> args = Arrays.asList("-encoding", encoding, "-d", "."); |
10 | 80 |
compiler.getTask(null, fm, dl, args, null, files).call(); |
81 |
if (error == good) { |
|
82 |
if (error) { |
|
83 |
throw new AssertionError("Error reported"); |
|
84 |
} else { |
|
85 |
throw new AssertionError("No error reported"); |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
||
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
90 |
void close() throws IOException { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
91 |
fm.close(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
92 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
93 |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
94 |
public static void main(String[] args) throws IOException { |
10 | 95 |
T6306137 self = new T6306137(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
96 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
97 |
self.test("utf-8", true); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
98 |
self.test("ascii", false); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
99 |
self.test("utf-8", true); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
100 |
} finally { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
101 |
self.close(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
102 |
} |
10 | 103 |
} |
104 |
} |