Skip to content

Commit a8e5b97

Browse files
author
Vincent Potucek
committed
[prone] Add StreamRulesRecipes
Signed-off-by: Vincent Potucek <[email protected]>
1 parent 4bc97ad commit a8e5b97

File tree

8 files changed

+46
-7
lines changed

8 files changed

+46
-7
lines changed

.github/actions/build/action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ runs:
5959
version=$(sed -n 's/version=\(.*\)/\1/p' gradle.properties)
6060
echo "Version is $version"
6161
echo "version=$version" >> $GITHUB_OUTPUT
62+
- name: SanityCheck
63+
id: build
64+
if: ${{ inputs.publish == 'false' }}
65+
shell: bash
66+
run: ./gradlew rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ plugins {
77
id 'com.gradleup.shadow' version "9.2.2" apply false
88
id 'me.champeau.jmh' version '0.7.2' apply false
99
id 'io.spring.nullability' version '0.0.8' apply false
10+
id 'org.openrewrite.rewrite' version '7.20.0' apply false
1011
}
1112

1213
ext {
@@ -16,6 +17,8 @@ ext {
1617

1718
description = "Spring Framework"
1819

20+
apply from: "$rootDir/gradle/rewrite.gradle"
21+
1922
configure(allprojects) { project ->
2023
apply plugin: "org.springframework.build.localdev"
2124
group = "org.springframework"

gradle/rewrite.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apply plugin: 'org.openrewrite.rewrite'
2+
3+
rewrite {
4+
activeRecipe('org.springframework.openrewrite.SanityCheck')
5+
setExportDatatables(true)
6+
setFailOnDryRunResults(true)
7+
}
8+
9+
dependencies {
10+
rewrite(platform('org.openrewrite.recipe:rewrite-recipe-bom:3.18.0'))
11+
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.15.0')
12+
}

rewrite.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: org.springframework.openrewrite.SanityCheck
4+
displayName: Apply all Java & Gradle best practices
5+
description: Comprehensive code quality recipe combining modernization, security, and best practices.
6+
tags:
7+
- java
8+
- gradle
9+
- static-analysis
10+
- cleanup
11+
recipeList:
12+
- org.openrewrite.gradle.EnableGradleBuildCache
13+
- org.openrewrite.gradle.EnableGradleParallelExecution
14+
- org.openrewrite.gradle.GradleBestPractices
15+
- tech.picnic.errorprone.refasterrules.StreamRulesRecipes
16+
# TBD
17+
# - org.openrewrite.java.migrate.Java8toJava11 # https://github.com/google/error-prone/pull/5328
18+
# - org.openrewrite.java.migrate.UpgradeToJava17 # https://github.com/checkstyle/checkstyle/pull/17730
19+
---

spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import java.util.HashSet;
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
23-
import java.util.stream.StreamSupport;
2423

24+
import com.google.common.collect.Streams;
2525
import org.jspecify.annotations.Nullable;
2626

2727
import org.springframework.aot.generate.GenerationContext;
@@ -65,7 +65,7 @@ public class ReflectiveProcessorAotContributionBuilder {
6565
* @param classes the classes to inspect
6666
*/
6767
public ReflectiveProcessorAotContributionBuilder withClasses(Iterable<Class<?>> classes) {
68-
this.classes.addAll(StreamSupport.stream(classes.spliterator(), false)
68+
this.classes.addAll(Streams.stream(classes)
6969
.filter(registrar::isCandidate).toList());
7070
return this;
7171
}

spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.HashMap;
2424
import java.util.List;
2525
import java.util.Map;
26-
import java.util.stream.Collectors;
2726

2827
import org.jspecify.annotations.Nullable;
2928

@@ -33,6 +32,8 @@
3332
import org.springframework.util.MultiValueMap;
3433
import org.springframework.util.StringUtils;
3534

35+
import static java.util.stream.Collectors.joining;
36+
3637
/**
3738
* Default implementation of {@link PathContainer}.
3839
*
@@ -191,7 +192,7 @@ static PathContainer subPath(PathContainer container, int fromIndex, int toIndex
191192
Assert.isTrue(fromIndex < toIndex, () -> "fromIndex: " + fromIndex + " should be < toIndex " + toIndex);
192193

193194
List<Element> subList = elements.subList(fromIndex, toIndex);
194-
String path = subList.stream().map(Element::value).collect(Collectors.joining(""));
195+
String path = subList.stream().map(Element::value).collect(joining());
195196
return new DefaultPathContainer(path, subList);
196197
}
197198

spring-webflux/src/test/java/org/springframework/web/reactive/function/server/AttributesTestVisitor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222
import java.util.Map;
2323
import java.util.Objects;
24-
import java.util.Optional;
2524
import java.util.function.Function;
2625
import java.util.stream.Stream;
2726

@@ -64,7 +63,7 @@ public void endNested(RequestPredicate predicate) {
6463

6564
@Override
6665
public void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction) {
67-
Stream<Map<String, Object>> current = Optional.ofNullable(attributes).stream();
66+
Stream<Map<String, Object>> current = Stream.ofNullable(attributes);
6867
Stream<Map<String, Object>> nested = nestedAttributes.stream().filter(Objects::nonNull);
6968
routerFunctionsAttributes.add(Stream.concat(current, nested).toList());
7069
attributes = null;

spring-webmvc/src/test/java/org/springframework/web/servlet/function/AttributesTestVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void endNested(RequestPredicate predicate) {
6363

6464
@Override
6565
public void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction) {
66-
Stream<Map<String, Object>> current = Optional.ofNullable(attributes).stream();
66+
Stream<Map<String, Object>> current = Stream.ofNullable(attributes);
6767
Stream<Map<String, Object>> nested = nestedAttributes.stream().filter(Objects::nonNull);
6868
routerFunctionsAttributes.add(Stream.concat(current, nested).toList());
6969
attributes = null;

0 commit comments

Comments
 (0)