From e10ac76761206c679dd4470c516937b6922edd25 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 20 Sep 2023 15:43:03 -0700 Subject: [PATCH 1/2] Polish --- .../bomr/StandardLibraryUpdateResolver.java | 12 +--- .../build/bom/bomr/UpgradeDependencies.java | 60 +++++++++---------- .../platform/socket/DomainSocket.java | 2 +- 3 files changed, 31 insertions(+), 43 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java index 1eddf80d75..a9a403164e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/StandardLibraryUpdateResolver.java @@ -51,16 +51,8 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver { StandardLibraryUpdateResolver(VersionResolver versionResolver, List> predicates) { this.versionResolver = versionResolver; - BiPredicate predicate = null; - for (BiPredicate p : predicates) { - if (predicate == null) { - predicate = p; - } - else { - predicate = predicate.and(p); - } - } - this.predicate = predicate; + this.predicate = (library, dependencyVersion) -> predicates.stream() + .allMatch((predicate) -> predicate.test(library, dependencyVersion)); } @Override diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java index 96a4eecb13..b4c9c7e218 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/UpgradeDependencies.java @@ -35,6 +35,7 @@ import java.util.stream.Collectors; import javax.inject.Inject; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; import org.gradle.api.DefaultTask; import org.gradle.api.InvalidUserDataException; import org.gradle.api.internal.tasks.userinput.UserInputHandler; @@ -228,42 +229,37 @@ public abstract class UpgradeDependencies extends DefaultTask { } protected List> determineUpdatePredicates(Milestone milestone) { - BiPredicate compilesWithUpgradePolicy = (library, - candidate) -> this.bom.getUpgrade().getPolicy().test(candidate, library.getVersion().getVersion()); - BiPredicate isAnUpgrade = (library, - candidate) -> library.getVersion().getVersion().isUpgrade(candidate, this.movingToSnapshots); - BiPredicate isPermitted = (library, candidate) -> { - for (ProhibitedVersion prohibitedVersion : library.getProhibitedVersions()) { - String candidateString = candidate.toString(); - if (prohibitedVersion.getRange() != null - && prohibitedVersion.getRange().containsVersion(new DefaultArtifactVersion(candidateString))) { - return false; - } - for (String startsWith : prohibitedVersion.getStartsWith()) { - if (candidateString.startsWith(startsWith)) { - return false; - } - } - for (String endsWith : prohibitedVersion.getEndsWith()) { - if (candidateString.endsWith(endsWith)) { - return false; - } - } - for (String contains : prohibitedVersion.getContains()) { - if (candidateString.contains(contains)) { - return false; - } - } - } - return true; - }; List> updatePredicates = new ArrayList<>(); - updatePredicates.add(compilesWithUpgradePolicy); - updatePredicates.add(isAnUpgrade); - updatePredicates.add(isPermitted); + updatePredicates.add(this::compilesWithUpgradePolicy); + updatePredicates.add(this::isAnUpgrade); + updatePredicates.add(this::isNotProhibited); return updatePredicates; } + private boolean compilesWithUpgradePolicy(Library library, DependencyVersion candidate) { + return this.bom.getUpgrade().getPolicy().test(candidate, library.getVersion().getVersion()); + } + + private boolean isAnUpgrade(Library library, DependencyVersion candidate) { + return library.getVersion().getVersion().isUpgrade(candidate, this.movingToSnapshots); + } + + private boolean isNotProhibited(Library library, DependencyVersion candidate) { + return !library.getProhibitedVersions() + .stream() + .anyMatch((prohibited) -> isProhibited(prohibited, candidate.toString())); + } + + private boolean isProhibited(ProhibitedVersion prohibited, String candidate) { + boolean result = false; + VersionRange range = prohibited.getRange(); + result = result || (range != null && range.containsVersion(new DefaultArtifactVersion(candidate))); + result = result || prohibited.getStartsWith().stream().anyMatch(candidate::startsWith); + result = result || prohibited.getStartsWith().stream().anyMatch(candidate::endsWith); + result = result || prohibited.getStartsWith().stream().anyMatch(candidate::contains); + return result; + } + private List matchingLibraries() { List matchingLibraries = this.bom.getLibraries() .stream() diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java index 1c4e8eb2ef..7d885efb54 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/socket/DomainSocket.java @@ -74,7 +74,7 @@ public abstract class DomainSocket extends AbstractSocket { return new FileDescriptor(handle, this::close); } catch (RuntimeException ex) { - this.close(handle); + close(handle); throw ex; } } From b83e7b42bbdd5fd912a50af52c8cfd00e8f31d29 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 20 Sep 2023 16:05:44 -0700 Subject: [PATCH 2/2] Update copyright year of changed files --- .../java/org/springframework/boot/build/bom/UpgradePolicy.java | 2 +- .../springframework/boot/build/bom/bomr/ReleaseSchedule.java | 2 +- .../springframework/boot/build/bom/bomr/github/Milestone.java | 2 +- .../boot/build/bom/bomr/version/AbstractDependencyVersion.java | 2 +- .../bom/bomr/version/CalendarVersionDependencyVersion.java | 2 +- .../build/bom/bomr/version/UnstructuredDependencyVersion.java | 2 +- .../boot/build/bom/bomr/ReleaseScheduleTests.java | 2 +- .../bom/bomr/version/CalendarVersionDependencyVersionTests.java | 2 +- .../build/bom/bomr/version/DependencyVersionUpgradeTests.java | 2 +- .../boot/autoconfigure/jms/artemis/ArtemisProperties.java | 2 +- .../web/embedded/NettyWebServerFactoryCustomizerTests.java | 2 +- .../boot/test/autoconfigure/jdbc/ExampleRepository.java | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java index af2341a8c1..e9d7239396 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/UpgradePolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/ReleaseSchedule.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/ReleaseSchedule.java index 28d827867c..c32518b462 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/ReleaseSchedule.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/ReleaseSchedule.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/Milestone.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/Milestone.java index 7a1ce8ae26..38d3f1dd5e 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/Milestone.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/Milestone.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java index 89860306c1..64eb84d5d2 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java index 59c685fd23..475e2149f9 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java index cdd44f9cbc..5799225958 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/UnstructuredDependencyVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/ReleaseScheduleTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/ReleaseScheduleTests.java index 3931221ffa..f4718e62f0 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/ReleaseScheduleTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/ReleaseScheduleTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java index 023b64b0bd..08ebb7dbf9 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/CalendarVersionDependencyVersionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java index f51b9eea9e..7220de730d 100644 --- a/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java +++ b/buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/DependencyVersionUpgradeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 the original author or authors. + * Copyright 2023-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java index e7db6ff2ba..15325c1c27 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java index 65795b60bd..b65a150a33 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java index 65de496073..4286cf9ca1 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.