You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/08/24 11:30:43 UTC
(maven) branch master updated: Fix #12610: Preserve coordinates when merging InputLocation
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 3d7f6e7920 Fix #12610: Preserve coordinates when merging InputLocation
3d7f6e7920 is described below
commit 3d7f6e792060a0e825caebba0fff2f42e643b71b
Author: ulofiai <ul...@protonmail.com>
AuthorDate: Mon Aug 24 19:30:36 2026 +0800
Fix #12610: Preserve coordinates when merging InputLocation
The merge logic in the InputLocation Velocity template
(src/mdo/java/InputLocation.java) always discarded line and column
coordinates to -1/-1 when creating merged results. This fix preserves
the dominant input's coordinates, falling back to the other input when
coordinates are unknown. The boolean merge overload uses the
source-dominant parameter to select the primary location; the indexed
list merge prefers the target. Regression tests cover both merge
overloads.
Closes #12747
---
.../maven/impl/model/MavenModelMergerTest.java | 33 ++++++++++++++++++++++
src/mdo/java/InputLocation.java | 24 ++++++++++++++--
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java
index d6bbdedbd5..bc943e6d6d 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/MavenModelMergerTest.java
@@ -20,6 +20,8 @@
import java.util.Collections;
+import org.apache.maven.api.model.InputLocation;
+import org.apache.maven.api.model.InputSource;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Prerequisites;
import org.apache.maven.api.model.Profile;
@@ -31,6 +33,37 @@
class MavenModelMergerTest {
private MavenModelMerger modelMerger = new MavenModelMerger();
+ @Test
+ void testMergeInputLocationCoordinates() {
+ InputLocation target = InputLocation.of(10, 20, InputSource.of("target", "target.xml"));
+ InputLocation source = InputLocation.of(30, 40, InputSource.of("source", "source.xml"));
+
+ assertCoordinates(30, 40, InputLocation.merge(target, source, true));
+ assertCoordinates(10, 20, InputLocation.merge(target, source, false));
+
+ InputLocation unknownTarget = InputLocation.of(-1, -1, target.getSource());
+ assertCoordinates(30, 40, InputLocation.merge(unknownTarget, source, false));
+
+ InputLocation unknownSource = InputLocation.of(-1, -1, source.getSource());
+ assertCoordinates(10, 20, InputLocation.merge(target, unknownSource, true));
+ }
+
+ @Test
+ void testMergeListInputLocationCoordinates() {
+ InputLocation target = InputLocation.of(10, 20, InputSource.of("target", "target.xml"));
+ InputLocation source = InputLocation.of(30, 40, InputSource.of("source", "source.xml"));
+
+ assertCoordinates(10, 20, InputLocation.merge(target, source, Collections.emptyList()));
+
+ InputLocation unknownTarget = InputLocation.of(-1, -1, target.getSource());
+ assertCoordinates(30, 40, InputLocation.merge(unknownTarget, source, Collections.emptyList()));
+ }
+
+ private static void assertCoordinates(int lineNumber, int columnNumber, InputLocation location) {
+ assertEquals(lineNumber, location.getLineNumber());
+ assertEquals(columnNumber, location.getColumnNumber());
+ }
+
// modelVersion is neither inherited nor injected
@Test
void testMergeModelModelVersion() {
diff --git a/src/mdo/java/InputLocation.java b/src/mdo/java/InputLocation.java
index c01343ad67..d916f1985a 100644
--- a/src/mdo/java/InputLocation.java
+++ b/src/mdo/java/InputLocation.java
@@ -315,9 +315,19 @@ public static InputLocation merge(InputLocation target, InputLocation source, bo
locations.putAll(sourceDominant ? sourceLocations : targetLocations);
}
+#if ( $isMavenModel )
+ InputLocation location = sourceDominant ? source : target;
+ if (location.getLineNumber() < 0 && location.getColumnNumber() < 0) {
+ location = sourceDominant ? target : source;
+ }
+#end
+
return new InputLocation(
#if ( $isMavenModel )
- -1, -1, InputSource.merge(source.getSource(), target.getSource()), locations);
+ location.getLineNumber(),
+ location.getColumnNumber(),
+ InputSource.merge(source.getSource(), target.getSource()),
+ locations);
#else
target.getLineNumber(), target.getColumnNumber(), target.getSource(), locations);
#end
@@ -359,9 +369,19 @@ public static InputLocation merge(InputLocation target, InputLocation source, Co
}
}
+#if ( $isMavenModel )
+ InputLocation location = target;
+ if (location.getLineNumber() < 0 && location.getColumnNumber() < 0) {
+ location = source;
+ }
+#end
+
return new InputLocation(
#if ( $isMavenModel )
- -1, -1, InputSource.merge(source.getSource(), target.getSource()), locations);
+ location.getLineNumber(),
+ location.getColumnNumber(),
+ InputSource.merge(source.getSource(), target.getSource()),
+ locations);
#else
target.getLineNumber(), target.getColumnNumber(), target.getSource(), locations);
#end