Skip to content

Commit 38dc034

Browse files
committed
[MNG-7344] Recursive imported from tracking
1 parent 198c581 commit 38dc034

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

api/maven-api-model/src/main/java/org/apache/maven/api/model/InputLocation.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ public class InputLocation implements Serializable, InputLocationTracker {
3232
private final int columnNumber;
3333
private final InputSource source;
3434
private final Map<Object, InputLocation> locations;
35-
private final InputLocation importedFrom = null;
35+
private final InputLocation importedFrom;
3636

3737
public InputLocation(InputSource source) {
3838
this.lineNumber = -1;
3939
this.columnNumber = -1;
4040
this.source = source;
4141
this.locations = Collections.singletonMap(0, this);
42+
this.importedFrom = null;
4243
}
4344

4445
public InputLocation(int lineNumber, int columnNumber) {
@@ -55,13 +56,23 @@ public InputLocation(int lineNumber, int columnNumber, InputSource source, Objec
5556
this.source = source;
5657
this.locations =
5758
selfLocationKey != null ? Collections.singletonMap(selfLocationKey, this) : Collections.emptyMap();
59+
this.importedFrom = null;
5860
}
5961

6062
public InputLocation(int lineNumber, int columnNumber, InputSource source, Map<Object, InputLocation> locations) {
6163
this.lineNumber = lineNumber;
6264
this.columnNumber = columnNumber;
6365
this.source = source;
6466
this.locations = ImmutableCollections.copy(locations);
67+
this.importedFrom = null;
68+
}
69+
70+
public InputLocation(InputLocation original, InputLocation importedFrom) {
71+
this.lineNumber = original.lineNumber;
72+
this.columnNumber = original.columnNumber;
73+
this.source = original.source;
74+
this.locations = original.locations;
75+
this.importedFrom = importedFrom;
6576
}
6677

6778
public int getLineNumber() {

maven-model-builder/src/main/java/org/apache/maven/model/composition/DefaultDependencyManagementImporter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Model importManagement(
7676
+ "to the dependencyManagement section of the POM."));
7777
}
7878

79-
if (request.isLocationTracking()) {
79+
if (present == null && request.isLocationTracking()) {
8080
Dependency updatedDependency = updateWithImportedFrom(dependency, source);
8181
dependencies.put(key, updatedDependency);
8282
}
@@ -179,6 +179,8 @@ static Dependency updateWithImportedFrom(Dependency dependency, DependencyManage
179179
// We modify the input location that is used for the whole file.
180180
// This is likely correct because the POM hierarchy applies to the whole POM, not just one dependency.
181181
// TODO What to do now?!
182-
return Dependency.newBuilder(dependency, true).importedFrom(bomLocation).build();
182+
return Dependency.newBuilder(dependency, true)
183+
.importedFrom(new InputLocation(bomLocation, dependency.getImportedFrom()))
184+
.build();
183185
}
184186
}

0 commit comments

Comments
 (0)