Skip to content

Commit

Permalink
Track location
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Sep 11, 2024
1 parent 3998f13 commit 0b793cd
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.maven.api.di.Named;
import org.apache.maven.api.di.Singleton;
import org.apache.maven.api.model.Dependency;
import org.apache.maven.api.model.InputLocation;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Parent;
import org.apache.maven.api.services.ModelTransformer;
Expand Down Expand Up @@ -90,26 +91,39 @@ void handleReactorDependencies(ModelTransformerContext context, Model model, Pat
List<Dependency> newDeps = new ArrayList<>();
boolean modified = false;
String groupId = model.getGroupId();
InputLocation groupIdLocation = model.getLocation("groupId");
if (groupId == null) {
groupId = model.getParent().getGroupId();
groupIdLocation = model.getParent().getLocation("groupId");
}
for (Dependency dep : model.getDependencies()) {
if (dep.getGroupId() == null) {
dep = dep.withGroupId(groupId);
modified = true;
Dependency.Builder depBuilder = null;
String depGroupId = dep.getGroupId();
if (depGroupId == null) {
depGroupId = groupId;
depBuilder = Dependency.newBuilder(dep).groupId(groupId).location("groupId", groupIdLocation);
}
if (dep.getVersion() == null) {
Model depModel = context.getRawModel(model.getPomFile(), dep.getGroupId(), dep.getArtifactId());
Model depModel = context.getRawModel(model.getPomFile(), depGroupId, dep.getArtifactId());
if (depModel != null) {
String v = depModel.getVersion();
if (v == null && depModel.getParent() != null) {
v = depModel.getParent().getVersion();
String version = depModel.getVersion();
InputLocation versionLocation = depModel.getLocation("version");
if (version == null && depModel.getParent() != null) {
version = depModel.getParent().getVersion();
versionLocation = depModel.getParent().getLocation("version");
}
if (depBuilder == null) {
depBuilder = Dependency.newBuilder(dep);
}
dep = dep.withVersion(v);
modified = true;
depBuilder.version(version).location("version", versionLocation);
}
}
newDeps.add(dep);
if (depBuilder != null) {
newDeps.add(depBuilder.build());
modified = true;
} else {
newDeps.add(dep);
}
}
if (modified) {
builder.dependencies(newDeps);
Expand Down

0 comments on commit 0b793cd

Please sign in to comment.