Skip to content

Commit

Permalink
[MNG-7344] Recursive imported from tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
juulhobert committed Feb 9, 2024
1 parent 198c581 commit 38dc034
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public class InputLocation implements Serializable, InputLocationTracker {
private final int columnNumber;
private final InputSource source;
private final Map<Object, InputLocation> locations;
private final InputLocation importedFrom = null;
private final InputLocation importedFrom;

public InputLocation(InputSource source) {
this.lineNumber = -1;
this.columnNumber = -1;
this.source = source;
this.locations = Collections.singletonMap(0, this);
this.importedFrom = null;
}

public InputLocation(int lineNumber, int columnNumber) {
Expand All @@ -55,13 +56,23 @@ public InputLocation(int lineNumber, int columnNumber, InputSource source, Objec
this.source = source;
this.locations =
selfLocationKey != null ? Collections.singletonMap(selfLocationKey, this) : Collections.emptyMap();
this.importedFrom = null;
}

public InputLocation(int lineNumber, int columnNumber, InputSource source, Map<Object, InputLocation> locations) {
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
this.source = source;
this.locations = ImmutableCollections.copy(locations);
this.importedFrom = null;
}

public InputLocation(InputLocation original, InputLocation importedFrom) {
this.lineNumber = original.lineNumber;
this.columnNumber = original.columnNumber;
this.source = original.source;
this.locations = original.locations;
this.importedFrom = importedFrom;
}

public int getLineNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Model importManagement(
+ "to the dependencyManagement section of the POM."));
}

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

0 comments on commit 38dc034

Please sign in to comment.