Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/sanity-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Sanity Check"

on:
push:
branches:
- main
- 'releases/**'
pull_request:
# The branches below must be a subset of the branches above
branches:
- main
- 'releases/**'
schedule:
- cron: '0 19 * * 3'

concurrency:
# Cancels in-progress runs only for pull requests
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions: {}

env:
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: java-kotlin
build-mode: manual
steps:
- name: Check out repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Sanity Check
if: matrix.build-mode == 'manual'
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: rewriteDryRun
# arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx8G
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ plugins {
id("junitbuild.jacoco-aggregation-conventions")
id("junitbuild.maven-central-publishing")
id("junitbuild.temp-maven-repo")
id("org.openrewrite.rewrite") version("7.20.0") apply false
}

apply(from = "gradle/rewrite.gradle")

description = "JUnit"
group = "org.junit"

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ nullaway = { id = "net.ltgt.nullaway", version = "2.3.0" }
plantuml = { id = "io.freefair.plantuml", version = "9.1.0" }
shadow = { id = "com.gradleup.shadow", version = "9.2.2" }
spotless = { id = "com.diffplug.spotless", version = "8.0.0" }
rewrite = { id = "org.openrewrite.rewrite", version = "7.20.0" }
1 change: 1 addition & 0 deletions gradle/plugins/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.plugins.nullaway.markerCoordinates)
implementation(libs.plugins.shadow.markerCoordinates)
implementation(libs.plugins.spotless.markerCoordinates)
implementation(libs.plugins.rewrite.markerCoordinates)
}

tasks.compileJava {
Expand Down
3 changes: 2 additions & 1 deletion gradle/plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ rootProject.name = "plugins"

include("backward-compatibility")
include("build-parameters")
include("common")
include("code-generator")
include("common")
include("publishing")
include("rewrite")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
25 changes: 25 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

project.apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe('org.junit.openrewrite.SanityCheck')
exclusion('**CollectionUtils.java')
setExportDatatables(true)
setFailOnDryRunResults(true)
}

dependencies {
rewrite(platform('org.openrewrite.recipe:rewrite-recipe-bom:3.17.0'))
rewrite('org.openrewrite.recipe:rewrite-migrate-java:3.20.0')
rewrite('org.openrewrite.recipe:rewrite-java-security:3.19.2')
rewrite('org.openrewrite.recipe:rewrite-rewrite:0.14.1')
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.20.0')
rewrite('org.openrewrite.recipe:rewrite-third-party:0.30.0')
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static org.apiguardian.api.API.Status.MAINTAINED;

import java.lang.reflect.Member;
import java.lang.reflect.Modifier;

import org.apiguardian.api.API;
import org.junit.platform.commons.util.ReflectionUtils;
Expand Down Expand Up @@ -47,7 +48,7 @@ private ModifierSupport() {
*
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is {@code public}
* @see java.lang.reflect.Modifier#isPublic(int)
* @see Modifier#isPublic(int)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only this unrelated change is quite impressive having a very modern codebase.

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}

*/
public static boolean isPublic(Class<?> clazz) {
return ReflectionUtils.isPublic(clazz);
Expand All @@ -58,7 +59,7 @@ public static boolean isPublic(Class<?> clazz) {
*
* @param member the member to check; never {@code null}
* @return {@code true} if the member is {@code public}
* @see java.lang.reflect.Modifier#isPublic(int)
* @see Modifier#isPublic(int)
*/
public static boolean isPublic(Member member) {
return ReflectionUtils.isPublic(member);
Expand All @@ -69,7 +70,7 @@ public static boolean isPublic(Member member) {
*
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is {@code private}
* @see java.lang.reflect.Modifier#isPrivate(int)
* @see Modifier#isPrivate(int)
*/
public static boolean isPrivate(Class<?> clazz) {
return ReflectionUtils.isPrivate(clazz);
Expand All @@ -80,7 +81,7 @@ public static boolean isPrivate(Class<?> clazz) {
*
* @param member the member to check; never {@code null}
* @return {@code true} if the member is {@code private}
* @see java.lang.reflect.Modifier#isPrivate(int)
* @see Modifier#isPrivate(int)
*/
public static boolean isPrivate(Member member) {
return ReflectionUtils.isPrivate(member);
Expand All @@ -96,9 +97,9 @@ public static boolean isPrivate(Member member) {
*
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is not {@code private}
* @see java.lang.reflect.Modifier#isPublic(int)
* @see java.lang.reflect.Modifier#isProtected(int)
* @see java.lang.reflect.Modifier#isPrivate(int)
* @see Modifier#isPublic(int)
* @see Modifier#isProtected(int)
* @see Modifier#isPrivate(int)
*/
public static boolean isNotPrivate(Class<?> clazz) {
return ReflectionUtils.isNotPrivate(clazz);
Expand All @@ -114,9 +115,9 @@ public static boolean isNotPrivate(Class<?> clazz) {
*
* @param member the member to check; never {@code null}
* @return {@code true} if the member is not {@code private}
* @see java.lang.reflect.Modifier#isPublic(int)
* @see java.lang.reflect.Modifier#isProtected(int)
* @see java.lang.reflect.Modifier#isPrivate(int)
* @see Modifier#isPublic(int)
* @see Modifier#isProtected(int)
* @see Modifier#isPrivate(int)
*/
public static boolean isNotPrivate(Member member) {
return ReflectionUtils.isNotPrivate(member);
Expand All @@ -127,7 +128,7 @@ public static boolean isNotPrivate(Member member) {
*
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is {@code abstract}
* @see java.lang.reflect.Modifier#isAbstract(int)
* @see Modifier#isAbstract(int)
*/
public static boolean isAbstract(Class<?> clazz) {
return ReflectionUtils.isAbstract(clazz);
Expand All @@ -138,7 +139,7 @@ public static boolean isAbstract(Class<?> clazz) {
*
* @param member the class to check; never {@code null}
* @return {@code true} if the member is {@code abstract}
* @see java.lang.reflect.Modifier#isAbstract(int)
* @see Modifier#isAbstract(int)
*/
public static boolean isAbstract(Member member) {
return ReflectionUtils.isAbstract(member);
Expand All @@ -150,7 +151,7 @@ public static boolean isAbstract(Member member) {
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is not {@code abstract}
* @since 1.13
* @see java.lang.reflect.Modifier#isAbstract(int)
* @see Modifier#isAbstract(int)
*/
@API(status = EXPERIMENTAL, since = "6.0")
public static boolean isNotAbstract(Class<?> clazz) {
Expand All @@ -163,7 +164,7 @@ public static boolean isNotAbstract(Class<?> clazz) {
* @param member the class to check; never {@code null}
* @return {@code true} if the member is not {@code abstract}
* @since 1.13
* @see java.lang.reflect.Modifier#isAbstract(int)
* @see Modifier#isAbstract(int)
*/
@API(status = EXPERIMENTAL, since = "6.0")
public static boolean isNotAbstract(Member member) {
Expand All @@ -175,7 +176,7 @@ public static boolean isNotAbstract(Member member) {
*
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is {@code static}
* @see java.lang.reflect.Modifier#isStatic(int)
* @see Modifier#isStatic(int)
*/
public static boolean isStatic(Class<?> clazz) {
return ReflectionUtils.isStatic(clazz);
Expand All @@ -186,7 +187,7 @@ public static boolean isStatic(Class<?> clazz) {
*
* @param member the member to check; never {@code null}
* @return {@code true} if the member is {@code static}
* @see java.lang.reflect.Modifier#isStatic(int)
* @see Modifier#isStatic(int)
*/
public static boolean isStatic(Member member) {
return ReflectionUtils.isStatic(member);
Expand All @@ -197,7 +198,7 @@ public static boolean isStatic(Member member) {
*
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is not {@code static}
* @see java.lang.reflect.Modifier#isStatic(int)
* @see Modifier#isStatic(int)
*/
public static boolean isNotStatic(Class<?> clazz) {
return ReflectionUtils.isNotStatic(clazz);
Expand All @@ -208,7 +209,7 @@ public static boolean isNotStatic(Class<?> clazz) {
*
* @param member the member to check; never {@code null}
* @return {@code true} if the member is not {@code static}
* @see java.lang.reflect.Modifier#isStatic(int)
* @see Modifier#isStatic(int)
*/
public static boolean isNotStatic(Member member) {
return ReflectionUtils.isNotStatic(member);
Expand All @@ -220,7 +221,7 @@ public static boolean isNotStatic(Member member) {
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is {@code final}
* @since 1.5
* @see java.lang.reflect.Modifier#isFinal(int)
* @see Modifier#isFinal(int)
*/
@API(status = MAINTAINED, since = "1.5")
public static boolean isFinal(Class<?> clazz) {
Expand All @@ -233,7 +234,7 @@ public static boolean isFinal(Class<?> clazz) {
* @param clazz the class to check; never {@code null}
* @return {@code true} if the class is not {@code final}
* @since 1.5
* @see java.lang.reflect.Modifier#isFinal(int)
* @see Modifier#isFinal(int)
*/
@API(status = MAINTAINED, since = "1.5")
public static boolean isNotFinal(Class<?> clazz) {
Expand All @@ -246,7 +247,7 @@ public static boolean isNotFinal(Class<?> clazz) {
* @param member the member to check; never {@code null}
* @return {@code true} if the member is {@code final}
* @since 1.5
* @see java.lang.reflect.Modifier#isFinal(int)
* @see Modifier#isFinal(int)
*/
@API(status = MAINTAINED, since = "1.5")
public static boolean isFinal(Member member) {
Expand All @@ -259,7 +260,7 @@ public static boolean isFinal(Member member) {
* @param member the member to check; never {@code null}
* @return {@code true} if the member is not {@code final}
* @since 1.5
* @see java.lang.reflect.Modifier#isFinal(int)
* @see Modifier#isFinal(int)
*/
@API(status = MAINTAINED, since = "1.5")
public static boolean isNotFinal(Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private static boolean containsFilesWithExtensions(Path dir, String... extension
return false;
};
try (Stream<Path> pathStream = Files.find(dir, 1, matcher)) {
return pathStream.findFirst().isPresent();
return pathStream.findAny().isPresent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

package platform.tooling.support.tests;

import static java.util.function.Predicate.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -24,7 +25,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.spi.ToolProvider;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -182,7 +182,8 @@ private static void treeWalk(Path root, Consumer<String> out) {
try (var stream = Files.walk(root)) {
stream.map(root::relativize) //
.map(path -> path.toString().replace('\\', '/')) //
.sorted().filter(Predicate.not(String::isEmpty)) //
.filter(not(String::isEmpty)) //
.sorted() //
.forEach(out);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import java.util.ServiceLoader;
import java.util.Set;
import java.util.spi.ToolProvider;
import java.util.stream.StreamSupport;

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

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

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

assertTrue(junit.isPresent(), "Tool 'junit' not found in modules: " + modules);
assertJUnitPrintsHelpMessage(junit.get());
Expand Down
19 changes: 19 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.junit.openrewrite.SanityCheck
displayName: Apply all Java & Gradle best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
tags:
- java
- gradle
- static-analysis
- cleanup
recipeList:
- org.openrewrite.gradle.EnableGradleBuildCache
- org.openrewrite.gradle.EnableGradleParallelExecution
- org.openrewrite.gradle.GradleBestPractices
- org.openrewrite.java.format.NormalizeLineBreaks
- org.openrewrite.java.format.RemoveTrailingWhitespace
- org.openrewrite.java.migrate.UpgradeToJava17
- tech.picnic.errorprone.refasterrules.StreamRulesRecipes
---
Loading