package de.sormuras.bach;

import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Version;
import java.net.URI;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/*BODY*/
/** Modular project model domain. */
public interface Domain {

  /** Modular project model. */
  class Project {
    /** Name of the project. */
    final String name;
    /** Version of the project. */
    final Version version;
    /** Library. */
    final Library library;
    /** List of realms. */
    final List<Realm> realms;
    /** Target directory. */
    final Path target;

    public Project(String name, Version version, Library library, List<Realm> realms, Path target) {
      this.name = name;
      this.version = version;
      this.library = library;
      this.realms = List.copyOf(realms);
      this.target = target;
    }
  }

  /** Manage external 3rd-party modules. */
  class Library {
    /** List of library paths to external 3rd-party modules. */
    final List<Path> modulePaths;
    /** Map external 3rd-party module names to their {@code URI}s. */
    final Function<String, URI> moduleMapper;

    public Library(List<Path> modulePaths, Function<String, URI> moduleMapper) {
      this.modulePaths = List.copyOf(modulePaths);
      this.moduleMapper = moduleMapper;
    }
  }

  /** Common base class for main- and test realms. */
  abstract class Realm {
    /** Name of the realm. */
    final String name;
    /** Map of declared module source unit. */
    final Map<String, ModuleSource> modules;

    /** Module source path specifies where to find input source files for multiple modules. */
    final String moduleSourcePath;

    Realm(String name, String moduleSourcePath, Map<String, ModuleSource> modules) {
      this.name = name;
      this.modules = modules;
      this.moduleSourcePath = moduleSourcePath;
    }
  }

  /** Main realm. */
  class MainRealm extends Realm {
    public MainRealm(String moduleSourcePath, Map<String, ModuleSource> declaredModules) {
      super("main", moduleSourcePath, declaredModules);
    }
  }

  /** Test realm. */
  class TestRealm extends Realm {
    /** Main realm reference. */
    final MainRealm main;

    public TestRealm(
        MainRealm main, String moduleSourcePath, Map<String, ModuleSource> declaredModules) {
      super("test", moduleSourcePath, declaredModules);
      this.main = main;
    }
  }

  /** Describes a Java module source unit. */
  class ModuleSource {
    /** Relative to the backing {@code module-info.java} file. */
    final Path info;
    /** Associated module descriptor, normally parsed from module {@link #info} file. */
    final ModuleDescriptor descriptor;

    public ModuleSource(Path info, ModuleDescriptor descriptor) {
      this.info = info;
      this.descriptor = descriptor;
    }
  }
}

@@ -393,32 +393,39 @@
 project. */%0A    
+public 
 final String nam
@@ -462,24 +462,31 @@
 ect. */%0A    
+public 
 final Versio
@@ -512,32 +512,39 @@
 Library. */%0A    
+public 
 final Library li
@@ -573,32 +573,39 @@
  realms. */%0A    
+public 
 final List%3CRealm
@@ -639,32 +639,39 @@
 rectory. */%0A    
+public 
 final Path targe
@@ -1065,24 +1065,31 @@
 les. */%0A    
+public 
 final List%3CP
@@ -1176,24 +1176,31 @@
 I%7Ds. */%0A    
+public 
 final Functi
@@ -1518,32 +1518,39 @@
 e realm. */%0A    
+public 
 final String nam
@@ -1595,32 +1595,39 @@
 ce unit. */%0A    
+public 
 final Map%3CString
@@ -1896,38 +1896,8 @@
 me;%0A
-      this.modules = modules;%0A
     
@@ -1940,16 +1940,58 @@
 cePath;%0A
+      this.modules = Map.copyOf(modules);%0A
     %7D%0A  
@@ -2294,24 +2294,31 @@
 nce. */%0A    
+public 
 final MainRe
@@ -2670,24 +2670,31 @@
 ile. */%0A    
+public 
 final Path i
@@ -2694,24 +2694,194 @@
  Path info;%0A
+    /** Relative path to the resources directory. */%0A    public final Path sources;%0A    /** Relative path to the resources directory. */%0A    public final Path resources;%0A
     /** Asso
@@ -2957,24 +2957,31 @@
 ile. */%0A    
+public 
 final Module
@@ -3038,16 +3038,46 @@
 th info,
+ Path sources, Path resources,
  ModuleD
@@ -3120,24 +3120,88 @@
 nfo = info;%0A
+      this.sources = sources;%0A      this.resources = resources;%0A
       this.d

Make read-only properties public