@@ -0,0 +1,2941 @@
+package com.github.sormuras.bach.lookup;%0A%0Aimport java.net.URI;%0Aimport java.nio.file.Path;%0A%0A/** A builder of external module objects. */%0Apublic class ExternalModuleLookupBuilder %7B%0A%0A  /** The name of the module to link. */%0A  private final String module;%0A%0A  /**%0A   * Constructs an instance of this class with the given components.%0A   *%0A   * @param module the name of the module to link%0A   */%0A  public ExternalModuleLookupBuilder(String module) %7B%0A    this.module = module;%0A  %7D%0A%0A  /**%0A   * Returns a module link whose uri is determined by the given target string.%0A   *%0A   * @param target the target to parse into a uri%0A   * @return a module link%0A   */%0A  public ExternalModuleLookup to(String target) %7B%0A    var maven = target.indexOf('/') == -1 && target.chars().filter(ch -%3E ch == ':').count() %3E= 2;%0A    if (maven) return toMavenCentral(target);%0A    return toUri(target);%0A  %7D%0A%0A  /**%0A   * Returns a module link pointing to local path.%0A   *%0A   * @param base the base directory%0A   * @param more the path to the file%0A   * @return an external module link%0A   */%0A  public ExternalModuleLookup toPath(String base, String more) %7B%0A    var first = base.equals(%22~%22) ? System.getProperty(%22user.home%22) : base;%0A    var path = Path.of(first, more);%0A    return toUri(path.normalize().toUri());%0A  %7D%0A%0A  /**%0A   * Returns a module link pointing to an artifact hosted at the given Maven repository.%0A   *%0A   * @param repository Maven repository%0A   * @param coordinates Maven groupId + ':' + artifactId + ':' version %5B+ ':' + classifier%5D%0A   * @return a Maven-based %7B@code Link%7D instance%0A   */%0A  public ExternalModuleLookup toMaven(String repository, String coordinates) %7B%0A    var split = coordinates.split(%22:%22);%0A    if (split.length %3C 3) throw new IllegalArgumentException();%0A    var joiner = Maven.Joiner.of(split%5B0%5D, split%5B1%5D, split%5B2%5D)%0A        .repository(repository)%0A        .classifier(split.length %3C 4 ? %22%22 : split%5B3%5D);%0A    return toUri(joiner.toString());%0A  %7D%0A%0A  /**%0A   * Returns a module link pointing to an artifact hosted at Maven Central.%0A   *%0A   * @param coordinates Maven groupId + ':' + artifactId + ':' version %5B+ ':' + classifier%5D%0A   * @return a Maven Central-based %7B@code Link%7D instance%0A   * @see %3Ca href=%22https://search.maven.org%22%3Esearch.maven.org%3C/a%3E%0A   */%0A  public ExternalModuleLookup toMavenCentral(String coordinates) %7B%0A    return toMaven(Maven.CENTRAL_REPOSITORY, coordinates);%0A  %7D%0A%0A  /**%0A   * Returns a module link pointing to the given uniform resource identifier.%0A   *%0A   * @param uri uniform resource identifier of the module%0A   * @return a module link%0A   */%0A  public ExternalModuleLookup toUri(String uri) %7B%0A    return toUri(URI.create(uri));%0A  %7D%0A%0A  /**%0A   * Returns a module link pointing to the given uniform resource identifier.%0A   *%0A   * @param uri uniform resource identifier of the module%0A   * @return a module link%0A   */%0A  public ExternalModuleLookup toUri(URI uri) %7B%0A    return new ExternalModuleLookup(module, uri.toString());%0A  %7D%0A%7D

Introduce external module lookup builder class