Search in sources :

Example 1 with Library

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

the class UpgradeApplicatorTests method whenUpgradeIsAppliedToLibraryWithVersionPropertyThenGradlePropertiesIsUpdated.

@Test
void whenUpgradeIsAppliedToLibraryWithVersionPropertyThenGradlePropertiesIsUpdated() throws IOException {
    File bom = new File(this.temp, "bom.gradle");
    FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
    File gradleProperties = new File(this.temp, "gradle.properties");
    FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
    new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply(new Upgrade(new Library("Kotlin", new LibraryVersion(DependencyVersion.parse("1.3.70"), null), null, null, null), DependencyVersion.parse("1.4")));
    Properties properties = new Properties();
    try (InputStream in = new FileInputStream(gradleProperties)) {
        properties.load(in);
    }
    assertThat(properties).containsOnly(entry("a", "alpha"), entry("b", "bravo"), entry("kotlinVersion", "1.4"), entry("t", "tango"));
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LibraryVersion(org.springframework.boot.build.bom.Library.LibraryVersion) Library(org.springframework.boot.build.bom.Library) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.jupiter.api.Test)

Example 2 with Library

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

the class UpgradeApplicatorTests method whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated.

@Test
void whenUpgradeIsAppliedToLibraryWithVersionThenBomIsUpdated() throws IOException {
    File bom = new File(this.temp, "bom.gradle");
    FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
    String originalContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
    File gradleProperties = new File(this.temp, "gradle.properties");
    FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
    new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply(new Upgrade(new Library("ActiveMQ", new LibraryVersion(DependencyVersion.parse("5.15.11"), null), null, null, null), DependencyVersion.parse("5.16")));
    String bomContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
    assertThat(bomContents.length()).isEqualTo(originalContents.length() - 3);
}
Also used : LibraryVersion(org.springframework.boot.build.bom.Library.LibraryVersion) Library(org.springframework.boot.build.bom.Library) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with Library

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

the class UpgradeApplicatorTests method whenUpgradeIsAppliedToLibraryWithAlignedVersionThenBomIsUpdated.

@Test
void whenUpgradeIsAppliedToLibraryWithAlignedVersionThenBomIsUpdated() throws IOException {
    File bom = new File(this.temp, "bom.gradle");
    FileCopyUtils.copy(new File("src/test/resources/bom.gradle"), bom);
    String originalContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
    File gradleProperties = new File(this.temp, "gradle.properties");
    FileCopyUtils.copy(new File("src/test/resources/gradle.properties"), gradleProperties);
    new UpgradeApplicator(bom.toPath(), gradleProperties.toPath()).apply(new Upgrade(new Library("OAuth2 OIDC SDK", new LibraryVersion(DependencyVersion.parse("8.36.1"), null), null, null, null), DependencyVersion.parse("8.36.2")));
    String bomContents = new String(Files.readAllBytes(bom.toPath()), StandardCharsets.UTF_8);
    assertThat(bomContents.length()).isEqualTo(originalContents.length());
    assertThat(bomContents).contains("version(\"8.36.2\")");
}
Also used : LibraryVersion(org.springframework.boot.build.bom.Library.LibraryVersion) Library(org.springframework.boot.build.bom.Library) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with Library

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

the class InteractiveUpgradeResolver method determineResolvedVersionOptions.

private List<VersionOption> determineResolvedVersionOptions(Library library) {
    Map<String, SortedSet<DependencyVersion>> moduleVersions = new LinkedHashMap<>();
    DependencyVersion libraryVersion = library.getVersion().getVersion();
    for (Group group : library.getGroups()) {
        for (Module module : group.getModules()) {
            moduleVersions.put(group.getId() + ":" + module.getName(), getLaterVersionsForModule(group.getId(), module.getName(), libraryVersion));
        }
        for (String bom : group.getBoms()) {
            moduleVersions.put(group.getId() + ":" + bom, getLaterVersionsForModule(group.getId(), bom, libraryVersion));
        }
        for (String plugin : group.getPlugins()) {
            moduleVersions.put(group.getId() + ":" + plugin, getLaterVersionsForModule(group.getId(), plugin, libraryVersion));
        }
    }
    List<DependencyVersion> allVersions = moduleVersions.values().stream().flatMap(SortedSet::stream).distinct().filter((dependencyVersion) -> isPermitted(dependencyVersion, library.getProhibitedVersions())).collect(Collectors.toList());
    if (allVersions.isEmpty()) {
        return Collections.emptyList();
    }
    return allVersions.stream().map((version) -> new ResolvedVersionOption(version, getMissingModules(moduleVersions, version))).collect(Collectors.toList());
}
Also used : UserInputHandler(org.gradle.api.internal.tasks.userinput.UserInputHandler) Module(org.springframework.boot.build.bom.Library.Module) SortedSet(java.util.SortedSet) DependencyVersions(org.springframework.boot.build.bom.Library.DependencyVersions) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) Collection(java.util.Collection) Group(org.springframework.boot.build.bom.Library.Group) Set(java.util.Set) HashMap(java.util.HashMap) Library(org.springframework.boot.build.bom.Library) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) UpgradePolicy(org.springframework.boot.build.bom.UpgradePolicy) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DependencyVersion(org.springframework.boot.build.bom.bomr.version.DependencyVersion) List(java.util.List) Map(java.util.Map) VersionAlignment(org.springframework.boot.build.bom.Library.VersionAlignment) ProhibitedVersion(org.springframework.boot.build.bom.Library.ProhibitedVersion) Collections(java.util.Collections) InvalidUserDataException(org.gradle.api.InvalidUserDataException) StringUtils(org.springframework.util.StringUtils) Group(org.springframework.boot.build.bom.Library.Group) DependencyVersion(org.springframework.boot.build.bom.bomr.version.DependencyVersion) Module(org.springframework.boot.build.bom.Library.Module) SortedSet(java.util.SortedSet) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with Library

use of org.springframework.boot.build.bom.Library 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

Library (org.springframework.boot.build.bom.Library)6 File (java.io.File)3 Test (org.junit.jupiter.api.Test)3 LibraryVersion (org.springframework.boot.build.bom.Library.LibraryVersion)3 HashSet (java.util.HashSet)2 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 DependencyVersions (org.springframework.boot.build.bom.Library.DependencyVersions)2 Group (org.springframework.boot.build.bom.Library.Group)2 Module (org.springframework.boot.build.bom.Library.Module)2 VersionAlignment (org.springframework.boot.build.bom.Library.VersionAlignment)2 DependencyVersion (org.springframework.boot.build.bom.bomr.version.DependencyVersion)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1