import org.apache.maven.model.Model; //导入方法依赖的package包/类
private List updateParentIfPossible(ModelWrapper wrapper, Versions versions,
Model model, List sourceChanges) {
String rootProjectName = wrapper.projectName();
String rootProjectGroupId = wrapper.groupId();
List changes = new ArrayList<>(sourceChanges);
if (model.getParent() == null || isEmpty(model.getParent().getVersion())) {
log.debug("Can't set the value for parent... Will return {}", sourceChanges);
return changes;
}
if (model.getGroupId() != null && !model.getGroupId().equals(rootProjectGroupId)) {
log.info("Will not update the project's [{}] parent [{}] since its group id [{}] is not equal the parent group id [{}]",
model.getArtifactId(), model.getParent().getArtifactId(), model.getGroupId(), rootProjectGroupId);
return changes;
}
String parentGroupId = model.getParent().getGroupId();
String parentArtifactId = model.getParent().getArtifactId();
log.debug("Searching for a version of parent [{}:{}]", parentGroupId, parentArtifactId);
String oldVersion = model.getParent().getVersion();
String version = versions.versionForProject(parentArtifactId);
log.debug("Found version is [{}]", version);
if (isEmpty(version)) {
if (hasText(model.getParent().getRelativePath())) {
version = versions.versionForProject(rootProjectName);
} else {
log.warn("There is no info on the [{}:{}] version", parentGroupId, parentArtifactId);
return changes;
}
}
if (oldVersion.equals(version)) {
log.debug("Won't update the version of parent [{}:{}] since you're already using the proper one", parentGroupId, parentArtifactId);
return changes;
}
log.info("Setting version of parent [{}] to [{}] for module [{}]", parentArtifactId,
version, model.getArtifactId());
if (hasText(version)) {
changes.add(new VersionChange(parentGroupId, parentArtifactId, oldVersion, version));
}
return changes;
}