Class ManifestWriter
Uses targeted text replacement rather than YAML serialization to avoid stripping comments or reordering keys.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordHalf-open character offsets of a subproject's body in the YAML text. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddOrUpdateSubprojectField(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.static StringCollapse duplicate field entries in every subproject block.static voidstripVersionQualifiers(Path manifestPath, String qualifier) Strip a branch qualifier from everyversion:field in the manifest, restoring the base-SNAPSHOTform.static booleansubprojectFieldExists(String yaml, String subprojectName, String field) Return whether the given field exists in the given subproject's block.static voidupdateBranches(Path manifestPath, Map<String, String> branchUpdates) Update the branch field for one or more subprojects.static voidupdateDefaultMavenVersion(Path manifestPath, String newVersion) Update the maven-version field in the defaults section.static voidupdateMavenVersions(Path manifestPath, Map<String, String> versionUpdates) Update the maven-version field for one or more subprojects.static voidupdateShas(Path manifestPath, Map<String, String> shaUpdates) Update the sha field for one or more subprojects.static StringupdateSubprojectBranch(String yaml, String subprojectName, String newBranch) Update the branch field for a single subproject in the YAML text.static StringupdateSubprojectField(String yaml, String subprojectName, String field, String newValue) Update a named field within a subproject block in the YAML text.
-
Method Details
-
updateBranches
public static void updateBranches(Path manifestPath, Map<String, String> branchUpdates) throws IOExceptionUpdate the branch field for one or more subprojects.- Parameters:
manifestPath- path to workspace.yamlbranchUpdates- 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.yamlnewVersion- 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 IOExceptionUpdate the maven-version field for one or more subprojects.- Parameters:
manifestPath- path to workspace.yamlversionUpdates- map of subproject name to new maven-version value- Throws:
IOException- if the file cannot be read or written
-
stripVersionQualifiers
Strip a branch qualifier from everyversion:field in the manifest, restoring the base-SNAPSHOTform. This is the inverse of the version qualificationws:feature-startapplies;ws:feature-finishcalls it so the manifest's recorded versions — each subproject'sversion:and, schema 1.1+, theworkspace-root:version:— return to base when a feature lands, instead of being stranded onX-<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.yamlqualifier- the branch qualifier to strip (e.g."view-options-popup")- Throws:
IOException- if the file cannot be read or written
-
updateShas
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.yamlshaUpdates- 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 contentsubprojectName- the subproject keyfield- the field name to update or insertnewValue- the new value (pre-quoted if needed)afterField- insert after this field if the target field is absent- Returns:
- updated YAML content
-
subprojectFieldExists
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-fixaddOrUpdateSubprojectField(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 contentsubprojectName- the subproject keyfield- the field name- Returns:
- true if the field appears at least once in the subproject's block
-
collapseDuplicateSubprojectFields
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 contentsubprojectName- the subproject key to findfield- the field name within the subproject blocknewValue- the new value- Returns:
- updated YAML content
-
updateSubprojectBranch
Update the branch field for a single subproject in the YAML text. If the subproject block does not yet declare abranch:field, it is inserted after therepo:line so the manifest and git state stay in sync (see issue #159).- Parameters:
yaml- full YAML contentsubprojectName- the subproject key to findnewBranch- the new branch value- Returns:
- updated YAML content (unchanged if the subproject is absent)
-