This commit is contained in:
Alan Bateman 2017-02-10 12:28:35 +00:00
commit 3460214b07
28 changed files with 177 additions and 78 deletions

View File

@ -102,7 +102,7 @@ public class MutableFieldsAnalyzer extends AbstractCodingRulesAnalyzer {
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$ModuleFinder",
"moduleFinderClass", "ofMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Configuration",
"configurationClass", "resolveRequiresAndUsesMethod");
"configurationClass", "resolveAndBindMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Layer",
"layerClass", "bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod");
ignoreFields("com.sun.tools.javac.util.JDK9Wrappers$Module",

View File

@ -123,6 +123,8 @@ public interface Element extends javax.lang.model.AnnotatedConstruct {
* @see TypeElement#getSimpleName
* @see VariableElement#getSimpleName
* @see ModuleElement#getSimpleName
* @revised 9
* @spec JPMS
*/
Name getSimpleName();
@ -158,6 +160,8 @@ public interface Element extends javax.lang.model.AnnotatedConstruct {
*
* @return the enclosing element, or {@code null} if there is none
* @see Elements#getPackageOf
* @revised 9
* @spec JPMS
*/
Element getEnclosingElement();
@ -193,6 +197,8 @@ public interface Element extends javax.lang.model.AnnotatedConstruct {
* @see Elements#getAllMembers
* @jls 8.8.9 Default Constructor
* @jls 8.9 Enums
* @revised 9
* @spec JPMS
*/
List<? extends Element> getEnclosedElements();

View File

@ -99,6 +99,7 @@ public enum ElementKind {
/**
* A module.
* @since 9
* @spec JPMS
*/
MODULE;

View File

@ -159,6 +159,7 @@ public interface ElementVisitor<R, P> {
* @param p a visitor-specified parameter
* @return a visitor-specified result
* @since 9
* @spec JPMS
*/
default R visitModule(ModuleElement e, P p) {
return visitUnknown(e, p);

View File

@ -33,6 +33,7 @@ import java.util.List;
*
* @see javax.lang.model.util.Elements#getModuleOf
* @since 9
* @spec JPMS
*/ // TODO: add @jls to module section
public interface ModuleElement extends Element, QualifiedNameable {
@ -104,6 +105,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
* future versions of the Java&trade; programming language.
*
* @since 9
* @spec JPMS
*/
enum DirectiveKind {
/** A "requires (static|transitive)* module-name" directive. */
@ -122,6 +124,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
* Represents a "module statement" within the declaration of this module.
*
* @since 9
* @spec JPMS
*
*/ // TODO: add jls to Module Statement
interface Directive {
@ -136,6 +139,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
/**
* A dependency of a module.
* @since 9
* @spec JPMS
*/
interface RequiresDirective extends Directive {
/**
@ -160,6 +164,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
/**
* An exported package of a module.
* @since 9
* @spec JPMS
*/
interface ExportsDirective extends Directive {
@ -181,6 +186,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
/**
* An opened package of a module.
* @since 9
* @spec JPMS
*/
interface OpensDirective extends Directive {
@ -202,6 +208,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
/**
* An implementation of a service provided by a module.
* @since 9
* @spec JPMS
*/
interface ProvidesDirective extends Directive {
/**
@ -220,6 +227,7 @@ public interface ModuleElement extends Element, QualifiedNameable {
/**
* A reference to a service used by a module.
* @since 9
* @spec JPMS
*/
interface UsesDirective extends Directive {
/**

View File

@ -93,6 +93,9 @@ public interface PackageElement extends Element, QualifiedNameable {
* source version} without modules.
*
* @return the enclosing module or {@code null} if no such module exists
*
* @revised 9
* @spec JPMS
*/
@Override
Element getEnclosingElement();

View File

@ -157,6 +157,7 @@ public enum TypeKind {
* A pseudo-type corresponding to a module element.
* @see NoType
* @since 9
* @spec JPMS
*/
MODULE;

View File

@ -136,6 +136,7 @@ public abstract class AbstractElementVisitor6<R, P> implements ElementVisitor<R,
* @return the result of {@code visitUnknown}
*
* @since 9
* @spec JPMS
*/
@Override
public R visitModule(ModuleElement e, P p) {

View File

@ -63,6 +63,7 @@ import static javax.lang.model.SourceVersion.*;
* @see AbstractElementVisitor7
* @see AbstractElementVisitor8
* @since 9
* @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public abstract class AbstractElementVisitor9<R, P> extends AbstractElementVisitor8<R, P> {

View File

@ -189,6 +189,7 @@ public class ElementFilter {
* @return a list of modules in {@code elements}
* @param elements the elements to filter
* @since 9
* @spec JPMS
*/
public static List<ModuleElement>
modulesIn(Iterable<? extends Element> elements) {
@ -200,6 +201,7 @@ public class ElementFilter {
* @return a set of modules in {@code elements}
* @param elements the elements to filter
* @since 9
* @spec JPMS
*/
public static Set<ModuleElement>
modulesIn(Set<? extends Element> elements) {
@ -236,6 +238,7 @@ public class ElementFilter {
* @return a list of {@code exports} directives in {@code directives}
* @param directives the directives to filter
* @since 9
* @spec JPMS
*/
public static List<ExportsDirective>
exportsIn(Iterable<? extends Directive> directives) {
@ -258,6 +261,7 @@ public class ElementFilter {
* @return a list of {@code provides} directives in {@code directives}
* @param directives the directives to filter
* @since 9
* @spec JPMS
*/
public static List<ProvidesDirective>
providesIn(Iterable<? extends Directive> directives) {
@ -269,6 +273,7 @@ public class ElementFilter {
* @return a list of {@code requires} directives in {@code directives}
* @param directives the directives to filter
* @since 9
* @spec JPMS
*/
public static List<RequiresDirective>
requiresIn(Iterable<? extends Directive> directives) {
@ -280,6 +285,7 @@ public class ElementFilter {
* @return a list of {@code uses} directives in {@code directives}
* @param directives the directives to filter
* @since 9
* @spec JPMS
*/
public static List<UsesDirective>
usesIn(Iterable<? extends Directive> directives) {

View File

@ -75,6 +75,7 @@ import javax.lang.model.SourceVersion;
* @see ElementKindVisitor7
* @see ElementKindVisitor8
* @since 9
* @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public class ElementKindVisitor9<R, P> extends ElementKindVisitor8<R, P> {

View File

@ -88,6 +88,7 @@ import static javax.lang.model.SourceVersion.*;
* @see ElementScanner7
* @see ElementScanner8
* @since 9
* @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public class ElementScanner9<R, P> extends ElementScanner8<R, P> {

View File

@ -111,6 +111,7 @@ public interface Elements {
* @param name the name
* @return the named module element, or {@code null} if it cannot be found
* @since 9
* @spec JPMS
*/
default ModuleElement getModuleElement(CharSequence name) {
return null;
@ -359,6 +360,7 @@ public interface Elements {
* @param type the element being examined
* @return the module of an element
* @since 9
* @spec JPMS
*/
default ModuleElement getModuleOf(Element type) {
return null;

View File

@ -71,6 +71,7 @@ import static javax.lang.model.SourceVersion.*;
* @see SimpleElementVisitor7
* @see SimpleElementVisitor8
* @since 9
* @spec JPMS
*/
@SupportedSourceVersion(RELEASE_9)
public class SimpleElementVisitor9<R, P> extends SimpleElementVisitor8<R, P> {

View File

@ -165,22 +165,42 @@ public class ForwardingJavaFileManager<M extends JavaFileManager> implements Jav
fileManager.close();
}
/**
* @since 9
* @spec JPMS
*/
public Location getLocationForModule(Location location, String moduleName) throws IOException {
return fileManager.getLocationForModule(location, moduleName);
}
/**
* @since 9
* @spec JPMS
*/
public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException {
return fileManager.getLocationForModule(location, fo, pkgName);
}
/**
* @since 9
* @spec JPMS
*/
public <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
return fileManager.getServiceLoader(location, service);
}
/**
* @since 9
* @spec JPMS
*/
public String inferModuleName(Location location) throws IOException {
return fileManager.inferModuleName(location);
}
/**
* @since 9
* @spec JPMS
*/
public Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
return fileManager.listLocationsForModules(location);
}

View File

@ -165,6 +165,7 @@ public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
*
* @return true if this location is expected to contain modules
* @since 9
* @spec JPMS
*/
default boolean isModuleOrientedLocation() {
return getName().matches("\\bMODULE\\b");
@ -472,6 +473,7 @@ public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
* @throws IllegalArgumentException if the location is neither an output location nor a
* module-oriented location
* @since 9
* @spec JPMS
*/ // TODO: describe failure modes
default Location getLocationForModule(Location location, String moduleName) throws IOException {
throw new UnsupportedOperationException();
@ -499,6 +501,7 @@ public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
* @throws IllegalArgumentException if the location is neither an output location nor a
* module-oriented location
* @since 9
* @spec JPMS
*/
default Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException {
throw new UnsupportedOperationException();
@ -522,6 +525,7 @@ public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
* @throws IOException if an I/O error occurred
* @throws UnsupportedOperationException if this operation if not supported by this file manager
* @since 9
* @spec JPMS
*/ // TODO: describe failure modes
default <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException {
throw new UnsupportedOperationException();
@ -540,6 +544,7 @@ public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
* @throws UnsupportedOperationException if this operation if not supported by this file manager
* @throws IllegalArgumentException if the location is not one known to this file manager
* @since 9
* @spec JPMS
*/ // TODO: describe failure modes
default String inferModuleName(Location location) throws IOException {
throw new UnsupportedOperationException();
@ -559,6 +564,7 @@ public interface JavaFileManager extends Closeable, Flushable, OptionChecker {
* @throws UnsupportedOperationException if this operation if not supported by this file manager
* @throws IllegalArgumentException if the location is not a module-oriented location
* @since 9
* @spec JPMS
*/ // TODO: describe failure modes
default Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException {
throw new UnsupportedOperationException();

View File

@ -64,6 +64,7 @@ public enum StandardLocation implements Location {
/**
* Location to search for modules containing annotation processors.
* @spec JPMS
* @since 9
*/
ANNOTATION_PROCESSOR_MODULE_PATH,
@ -82,24 +83,28 @@ public enum StandardLocation implements Location {
/**
* Location to search for the source code of modules.
* @spec JPMS
* @since 9
*/
MODULE_SOURCE_PATH,
/**
* Location to search for upgradeable system modules.
* @spec JPMS
* @since 9
*/
UPGRADE_MODULE_PATH,
/**
* Location to search for system modules.
* @spec JPMS
* @since 9
*/
SYSTEM_MODULES,
/**
* Location to search for precompiled user modules.
* @spec JPMS
* @since 9
*/
MODULE_PATH;
@ -115,6 +120,9 @@ public enum StandardLocation implements Location {
*
* @param name a name
* @return a location
*
* @revised 9
* @spec JPMS
*/
public static Location locationFor(final String name) {
if (locations.isEmpty()) {

View File

@ -53,8 +53,8 @@ public abstract class Directive implements ModuleElement.Directive {
/** Flags for RequiresDirective. */
public enum RequiresFlag {
TRANSITIVE(0x0010),
STATIC_PHASE(0x0020),
TRANSITIVE(0x0020),
STATIC_PHASE(0x0040),
SYNTHETIC(0x1000),
MANDATED(0x8000),
EXTRA(0x10000);

View File

@ -968,7 +968,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
Collection<Path> paths = locations.getLocation(location);
ModuleFinder finder = ModuleFinder.of(paths.toArray(new Path[paths.size()]));
Layer bootLayer = Layer.boot();
Configuration cf = bootLayer.configuration().resolveRequiresAndUses(ModuleFinder.of(), finder, Collections.emptySet());
Configuration cf = bootLayer.configuration().resolveAndBind(ModuleFinder.of(), finder, Collections.emptySet());
Layer layer = bootLayer.defineModulesWithOneLoader(cf, ClassLoader.getSystemClassLoader());
return ServiceLoaderHelper.load(layer, service);
} else {

View File

@ -272,12 +272,12 @@ public class JDK9Wrappers {
init();
}
public Configuration resolveRequiresAndUses(
public Configuration resolveAndBind(
ModuleFinder beforeFinder,
ModuleFinder afterFinder,
Collection<String> roots) {
try {
Object result = resolveRequiresAndUsesMethod.invoke(theRealConfiguration,
Object result = resolveAndBindMethod.invoke(theRealConfiguration,
beforeFinder.theRealModuleFinder,
afterFinder.theRealModuleFinder,
roots
@ -293,7 +293,7 @@ public class JDK9Wrappers {
// -----------------------------------------------------------------------------------------
private static Class<?> configurationClass = null;
private static Method resolveRequiresAndUsesMethod;
private static Method resolveAndBindMethod;
static final Class<?> getConfigurationClass() {
init();
@ -305,7 +305,7 @@ public class JDK9Wrappers {
try {
configurationClass = Class.forName("java.lang.module.Configuration", false, null);
Class<?> moduleFinderInterface = ModuleFinder.getModuleFinderClass();
resolveRequiresAndUsesMethod = configurationClass.getDeclaredMethod("resolveRequiresAndUses",
resolveAndBindMethod = configurationClass.getDeclaredMethod("resolveAndBind",
moduleFinderInterface,
moduleFinderInterface,
Collection.class

View File

@ -38,8 +38,8 @@ import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info;
* deletion without notice.</b>
*/
public class Module_attribute extends Attribute {
public static final int ACC_TRANSITIVE = 0x10;
public static final int ACC_STATIC_PHASE = 0x20;
public static final int ACC_TRANSITIVE = 0x20;
public static final int ACC_STATIC_PHASE = 0x40;
public static final int ACC_OPEN = 0x20;
public static final int ACC_SYNTHETIC = 0x1000;
public static final int ACC_MANDATED = 0x8000;

View File

@ -118,7 +118,7 @@ public class JdepsConfiguration implements AutoCloseable {
}
this.configuration = Configuration.empty()
.resolveRequires(finder, ModuleFinder.of(), mods);
.resolve(finder, ModuleFinder.of(), mods);
this.configuration.modules().stream()
.map(ResolvedModule::reference)
@ -272,7 +272,7 @@ public class JdepsConfiguration implements AutoCloseable {
return nameToModule.values().stream();
} else {
return Configuration.empty()
.resolveRequires(finder, ModuleFinder.of(), roots)
.resolve(finder, ModuleFinder.of(), roots)
.modules().stream()
.map(ResolvedModule::name)
.map(nameToModule::get);
@ -422,18 +422,13 @@ public class JdepsConfiguration implements AutoCloseable {
}
private ModuleDescriptor dropHashes(ModuleDescriptor md) {
ModuleDescriptor.Builder builder = ModuleDescriptor.module(md.name());
ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(md.name());
md.requires().forEach(builder::requires);
md.exports().forEach(builder::exports);
md.opens().forEach(builder::opens);
md.provides().stream().forEach(builder::provides);
md.uses().stream().forEach(builder::uses);
Set<String> concealed = new HashSet<>(md.packages());
md.exports().stream().map(Exports::source).forEach(concealed::remove);
md.opens().stream().map(Opens::source).forEach(concealed::remove);
concealed.forEach(builder::contains);
builder.packages(md.packages());
return builder.build();
}

View File

@ -26,8 +26,6 @@
package com.sun.tools.jdeps;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Exports;
import java.lang.module.ModuleDescriptor.Opens;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
@ -55,6 +53,7 @@ class Module extends Archive {
private final ModuleDescriptor descriptor;
private final Map<String, Set<String>> exports;
private final Map<String, Set<String>> opens;
private final boolean isSystem;
private final URI location;
@ -63,6 +62,7 @@ class Module extends Archive {
this.descriptor = null;
this.location = null;
this.exports = Collections.emptyMap();
this.opens = Collections.emptyMap();
this.isSystem = true;
}
@ -70,12 +70,14 @@ class Module extends Archive {
URI location,
ModuleDescriptor descriptor,
Map<String, Set<String>> exports,
Map<String, Set<String>> opens,
boolean isSystem,
ClassFileReader reader) {
super(name, location, reader);
this.descriptor = descriptor;
this.location = location;
this.exports = Collections.unmodifiableMap(exports);
this.opens = Collections.unmodifiableMap(opens);
this.isSystem = isSystem;
}
@ -124,35 +126,52 @@ class Module extends Archive {
return descriptor.packages();
}
/**
* Tests if the package of the given name is exported.
*/
public boolean isExported(String pn) {
return exports.containsKey(pn) ? exports.get(pn).isEmpty() : false;
}
public boolean isJDKUnsupported() {
return JDK_UNSUPPORTED.equals(this.name());
}
/**
* Converts this module to a strict module with the given dependences
* Converts this module to a normal module with the given dependences
*
* @throws IllegalArgumentException if this module is not an automatic module
*/
public Module toStrictModule(Map<String, Boolean> requires) {
public Module toNormalModule(Map<String, Boolean> requires) {
if (!isAutomatic()) {
throw new IllegalArgumentException(name() + " already a strict module");
throw new IllegalArgumentException(name() + " not an automatic module");
}
return new StrictModule(this, requires);
return new NormalModule(this, requires);
}
/**
* Tests if the package of the given name is qualifiedly exported
* to the target.
* Tests if the package of the given name is exported.
*/
public boolean isExported(String pn) {
return exports.containsKey(pn) && exports.get(pn).isEmpty();
}
/**
* Tests if the package of the given name is exported to the target
* in a qualified fashion.
*/
public boolean isExported(String pn, String target) {
return isExported(pn) || exports.containsKey(pn) && exports.get(pn).contains(target);
return isExported(pn)
|| exports.containsKey(pn) && exports.get(pn).contains(target);
}
/**
* Tests if the package of the given name is open.
*/
public boolean isOpen(String pn) {
return opens.containsKey(pn) && opens.get(pn).isEmpty();
}
/**
* Tests if the package of the given name is open to the target
* in a qualified fashion.
*/
public boolean isOpen(String pn, String target) {
return isOpen(pn)
|| opens.containsKey(pn) && opens.get(pn).contains(target);
}
@Override
@ -193,19 +212,28 @@ class Module extends Archive {
}
Map<String, Set<String>> exports = new HashMap<>();
Map<String, Set<String>> opens = new HashMap<>();
descriptor.exports().stream()
.forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
return new Module(name, location, descriptor, exports, isSystem, reader);
if (descriptor.isAutomatic()) {
// ModuleDescriptor::exports and opens returns an empty set
descriptor.packages().forEach(pn -> exports.put(pn, Collections.emptySet()));
descriptor.packages().forEach(pn -> opens.put(pn, Collections.emptySet()));
} else {
descriptor.exports().stream()
.forEach(exp -> exports.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
descriptor.opens().stream()
.forEach(exp -> opens.computeIfAbsent(exp.source(), _k -> new HashSet<>())
.addAll(exp.targets()));
}
return new Module(name, location, descriptor, exports, opens, isSystem, reader);
}
}
private static class UnnamedModule extends Module {
private UnnamedModule() {
super("unnamed", null, null,
Collections.emptyMap(),
Collections.emptyMap(), Collections.emptyMap(),
false, null);
}
@ -230,19 +258,22 @@ class Module extends Archive {
}
}
private static class StrictModule extends Module {
/**
* A normal module has a module-info.class
*/
private static class NormalModule extends Module {
private final ModuleDescriptor md;
/**
* Converts the given automatic module to a strict module.
* Converts the given automatic module to a normal module.
*
* Replace this module's dependences with the given requires and also
* declare service providers, if specified in META-INF/services configuration file
*/
private StrictModule(Module m, Map<String, Boolean> requires) {
super(m.name(), m.location, m.descriptor, m.exports, m.isSystem, m.reader());
private NormalModule(Module m, Map<String, Boolean> requires) {
super(m.name(), m.location, m.descriptor, m.exports, m.opens, m.isSystem, m.reader());
ModuleDescriptor.Builder builder = ModuleDescriptor.module(m.name());
ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(m.name());
requires.keySet().forEach(mn -> {
if (requires.get(mn).equals(Boolean.TRUE)) {
builder.requires(Set.of(ModuleDescriptor.Requires.Modifier.TRANSITIVE), mn);
@ -250,16 +281,10 @@ class Module extends Archive {
builder.requires(mn);
}
});
m.descriptor.exports().forEach(e -> builder.exports(e));
m.descriptor.opens().forEach(o -> builder.opens(o));
m.descriptor.uses().forEach(s -> builder.uses(s));
m.descriptor.provides().forEach(p -> builder.provides(p));
Set<String> concealed = new HashSet<>(m.descriptor.packages());
m.descriptor.exports().stream().map(Exports::source).forEach(concealed::remove);
m.descriptor.opens().stream().map(Opens::source).forEach(concealed::remove);
concealed.forEach(builder::contains);
// exports all packages
m.descriptor.packages().forEach(builder::exports);
m.descriptor.uses().forEach(builder::uses);
m.descriptor.provides().forEach(builder::provides);
this.md = builder.build();
}

View File

@ -150,7 +150,7 @@ public class ModuleAnalyzer {
private ModuleDescriptor descriptor(Set<Module> requiresTransitive,
Set<Module> requires) {
ModuleDescriptor.Builder builder = ModuleDescriptor.module(root.name());
ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(root.name());
if (!root.name().equals(JAVA_BASE))
builder.requires(Set.of(MANDATED), JAVA_BASE);

View File

@ -181,7 +181,7 @@ public class ModuleExportsAnalyzer extends DepsAnalyzer {
RootModule(String name) {
super(name);
ModuleDescriptor.Builder builder = ModuleDescriptor.module(name);
ModuleDescriptor.Builder builder = ModuleDescriptor.newModule(name);
this.descriptor = builder.build();
}

View File

@ -43,10 +43,12 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.util.stream.Collectors.*;
@ -60,8 +62,8 @@ public class ModuleInfoBuilder {
final Analyzer analyzer;
// an input JAR file (loaded as an automatic module for analysis)
// maps to an explicit module to generate module-info.java
final Map<Module, Module> automaticToExplicitModule;
// maps to a normal module to generate module-info.java
final Map<Module, Module> automaticToNormalModule;
public ModuleInfoBuilder(JdepsConfiguration configuration,
List<String> args,
Path outputdir,
@ -78,20 +80,20 @@ public class ModuleInfoBuilder {
.map(fn -> Paths.get(fn))
.collect(toList());
// automatic module to convert to explicit module
this.automaticToExplicitModule = ModuleFinder.of(paths.toArray(new Path[0]))
// automatic module to convert to normal module
this.automaticToNormalModule = ModuleFinder.of(paths.toArray(new Path[0]))
.findAll().stream()
.map(configuration::toModule)
.collect(toMap(Function.identity(), Function.identity()));
Optional<Module> om = automaticToExplicitModule.keySet().stream()
Optional<Module> om = automaticToNormalModule.keySet().stream()
.filter(m -> !m.descriptor().isAutomatic())
.findAny();
if (om.isPresent()) {
throw new UncheckedBadArgs(new BadArgs("err.genmoduleinfo.not.jarfile",
om.get().getPathName()));
}
if (automaticToExplicitModule.isEmpty()) {
if (automaticToNormalModule.isEmpty()) {
throw new UncheckedBadArgs(new BadArgs("err.invalid.path", args));
}
}
@ -115,13 +117,13 @@ public class ModuleInfoBuilder {
Path file = outputdir.resolve(m.name()).resolve("module-info.java");
// computes requires and requires transitive
Module explicitModule = toExplicitModule(m, apiDeps);
if (explicitModule != null) {
automaticToExplicitModule.put(m, explicitModule);
Module normalModule = toNormalModule(m, apiDeps);
if (normalModule != null) {
automaticToNormalModule.put(m, normalModule);
// generate module-info.java
System.out.format("writing to %s%n", file);
writeModuleInfo(file, explicitModule.descriptor());
writeModuleInfo(file, normalModule.descriptor());
} else {
// find missing dependences
System.out.format("Missing dependence: %s not generated%n", file);
@ -139,7 +141,7 @@ public class ModuleInfoBuilder {
return m == NOT_FOUND || m == REMOVED_JDK_INTERNALS;
}
private Module toExplicitModule(Module module, Set<Archive> requiresTransitive)
private Module toNormalModule(Module module, Set<Archive> requiresTransitive)
throws IOException
{
// done analysis
@ -159,21 +161,21 @@ public class ModuleInfoBuilder {
.map(Archive::getModule)
.forEach(d -> requires.putIfAbsent(d.name(), Boolean.FALSE));
return module.toStrictModule(requires);
return module.toNormalModule(requires);
}
/**
* Returns the stream of resulting modules
*/
Stream<Module> modules() {
return automaticToExplicitModule.values().stream();
return automaticToNormalModule.values().stream();
}
/**
* Returns the stream of resulting ModuleDescriptors
*/
public Stream<ModuleDescriptor> descriptors() {
return automaticToExplicitModule.entrySet().stream()
return automaticToNormalModule.entrySet().stream()
.map(Map.Entry::getValue)
.map(Module::descriptor);
}
@ -205,13 +207,14 @@ public class ModuleInfoBuilder {
md.requires().stream()
.filter(req -> !req.name().equals("java.base")) // implicit requires
.sorted(Comparator.comparing(Requires::name))
.forEach(req -> writer.format(" requires %s;%n", req));
.forEach(req -> writer.format(" requires %s;%n",
toString(req.modifiers(), req.name())));
if (!open) {
md.exports().stream()
.peek(exp -> {
if (exp.targets().size() > 0)
throw new InternalError(md.name() + " qualified exports: " + exp);
if (exp.isQualified())
throw new InternalError(md.name() + " qualified exports: " + exp);
})
.sorted(Comparator.comparing(Exports::source))
.forEach(exp -> writer.format(" exports %s;%n", exp.source()));
@ -231,7 +234,16 @@ public class ModuleInfoBuilder {
}
private Set<Module> automaticModules() {
return automaticToExplicitModule.keySet();
return automaticToNormalModule.keySet();
}
/**
* Returns a string containing the given set of modifiers and label.
*/
private static <M> String toString(Set<M> mods, String what) {
return (Stream.concat(mods.stream().map(e -> e.toString().toLowerCase(Locale.US)),
Stream.of(what)))
.collect(Collectors.joining(" "));
}
/**

View File

@ -213,7 +213,7 @@ public class KullaTesting {
ModuleFinder finder = ModuleFinder.of(modPath);
Layer parent = Layer.boot();
Configuration cf = parent.configuration()
.resolveRequires(finder, ModuleFinder.of(), Set.of(moduleName));
.resolve(finder, ModuleFinder.of(), Set.of(moduleName));
ClassLoader scl = ClassLoader.getSystemClassLoader();
Layer layer = parent.defineModulesWithOneLoader(cf, scl);
ClassLoader loader = layer.findLoader(moduleName);

View File

@ -107,7 +107,7 @@ public class DetectMutableStaticFields {
// by reflective lookup, to avoid explicit references that are not available
// when running javac on JDK 8.
ignore("com/sun/tools/javac/util/JDK9Wrappers$Configuration",
"resolveRequiresAndUsesMethod", "configurationClass");
"resolveAndBindMethod", "configurationClass");
ignore("com/sun/tools/javac/util/JDK9Wrappers$Layer",
"bootMethod", "defineModulesWithOneLoaderMethod", "configurationMethod", "layerClass");
ignore("com/sun/tools/javac/util/JDK9Wrappers$Module",