Repository navigation
Commit bee24b3
authored
Add dependency insertion ordering auto-detection (#286)
addAligned() now detects whether the project's <dependencies> container
follows an ordering convention and inserts new dependencies at the correct
position, transparently to callers.
New AlignOptions.InsertionOrdering enum: NONE, ALPHA, SCOPE, SCOPE_THEN_ALPHA.
Follows the existing nullable-field convention (null = auto-detect), consistent
with VersionStyle, VersionSource, and PropertyNamingConvention.
Detection (detectInsertionOrdering): analyses consecutive dependency pairs with
a 75% threshold heuristic. Priority: SCOPE_THEN_ALPHA > SCOPE > ALPHA > NONE.
Fewer than 3 deps returns NONE (signal too weak). SCOPE and SCOPE_THEN_ALPHA
require actual scope variation; an all-same-scope alpha list returns ALPHA.
Plugged into detectConventions(), which returns null (not NONE) for the
insertionOrdering field when the direct-deps container is absent or too small,
so callers relying on auto-detection are not inadvertently blocked.
Canonical scope order: compile, provided, runtime, system, test, import.
Null or empty scope is normalised to compile (DEFAULT_SCOPE constant).
addAligned(Coordinates, AlignOptions) resolves the effective ordering (explicit
option wins, else auto-detect from the appropriate container) and inserts at the
anchor position computed by findInsertionAnchor(). ensureManagedDependency()
applies the same logic, independently detecting ordering from the managed
container — managed-only POMs with no direct <dependencies> are handled
correctly.
New InsertionOrderingTest (17 tests) covers detection and insertion for ALPHA,
SCOPE, SCOPE_THEN_ALPHA, weak-signal (< 3 deps), empty container, inconsistent
order, managed-only POM, null/empty scope, and explicit NONE override.
No existing public method signatures changed; all 340 existing tests pass.1 parent 3dd2661 commit bee24b3
4 files changed
Lines changed: 1001 additions & 7 deletions
File tree
- maven/src
- main/java/eu/maveniverse/domtrip/maven
- test/java/eu/maveniverse/domtrip/maven
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
76 | 92 | | |
77 | 93 | | |
78 | 94 | | |
| |||
92 | 108 | | |
93 | 109 | | |
94 | 110 | | |
| 111 | + | |
95 | 112 | | |
96 | 113 | | |
97 | 114 | | |
| |||
105 | 122 | | |
106 | 123 | | |
107 | 124 | | |
| 125 | + | |
108 | 126 | | |
109 | 127 | | |
110 | 128 | | |
| |||
113 | 131 | | |
114 | 132 | | |
115 | 133 | | |
| 134 | + | |
116 | 135 | | |
117 | 136 | | |
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
121 | 140 | | |
| 141 | + | |
122 | 142 | | |
123 | 143 | | |
124 | 144 | | |
| |||
131 | 151 | | |
132 | 152 | | |
133 | 153 | | |
134 | | - | |
| 154 | + | |
135 | 155 | | |
136 | 156 | | |
137 | 157 | | |
| |||
174 | 194 | | |
175 | 195 | | |
176 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
177 | 207 | | |
178 | 208 | | |
179 | 209 | | |
| |||
278 | 308 | | |
279 | 309 | | |
280 | 310 | | |
| 311 | + | |
281 | 312 | | |
282 | 313 | | |
283 | 314 | | |
| |||
320 | 351 | | |
321 | 352 | | |
322 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
323 | 366 | | |
324 | 367 | | |
325 | 368 | | |
| |||
372 | 415 | | |
373 | 416 | | |
374 | 417 | | |
375 | | - | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
376 | 425 | | |
377 | 426 | | |
378 | 427 | | |
0 commit comments