/*
 * 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.lang.module.ModuleDescriptor;
import java.lang.module.ModuleDescriptor.Version;
import java.nio.file.Path;
import java.util.List;

/** Bach's own build program. */
class Build {

  public static void main(String... args) {
    new Bach(System.out::println, true, false).build(newProject("Bach.java", "11.0-ea"));
  }

  static Bach.Project newProject(String name, String version) {
    return new Bach.Project(
        name,
        Version.parse(version),
        new Bach.Structure(List.of(newMain(), newTest(), newTestPreview())));
  }

  static Bach.ModuleCollection newMain() {
    return new Bach.ModuleCollection(
        "main",
        11,
        false,
        List.of(
            new Bach.ModuleDescription(
                ModuleDescriptor.newModule("de.sormuras.bach").build(),
                Bach.Directory.listOf(Path.of("src/de.sormuras.bach/main")))));
  }

  static Bach.ModuleCollection newTest() {
    return new Bach.ModuleCollection(
        "test",
        11,
        false,
        List.of(
            //
            new Bach.ModuleDescription(
                ModuleDescriptor.newOpenModule("de.sormuras.bach").build(),
                Bach.Directory.listOf(Path.of("src/de.sormuras.bach/test"))),
            //
            new Bach.ModuleDescription(
                ModuleDescriptor.newOpenModule("test.base").build(),
                Bach.Directory.listOf(Path.of("src/test.base/test"))),
            //
            new Bach.ModuleDescription(
                ModuleDescriptor.newOpenModule("test.modules").build(),
                Bach.Directory.listOf(Path.of("src/test.modules/test")))));
  }

  static Bach.ModuleCollection newTestPreview() {
    return new Bach.ModuleCollection(
        "test-preview",
        Runtime.version().feature(),
        true,
        List.of(
            new Bach.ModuleDescription(
                ModuleDescriptor.newOpenModule("test.preview").build(),
                Bach.Directory.listOf(Path.of("src/test.preview/test-preview/java")))));
  }
}

@@ -915,20 +915,17 @@
 ).build(
-newP
+p
 roject(%22
@@ -980,12 +980,9 @@
 ect 
-newP
+p
 roje
@@ -1057,24 +1057,16 @@
    name,
-%0A       
  Version
@@ -1081,24 +1081,16 @@
 ersion),
-%0A       
  new Bac
@@ -1113,44 +1113,30 @@
 .of(
-newMain(), newTest(), newTestPreview
+mainRealm(), testRealm
 ()))
@@ -1161,32 +1161,23 @@
 ach.
-ModuleCollection newMain
+Realm mainRealm
 () %7B
@@ -1197,32 +1197,21 @@
 ew Bach.
-ModuleCollection
+Realm
 (%0A      
@@ -1285,33 +1285,20 @@
 ew Bach.
-ModuleDescription
+Unit
 (%0A      
@@ -1466,32 +1466,23 @@
 ach.
-ModuleCollection newTest
+Realm testRealm
 () %7B
@@ -1502,32 +1502,21 @@
 ew Bach.
-ModuleCollection
+Realm
 (%0A      
@@ -1605,33 +1605,20 @@
 ew Bach.
-ModuleDescription
+Unit
 (%0A      
@@ -1801,33 +1801,20 @@
 ew Bach.
-ModuleDescription
+Unit
 (%0A      
@@ -1983,33 +1983,20 @@
 ew Bach.
-ModuleDescription
+Unit
 (%0A      
@@ -2144,393 +2144,7 @@
 %0A  %7D
-%0A%0A  static Bach.ModuleCollection newTestPreview() %7B%0A    return new Bach.ModuleCollection(%0A        %22test-preview%22,%0A        Runtime.version().feature(),%0A        true,%0A        List.of(%0A            new Bach.ModuleDescription(%0A                ModuleDescriptor.newOpenModule(%22test.preview%22).build(),%0A                Bach.Directory.listOf(Path.of(%22src/test.preview/test-preview/java%22)))));%0A  %7D
 %0A%7D%0A

Update build program