/*
 * Bach - Java Shell Builder
 * Copyright (C) 2019 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.Version;
import java.util.ArrayList;
import java.util.List;

/**
 * Build modular Java project.
 */
public class Bach {

  public static String VERSION = "2.0-ea";

  /**
   * Main entry-point.
   */
  public static void main(String... args) {
    System.out.println("Bach " + VERSION);
  }

  /**
   * Project model.
   */
  public static /*record*/ class Project {
    final String name;
    final Version version;

    public Project(String name, Version version) {
      this.name = name;
      this.version = version;
    }
  }

  /**
   * Java source generator.
   */
  public static class SourceGenerator {

    String $(Object object) {
      return object == null ? "null" : "\"" + object + "\"";
    }

    public List<String> toSource(Project project) {
      var lines = new ArrayList<String>();
      lines.add(String.format("new Project(%s, Version.parse(%s));", $(project.name), $(project.version)));
      return lines;
    }
  }
}

@@ -677,16 +677,43 @@
 ersion;%0A
+import java.nio.file.Path;%0A
 import j
@@ -754,16 +754,69 @@
 il.List;
+%0Aimport java.util.Objects;%0Aimport java.util.Optional;
 %0A%0A/**%0A *
@@ -1272,24 +1272,884 @@
 rsion;%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A      if (this == o) return true;%0A      if (o == null %7C%7C getClass() != o.getClass()) return false;%0A      Project project = (Project) o;%0A      return name.equals(project.name) &&%0A             version.equals(project.version);%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A      return Objects.hash(name, version);%0A    %7D%0A  %7D%0A%0A  /**%0A   * Mutable project builder.%0A   */%0A  public static class ProjectBuilder %7B%0A%0A    static ProjectBuilder of(Path path) %7B%0A      var builder = new ProjectBuilder();%0A      builder.name = Optional.ofNullable(path.toAbsolutePath().getFileName()).map(Path::toString).orElse(%22project%22);%0A      builder.version = %220%22;%0A      return builder;%0A    %7D%0A%0A    String name = %22project%22;%0A    String version = %220%22;%0A%0A    Project build() %7B%0A      return new Project(name, Version.parse(version));%0A    %7D
 %0A  %7D%0A%0A  /**%0A

Add ProjectBuilder class