langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/platform/JDKPlatformProvider.java
equal
deleted
inserted
replaced
24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.javac.platform; |
26 package com.sun.tools.javac.platform; |
27 |
27 |
28 import java.io.IOException; |
28 import java.io.IOException; |
|
29 import java.net.URI; |
|
30 import java.nio.charset.Charset; |
29 import java.nio.file.DirectoryStream; |
31 import java.nio.file.DirectoryStream; |
30 import java.nio.file.FileSystem; |
32 import java.nio.file.FileSystem; |
31 import java.nio.file.FileSystems; |
33 import java.nio.file.FileSystems; |
32 import java.nio.file.Files; |
34 import java.nio.file.Files; |
33 import java.nio.file.Path; |
35 import java.nio.file.Path; |
39 import java.util.HashMap; |
41 import java.util.HashMap; |
40 import java.util.List; |
42 import java.util.List; |
41 import java.util.Map; |
43 import java.util.Map; |
42 import java.util.Set; |
44 import java.util.Set; |
43 import java.util.TreeSet; |
45 import java.util.TreeSet; |
|
46 import java.util.stream.Stream; |
44 |
47 |
45 import javax.annotation.processing.Processor; |
48 import javax.annotation.processing.Processor; |
46 |
49 |
47 import com.sun.source.util.Plugin; |
50 import com.sun.source.util.Plugin; |
48 import com.sun.tools.javac.jvm.Target; |
51 import com.sun.tools.javac.jvm.Target; |
88 } |
91 } |
89 } |
92 } |
90 } catch (IOException | ProviderNotFoundException ex) { |
93 } catch (IOException | ProviderNotFoundException ex) { |
91 } |
94 } |
92 } |
95 } |
93 SUPPORTED_JAVA_PLATFORM_VERSIONS.add(targetNumericVersion(Target.DEFAULT)); |
|
94 } |
96 } |
95 |
97 |
96 private static String targetNumericVersion(Target target) { |
98 private static String targetNumericVersion(Target target) { |
97 return Integer.toString(target.ordinal() - Target.JDK1_1.ordinal() + 1); |
99 return Integer.toString(target.ordinal() - Target.JDK1_1.ordinal() + 1); |
98 } |
100 } |
106 this.version = version; |
108 this.version = version; |
107 } |
109 } |
108 |
110 |
109 @Override |
111 @Override |
110 public Collection<Path> getPlatformPath() { |
112 public Collection<Path> getPlatformPath() { |
111 if (Target.lookup(version) == Target.DEFAULT) { |
|
112 return null; |
|
113 } |
|
114 |
|
115 List<Path> paths = new ArrayList<>(); |
113 List<Path> paths = new ArrayList<>(); |
116 Path file = findCtSym(); |
114 Path file = findCtSym(); |
117 // file == ${jdk.home}/lib/ct.sym |
115 // file == ${jdk.home}/lib/ct.sym |
118 if (Files.exists(file)) { |
116 if (Files.exists(file)) { |
119 FileSystem fs = ctSym2FileSystem.get(file); |
117 FileSystem fs = ctSym2FileSystem.get(file); |
126 } |
124 } |
127 Path root = fs.getRootDirectories().iterator().next(); |
125 Path root = fs.getRootDirectories().iterator().next(); |
128 try (DirectoryStream<Path> dir = Files.newDirectoryStream(root)) { |
126 try (DirectoryStream<Path> dir = Files.newDirectoryStream(root)) { |
129 for (Path section : dir) { |
127 for (Path section : dir) { |
130 if (section.getFileName().toString().contains(version)) { |
128 if (section.getFileName().toString().contains(version)) { |
131 paths.add(section); |
129 Path systemModules = section.resolve("system-modules"); |
|
130 |
|
131 if (Files.isRegularFile(systemModules)) { |
|
132 Path modules = |
|
133 FileSystems.getFileSystem(URI.create("jrt:/")) |
|
134 .getPath("modules"); |
|
135 try (Stream<String> lines = |
|
136 Files.lines(systemModules, Charset.forName("UTF-8"))) { |
|
137 lines.map(line -> modules.resolve(line)) |
|
138 .filter(mod -> Files.exists(mod)) |
|
139 .forEach(mod -> paths.add(mod)); |
|
140 } |
|
141 } else { |
|
142 paths.add(section); |
|
143 } |
132 } |
144 } |
133 } |
145 } |
134 } catch (IOException ex) { |
146 } catch (IOException ex) { |
135 throw new IllegalStateException(ex); |
147 throw new IllegalStateException(ex); |
136 } |
148 } |