Class ScaffoldMojoSupport

java.lang.Object
network.ike.plugin.scaffold.ScaffoldMojoSupport

public final class ScaffoldMojoSupport extends Object
Shared plumbing for ike:scaffold-draft, ike:scaffold-publish, and ike:scaffold-revert.

Resolves the scaffold tree (manifest + templates), loads per-scope lockfiles from disk, and offers pure-function helpers the three mojos use. Written as a final class with static methods so the mojos can share wiring without inheritance.

  • Field Details

    • MANIFEST_FILE

      public static final String MANIFEST_FILE
      File name of the manifest inside a scaffold tree.
      See Also:
    • PROJECT_LOCKFILE_REL

      public static final String PROJECT_LOCKFILE_REL
      Relative path of the per-project lockfile.
      See Also:
    • USER_LOCKFILE_REL

      public static final String USER_LOCKFILE_REL
      Relative path of the per-user lockfile.
      See Also:
  • Method Details

    • resolveProjectRoot

      public static Path resolveProjectRoot(String projectRootOverride, org.apache.maven.api.Session session)
      Resolve the effective project root for a scaffold goal.

      Goals annotated projectRequired = false cannot rely on Maven's parameter-default expansion of ${project.basedir} — Maven 4 leaves the placeholder uninterpolated when no project is required, even when one is in scope. Callers therefore pass an explicit projectRoot parameter when supplied by the user; when blank, this helper derives the directory from Session#getTopDirectory() (the directory Maven was launched from).

      The result is null when no pom.xml sits at the resolved location, which the calling mojo treats as fresh-machine bootstrap (user scope only, no project scope).

      Parameters:
      projectRootOverride - raw value of the projectRoot parameter; null/blank means "auto-detect"
      session - Maven 4 session; required for auto-detection. May be null in tests that supply an explicit override.
      Returns:
      absolute project root, or null when no project is in scope at the resolved location
    • loadManifest

      public static ScaffoldManifest loadManifest(Path scaffoldDir)
      Resolve the manifest file at the root of a scaffold tree.
      Parameters:
      scaffoldDir - the directory containing "scaffold-manifest.yaml" and templates
      Returns:
      parsed manifest
      Throws:
      ScaffoldException - if the directory or manifest is missing
    • projectLockfilePath

      public static Path projectLockfilePath(Path projectRoot)
      Resolve the project lockfile path, creating nothing.
      Parameters:
      projectRoot - project base directory; may be null when no project is in scope
      Returns:
      absolute path to {projectRoot}/.ike/scaffold.lock, or null if projectRoot is null
    • userLockfilePath

      public static Path userLockfilePath(Path userHome)
      Resolve the user lockfile path, creating nothing.
      Parameters:
      userHome - the user's home directory; required
      Returns:
      absolute path to {userHome}/.ike/scaffold.lock
    • loadLockfileOrEmpty

      public static ScaffoldLockfile loadLockfileOrEmpty(Path lockfilePath)
      Load a lockfile from disk, returning ScaffoldLockfile.empty() when the file is absent.
      Parameters:
      lockfilePath - path to the lockfile; may be null (returns empty)
      Returns:
      the loaded lockfile, or an empty lockfile
    • renderPlanReport

      public static String renderPlanReport(ScaffoldPlan plan, ScaffoldScope scope)
      Render a draft-style listing of a plan suitable for log output.

      Lines look like:

      [INSTALL]  mvnw                         -> /path/to/mvnw
      [UPDATE]   .mvn/maven.config            -> refresh
      [SKIP]     .gitignore                   user-edited; +3/-1
      [OK]       ~/.m2/settings.xml           up-to-date
      [USER]     ~/.gitconfig                 deferred to user value for [core].hooksPath
      
      Parameters:
      plan - the plan to render
      scope - the scope the plan was built for (used as a header)
      Returns:
      multi-line human-readable report (no trailing newline)
    • renderOrphanReport

      public static String renderOrphanReport(List<OrphanEntry> orphans, ScaffoldScope scope)
      Render an orphan listing suitable for log output. Orphans are lockfile entries the current manifest no longer ships.
      Parameters:
      orphans - the orphans found by OrphanScanner
      scope - the scope the scan targeted (used as a header)
      Returns:
      multi-line human-readable report (no trailing newline)
    • countActions

      public static ScaffoldMojoSupport.Counts countActions(ScaffoldPlan plan)
      One-line summary of what the plan would change, for post-publish telemetry and draft headers.
      Parameters:
      plan - the plan to summarise
      Returns:
      counts of each action type
    • renderRevertReport

      public static String renderRevertReport(ScaffoldReverter.RevertResult result, ScaffoldScope scope)
      Render a revert-outcome listing suitable for log output.
      Parameters:
      result - the revert result
      scope - the scope the revert targeted
      Returns:
      multi-line human-readable report (no trailing newline)
    • logLines

      public static void logLines(org.apache.maven.api.plugin.Log log, String multiLine)
      Write a batch of plan-report lines through the supplied log. Each \n-separated segment becomes a separate log.info call so Maven's level/colour formatting works on each line.
      Parameters:
      log - the mojo log
      multiLine - multi-line text
    • scopesToProcess

      public static List<ScaffoldScope> scopesToProcess(boolean inProject)
      Scopes the mojos should run for given a project-required context: in a project, both scopes apply; standalone, only user.
      Parameters:
      inProject - whether the mojo invocation has a project
      Returns:
      scopes to process, in order