src/jdk.compiler/share/classes/com/sun/tools/javac/platform/JDKPlatformProvider.java
changeset 47703 dbfac941197a
parent 47702 cf8310446245
child 50566 c0b896fc3f08
equal deleted inserted replaced
47702:cf8310446245 47703:dbfac941197a
    45 import java.util.List;
    45 import java.util.List;
    46 import java.util.Map;
    46 import java.util.Map;
    47 import java.util.NoSuchElementException;
    47 import java.util.NoSuchElementException;
    48 import java.util.Set;
    48 import java.util.Set;
    49 import java.util.TreeSet;
    49 import java.util.TreeSet;
       
    50 import java.util.stream.Collectors;
    50 import java.util.stream.Stream;
    51 import java.util.stream.Stream;
    51 
    52 
    52 import javax.annotation.processing.Processor;
    53 import javax.annotation.processing.Processor;
    53 import javax.tools.ForwardingJavaFileObject;
    54 import javax.tools.ForwardingJavaFileObject;
    54 import javax.tools.JavaFileManager;
    55 import javax.tools.JavaFileManager;
    62 import com.sun.tools.javac.file.CacheFSInfo;
    63 import com.sun.tools.javac.file.CacheFSInfo;
    63 import com.sun.tools.javac.file.JavacFileManager;
    64 import com.sun.tools.javac.file.JavacFileManager;
    64 import com.sun.tools.javac.jvm.Target;
    65 import com.sun.tools.javac.jvm.Target;
    65 import com.sun.tools.javac.util.Context;
    66 import com.sun.tools.javac.util.Context;
    66 import com.sun.tools.javac.util.Log;
    67 import com.sun.tools.javac.util.Log;
       
    68 import com.sun.tools.javac.util.StringUtils;
    67 
    69 
    68 /** PlatformProvider for JDK N.
    70 /** PlatformProvider for JDK N.
    69  *
    71  *
    70  *  <p><b>This is NOT part of any supported API.
    72  *  <p><b>This is NOT part of any supported API.
    71  *  If you write code that depends on this, you do so at your own risk.
    73  *  If you write code that depends on this, you do so at your own risk.
    94         if (Files.exists(ctSymFile)) {
    96         if (Files.exists(ctSymFile)) {
    95             try (FileSystem fs = FileSystems.newFileSystem(ctSymFile, null);
    97             try (FileSystem fs = FileSystems.newFileSystem(ctSymFile, null);
    96                  DirectoryStream<Path> dir =
    98                  DirectoryStream<Path> dir =
    97                          Files.newDirectoryStream(fs.getRootDirectories().iterator().next())) {
    99                          Files.newDirectoryStream(fs.getRootDirectories().iterator().next())) {
    98                 for (Path section : dir) {
   100                 for (Path section : dir) {
       
   101                     if (section.getFileName().toString().contains("-"))
       
   102                         continue;
    99                     for (char ver : section.getFileName().toString().toCharArray()) {
   103                     for (char ver : section.getFileName().toString().toCharArray()) {
   100                         String verString = Character.toString(ver);
   104                         String verString = Character.toString(ver);
   101                         Target t = Target.lookup(verString);
   105                         Target t = Target.lookup("" + Integer.parseInt(verString, 16));
   102 
   106 
   103                         if (t != null) {
   107                         if (t != null) {
   104                             SUPPORTED_JAVA_PLATFORM_VERSIONS.add(targetNumericVersion(t));
   108                             SUPPORTED_JAVA_PLATFORM_VERSIONS.add(targetNumericVersion(t));
   105                         }
   109                         }
   106                     }
   110                     }
   107                 }
   111                 }
   108             } catch (IOException | ProviderNotFoundException ex) {
   112             } catch (IOException | ProviderNotFoundException ex) {
   109             }
   113             }
   110         }
   114         }
   111 
       
   112         if (SUPPORTED_JAVA_PLATFORM_VERSIONS.contains("9")) {
       
   113             SUPPORTED_JAVA_PLATFORM_VERSIONS.add("10");
       
   114         }
       
   115     }
   115     }
   116 
   116 
   117     private static String targetNumericVersion(Target target) {
   117     private static String targetNumericVersion(Target target) {
   118         return Integer.toString(target.ordinal() - Target.JDK1_1.ordinal() + 1);
   118         return Integer.toString(target.ordinal() - Target.JDK1_1.ordinal() + 1);
   119     }
   119     }
   120 
   120 
   121     static class PlatformDescriptionImpl implements PlatformDescription {
   121     static class PlatformDescriptionImpl implements PlatformDescription {
   122 
   122 
   123         private final Map<Path, FileSystem> ctSym2FileSystem = new HashMap<>();
   123         private final Map<Path, FileSystem> ctSym2FileSystem = new HashMap<>();
   124         private final String version;
   124         private final String sourceVersion;
   125 
   125         private final String ctSymVersion;
   126         PlatformDescriptionImpl(String version) {
   126 
   127             this.version = version;
   127         PlatformDescriptionImpl(String sourceVersion) {
       
   128             this.sourceVersion = sourceVersion;
       
   129             this.ctSymVersion =
       
   130                     StringUtils.toUpperCase(Integer.toHexString(Integer.parseInt(sourceVersion)));
   128         }
   131         }
   129 
   132 
   130         @Override
   133         @Override
   131         public JavaFileManager getFileManager() {
   134         public JavaFileManager getFileManager() {
   132             Context context = new Context();
   135             Context context = new Context();
   232                     if (fs == null) {
   235                     if (fs == null) {
   233                         ctSym2FileSystem.put(file, fs = FileSystems.newFileSystem(file, null));
   236                         ctSym2FileSystem.put(file, fs = FileSystems.newFileSystem(file, null));
   234                     }
   237                     }
   235 
   238 
   236                     List<Path> paths = new ArrayList<>();
   239                     List<Path> paths = new ArrayList<>();
       
   240                     Path modules = fs.getPath(ctSymVersion + "-modules");
   237                     Path root = fs.getRootDirectories().iterator().next();
   241                     Path root = fs.getRootDirectories().iterator().next();
   238                     boolean pathsSet = false;
   242                     boolean pathsSet = false;
   239                     Charset utf8 = Charset.forName("UTF-8");
   243                     Charset utf8 = Charset.forName("UTF-8");
   240 
   244 
   241                     try (DirectoryStream<Path> dir = Files.newDirectoryStream(root)) {
   245                     try (DirectoryStream<Path> dir = Files.newDirectoryStream(root)) {
   242                         for (Path section : dir) {
   246                         for (Path section : dir) {
   243                             if (section.getFileName().toString().contains(version)) {
   247                             if (section.getFileName().toString().contains(ctSymVersion) &&
       
   248                                 !section.getFileName().toString().contains("-")) {
   244                                 Path systemModules = section.resolve("system-modules");
   249                                 Path systemModules = section.resolve("system-modules");
   245 
   250 
   246                                 if (Files.isRegularFile(systemModules)) {
   251                                 if (Files.isRegularFile(systemModules)) {
   247                                     fm.handleOption("--system", Arrays.asList("none").iterator());
   252                                     fm.handleOption("--system", Arrays.asList("none").iterator());
   248 
   253 
   261                                 }
   266                                 }
   262                             }
   267                             }
   263                         }
   268                         }
   264                     }
   269                     }
   265 
   270 
   266                     if (!pathsSet) {
   271                     if (Files.isDirectory(modules)) {
       
   272                         try (DirectoryStream<Path> dir = Files.newDirectoryStream(modules)) {
       
   273                             fm.handleOption("--system", Arrays.asList("none").iterator());
       
   274 
       
   275                             for (Path module : dir) {
       
   276                                 fm.setLocationForModule(StandardLocation.SYSTEM_MODULES,
       
   277                                                         module.getFileName().toString(),
       
   278                                                         Stream.concat(paths.stream(),
       
   279                                                                       Stream.of(module))
       
   280                                   .collect(Collectors.toList()));
       
   281                             }
       
   282                         }
       
   283                     } else if (!pathsSet) {
   267                         fm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, paths);
   284                         fm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, paths);
   268                     }
   285                     }
   269 
   286 
   270                     return fm;
   287                     return fm;
   271                 } catch (IOException ex) {
   288                 } catch (IOException ex) {
   307             }
   324             }
   308         }
   325         }
   309 
   326 
   310         @Override
   327         @Override
   311         public String getSourceVersion() {
   328         public String getSourceVersion() {
   312             return version;
   329             return sourceVersion;
   313         }
   330         }
   314 
   331 
   315         @Override
   332         @Override
   316         public String getTargetVersion() {
   333         public String getTargetVersion() {
   317             return version;
   334             return sourceVersion;
   318         }
   335         }
   319 
   336 
   320         @Override
   337         @Override
   321         public List<PluginInfo<Processor>> getAnnotationProcessors() {
   338         public List<PluginInfo<Processor>> getAnnotationProcessors() {
   322             return Collections.emptyList();
   339             return Collections.emptyList();