package com.github.sormuras.bach.project;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;

/**
 * A source directory potentially targeting a specific Java SE release.
 *
 * @param path the directory
 * @param release the feature number of the Java SE release
 */
public record SourceFolder(Path path, int release) {

  /** @return {@code true} if a non-zero release is stored, else {@code false} */
  public boolean isTargeted() {
    return release != 0;
  }

  /** @return {@code true} if a regular file named {@code module-info.java} is in {@link #path()} */
  public boolean isModuleInfoJavaPresent() {
    return Files.isRegularFile(path.resolve("module-info.java"));
  }

  static final Pattern RELEASE_PATTERN = Pattern.compile(".*?(\\d+)$");

  static int parseReleaseNumber(String string) {
    if (string == null || string.isEmpty()) return 0;
    var matcher = RELEASE_PATTERN.matcher(string);
    return matcher.matches() ? Integer.parseInt(matcher.group(1)) : 0;
  }

  static SourceFolder of(Path path) {
    if (Files.isRegularFile(path)) throw new IllegalArgumentException("Not a directory: " + path);
    var file = path.normalize().getFileName();
    var name = file != null ? file : path.toAbsolutePath().getFileName();
    return new SourceFolder(path, parseReleaseNumber(name.toString()));
  }
}

@@ -36,16 +36,64 @@
 oject;%0A%0A
+import com.github.sormuras.bach.internal.Paths;%0A
 import j
@@ -1203,129 +1203,8 @@
 h);%0A
-    var file = path.normalize().getFileName();%0A    var name = file != null ? file : path.toAbsolutePath().getFileName();%0A
     
@@ -1256,22 +1256,23 @@
 ber(
-name.toString(
+Paths.name(path
 )));

Use internal path to name function