< prev index next >

src/java.base/share/classes/java/lang/module/Configuration.java

Print this page




  25 
  26 package java.lang.module;
  27 
  28 import java.io.PrintStream;
  29 import java.util.ArrayDeque;
  30 import java.util.ArrayList;
  31 import java.util.Collection;
  32 import java.util.Collections;
  33 import java.util.Deque;
  34 import java.util.HashMap;
  35 import java.util.HashSet;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.Map.Entry;
  39 import java.util.Objects;
  40 import java.util.Optional;
  41 import java.util.Set;
  42 import java.util.stream.Collectors;
  43 import java.util.stream.Stream;
  44 

  45 import jdk.internal.module.ModuleReferenceImpl;
  46 import jdk.internal.module.ModuleTarget;

  47 
  48 /**
  49  * A configuration that is the result of <a href="package-summary.html#resolution">
  50  * resolution</a> or resolution with
  51  * <a href="{@docRoot}/java.base/java/lang/module/Configuration.html#service-binding">service binding</a>.
  52  *
  53  * <p> A configuration encapsulates the <em>readability graph</em> that is the
  54  * output of resolution. A readability graph is a directed graph whose vertices
  55  * are of type {@link ResolvedModule} and the edges represent the readability
  56  * amongst the modules. {@code Configuration} defines the {@link #modules()
  57  * modules()} method to get the set of resolved modules in the graph. {@code
  58  * ResolvedModule} defines the {@link ResolvedModule#reads() reads()} method to
  59  * get the set of modules that a resolved module reads. The modules that are
  60  * read may be in the same configuration or may be in {@link #parents() parent}
  61  * configurations. </p>
  62  *
  63  * <p> Configuration defines the {@link #resolve(ModuleFinder,List,ModuleFinder,Collection)
  64  * resolve} method to resolve a collection of root modules, and the {@link
  65  * #resolveAndBind(ModuleFinder,List,ModuleFinder,Collection) resolveAndBind}
  66  * method to do resolution with service binding. There are instance and


  87  *
  88  *    Configuration parent = ModuleLayer.boot().configuration();
  89  *
  90  *    Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
  91  *    cf.modules().forEach(m -> {
  92  *        System.out.format("%s -> %s%n",
  93  *            m.name(),
  94  *            m.reads().stream()
  95  *                .map(ResolvedModule::name)
  96  *                .collect(Collectors.joining(", ")));
  97  *    });
  98  * }</pre>
  99  *
 100  * @since 9
 101  * @spec JPMS
 102  * @see java.lang.ModuleLayer
 103  */
 104 public final class Configuration {
 105 
 106     // @see Configuration#empty()
 107     private static final Configuration EMPTY_CONFIGURATION = new Configuration();










 108 
 109     // parent configurations, in search order
 110     private final List<Configuration> parents;
 111 
 112     private final Map<ResolvedModule, Set<ResolvedModule>> graph;
 113     private final Set<ResolvedModule> modules;
 114     private final Map<String, ResolvedModule> nameToModule;
 115 
 116     // constraint on target platform
 117     private final String targetPlatform;
 118 
 119     String targetPlatform() { return targetPlatform; }
 120 
 121     private Configuration() {
 122         this.parents = Collections.emptyList();
 123         this.graph = Collections.emptyMap();
 124         this.modules = Collections.emptySet();
 125         this.nameToModule = Collections.emptyMap();
 126         this.targetPlatform = null;
 127     }




  25 
  26 package java.lang.module;
  27 
  28 import java.io.PrintStream;
  29 import java.util.ArrayDeque;
  30 import java.util.ArrayList;
  31 import java.util.Collection;
  32 import java.util.Collections;
  33 import java.util.Deque;
  34 import java.util.HashMap;
  35 import java.util.HashSet;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.Map.Entry;
  39 import java.util.Objects;
  40 import java.util.Optional;
  41 import java.util.Set;
  42 import java.util.stream.Collectors;
  43 import java.util.stream.Stream;
  44 
  45 import jdk.internal.misc.VM;
  46 import jdk.internal.module.ModuleReferenceImpl;
  47 import jdk.internal.module.ModuleTarget;
  48 import jdk.internal.vm.annotation.Stable;
  49 
  50 /**
  51  * A configuration that is the result of <a href="package-summary.html#resolution">
  52  * resolution</a> or resolution with
  53  * <a href="{@docRoot}/java.base/java/lang/module/Configuration.html#service-binding">service binding</a>.
  54  *
  55  * <p> A configuration encapsulates the <em>readability graph</em> that is the
  56  * output of resolution. A readability graph is a directed graph whose vertices
  57  * are of type {@link ResolvedModule} and the edges represent the readability
  58  * amongst the modules. {@code Configuration} defines the {@link #modules()
  59  * modules()} method to get the set of resolved modules in the graph. {@code
  60  * ResolvedModule} defines the {@link ResolvedModule#reads() reads()} method to
  61  * get the set of modules that a resolved module reads. The modules that are
  62  * read may be in the same configuration or may be in {@link #parents() parent}
  63  * configurations. </p>
  64  *
  65  * <p> Configuration defines the {@link #resolve(ModuleFinder,List,ModuleFinder,Collection)
  66  * resolve} method to resolve a collection of root modules, and the {@link
  67  * #resolveAndBind(ModuleFinder,List,ModuleFinder,Collection) resolveAndBind}
  68  * method to do resolution with service binding. There are instance and


  89  *
  90  *    Configuration parent = ModuleLayer.boot().configuration();
  91  *
  92  *    Configuration cf = parent.resolve(finder, ModuleFinder.of(), Set.of("myapp"));
  93  *    cf.modules().forEach(m -> {
  94  *        System.out.format("%s -> %s%n",
  95  *            m.name(),
  96  *            m.reads().stream()
  97  *                .map(ResolvedModule::name)
  98  *                .collect(Collectors.joining(", ")));
  99  *    });
 100  * }</pre>
 101  *
 102  * @since 9
 103  * @spec JPMS
 104  * @see java.lang.ModuleLayer
 105  */
 106 public final class Configuration {
 107 
 108     // @see Configuration#empty()
 109     // EMPTY_CONFIGURATION may be initialized from the CDS archive.
 110     private static @Stable Configuration EMPTY_CONFIGURATION;
 111 
 112     static {
 113         // Initialize EMPTY_CONFIGURATION from the archive.
 114         VM.initializeFromArchive(Configuration.class);
 115         // Create a new empty Configuration if there is no archived version.
 116         if (EMPTY_CONFIGURATION == null) {
 117             EMPTY_CONFIGURATION = new Configuration();
 118         }
 119     }
 120 
 121     // parent configurations, in search order
 122     private final List<Configuration> parents;
 123 
 124     private final Map<ResolvedModule, Set<ResolvedModule>> graph;
 125     private final Set<ResolvedModule> modules;
 126     private final Map<String, ResolvedModule> nameToModule;
 127 
 128     // constraint on target platform
 129     private final String targetPlatform;
 130 
 131     String targetPlatform() { return targetPlatform; }
 132 
 133     private Configuration() {
 134         this.parents = Collections.emptyList();
 135         this.graph = Collections.emptyMap();
 136         this.modules = Collections.emptySet();
 137         this.nameToModule = Collections.emptyMap();
 138         this.targetPlatform = null;
 139     }


< prev index next >