Skip to content

Commit 76d6a50

Browse files
author
Vincent Potucek
committed
[prone] Add StreamRulesRecipes
Changes have been made to junit-platform-commons/src/main/java/org/junit/platform/commons/support/ModifierSupport.java by: org.openrewrite.java.migrate.UpgradeToJava17 org.openrewrite.java.migrate.RemovedModifierAndConstantBootstrapsConstructors org.openrewrite.java.ChangeMethodTargetToStatic: {methodPattern=java.lang.reflect.Modifier *(..), fullyQualifiedTargetTypeName=java.lang.reflect.Modifier} Signed-off-by: Vincent Potucek <[email protected]>
1 parent 786aa07 commit 76d6a50

File tree

9 files changed

+127
-29
lines changed

9 files changed

+127
-29
lines changed

.github/workflows/sanity-check.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: "Sanity Check"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/**'
8+
pull_request:
9+
# The branches below must be a subset of the branches above
10+
branches:
11+
- main
12+
- 'releases/**'
13+
schedule:
14+
- cron: '0 19 * * 3'
15+
16+
concurrency:
17+
# Cancels in-progress runs only for pull requests
18+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
19+
cancel-in-progress: true
20+
21+
permissions: {}
22+
23+
env:
24+
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
25+
26+
jobs:
27+
analyze:
28+
name: Analyze (${{ matrix.language }})
29+
runs-on: ubuntu-latest
30+
permissions:
31+
security-events: write
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
- language: actions
37+
build-mode: none
38+
- language: java-kotlin
39+
build-mode: manual
40+
steps:
41+
- name: Check out repository
42+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
43+
with:
44+
persist-credentials: false
45+
- name: Sanity Check
46+
if: matrix.build-mode == 'manual'
47+
uses: ./.github/actions/run-gradle
48+
with:
49+
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
50+
arguments: rewriteDryRun
51+
# arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ plugins {
77
id("junitbuild.jacoco-aggregation-conventions")
88
id("junitbuild.maven-central-publishing")
99
id("junitbuild.temp-maven-repo")
10+
id("org.openrewrite.rewrite") version("7.19.0") apply false
1011
}
1112

13+
apply(from = "gradle/rewrite.gradle")
14+
1215
description = "JUnit"
1316
group = "org.junit"
1417

gradle/rewrite.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
project.apply plugin: 'org.openrewrite.rewrite'
10+
11+
rewrite {
12+
activeRecipe('org.opensearch.openrewrite.SanityCheck')
13+
exclusion('**package-info.java')
14+
setExportDatatables(true)
15+
setFailOnDryRunResults(true)
16+
}
17+
18+
dependencies {
19+
rewrite(platform('org.openrewrite.recipe:rewrite-recipe-bom:3.17.0'))
20+
rewrite('org.openrewrite.recipe:rewrite-migrate-java:3.20.0')
21+
rewrite('org.openrewrite.recipe:rewrite-java-security:3.19.2')
22+
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.14.1')
23+
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.20.0')
24+
rewrite('org.openrewrite.recipe:rewrite-third-party:0.30.0')
25+
}

junit-platform-commons/src/main/java/org/junit/platform/commons/support/ModifierSupport.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.apiguardian.api.API.Status.MAINTAINED;
1515

1616
import java.lang.reflect.Member;
17+
import java.lang.reflect.Modifier;
1718

1819
import org.apiguardian.api.API;
1920
import org.junit.platform.commons.util.ReflectionUtils;
@@ -47,7 +48,7 @@ private ModifierSupport() {
4748
*
4849
* @param clazz the class to check; never {@code null}
4950
* @return {@code true} if the class is {@code public}
50-
* @see java.lang.reflect.Modifier#isPublic(int)
51+
* @see Modifier#isPublic(int)
5152
*/
5253
public static boolean isPublic(Class<?> clazz) {
5354
return ReflectionUtils.isPublic(clazz);
@@ -58,7 +59,7 @@ public static boolean isPublic(Class<?> clazz) {
5859
*
5960
* @param member the member to check; never {@code null}
6061
* @return {@code true} if the member is {@code public}
61-
* @see java.lang.reflect.Modifier#isPublic(int)
62+
* @see Modifier#isPublic(int)
6263
*/
6364
public static boolean isPublic(Member member) {
6465
return ReflectionUtils.isPublic(member);
@@ -69,7 +70,7 @@ public static boolean isPublic(Member member) {
6970
*
7071
* @param clazz the class to check; never {@code null}
7172
* @return {@code true} if the class is {@code private}
72-
* @see java.lang.reflect.Modifier#isPrivate(int)
73+
* @see Modifier#isPrivate(int)
7374
*/
7475
public static boolean isPrivate(Class<?> clazz) {
7576
return ReflectionUtils.isPrivate(clazz);
@@ -80,7 +81,7 @@ public static boolean isPrivate(Class<?> clazz) {
8081
*
8182
* @param member the member to check; never {@code null}
8283
* @return {@code true} if the member is {@code private}
83-
* @see java.lang.reflect.Modifier#isPrivate(int)
84+
* @see Modifier#isPrivate(int)
8485
*/
8586
public static boolean isPrivate(Member member) {
8687
return ReflectionUtils.isPrivate(member);
@@ -96,9 +97,9 @@ public static boolean isPrivate(Member member) {
9697
*
9798
* @param clazz the class to check; never {@code null}
9899
* @return {@code true} if the class is not {@code private}
99-
* @see java.lang.reflect.Modifier#isPublic(int)
100-
* @see java.lang.reflect.Modifier#isProtected(int)
101-
* @see java.lang.reflect.Modifier#isPrivate(int)
100+
* @see Modifier#isPublic(int)
101+
* @see Modifier#isProtected(int)
102+
* @see Modifier#isPrivate(int)
102103
*/
103104
public static boolean isNotPrivate(Class<?> clazz) {
104105
return ReflectionUtils.isNotPrivate(clazz);
@@ -114,9 +115,9 @@ public static boolean isNotPrivate(Class<?> clazz) {
114115
*
115116
* @param member the member to check; never {@code null}
116117
* @return {@code true} if the member is not {@code private}
117-
* @see java.lang.reflect.Modifier#isPublic(int)
118-
* @see java.lang.reflect.Modifier#isProtected(int)
119-
* @see java.lang.reflect.Modifier#isPrivate(int)
118+
* @see Modifier#isPublic(int)
119+
* @see Modifier#isProtected(int)
120+
* @see Modifier#isPrivate(int)
120121
*/
121122
public static boolean isNotPrivate(Member member) {
122123
return ReflectionUtils.isNotPrivate(member);
@@ -127,7 +128,7 @@ public static boolean isNotPrivate(Member member) {
127128
*
128129
* @param clazz the class to check; never {@code null}
129130
* @return {@code true} if the class is {@code abstract}
130-
* @see java.lang.reflect.Modifier#isAbstract(int)
131+
* @see Modifier#isAbstract(int)
131132
*/
132133
public static boolean isAbstract(Class<?> clazz) {
133134
return ReflectionUtils.isAbstract(clazz);
@@ -138,7 +139,7 @@ public static boolean isAbstract(Class<?> clazz) {
138139
*
139140
* @param member the class to check; never {@code null}
140141
* @return {@code true} if the member is {@code abstract}
141-
* @see java.lang.reflect.Modifier#isAbstract(int)
142+
* @see Modifier#isAbstract(int)
142143
*/
143144
public static boolean isAbstract(Member member) {
144145
return ReflectionUtils.isAbstract(member);
@@ -150,7 +151,7 @@ public static boolean isAbstract(Member member) {
150151
* @param clazz the class to check; never {@code null}
151152
* @return {@code true} if the class is not {@code abstract}
152153
* @since 1.13
153-
* @see java.lang.reflect.Modifier#isAbstract(int)
154+
* @see Modifier#isAbstract(int)
154155
*/
155156
@API(status = EXPERIMENTAL, since = "6.0")
156157
public static boolean isNotAbstract(Class<?> clazz) {
@@ -163,7 +164,7 @@ public static boolean isNotAbstract(Class<?> clazz) {
163164
* @param member the class to check; never {@code null}
164165
* @return {@code true} if the member is not {@code abstract}
165166
* @since 1.13
166-
* @see java.lang.reflect.Modifier#isAbstract(int)
167+
* @see Modifier#isAbstract(int)
167168
*/
168169
@API(status = EXPERIMENTAL, since = "6.0")
169170
public static boolean isNotAbstract(Member member) {
@@ -175,7 +176,7 @@ public static boolean isNotAbstract(Member member) {
175176
*
176177
* @param clazz the class to check; never {@code null}
177178
* @return {@code true} if the class is {@code static}
178-
* @see java.lang.reflect.Modifier#isStatic(int)
179+
* @see Modifier#isStatic(int)
179180
*/
180181
public static boolean isStatic(Class<?> clazz) {
181182
return ReflectionUtils.isStatic(clazz);
@@ -186,7 +187,7 @@ public static boolean isStatic(Class<?> clazz) {
186187
*
187188
* @param member the member to check; never {@code null}
188189
* @return {@code true} if the member is {@code static}
189-
* @see java.lang.reflect.Modifier#isStatic(int)
190+
* @see Modifier#isStatic(int)
190191
*/
191192
public static boolean isStatic(Member member) {
192193
return ReflectionUtils.isStatic(member);
@@ -197,7 +198,7 @@ public static boolean isStatic(Member member) {
197198
*
198199
* @param clazz the class to check; never {@code null}
199200
* @return {@code true} if the class is not {@code static}
200-
* @see java.lang.reflect.Modifier#isStatic(int)
201+
* @see Modifier#isStatic(int)
201202
*/
202203
public static boolean isNotStatic(Class<?> clazz) {
203204
return ReflectionUtils.isNotStatic(clazz);
@@ -208,7 +209,7 @@ public static boolean isNotStatic(Class<?> clazz) {
208209
*
209210
* @param member the member to check; never {@code null}
210211
* @return {@code true} if the member is not {@code static}
211-
* @see java.lang.reflect.Modifier#isStatic(int)
212+
* @see Modifier#isStatic(int)
212213
*/
213214
public static boolean isNotStatic(Member member) {
214215
return ReflectionUtils.isNotStatic(member);
@@ -220,7 +221,7 @@ public static boolean isNotStatic(Member member) {
220221
* @param clazz the class to check; never {@code null}
221222
* @return {@code true} if the class is {@code final}
222223
* @since 1.5
223-
* @see java.lang.reflect.Modifier#isFinal(int)
224+
* @see Modifier#isFinal(int)
224225
*/
225226
@API(status = MAINTAINED, since = "1.5")
226227
public static boolean isFinal(Class<?> clazz) {
@@ -233,7 +234,7 @@ public static boolean isFinal(Class<?> clazz) {
233234
* @param clazz the class to check; never {@code null}
234235
* @return {@code true} if the class is not {@code final}
235236
* @since 1.5
236-
* @see java.lang.reflect.Modifier#isFinal(int)
237+
* @see Modifier#isFinal(int)
237238
*/
238239
@API(status = MAINTAINED, since = "1.5")
239240
public static boolean isNotFinal(Class<?> clazz) {
@@ -246,7 +247,7 @@ public static boolean isNotFinal(Class<?> clazz) {
246247
* @param member the member to check; never {@code null}
247248
* @return {@code true} if the member is {@code final}
248249
* @since 1.5
249-
* @see java.lang.reflect.Modifier#isFinal(int)
250+
* @see Modifier#isFinal(int)
250251
*/
251252
@API(status = MAINTAINED, since = "1.5")
252253
public static boolean isFinal(Member member) {
@@ -259,7 +260,7 @@ public static boolean isFinal(Member member) {
259260
* @param member the member to check; never {@code null}
260261
* @return {@code true} if the member is not {@code final}
261262
* @since 1.5
262-
* @see java.lang.reflect.Modifier#isFinal(int)
263+
* @see Modifier#isFinal(int)
263264
*/
264265
@API(status = MAINTAINED, since = "1.5")
265266
public static boolean isNotFinal(Member member) {

junit-platform-commons/src/main/java/org/junit/platform/commons/util/CollectionUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static Stream<?> toStream(Object object) {
160160
return collection.stream();
161161
}
162162
if (object instanceof Iterable<?> iterable) {
163-
return stream(iterable.spliterator(), false);
163+
return CollectionUtils.toStream(iterable);
164164
}
165165
if (object instanceof Iterator<?> iterator) {
166166
return stream(spliteratorUnknownSize(iterator, ORDERED), false);

junit-platform-launcher/src/main/java/org/junit/platform/launcher/listeners/OutputDir.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private static boolean containsFilesWithExtensions(Path dir, String... extension
140140
return false;
141141
};
142142
try (Stream<Path> pathStream = Files.find(dir, 1, matcher)) {
143-
return pathStream.findFirst().isPresent();
143+
return pathStream.findAny().isPresent();
144144
}
145145
}
146146
}

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ModularUserGuideTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ private static List<String> treeWalk(Path root) {
181181
private static void treeWalk(Path root, Consumer<String> out) {
182182
try (var stream = Files.walk(root)) {
183183
stream.map(root::relativize) //
184-
.map(path -> path.toString().replace('\\', '/')) //
185-
.sorted().filter(Predicate.not(String::isEmpty)) //
184+
.map(path -> path.toString().replace('\\', '/')).filter(Predicate.not(String::isEmpty)).sorted() //
186185
.forEach(out);
187186
}
188187
catch (Exception e) {

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/ToolProviderTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import java.util.ServiceLoader;
3232
import java.util.Set;
3333
import java.util.spi.ToolProvider;
34-
import java.util.stream.StreamSupport;
3534

35+
import org.assertj.core.util.Streams;
3636
import org.junit.jupiter.api.AfterAll;
3737
import org.junit.jupiter.api.BeforeAll;
3838
import org.junit.jupiter.api.Order;
@@ -90,7 +90,7 @@ static void triggerReleaseOfFileHandlesOnWindows() throws Exception {
9090
void findAndRunJUnitOnTheClassPath() {
9191
try (var loader = new URLClassLoader("junit", urls(lib), ClassLoader.getPlatformClassLoader())) {
9292
var sl = ServiceLoader.load(ToolProvider.class, loader);
93-
var junit = StreamSupport.stream(sl.spliterator(), false).filter(p -> p.name().equals("junit")).findFirst();
93+
var junit = Streams.stream(sl).filter(p -> p.name().equals("junit")).findFirst();
9494

9595
assertTrue(junit.isPresent(), "Tool 'junit' not found in: " + lib);
9696
assertJUnitPrintsHelpMessage(junit.get());
@@ -116,7 +116,7 @@ void findAndRunJUnitOnTheModulePath() {
116116
var layer = bootLayer.defineModulesWithOneLoader(configuration, ClassLoader.getPlatformClassLoader());
117117

118118
var sl = ServiceLoader.load(layer, ToolProvider.class);
119-
var junit = StreamSupport.stream(sl.spliterator(), false).filter(p -> p.name().equals("junit")).findFirst();
119+
var junit = Streams.stream(sl).filter(p -> p.name().equals("junit")).findFirst();
120120

121121
assertTrue(junit.isPresent(), "Tool 'junit' not found in modules: " + modules);
122122
assertJUnitPrintsHelpMessage(junit.get());

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.opensearch.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+
- org.openrewrite.java.format.NormalizeLineBreaks
16+
- org.openrewrite.java.format.RemoveTrailingWhitespace
17+
- org.openrewrite.java.migrate.UpgradeToJava17
18+
- tech.picnic.errorprone.refasterrules.StreamRulesRecipes
19+
---

0 commit comments

Comments
 (0)