package com.github.sormuras.bach.internal;

import java.lang.module.ModuleFinder;
import java.util.List;
import java.util.Set;

/** Module-related utilities. */
public class Modules {

  public static ModuleLayer layer(ModuleFinder finder) {
    var boot = ModuleLayer.boot();
    var configuration = boot.configuration().resolveAndBind(ModuleFinder.of(), finder, Set.of());
    var parent = Modules.class.getClassLoader();
    var controller = ModuleLayer.defineModulesWithOneLoader(configuration, List.of(boot), parent);
    return controller.layer();
  }

  /** Hide default constructor. */
  private Modules() {}
}

@@ -71,117 +71,1257 @@
 dule
-Finder;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0A/** Module-related utilities. */%0Apublic class Modules %7B
+Descriptor;%0Aimport java.lang.module.ModuleDescriptor.Requires;%0Aimport java.lang.module.ModuleFinder;%0Aimport java.lang.module.ModuleReference;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.TreeSet;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.Stream;%0A%0A/** Module-related utilities. */%0Apublic class Modules %7B%0A%0A  public static Set%3CString%3E declared(ModuleFinder finder) %7B%0A    return declared(finder.findAll().stream().map(ModuleReference::descriptor));%0A  %7D%0A%0A  public static Set%3CString%3E declared(Stream%3CModuleDescriptor%3E descriptors) %7B%0A    return descriptors.map(ModuleDescriptor::name).collect(Collectors.toCollection(TreeSet::new));%0A  %7D%0A%0A  public static Set%3CString%3E required(ModuleFinder finder) %7B%0A    return required(finder.findAll().stream().map(ModuleReference::descriptor));%0A  %7D%0A%0A  public static Set%3CString%3E required(Stream%3CModuleDescriptor%3E descriptors) %7B%0A    return descriptors%0A        .map(ModuleDescriptor::requires)%0A        .flatMap(Set::stream)%0A        .filter(requires -%3E !requires.modifiers().contains(Requires.Modifier.MANDATED))%0A        .filter(requires -%3E !requires.modifiers().contains(Requires.Modifier.SYNTHETIC))%0A        .map(Requires::name)%0A        .collect(Collectors.toCollection(TreeSet::new));%0A  %7D
 %0A%0A  

Extend module-related utilities with declared and required methods