Class ManifestWriter

java.lang.Object
network.ike.workspace.ManifestWriter

public final class ManifestWriter extends Object
Updates specific fields in workspace.yaml while preserving comments, formatting, and structure.

Uses targeted text replacement rather than YAML serialization to avoid stripping comments or reordering keys.

  • Method Details

    • updateBranches

      public static void updateBranches(Path manifestPath, Map<String,String> branchUpdates) throws IOException
      Update the branch field for one or more subprojects.
      Parameters:
      manifestPath - path to workspace.yaml
      branchUpdates - map of subproject name to new branch value
      Throws:
      IOException - if the file cannot be read or written
    • updateDefaultMavenVersion

      public static void updateDefaultMavenVersion(Path manifestPath, String newVersion) throws IOException
      Update the maven-version field in the defaults section.
      Parameters:
      manifestPath - path to workspace.yaml
      newVersion - the new Maven version string
      Throws:
      IOException - if the file cannot be read or written
    • updateMavenVersions

      public static void updateMavenVersions(Path manifestPath, Map<String,String> versionUpdates) throws IOException
      Update the maven-version field for one or more subprojects.
      Parameters:
      manifestPath - path to workspace.yaml
      versionUpdates - map of subproject name to new maven-version value
      Throws:
      IOException - if the file cannot be read or written
    • stripVersionQualifiers

      public static void stripVersionQualifiers(Path manifestPath, String qualifier) throws IOException
      Strip a branch qualifier from every version: field in the manifest, restoring the base -SNAPSHOT form. This is the inverse of the version qualification ws:feature-start applies; ws:feature-finish calls it so the manifest's recorded versions — each subproject's version: and, schema 1.1+, the workspace-root: version: — return to base when a feature lands, instead of being stranded on X-<feature>-SNAPSHOT (ike-issues#768/#763).

      Only version: field values carrying the exact qualifier are touched: maven-version:, branch:, and unrelated fields are left alone, as are versions with a different (or no) qualifier. The operation is idempotent.

      Parameters:
      manifestPath - path to workspace.yaml
      qualifier - the branch qualifier to strip (e.g. "view-options-popup")
      Throws:
      IOException - if the file cannot be read or written
    • updateShas

      public static void updateShas(Path manifestPath, Map<String,String> shaUpdates) throws IOException
      Update the sha field for one or more subprojects. If the sha field does not exist in the subproject block, it is inserted after the branch field.
      Parameters:
      manifestPath - path to workspace.yaml
      shaUpdates - map of subproject name to SHA value
      Throws:
      IOException - if the file cannot be read or written
    • addOrUpdateSubprojectField

      public static String addOrUpdateSubprojectField(String yaml, String subprojectName, String field, String newValue, String afterField)
      Update a field in a subproject block, or insert it after a reference field if it doesn't exist yet.

      If the field exists multiple times in the block (a corrupted state from a prior version of this writer, see #387), all duplicates are collapsed into a single entry with the new value.

      Parameters:
      yaml - full YAML content
      subprojectName - the subproject key
      field - the field name to update or insert
      newValue - the new value (pre-quoted if needed)
      afterField - insert after this field if the target field is absent
      Returns:
      updated YAML content
    • subprojectFieldExists

      public static boolean subprojectFieldExists(String yaml, String subprojectName, String field)
      Return whether the given field exists in the given subproject's block. Block-bounded scan so a same-named field in a sibling subproject does not produce a false positive.

      This is the explicit replacement for the historical pattern of calling updateSubprojectField(String, String, String, String) and comparing the result to the original yaml — that approach (still used inside the pre-fix addOrUpdateSubprojectField(String, String, String, String, String)) couldn't distinguish "field absent" from "field present with same value" and produced the duplicate-key bug fixed in IKE-Network/ike-issues#387.

      Parameters:
      yaml - full YAML content
      subprojectName - the subproject key
      field - the field name
      Returns:
      true if the field appears at least once in the subproject's block
    • collapseDuplicateSubprojectFields

      public static String collapseDuplicateSubprojectFields(String yaml)
      Collapse duplicate field entries in every subproject block.

      For each subproject, if any field name appears more than once in the block, keep only the LAST occurrence (matches YAML last-wins semantics for duplicate keys) and remove the rest.

      Safety-net cleanup for workspaces affected by the pre-fix duplicate-key bug (#387). Idempotent: running on a clean file is a no-op.

      Parameters:
      yaml - full YAML content
      Returns:
      yaml with duplicates collapsed
    • updateSubprojectField

      public static String updateSubprojectField(String yaml, String subprojectName, String field, String newValue)
      Update a named field within a subproject block in the YAML text.
      Parameters:
      yaml - full YAML content
      subprojectName - the subproject key to find
      field - the field name within the subproject block
      newValue - the new value
      Returns:
      updated YAML content
    • updateSubprojectBranch

      public static String updateSubprojectBranch(String yaml, String subprojectName, String newBranch)
      Update the branch field for a single subproject in the YAML text. If the subproject block does not yet declare a branch: field, it is inserted after the repo: line so the manifest and git state stay in sync (see issue #159).
      Parameters:
      yaml - full YAML content
      subprojectName - the subproject key to find
      newBranch - the new branch value
      Returns:
      updated YAML content (unchanged if the subproject is absent)