Class MavenWrapper

java.lang.Object
network.ike.plugin.ws.MavenWrapper

public final class MavenWrapper extends Object
Shared generator for the three Maven Wrapper files that every workspace needs at the root:
  • .mvn/wrapper/maven-wrapper.properties
  • mvnw (POSIX launcher — must be LF; executable bit set)
  • mvnw.cmd (Windows launcher — must be CRLF on Windows; see .gitattributes *.cmd text eol=crlf rule)

The mvnw / mvnw.cmd scripts are the standard Apache Maven Wrapper launchers, vendored verbatim as plugin resources under wrapper/. The only-script distribution type is used — the scripts download Maven themselves, so no maven-wrapper.jar binary is committed to a workspace repo. The properties file carries the standard wrapperVersion, distributionType, and distributionUrl keys, which is what IDEs (IntelliJ) key on to auto-adopt the wrapper.

Used by ws:scaffold-init when scaffolding a new workspace, and by ScaffoldConventionReconciler's mvnw step (run as part of ws:scaffold-publish) — both to fill in missing files and to replace the legacy custom "minimal bootstrap" wrapper that earlier plugin versions generated (IKE-Network/ike-issues#405).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Wrapper distribution type.
    static final String
    Apache Maven Wrapper version of the vendored mvnw / mvnw.cmd scripts.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Report whether the workspace carries the legacy custom "minimal bootstrap" mvnw that pre-standardization plugin versions generated.
    static String
    Read the pinned Maven version from an existing .mvn/wrapper/maven-wrapper.properties, or return null if the file does not exist or no version can be determined.
    static void
    writeAll(Path wsDir, String mavenVersion)
    Unconditionally (re)write all three wrapper files, overwriting any that already exist.
    static int
    writeMissingFiles(Path wsDir, String mavenVersion)
    Install any of the three wrapper files that are missing from the given workspace directory.
    static void
    Write the standard Apache Windows mvnw.cmd launcher script.
    static void
    Write the standard Apache POSIX mvnw launcher script and mark it executable.
    static void
    writePropertiesFile(Path propsFile, String mavenVersion)
    Write maven-wrapper.properties in the standard only-script form for the given Maven version.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • WRAPPER_VERSION

      public static final String WRAPPER_VERSION
      Apache Maven Wrapper version of the vendored mvnw / mvnw.cmd scripts. Written into wrapperVersion of the generated maven-wrapper.properties.
      See Also:
    • DISTRIBUTION_TYPE

      public static final String DISTRIBUTION_TYPE
      Wrapper distribution type. only-script keeps the wrapper jar-free — the launcher scripts download Maven directly.
      See Also:
  • Method Details

    • writeMissingFiles

      public static int writeMissingFiles(Path wsDir, String mavenVersion) throws IOException
      Install any of the three wrapper files that are missing from the given workspace directory. Never overwrites an existing file — the user may have pinned a specific version in maven-wrapper.properties or customized the launcher scripts. To replace a legacy wrapper in full, use writeAll(Path, String).
      Parameters:
      wsDir - workspace root
      mavenVersion - Maven version to write into maven-wrapper.properties when creating it
      Returns:
      the number of files created (0 when all three already exist)
      Throws:
      IOException - if writing any of the files fails
    • writeAll

      public static void writeAll(Path wsDir, String mavenVersion) throws IOException
      Unconditionally (re)write all three wrapper files, overwriting any that already exist. Used to replace the legacy custom wrapper with the standard one — see isLegacyWrapper(Path).
      Parameters:
      wsDir - workspace root
      mavenVersion - Maven version to write into maven-wrapper.properties
      Throws:
      IOException - if writing any of the files fails
    • isLegacyWrapper

      public static boolean isLegacyWrapper(Path wsDir) throws IOException
      Report whether the workspace carries the legacy custom "minimal bootstrap" mvnw that pre-standardization plugin versions generated. Detected by the minimal bootstrap marker in the script header — the standard Apache launcher does not carry it, and neither would a user's own hand-written mvnw.
      Parameters:
      wsDir - workspace root
      Returns:
      true when mvnw exists and is the legacy custom launcher; false when absent, standard, or user-authored
      Throws:
      IOException - if mvnw exists but cannot be read
    • readPinnedVersion

      public static String readPinnedVersion(Path wsDir) throws IOException
      Read the pinned Maven version from an existing .mvn/wrapper/maven-wrapper.properties, or return null if the file does not exist or no version can be determined.

      The version is parsed from the standard distributionUrl key. A legacy wrapper's explicit maven.version key is used as a fallback so that migrating an old workspace preserves its pinned version.

      Parameters:
      wsDir - workspace root
      Returns:
      the pinned Maven version, or null when not determinable
      Throws:
      IOException - if the properties file exists but cannot be read
    • writePropertiesFile

      public static void writePropertiesFile(Path propsFile, String mavenVersion) throws IOException
      Write maven-wrapper.properties in the standard only-script form for the given Maven version. Creates the parent directory as needed. Overwrites any existing file.
      Parameters:
      propsFile - target path (typically .mvn/wrapper/maven-wrapper.properties)
      mavenVersion - Maven version (e.g. 4.0.0-rc-5)
      Throws:
      IOException - if writing fails
    • writeMvnwScript

      public static void writeMvnwScript(Path mvnw) throws IOException
      Write the standard Apache POSIX mvnw launcher script and mark it executable. The script reads distributionUrl from .mvn/wrapper/maven-wrapper.properties at runtime and downloads Maven on first use. Overwrites any existing file.
      Parameters:
      mvnw - target path (typically mvnw at workspace root)
      Throws:
      IOException - if writing fails
    • writeMvnwCmdScript

      public static void writeMvnwCmdScript(Path mvnwCmd) throws IOException
      Write the standard Apache Windows mvnw.cmd launcher script. The workspace .gitattributes *.cmd text eol=crlf rule is what keeps this file usable on Windows after checkout — without it, cmd.exe chokes on LF line endings (IKE-Network/ike-issues#189). Overwrites any existing file.
      Parameters:
      mvnwCmd - target path (typically mvnw.cmd at workspace root)
      Throws:
      IOException - if writing fails