Skip to content

Conversation

@stechio
Copy link
Contributor

@stechio stechio commented May 12, 2025

As reported in #400, resolveCiFriendliesOnly flattenMode doesn't preserve POM content ordering, formatting or comments (KeepCommentsInPom is just a less-than-ideal workaround which quickly falls apart when comment nodes relate to sections rather than single elements); this is typically inconvenient, as users who don't apply other transformations may legitimately expect the output being identical to the input, interpolation aside.

This fix provides such functionality, interpolating the original POM without interfering with its formatting, ordering or comments. Leveraging the simple placeholder syntax (which doesn't require deserialization for modifications), the original POM content string is processed for interpolation as a whole.

En passant, this PR possibly fixes also #401 as, debugging the main fix, CiInterpolatorImpl.interpolate(...) initially behaved weirdly, assigning a spurious value to unresolved placeholders (any expression other than CI-friendly properties was resolved to its name (eg, "${test.version}" -> "test.version")?!):

Object value = existingAnswers.get(realExpr);
if (!wholeExpr.equals("${revision}")
        && !wholeExpr.contains("${sha1}")
        && !wholeExpr.contains("${changelist}")) {
    value = realExpr;
}

With this fix, any unknown placeholder is duly left unresolved:

Object value = null;
if (wholeExpr.equals("${revision}")
        || wholeExpr.contains("${sha1}")
        || wholeExpr.contains("${changelist}")) {
    value = existingAnswers.get(realExpr);
    . . .
}

Additionally, toString() method of PomProperty and CacheField has been overridden to improve debugging intelligibility.

Testing

…content ordering

`resolveCiFriendliesOnly` flattenMode doesn't retain POM content
ordering, formatting or comments (`KeepCommentsInPom` is just a less-
than-ideal workaround which quickly falls apart when comment nodes
relate to sections rather than single elements); this is typically
inconvenient, as users who don't apply other transformations may
legitimately expect the output being identical to the input,
interpolation aside.

This fix provides such functionality, interpolating the original POM
without interfering with its formatting, ordering or comments.

En passant, it possibly fixes also mojohaus#401 (not tested) as, debugging
the main fix, `CiInterpolatorImpl.interpolate(...)` behaved weirdly,
assigning a spurious value to unresolved placeholders.
@stechio stechio changed the title Fix #400 - resolveCiFriendliesOnly flattenMode messes up POM content ordering Fix #400 - Retain POM content ordering (and formatting) on resolveCiFriendliesOnly flattenMode May 12, 2025
@stechio stechio changed the title Fix #400 - Retain POM content ordering (and formatting) on resolveCiFriendliesOnly flattenMode Fix #400 - Preserve POM content ordering (and formatting) on resolveCiFriendliesOnly flattenMode May 12, 2025
…/issue-400-ci-friendly-version-model-reordering
@slawekjaranowski slawekjaranowski linked an issue Jun 15, 2025 that may be closed by this pull request
@slawekjaranowski slawekjaranowski merged commit 9e803ea into mojohaus:master Jun 16, 2025
20 checks passed
stechio added a commit to pdfclown/pdfclown-common that referenced this pull request Jun 24, 2025
stechio added a commit to pdfclown/pdfclown-common that referenced this pull request Jul 4, 2025
As flatten-maven-plugin now (1.7.1) incorporates the fix to preserve
POM content ordering (and formatting) on `resolveCiFriendliesOnly`
flattenMode (see
<mojohaus/flatten-maven-plugin#446>), its
dependency replaces the temporary pdfclown-common-maven-plugin
subproject.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

resolveCiFriendliesOnly garbles non ci-friendly property-placeholder if used in the same property Content gets heavily reordered after "flatten"

2 participants