Skip to content

Commit 0959db6

Browse files
author
Vincent Potucek
committed
[rewrite] Add StreamRulesRecipes
Signed-off-by: Vincent Potucek <[email protected]>
1 parent 20a5694 commit 0959db6

File tree

10 files changed

+73
-26
lines changed

10 files changed

+73
-26
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
- name: 'Test'
5656
shell: bash
5757
run: ./mvnw -B -P!standard-with-extra-repos -Dtoolchain.skip verify -U -Dmaven.javadoc.skip=true -Dsurefire.toolchain.version=${{ matrix.java }} -f $ROOT_POM
58+
- name: 'SanityCheck'
59+
shell: bash
60+
run: ./mvnw -B -P!standard-with-extra-repos -Dtoolchain.skip rewrite:dryRun -U -Dmaven.javadoc.skip=true -Dsurefire.toolchain.version=${{ matrix.java }} -f $ROOT_POM
5861
- name: 'Print Surefire reports'
5962
# Note: Normally a step won't run if the job has failed, but this causes it to
6063
if: ${{ failure() }}

.mvn/wrapper/maven-wrapper.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
# under the License.
1717
wrapperVersion=3.3.2
1818
distributionType=script
19-
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
20-
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar
21-
distributionSha256Sum=4ec3f26fb1a692473aea0235c300bd20f0f9fe741947c82c1234cefd76ac3a3c
19+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
20+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar
21+
distributionSha256Sum=0d7125e8c91097b36edb990ea5934e6c68b4440eef4ea96510a0f6815e7eeadb

guava-tests/test/com/google/common/collect/StreamsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void testStream_optionalDouble() {
275275
}
276276

277277
public void testConcatInfiniteStream() {
278-
assertThat(Streams.concat(Stream.of(1, 2, 3), Stream.generate(() -> 5)).limit(5))
278+
assertThat(Stream.concat(Stream.of(1, 2, 3), Stream.generate(() -> 5)).limit(5))
279279
.containsExactly(1, 2, 3, 5, 5)
280280
.inOrder();
281281
}

guava-tests/test/com/google/common/io/CharSinkTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.StringReader;
2929
import java.io.Writer;
3030
import java.util.EnumSet;
31+
import java.util.stream.Stream;
3132
import org.jspecify.annotations.NullUnmarked;
3233

3334
/**
@@ -94,13 +95,13 @@ public void testWriteLines_withDefaultSeparator() throws IOException {
9495
}
9596

9697
public void testWriteLines_stream() throws IOException {
97-
sink.writeLines(ImmutableList.of("foo", "bar", "baz").stream());
98+
sink.writeLines(Stream.of("foo", "bar", "baz"));
9899
String separator = LINE_SEPARATOR.value();
99100
assertEquals("foo" + separator + "bar" + separator + "baz" + separator, sink.getString());
100101
}
101102

102103
public void testWriteLines_stream_separator() throws IOException {
103-
sink.writeLines(ImmutableList.of("foo", "bar", "baz").stream(), "!");
104+
sink.writeLines(Stream.of("foo", "bar", "baz"), "!");
104105
assertEquals("foo!bar!baz!", sink.getString());
105106
}
106107

guava/src/com/google/common/base/Splitter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import static com.google.common.base.Preconditions.checkArgument;
1818
import static com.google.common.base.Preconditions.checkNotNull;
19+
import static com.google.common.collect.Streams.stream;
1920

2021
import com.google.common.annotations.GwtCompatible;
2122
import com.google.common.annotations.GwtIncompatible;
@@ -27,7 +28,6 @@
2728
import java.util.Map;
2829
import java.util.regex.Pattern;
2930
import java.util.stream.Stream;
30-
import java.util.stream.StreamSupport;
3131
import org.jspecify.annotations.Nullable;
3232

3333
/**
@@ -419,8 +419,7 @@ public List<String> splitToList(CharSequence sequence) {
419419
* @since 28.2 (but only since 33.4.0 in the Android flavor)
420420
*/
421421
public Stream<String> splitToStream(CharSequence sequence) {
422-
// Can't use Streams.stream() from base
423-
return StreamSupport.stream(split(sequence).spliterator(), false);
422+
return stream(split(sequence));
424423
}
425424

426425
/**

guava/src/com/google/common/collect/Streams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public final class Streams {
6666
public static <T extends @Nullable Object> Stream<T> stream(Iterable<T> iterable) {
6767
return (iterable instanceof Collection)
6868
? ((Collection<T>) iterable).stream()
69-
: StreamSupport.stream(iterable.spliterator(), false);
69+
: Streams.stream(iterable);
7070
}
7171

7272
/**

mvnw

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# ----------------------------------------------------------------------------
2020

2121
# ----------------------------------------------------------------------------
22-
# Apache Maven Wrapper startup batch script, version 3.3.2
22+
# Apache Maven Wrapper startup batch script, version 3.3.4
2323
#
2424
# Required ENV vars:
2525
# ------------------
@@ -201,6 +201,14 @@ MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
201201
export MAVEN_PROJECTBASEDIR
202202
log "$MAVEN_PROJECTBASEDIR"
203203

204+
trim() {
205+
# MWRAPPER-139:
206+
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
207+
# Needed for removing poorly interpreted newline sequences when running in more
208+
# exotic environments such as mingw bash on Windows.
209+
printf "%s" "${1}" | tr -d '[:space:]'
210+
}
211+
204212
##########################################################################################
205213
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
206214
# This allows using the maven wrapper in projects that prohibit checking in binary data.
@@ -212,15 +220,13 @@ else
212220
log "Couldn't find $wrapperJarPath, downloading it ..."
213221

214222
if [ -n "$MVNW_REPOURL" ]; then
215-
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar"
223+
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar"
216224
else
217-
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar"
225+
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar"
218226
fi
219227
while IFS="=" read -r key value; do
220-
# Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' )
221-
safeValue=$(echo "$value" | tr -d '\r')
222228
case "$key" in wrapperUrl)
223-
wrapperUrl="$safeValue"
229+
wrapperUrl=$(trim "${value-}")
224230
break
225231
;;
226232
esac
@@ -235,17 +241,17 @@ else
235241
log "Found wget ... using wget"
236242
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet"
237243
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
238-
wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
244+
wget ${QUIET:+"$QUIET"} "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
239245
else
240-
wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
246+
wget ${QUIET:+"$QUIET"} --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
241247
fi
242248
elif command -v curl >/dev/null; then
243249
log "Found curl ... using curl"
244250
[ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent"
245251
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
246-
curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
252+
curl ${QUIET:+"$QUIET"} -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
247253
else
248-
curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
254+
curl ${QUIET:+"$QUIET"} --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath"
249255
fi
250256
else
251257
log "Falling back to using Java to download"
@@ -276,15 +282,15 @@ fi
276282
wrapperSha256Sum=""
277283
while IFS="=" read -r key value; do
278284
case "$key" in wrapperSha256Sum)
279-
wrapperSha256Sum=$value
285+
wrapperSha256Sum=$(trim "${value-}")
280286
break
281287
;;
282288
esac
283289
done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties"
284290
if [ -n "$wrapperSha256Sum" ]; then
285291
wrapperSha256Result=false
286292
if command -v sha256sum >/dev/null; then
287-
if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c >/dev/null 2>&1; then
293+
if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c - >/dev/null 2>&1; then
288294
wrapperSha256Result=true
289295
fi
290296
elif command -v shasum >/dev/null; then

mvnw.cmd

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@REM ----------------------------------------------------------------------------
1919

2020
@REM ----------------------------------------------------------------------------
21-
@REM Apache Maven Wrapper startup batch script, version 3.3.2
21+
@REM Apache Maven Wrapper startup batch script, version 3.3.4
2222
@REM
2323
@REM Required ENV vars:
2424
@REM JAVA_HOME - location of a JDK home dir
@@ -119,7 +119,7 @@ SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
119119
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120120
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121121

122-
set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar"
122+
set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar"
123123

124124
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
125125
IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
@@ -133,7 +133,7 @@ if exist %WRAPPER_JAR% (
133133
)
134134
) else (
135135
if not "%MVNW_REPOURL%" == "" (
136-
SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar"
136+
SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.3.4/maven-wrapper-3.3.4.jar"
137137
)
138138
if "%MVNW_VERBOSE%" == "true" (
139139
echo Couldn't find %WRAPPER_JAR%, downloading it ...

pom.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,38 @@
184184
<version>${central-publishing-maven-plugin.version}</version>
185185
<extensions>true</extensions>
186186
</plugin>
187+
<plugin>
188+
<groupId>org.openrewrite.maven</groupId>
189+
<artifactId>rewrite-maven-plugin</artifactId>
190+
</plugin>
187191
</plugins>
188192
<pluginManagement>
189193
<plugins>
190-
<plugin>
194+
<plugin>
195+
<groupId>org.openrewrite.maven</groupId>
196+
<artifactId>rewrite-maven-plugin</artifactId>
197+
<version>6.23.0</version>
198+
<configuration>
199+
<activeRecipes>
200+
<recipe>com.google.openrewrite.SanityCheck</recipe>
201+
</activeRecipes>
202+
<exportDatatables>true</exportDatatables>
203+
<failOnDryRunResults>true</failOnDryRunResults>
204+
</configuration>
205+
<dependencies>
206+
<dependency>
207+
<groupId>org.openrewrite.recipe</groupId>
208+
<artifactId>rewrite-migrate-java</artifactId>
209+
<version>3.21.2</version>
210+
</dependency>
211+
<!-- <dependency>-->
212+
<!-- <groupId>org.openrewrite.recipe</groupId>-->
213+
<!-- <artifactId>rewrite-rewrite</artifactId>-->
214+
<!-- <version>0.15.0</version>-->
215+
<!-- </dependency>-->
216+
</dependencies>
217+
</plugin>
218+
<plugin>
191219
<artifactId>maven-antrun-plugin</artifactId>
192220
<version>${maven-antrun-plugin.version}</version>
193221
</plugin>

rewrite.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
type: specs.openrewrite.org/v1beta/recipe
3+
name: com.google.openrewrite.SanityCheck
4+
displayName: Apply Java & Maven best practices
5+
description: Comprehensive code quality recipe combining modernization, security, and best practices.
6+
recipeList:
7+
- org.openrewrite.java.security.JavaSecurityBestPractices
8+
- org.openrewrite.maven.UpdateMavenWrapper
9+
- tech.picnic.errorprone.refasterrules.StreamRulesRecipes
10+
---

0 commit comments

Comments
 (0)