1 /* |
1 /* |
2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
25 |
25 |
26 package com.sun.tools.javac.file; |
26 package com.sun.tools.javac.file; |
27 |
27 |
28 import java.io.File; |
28 import java.io.File; |
29 import java.io.IOException; |
29 import java.io.IOException; |
|
30 import java.lang.module.Configuration; |
|
31 import java.lang.module.ModuleFinder; |
30 import java.net.MalformedURLException; |
32 import java.net.MalformedURLException; |
31 import java.net.URI; |
33 import java.net.URI; |
32 import java.net.URISyntaxException; |
34 import java.net.URISyntaxException; |
33 import java.net.URL; |
35 import java.net.URL; |
34 import java.nio.CharBuffer; |
36 import java.nio.CharBuffer; |
75 import com.sun.tools.javac.util.Context.Factory; |
77 import com.sun.tools.javac.util.Context.Factory; |
76 import com.sun.tools.javac.util.DefinedBy; |
78 import com.sun.tools.javac.util.DefinedBy; |
77 import com.sun.tools.javac.util.DefinedBy.Api; |
79 import com.sun.tools.javac.util.DefinedBy.Api; |
78 import com.sun.tools.javac.util.List; |
80 import com.sun.tools.javac.util.List; |
79 import com.sun.tools.javac.util.ListBuffer; |
81 import com.sun.tools.javac.util.ListBuffer; |
80 import com.sun.tools.javac.util.JDK9Wrappers.Configuration; |
|
81 import com.sun.tools.javac.util.JDK9Wrappers.Layer; |
|
82 import com.sun.tools.javac.util.JDK9Wrappers.ModuleFinder; |
|
83 import com.sun.tools.javac.util.JDK9Wrappers.Module; |
|
84 import com.sun.tools.javac.util.JDK9Wrappers.ServiceLoaderHelper; |
|
85 |
82 |
86 import static java.nio.file.FileVisitOption.FOLLOW_LINKS; |
83 import static java.nio.file.FileVisitOption.FOLLOW_LINKS; |
87 |
84 |
88 import static javax.tools.StandardLocation.*; |
85 import static javax.tools.StandardLocation.*; |
89 |
86 |
978 |
975 |
979 @Override @DefinedBy(Api.COMPILER) |
976 @Override @DefinedBy(Api.COMPILER) |
980 public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException { |
977 public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException { |
981 nullCheck(location); |
978 nullCheck(location); |
982 nullCheck(service); |
979 nullCheck(service); |
983 Module.getModule(getClass()).addUses(service); |
980 getClass().getModule().addUses(service); |
984 if (location.isModuleOrientedLocation()) { |
981 if (location.isModuleOrientedLocation()) { |
985 Collection<Path> paths = locations.getLocation(location); |
982 Collection<Path> paths = locations.getLocation(location); |
986 ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()])); |
983 ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()])); |
987 Layer bootLayer = Layer.boot(); |
984 ModuleLayer bootLayer = ModuleLayer.boot(); |
988 Configuration cf = bootLayer.configuration().resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet()); |
985 Configuration cf = bootLayer.configuration().resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet()); |
989 Layer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader()); |
986 ModuleLayer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader()); |
990 return ServiceLoaderHelper.load(layer, service); |
987 return ServiceLoader.load(layer, service); |
991 } else { |
988 } else { |
992 return ServiceLoader.load(service, getClassLoader(location)); |
989 return ServiceLoader.load(service, getClassLoader(location)); |
993 } |
990 } |
994 } |
991 } |
995 |
992 |