author | sherman |
Thu, 26 Feb 2015 14:40:43 -0800 | |
changeset 29123 | c748c18fb05c |
parent 28969 | f980bee32887 |
child 31673 | 135283550686 |
permissions | -rw-r--r-- |
4817 | 1 |
/* |
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
2 |
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. |
4817 | 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 |
* |
|
5506 | 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. |
|
4817 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
26 |
* @bug 4777124 6920545 6911753 8073924 |
4817 | 27 |
* @summary Verify that all Charset subclasses are available through the API |
28 |
*/ |
|
29 |
||
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
30 |
import java.net.URI; |
4817 | 31 |
import java.nio.charset.Charset; |
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
32 |
import java.nio.file.FileSystem; |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
33 |
import java.nio.file.FileSystems; |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
34 |
import java.nio.file.Files; |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
35 |
import java.nio.file.Path; |
4817 | 36 |
import java.util.HashSet; |
37 |
import java.util.Set; |
|
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
38 |
import java.util.stream.Collectors; |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
39 |
import java.util.stream.Stream; |
4817 | 40 |
|
41 |
public class NIOCharsetAvailabilityTest { |
|
42 |
||
43 |
public static void main(String[] args) throws Exception { |
|
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
44 |
|
4817 | 45 |
// build the set of all Charset subclasses in the |
46 |
// two known charset implementation packages |
|
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
47 |
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
48 |
Set<Class> charsets = |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
49 |
Stream.concat(Files.walk(fs.getPath("/java.base/sun/nio/cs/")), |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
50 |
Files.walk(fs.getPath("/jdk.charsets/sun/nio/cs/ext/"))) |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
51 |
.map( p -> p.subpath(1, p.getNameCount()).toString()) |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
52 |
.filter( s -> s.indexOf("$") == -1 && s.endsWith(".class")) |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
53 |
.map( s -> { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
54 |
try { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
55 |
return Class.forName(s.substring(0, s.length() - 6) |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
56 |
.replace('/', '.')); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
57 |
} catch (Exception x) { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
58 |
throw new RuntimeException(x); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
59 |
} |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
60 |
}) |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
61 |
.filter( clz -> { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
62 |
Class superclazz = clz.getSuperclass(); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
63 |
while (superclazz != null && !superclazz.equals(Object.class)) { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
64 |
if (superclazz.equals(Charset.class)) { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
65 |
return true; |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
66 |
} else { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
67 |
superclazz = superclazz.getSuperclass(); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
68 |
} |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
69 |
} |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
70 |
return false; |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
71 |
}) |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
72 |
.collect(Collectors.toCollection(HashSet::new)); |
4817 | 73 |
// remove the charsets that the API says are available |
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
74 |
Charset.availableCharsets() |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
75 |
.values() |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
76 |
.stream() |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
77 |
.forEach(cs -> { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
78 |
if (!charsets.contains(cs.getClass())) { |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
79 |
System.out.println(" missing -> " + cs.getClass()); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
80 |
} |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
81 |
charsets.remove(cs.getClass()); |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
82 |
}); |
4817 | 83 |
|
84 |
// remove the known pseudo-charsets that serve only to implement |
|
85 |
// other charsets, but shouldn't be known to the public |
|
86 |
charsets.remove(Class.forName("sun.nio.cs.Unicode")); |
|
87 |
charsets.remove(Class.forName("sun.nio.cs.ext.ISO2022")); |
|
88 |
charsets.remove(Class.forName("sun.nio.cs.ext.ISO2022_CN_GB")); |
|
89 |
charsets.remove(Class.forName("sun.nio.cs.ext.ISO2022_CN_CNS")); |
|
13366
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
5506
diff
changeset
|
90 |
charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_MS932")); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
5506
diff
changeset
|
91 |
charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0212_MS5022X")); |
2f5fdf6d8c22
6653797: Reimplement JDK charset repository charsets.jar
sherman
parents:
5506
diff
changeset
|
92 |
charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_MS5022X")); |
28969
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
93 |
try { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
94 |
charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0208_Solaris")); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
95 |
charsets.remove(Class.forName("sun.nio.cs.ext.JIS_X_0212_Solaris")); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
96 |
} catch (ClassNotFoundException x) { |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
97 |
// these two might be moved into stdcs |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
98 |
charsets.remove(Class.forName("sun.nio.cs.JIS_X_0208_Solaris")); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
99 |
charsets.remove(Class.forName("sun.nio.cs.JIS_X_0212_Solaris")); |
f980bee32887
8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
27798
diff
changeset
|
100 |
} |
4817 | 101 |
// report the charsets that are implemented but not available |
102 |
if (charsets.size() > 0) { |
|
29123
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
103 |
charsets.stream() |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
104 |
.forEach( clz -> |
c748c18fb05c
8073924: Update test/java/nio/charset/Charset/NIOCharsetAvailability.java to work with module system
sherman
parents:
28969
diff
changeset
|
105 |
System.out.println("Unused Charset subclass: " + clz)); |
4817 | 106 |
throw new RuntimeException(); |
107 |
} |
|
108 |
} |
|
109 |
} |