/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

/** Bach's own build program. */
class Build {
  public static void main(String... args) {
    var bach = new Bach();
    bach.print("Build Bach.java using %s", bach);
    var project = newProjectDescriptor();
    bach.print("%s", project);
    // bach.build(project).assertSuccessful();
  }

  private static Object newProjectDescriptor() {
    var folders = new ArrayList<Bach.Folder>();
    folders.addAll(mainFolders());
    folders.addAll(testFolders());
    return folders;
  }

  private static List<Bach.Folder> mainFolders() {
    return List.of(new Bach.Folder(Path.of("src/de.sormuras.bach/main/java"), 11));
  }

  private static List<Bach.Folder> testFolders() {
    return List.of(
        new Bach.Folder(Path.of("src/de.sormuras.bach/test/java"), 14),
        new Bach.Folder(Path.of("src/de.sormuras.bach/test/java-module"), 9),
        new Bach.Folder(Path.of("src/test.base/test/java"), 14),
        new Bach.Folder(Path.of("src/test.module/test/java"), 14),
        new Bach.Folder(Path.of("src/test.preview/test-preview/java"), 14));
  }
}

@@ -643,49 +643,63 @@
 ava.
-nio.file.Path;%0Aimport java.util.ArrayList
+lang.module.ModuleDescriptor;%0Aimport java.nio.file.Path
 ;%0Aim
@@ -767,16 +767,17 @@
 Build %7B%0A
+%0A
   public
@@ -808,24 +808,53 @@
 ... args) %7B%0A
+    var project = project();%0A
     var bach
@@ -922,50 +922,8 @@
 h);%0A
-    var project = newProjectDescriptor();%0A
     
@@ -1029,387 +1029,747 @@
 ect 
-newP
+p
 roject
-Descriptor() %7B%0A    var folders = new ArrayList%3CBach.Folder%3E();%0A    folders.addAll(mainFolders());%0A    folders.addAll(
+() %7B%0A    return List.of(mainRealm(), testRealm(), testPreviewRealm());%0A  %7D%0A%0A  priva
 te
+ 
 st
-Folders());%0A    return folders;%0A  %7D%0A%0A  private static List%3CBach.Folder%3E mainFolders() %7B%0A    return List.of(new Bach.Folder(Path.of(%22src/de.sormuras.bach/main/java%22), 11));%0A  %7D%0A%0A  private static List%3CBach.Folder%3E testFolders() %7B%0A    return List.of(%0A
+atic Bach.Realm mainRealm() %7B%0A    return new Bach.Realm(%0A        %22main%22,%0A        11,%0A        false,%0A        List.of(%0A            new Bach.Unit(%0A                ModuleDescriptor.newModule(%22de.sormuras.bach%22).build(),%0A                List.of(new Bach.Folder(Path.of(%22src/de.sormuras.bach/main/java%22), 0)) //%0A                ) //%0A            ) //%0A        );%0A  %7D%0A%0A  private static Bach.Realm testRealm() %7B%0A    return new Bach.Realm(%0A        %22test%22,%0A        11,%0A        false,%0A        List.of(%0A            //%0A            new Bach.Unit(%0A                ModuleDescriptor.newOpenModule(%22de.sormuras.bach%22).build(),%0A                List.of(%0A            
     
@@ -1823,37 +1823,48 @@
 ch/test/java%22), 
-14
+0
 ),%0A
+            
         new Bach
@@ -1925,20 +1925,149 @@
 %22), 
-9),%0A        
+0))),%0A            //%0A            new Bach.Unit(%0A                ModuleDescriptor.newOpenModule(%22test.base%22).build(),%0A                List.of(
 new 
@@ -2106,34 +2106,35 @@
 se/test/java%22), 
-14
+0))
 ),%0A        new B
@@ -2120,32 +2120,162 @@
 , 0))),%0A        
+    //%0A            new Bach.Unit(%0A                ModuleDescriptor.newOpenModule(%22test.modules%22).build(),%0A                List.of(
 new Bach.Folder(
@@ -2298,16 +2298,17 @@
 t.module
+s
 /test/ja
@@ -2317,86 +2317,442 @@
 %22), 
-14),%0A        new Bach.Folder(Path.of(%22src/test.preview/test-preview/java%22), 14
+0)))%0A            //%0A            ));%0A  %7D%0A%0A  private static Bach.Realm testPreviewRealm() %7B%0A    var descriptor = ModuleDescriptor.newOpenModule(%22test.preview%22).build();%0A    var release = Runtime.version().feature();%0A    var folders = List.of(new Bach.Folder(Path.of(%22src/test.preview/test-preview/java%22), release));%0A    var unit = new Bach.Unit(descriptor, folders);%0A    return new Bach.Realm(%22test-preview%22, release, true, List.of(unit
 ));%0A

Create three realms in build program