Merge branch '3.1.x'

Closes gh-36238
pull/35191/head
Andy Wilkinson 1 year ago
commit ce8253ea95

@ -70,15 +70,15 @@ public abstract class ArchitectureCheck extends DefaultTask {
@TaskAction @TaskAction
void checkArchitecture() throws IOException { void checkArchitecture() throws IOException {
JavaClasses javaClasses = new ClassFileImporter() JavaClasses javaClasses = new ClassFileImporter()
.importPaths(this.classes.getFiles().stream().map(File::toPath).collect(Collectors.toList())); .importPaths(this.classes.getFiles().stream().map(File::toPath).toList());
List<EvaluationResult> violations = Stream.of(allPackagesShouldBeFreeOfTangles(), List<EvaluationResult> violations = Stream.of(allPackagesShouldBeFreeOfTangles(),
allBeanPostProcessorBeanMethodsShouldBeStaticAndHaveParametersThatWillNotCausePrematureInitialization(), allBeanPostProcessorBeanMethodsShouldBeStaticAndHaveParametersThatWillNotCausePrematureInitialization(),
allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters(), allBeanFactoryPostProcessorBeanMethodsShouldBeStaticAndHaveNoParameters(),
noClassesShouldCallStepVerifierStepVerifyComplete(), noClassesShouldCallStepVerifierStepVerifyComplete(),
noClassesShouldConfigureDefaultStepVerifierTimeout()) noClassesShouldConfigureDefaultStepVerifierTimeout(), noClassesShouldCallCollectorsToList())
.map((rule) -> rule.evaluate(javaClasses)) .map((rule) -> rule.evaluate(javaClasses))
.filter(EvaluationResult::hasViolation) .filter(EvaluationResult::hasViolation)
.collect(Collectors.toList()); .toList();
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile(); File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
outputFile.getParentFile().mkdirs(); outputFile.getParentFile().mkdirs();
if (!violations.isEmpty()) { if (!violations.isEmpty()) {
@ -178,6 +178,13 @@ public abstract class ArchitectureCheck extends DefaultTask {
.because("expectComplete().verify(Duration) should be used instead"); .because("expectComplete().verify(Duration) should be used instead");
} }
private ArchRule noClassesShouldCallCollectorsToList() {
return ArchRuleDefinition.noClasses()
.should()
.callMethod(Collectors.class, "toList")
.because("java.util.stream.Stream.toList() should be used instead");
}
public void setClasses(FileCollection classes) { public void setClasses(FileCollection classes) {
this.classes = classes; this.classes = classes;
} }

@ -103,7 +103,7 @@ class StandardLibraryUpdateResolver implements LibraryUpdateResolver {
.flatMap(SortedSet::stream) .flatMap(SortedSet::stream)
.distinct() .distinct()
.filter((dependencyVersion) -> isPermitted(dependencyVersion, library.getProhibitedVersions())) .filter((dependencyVersion) -> isPermitted(dependencyVersion, library.getProhibitedVersions()))
.collect(Collectors.toList()); .toList();
if (allVersions.isEmpty()) { if (allVersions.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }

@ -50,7 +50,7 @@ class ArtifactCollector {
Collection<DeployableArtifact> collectArtifacts(Path root) { Collection<DeployableArtifact> collectArtifacts(Path root) {
try (Stream<Path> artifacts = Files.walk(root)) { try (Stream<Path> artifacts = Files.walk(root)) {
return artifacts.filter(Files::isRegularFile).filter(this.excludeFilter) return artifacts.filter(Files::isRegularFile).filter(this.excludeFilter)
.map((artifact) -> deployableArtifact(artifact, root)).collect(Collectors.toList()); .map((artifact) -> deployableArtifact(artifact, root)).toList();
} }
catch (IOException ex) { catch (IOException ex) {
throw new RuntimeException("Could not read artifacts from '" + root + "'"); throw new RuntimeException("Could not read artifacts from '" + root + "'");

@ -208,7 +208,7 @@ public class SonatypeService {
List<String> failureMessages = Stream.of(activities).flatMap((activity) -> activity.events.stream()) List<String> failureMessages = Stream.of(activities).flatMap((activity) -> activity.events.stream())
.filter((event) -> event.severity > 0).flatMap((event) -> event.properties.stream()) .filter((event) -> event.severity > 0).flatMap((event) -> event.properties.stream())
.filter((property) -> "failureMessage".equals(property.name)) .filter((property) -> "failureMessage".equals(property.name))
.map((property) -> " " + property.value).collect(Collectors.toList()); .map((property) -> " " + property.value).toList();
if (failureMessages.isEmpty()) { if (failureMessages.isEmpty()) {
logger.error("Close failed for unknown reasons"); logger.error("Close failed for unknown reasons");
} }

@ -21,7 +21,6 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.flywaydb.core.Flyway; import org.flywaydb.core.Flyway;
@ -116,7 +115,7 @@ public class FlywayEndpoint {
private final List<FlywayMigrationDescriptor> migrations; private final List<FlywayMigrationDescriptor> migrations;
private FlywayDescriptor(MigrationInfo[] migrations) { private FlywayDescriptor(MigrationInfo[] migrations) {
this.migrations = Stream.of(migrations).map(FlywayMigrationDescriptor::new).collect(Collectors.toList()); this.migrations = Stream.of(migrations).map(FlywayMigrationDescriptor::new).toList();
} }
public FlywayDescriptor(List<FlywayMigrationDescriptor> migrations) { public FlywayDescriptor(List<FlywayMigrationDescriptor> migrations) {

@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.jms.activemq; package org.springframework.boot.autoconfigure.jms.activemq;
import java.util.stream.Collectors;
import jakarta.jms.ConnectionFactory; import jakarta.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.PooledObject;
@ -60,8 +58,7 @@ class ActiveMQConnectionFactoryConfiguration {
private static ActiveMQConnectionFactory createJmsConnectionFactory(ActiveMQProperties properties, private static ActiveMQConnectionFactory createJmsConnectionFactory(ActiveMQProperties properties,
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) { ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
return new ActiveMQConnectionFactoryFactory(properties, return new ActiveMQConnectionFactoryFactory(properties, factoryCustomizers.orderedStream().toList())
factoryCustomizers.orderedStream().collect(Collectors.toList()))
.createConnectionFactory(ActiveMQConnectionFactory.class); .createConnectionFactory(ActiveMQConnectionFactory.class);
} }
@ -96,7 +93,7 @@ class ActiveMQConnectionFactoryConfiguration {
JmsPoolConnectionFactory jmsConnectionFactory(ActiveMQProperties properties, JmsPoolConnectionFactory jmsConnectionFactory(ActiveMQProperties properties,
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) { ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties, ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
factoryCustomizers.orderedStream().collect(Collectors.toList())) factoryCustomizers.orderedStream().toList())
.createConnectionFactory(ActiveMQConnectionFactory.class); .createConnectionFactory(ActiveMQConnectionFactory.class);
return new JmsPoolConnectionFactoryFactory(properties.getPool()) return new JmsPoolConnectionFactoryFactory(properties.getPool())
.createPooledConnectionFactory(connectionFactory); .createPooledConnectionFactory(connectionFactory);

@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.jms.activemq; package org.springframework.boot.autoconfigure.jms.activemq;
import java.util.stream.Collectors;
import jakarta.jms.ConnectionFactory; import jakarta.jms.ConnectionFactory;
import jakarta.transaction.TransactionManager; import jakarta.transaction.TransactionManager;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
@ -51,7 +49,7 @@ class ActiveMQXAConnectionFactoryConfiguration {
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers, XAConnectionFactoryWrapper wrapper) ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers, XAConnectionFactoryWrapper wrapper)
throws Exception { throws Exception {
ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties, ActiveMQXAConnectionFactory connectionFactory = new ActiveMQConnectionFactoryFactory(properties,
factoryCustomizers.orderedStream().collect(Collectors.toList())) factoryCustomizers.orderedStream().toList())
.createConnectionFactory(ActiveMQXAConnectionFactory.class); .createConnectionFactory(ActiveMQXAConnectionFactory.class);
return wrapper.wrapConnectionFactory(connectionFactory); return wrapper.wrapConnectionFactory(connectionFactory);
} }
@ -61,8 +59,7 @@ class ActiveMQXAConnectionFactoryConfiguration {
matchIfMissing = true) matchIfMissing = true)
ActiveMQConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties, ActiveMQConnectionFactory nonXaJmsConnectionFactory(ActiveMQProperties properties,
ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) { ObjectProvider<ActiveMQConnectionFactoryCustomizer> factoryCustomizers) {
return new ActiveMQConnectionFactoryFactory(properties, return new ActiveMQConnectionFactoryFactory(properties, factoryCustomizers.orderedStream().toList())
factoryCustomizers.orderedStream().collect(Collectors.toList()))
.createConnectionFactory(ActiveMQConnectionFactory.class); .createConnectionFactory(ActiveMQConnectionFactory.class);
} }

@ -17,7 +17,6 @@
package org.springframework.boot.configurationmetadata.changelog; package org.springframework.boot.configurationmetadata.changelog;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -43,13 +42,13 @@ class ChangelogTests {
List<Difference> added = differences.differences() List<Difference> added = differences.differences()
.stream() .stream()
.filter((difference) -> difference.type() == DifferenceType.ADDED) .filter((difference) -> difference.type() == DifferenceType.ADDED)
.collect(Collectors.toList()); .toList();
assertThat(added).hasSize(1); assertThat(added).hasSize(1);
assertProperty(added.get(0).newProperty(), "test.add", String.class, "new"); assertProperty(added.get(0).newProperty(), "test.add", String.class, "new");
List<Difference> deleted = differences.differences() List<Difference> deleted = differences.differences()
.stream() .stream()
.filter((difference) -> difference.type() == DifferenceType.DELETED) .filter((difference) -> difference.type() == DifferenceType.DELETED)
.collect(Collectors.toList()); .toList();
assertThat(deleted).hasSize(2) assertThat(deleted).hasSize(2)
.anySatisfy((entry) -> assertProperty(entry.oldProperty(), "test.delete", String.class, "delete")) .anySatisfy((entry) -> assertProperty(entry.oldProperty(), "test.delete", String.class, "delete"))
.anySatisfy( .anySatisfy(
@ -57,7 +56,7 @@ class ChangelogTests {
List<Difference> deprecated = differences.differences() List<Difference> deprecated = differences.differences()
.stream() .stream()
.filter((difference) -> difference.type() == DifferenceType.DEPRECATED) .filter((difference) -> difference.type() == DifferenceType.DEPRECATED)
.collect(Collectors.toList()); .toList();
assertThat(deprecated).hasSize(1); assertThat(deprecated).hasSize(1);
assertProperty(deprecated.get(0).oldProperty(), "test.deprecate", String.class, "wrong"); assertProperty(deprecated.get(0).oldProperty(), "test.deprecate", String.class, "wrong");
assertProperty(deprecated.get(0).newProperty(), "test.deprecate", String.class, "wrong"); assertProperty(deprecated.get(0).newProperty(), "test.deprecate", String.class, "wrong");

@ -84,10 +84,10 @@ class ResolvedDependencies {
} }
void resolvedArtifacts(Provider<Set<ResolvedArtifactResult>> resolvedArtifacts) { void resolvedArtifacts(Provider<Set<ResolvedArtifactResult>> resolvedArtifacts) {
this.artifactFiles.addAll(resolvedArtifacts this.artifactFiles.addAll(
.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).collect(Collectors.toList()))); resolvedArtifacts.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getFile).toList()));
this.artifactIds.addAll(resolvedArtifacts this.artifactIds.addAll(
.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).collect(Collectors.toList()))); resolvedArtifacts.map((artifacts) -> artifacts.stream().map(ResolvedArtifactResult::getId).toList()));
} }
DependencyDescriptor find(File file) { DependencyDescriptor find(File file) {

@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty; import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository; import org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
@ -82,9 +81,7 @@ class PropertiesMigrationReporter {
private PropertySource<?> mapPropertiesWithReplacement(PropertiesMigrationReport report, String name, private PropertySource<?> mapPropertiesWithReplacement(PropertiesMigrationReport report, String name,
List<PropertyMigration> properties) { List<PropertyMigration> properties) {
report.add(name, properties); report.add(name, properties);
List<PropertyMigration> renamed = properties.stream() List<PropertyMigration> renamed = properties.stream().filter(PropertyMigration::isCompatibleType).toList();
.filter(PropertyMigration::isCompatibleType)
.collect(Collectors.toList());
if (renamed.isEmpty()) { if (renamed.isEmpty()) {
return null; return null;
} }
@ -118,10 +115,7 @@ class PropertiesMigrationReporter {
private Map<String, List<PropertyMigration>> getMatchingProperties( private Map<String, List<PropertyMigration>> getMatchingProperties(
Predicate<ConfigurationMetadataProperty> filter) { Predicate<ConfigurationMetadataProperty> filter) {
MultiValueMap<String, PropertyMigration> result = new LinkedMultiValueMap<>(); MultiValueMap<String, PropertyMigration> result = new LinkedMultiValueMap<>();
List<ConfigurationMetadataProperty> candidates = this.allProperties.values() List<ConfigurationMetadataProperty> candidates = this.allProperties.values().stream().filter(filter).toList();
.stream()
.filter(filter)
.collect(Collectors.toList());
getPropertySourcesAsMap().forEach((propertySourceName, propertySource) -> candidates.forEach((metadata) -> { getPropertySourcesAsMap().forEach((propertySourceName, propertySource) -> candidates.forEach((metadata) -> {
ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId()) ConfigurationPropertyName metadataName = ConfigurationPropertyName.isValid(metadata.getId())
? ConfigurationPropertyName.of(metadata.getId()) ? ConfigurationPropertyName.of(metadata.getId())

@ -34,7 +34,6 @@ import java.util.Set;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
@ -107,7 +106,7 @@ final class ModifiedClassPathClassLoader extends URLClassLoader {
candidates.addAll(getAnnotatedElements(arguments.toArray())); candidates.addAll(getAnnotatedElements(arguments.toArray()));
List<AnnotatedElement> annotatedElements = candidates.stream() List<AnnotatedElement> annotatedElements = candidates.stream()
.filter(ModifiedClassPathClassLoader::hasAnnotation) .filter(ModifiedClassPathClassLoader::hasAnnotation)
.collect(Collectors.toList()); .toList();
if (annotatedElements.isEmpty()) { if (annotatedElements.isEmpty()) {
return null; return null;
} }

Loading…
Cancel
Save