Skip to content

Commit

Permalink
[MPH-183] Fix error in import path and small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Giovds committed Mar 15, 2024
1 parent 069ae93 commit 3cd4d9d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public InputLocation(int lineNumber, int columnNumber, InputSource source, Map<O
this.importedFrom = null;
}

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

public int getLineNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,18 +1660,18 @@ private void importDependencyManagement(
Model model,
ModelBuildingRequest request,
DefaultModelProblemCollector problems,
Collection<String> importIds) { // a chain of model ID's that caused this depMgt to be loaded?!
Collection<String> importIds) {
DependencyManagement depMgmt = model.getDependencyManagement();

if (depMgmt == null) {
return;
}

// the one that's causing the import to happen?
String importing = model.getGroupId() + ':' + model.getArtifactId() + ':' + model.getVersion();

importIds.add(importing);

// Model v4
List<org.apache.maven.api.model.DependencyManagement> importMgmts = null;

for (Iterator<Dependency> it = depMgmt.getDependencies().iterator(); it.hasNext(); ) {
Expand All @@ -1684,6 +1684,7 @@ private void importDependencyManagement(

it.remove();

// Model v3
DependencyManagement importMgmt = loadDependencyManagement(model, request, problems, dependency, importIds);

if (importMgmt != null) {
Expand All @@ -1693,6 +1694,7 @@ private void importDependencyManagement(

if (request.isLocationTracking()) {
// Keep track of why this DependencyManagement was imported.
// And map model v3 to model v4 -> importMgmt(v3).getDelegate() returns a v4 object
importMgmts.add(
org.apache.maven.api.model.DependencyManagement.newBuilder(importMgmt.getDelegate(), true)
.importedFrom(dependency.getDelegate().getLocation(""))
Expand All @@ -1705,10 +1707,8 @@ private void importDependencyManagement(

importIds.remove(importing);

org.apache.maven.api.model.Model updatedModel =
dependencyManagementImporter.importManagement(model.getDelegate(), importMgmts, request, problems);
model.update(updatedModel);
model.setDependencyManagement(new DependencyManagement(updatedModel.getDependencyManagement()));
model.update(
dependencyManagementImporter.importManagement(model.getDelegate(), importMgmts, request, problems));
}

private DependencyManagement loadDependencyManagement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,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(new InputLocation(bomLocation, dependency.getImportedFrom()))
.importedFrom(new InputLocation(bomLocation))
.build();
}
}

0 comments on commit 3cd4d9d

Please sign in to comment.