Skip to content

Commit

Permalink
Extract method, lazy create list
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 19, 2024
1 parent 096df9c commit a52f543
Showing 1 changed file with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,42 +564,49 @@ public void mergeRepositories(List<Repository> toAdd, boolean replace) {
// Infer inner reactor dependencies version
//
Model transformFileToRaw(Model model) {
List<Dependency> newDeps = new ArrayList<>(model.getDependencies().size());
boolean modified = false;
for (Dependency dep : model.getDependencies()) {
if (dep.getVersion() == null) {
Dependency.Builder depBuilder = null;
Model depModel = getRawModel(model.getPomFile(), dep.getGroupId(), dep.getArtifactId());
if (depModel != null) {
String version = depModel.getVersion();
InputLocation versionLocation = depModel.getLocation("version");
if (version == null && depModel.getParent() != null) {
version = depModel.getParent().getVersion();
versionLocation = depModel.getParent().getLocation("version");
}
depBuilder = Dependency.newBuilder(dep);
depBuilder.version(version).location("version", versionLocation);
if (dep.getGroupId() == null) {
String depGroupId = depModel.getGroupId();
InputLocation groupIdLocation = depModel.getLocation("groupId");
if (depGroupId == null && depModel.getParent() != null) {
depGroupId = depModel.getParent().getGroupId();
groupIdLocation = depModel.getParent().getLocation("groupId");
}
depBuilder.groupId(depGroupId).location("groupId", groupIdLocation);
}
List<Dependency> deps = model.getDependencies();
List<Dependency> newDeps = null;
for (int i = 0; i < deps.size(); i++) {
Dependency dep = deps.get(i);
Dependency newDep = inferDependencyVersion(model, dep);
if (newDep != null) {
if (newDeps == null) {
newDeps = new ArrayList<>(deps);
}
if (depBuilder != null) {
newDeps.add(depBuilder.build());
modified = true;
} else {
newDeps.add(dep);
newDeps.set(i, newDep);
}
}
if (newDeps != null) {
return model.withDependencies(newDeps);
} else {
return model;
}
}

private Dependency inferDependencyVersion(Model model, Dependency dep) {
Dependency.Builder depBuilder = null;
Model depModel = getRawModel(model.getPomFile(), dep.getGroupId(), dep.getArtifactId());
if (depModel != null) {
String version = depModel.getVersion();
InputLocation versionLocation = depModel.getLocation("version");
if (version == null && depModel.getParent() != null) {
version = depModel.getParent().getVersion();
versionLocation = depModel.getParent().getLocation("version");
}
depBuilder = Dependency.newBuilder(dep);
depBuilder.version(version).location("version", versionLocation);
if (dep.getGroupId() == null) {
String depGroupId = depModel.getGroupId();
InputLocation groupIdLocation = depModel.getLocation("groupId");
if (depGroupId == null && depModel.getParent() != null) {
depGroupId = depModel.getParent().getGroupId();
groupIdLocation = depModel.getParent().getLocation("groupId");
}
} else {
newDeps.add(dep);
depBuilder.groupId(depGroupId).location("groupId", groupIdLocation);
}
return depBuilder.build();
}
return modified ? model.withDependencies(newDeps) : model;
return null;
}

String replaceCiFriendlyVersion(Map<String, String> properties, String version) {
Expand Down

0 comments on commit a52f543

Please sign in to comment.