Skip to content
Open
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
36 changes: 35 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI ♻️

on:
push:
Expand Down Expand Up @@ -134,3 +134,37 @@ jobs:
antora \
-Pantora.downloadNode=false \
-Dscan.tag.Documentation

sanity:
name: Sanity Check 🕊
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
persist-credentials: false
- name: Checkstyle ☑️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: checkstyleMain
- name: Spotless ✨
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: spotlessCheck
- name: ArchUnit 🏛️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: archUnit
- name: OSGi 🧩
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: verifyOSGiTask
- name: Rewrite ⚙️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx3G
48 changes: 48 additions & 0 deletions .github/workflows/sanity-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Sanity Check 🕊
on:
push:
branches:
- main
- 'releases/**'
paths:
- '.github/**'
pull_request:
paths:
- '.github/**'
permissions: {}
jobs:
validate:
name: Validate 📊
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Checkout Repository 📥
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
persist-credentials: false
- name: Checkstyle ☑️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: checkstyleMain
- name: Spotless ✨
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: spotlessCheck
- name: ArchUnit 🏛️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: archUnit
- name: OSGi 🧩
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: verifyOSGiTask
- name: Rewrite ⚙️
uses: ./.github/actions/run-gradle
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: rewriteDryRun -Dorg.gradle.jvmargs=-Xmx3G
4 changes: 2 additions & 2 deletions documentation/src/main/java/example/domain/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public LocalDate getDateOfBirth() {

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
final var prime = 31;
var result = 1;
result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
return result;
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/main/java/example/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
public class StringUtils {

public static boolean isPalindrome(@Nullable String candidate) {
int length = requireNonNull(candidate).length();
for (int i = 0; i < length / 2; i++) {
var length = requireNonNull(candidate).length();
for (var i = 0; i < length / 2; i++) {
if (candidate.charAt(i) != candidate.charAt(length - (i + 1))) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void main(String... args) {
// -------------------------------------------------------------------------

private static Map<Status, StreamOpener> parseArgs(String[] args) {
Map<Status, StreamOpener> outputByStatus = new EnumMap<>(Status.class);
var outputByStatus = new EnumMap<Status, StreamOpener>(Status.class);
if (args.length == 0) {
outputByStatus.put(Status.EXPERIMENTAL, () -> null);
}
Expand All @@ -107,7 +107,7 @@ private interface StreamOpener {
}

private static ApiReport generateReport(ScanResult scanResult) {
Map<Status, List<Declaration>> declarations = new EnumMap<>(Status.class);
var declarations = new EnumMap<Status, List<Declaration>>(Status.class);
for (var status : Status.values()) {
declarations.put(status, new ArrayList<>());
}
Expand Down
15 changes: 15 additions & 0 deletions gradle/config/rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.junit.openrewrite.SanityCheck
displayName: Apply all common best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
recipeList:
- org.openrewrite.java.migrate.lang.var.UseVarForGenericsConstructors
- org.openrewrite.java.migrate.lang.var.UseVarForPrimitive
- org.openrewrite.staticanalysis.NoDoubleBraceInitialization
Copy link
Owner Author

Choose a reason for hiding this comment

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

# - org.openrewrite.gradle.UpdateGradleWrapper
# - org.openrewrite.java.migrate.lang.var.UseVarForGenericMethodInvocations # bug
# - org.openrewrite.java.migrate.lang.var.UseVarForObject # bug
# - org.openrewrite.java.testing.junit.JupiterBestPractices
# - org.openrewrite.java.testing.junit5.CleanupAssertions
---
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ commonCustomUserData = { id = "com.gradle.common-custom-user-data-gradle-plugin"
develocity = { id = "com.gradle.develocity", version = "4.2.2" }
download = { id = "de.undercouch.download", version = "5.6.0" }
errorProne = { id = "net.ltgt.errorprone", version = "4.3.0" }
rewrite = { id = "org.openrewrite.rewrite", version = "7.22.0" }
foojayResolver = { id = "org.gradle.toolchains.foojay-resolver", version = "1.0.0" }
jmh = { id = "me.champeau.jmh", version = "0.7.3" }
jreleaser = { id = "org.jreleaser", version = "1.21.0" }
Expand Down
5 changes: 3 additions & 2 deletions gradle/plugins/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ plugins {

dependencies {
implementation("junitbuild.base:dsl-extensions")
implementation(projects.buildParameters)
implementation(projects.backwardCompatibility)
implementation(libs.plugins.kotlin.markerCoordinates)
implementation(projects.buildParameters)
implementation(libs.plugins.bnd.markerCoordinates)
implementation(libs.plugins.commonCustomUserData.markerCoordinates)
implementation(libs.plugins.develocity.markerCoordinates)
implementation(libs.plugins.errorProne.markerCoordinates)
implementation(libs.plugins.foojayResolver.markerCoordinates)
implementation(libs.plugins.jmh.markerCoordinates)
implementation(libs.plugins.kotlin.markerCoordinates)
implementation(libs.plugins.nullaway.markerCoordinates)
implementation(libs.plugins.rewrite.markerCoordinates)
implementation(libs.plugins.shadow.markerCoordinates)
implementation(libs.plugins.spotless.markerCoordinates)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ checkstyle {
toolVersion = requiredVersionFromLibs("checkstyle")
configDirectory = rootProject.layout.projectDirectory.dir("gradle/config/checkstyle")
}

tasks.check {
dependsOn(tasks.withType<Checkstyle>())
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id("junitbuild.eclipse-conventions")
id("junitbuild.jacoco-java-conventions")
id("junitbuild.java-errorprone-conventions")
id("junitbuild.rewrite-conventions")
}

val mavenizedProjects: List<Project> by rootProject.extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,21 @@ val osgiVerificationClasspath = configurations.resolvable("osgiVerificationClass
extendsFrom(osgiVerification.get())
}

// Make the task available for calling from outside
tasks.register("verifyOSGiTask") {
description = "Verifies OSGi metadata in the built jar"
group = "verification"
dependsOn(verify)
}

// Bnd's Resolve task is what verifies that a jar can be used in OSGi and
// that its metadata is valid. If the metadata is invalid this task will
// fail.
val verifyOSGi by tasks.registering(Resolve::class) {
val verify by tasks.registering(Resolve::class) {
bndrun = osgiProperties.flatMap { it.destinationFile }
outputBndrun = layout.buildDirectory.file("resolvedOSGiProperties.bndrun")
isReportOptional = false
// By default bnd will use jars found in:
// By default, bnd will use jars found in:
// 1. project.sourceSets.main.runtimeClasspath
// 2. project.configurations.archives.artifacts.files
// to validate the metadata.
Expand All @@ -116,7 +123,3 @@ val verifyOSGi by tasks.registering(Resolve::class) {
bundles(osgiVerificationClasspath)
properties.empty()
}

tasks.check {
dependsOn(verifyOSGi)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
plugins {
id("org.openrewrite.rewrite")
}

dependencies {
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.24.0")
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.23.0")
rewrite("org.openrewrite.recipe:rewrite-testing-frameworks:3.23.0")
}

rewrite {
activeRecipe("org.junit.openrewrite.SanityCheck")
configFile = project.getRootProject().file("gradle/config/rewrite.yml")
exclusion(
// "**AssertionsTests.java", // https://github.com/openrewrite/rewrite-static-analysis/issues/799
// legacy
"**TestCase.java",
"**TestCases.java",
"**documentation/src/test/java/example**",
"**testFixtures/java/org/junit/vintage/engine/samples**",
)
setExportDatatables(true)
setFailOnDryRunResults(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static void assertArrayEquals(boolean @Nullable [] expected, boolean @Nu
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -217,7 +217,7 @@ private static void assertArrayEquals(char @Nullable [] expected, char @Nullable
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -239,7 +239,7 @@ private static void assertArrayEquals(byte @Nullable [] expected, byte @Nullable
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -261,7 +261,7 @@ private static void assertArrayEquals(short @Nullable [] expected, short @Nullab
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -283,7 +283,7 @@ private static void assertArrayEquals(int @Nullable [] expected, int @Nullable [
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -305,7 +305,7 @@ private static void assertArrayEquals(long @Nullable [] expected, long @Nullable
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -327,7 +327,7 @@ private static void assertArrayEquals(float @Nullable [] expected, float @Nullab
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (!AssertionUtils.floatsAreEqual(expected[i], actual[i])) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -350,7 +350,7 @@ private static void assertArrayEquals(float @Nullable [] expected, float @Nullab
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (!AssertionUtils.floatsAreEqual(expected[i], actual[i], delta)) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -372,7 +372,7 @@ private static void assertArrayEquals(double @Nullable [] expected, double @Null
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (!AssertionUtils.doublesAreEqual(expected[i], actual[i])) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -395,7 +395,7 @@ private static void assertArrayEquals(double @Nullable [] expected, double @Null
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
if (!AssertionUtils.doublesAreEqual(expected[i], actual[i], delta)) {
failArraysNotEqual(expected[i], actual[i], nullSafeIndexes(indexes, i), messageOrSupplier);
}
Expand All @@ -417,7 +417,7 @@ private static void assertArrayEquals(@Nullable Object @Nullable [] expected, @N
}
assertArraysHaveSameLength(expected.length, actual.length, indexes, messageOrSupplier);

for (int i = 0; i < expected.length; i++) {
for (var i = 0; i < expected.length; i++) {
Object expectedElement = expected[i];
Object actualElement = actual[i];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private static void assertIterableEquals(@Nullable Iterable<?> expected, @Nullab
Iterator<?> expectedIterator = expected.iterator();
Iterator<?> actualIterator = actual.iterator();

int processed = 0;
var processed = 0;
while (expectedIterator.hasNext() && actualIterator.hasNext()) {
Object expectedElement = expectedIterator.next();
Object actualElement = actualIterator.next();
Expand Down
Loading