Search in sources :

Example 1 with DependencyVersions

use of org.springframework.boot.build.bom.Library.DependencyVersions in project spring-boot by spring-projects.

the class InteractiveUpgradeResolver method alignedVersionOption.

private VersionOption alignedVersionOption(Library library, Map<String, Library> libraries) {
    VersionAlignment versionAlignment = library.getVersion().getVersionAlignment();
    Library alignmentLibrary = libraries.get(versionAlignment.getLibraryName());
    DependencyVersions dependencyVersions = alignmentLibrary.getDependencyVersions();
    if (dependencyVersions == null) {
        throw new InvalidUserDataException("Cannot align with library '" + versionAlignment.getLibraryName() + "' as it does not define any dependency versions");
    }
    if (!dependencyVersions.available()) {
        return null;
    }
    Set<String> versions = new HashSet<>();
    for (Group group : library.getGroups()) {
        for (Module module : group.getModules()) {
            String version = dependencyVersions.getVersion(group.getId(), module.getName());
            if (version != null) {
                versions.add(version);
            }
        }
    }
    if (versions.isEmpty()) {
        throw new InvalidUserDataException("Cannot align with library '" + versionAlignment.getLibraryName() + "' as its dependency versions do not include any of this library's modules");
    }
    if (versions.size() > 1) {
        throw new InvalidUserDataException("Cannot align with library '" + versionAlignment.getLibraryName() + "' as it uses multiple different versions of this library's modules");
    }
    DependencyVersion version = DependencyVersion.parse(versions.iterator().next());
    return library.getVersion().getVersion().equals(version) ? null : new AlignedVersionOption(version, alignmentLibrary);
}
Also used : Group(org.springframework.boot.build.bom.Library.Group) DependencyVersions(org.springframework.boot.build.bom.Library.DependencyVersions) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DependencyVersion(org.springframework.boot.build.bom.bomr.version.DependencyVersion) Library(org.springframework.boot.build.bom.Library) VersionAlignment(org.springframework.boot.build.bom.Library.VersionAlignment) Module(org.springframework.boot.build.bom.Library.Module) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Library (org.springframework.boot.build.bom.Library)1 DependencyVersions (org.springframework.boot.build.bom.Library.DependencyVersions)1 Group (org.springframework.boot.build.bom.Library.Group)1 Module (org.springframework.boot.build.bom.Library.Module)1 VersionAlignment (org.springframework.boot.build.bom.Library.VersionAlignment)1 DependencyVersion (org.springframework.boot.build.bom.bomr.version.DependencyVersion)1