Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: rewriteDryRun
Copy link
Author

Choose a reason for hiding this comment

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

this is just an reminder of course you need to choose where to put this best.

uses: ./.github/actions/main-build
with:
encryptionKey: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
arguments: rewriteDryRun

Windows:
runs-on: windows-latest
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id("junitbuild.jacoco-aggregation-conventions")
id("junitbuild.maven-central-publishing")
id("junitbuild.temp-maven-repo")
id("org.openrewrite.rewrite") version "7.17.0" apply false
}

description = "JUnit"
Expand Down Expand Up @@ -54,3 +55,5 @@ dependencies {
jacocoAggregation(projects.jupiterTests)
jacocoAggregation(projects.platformTests)
}

apply(from = "$rootDir/gradle/rewrite.gradle")
16 changes: 16 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apply plugin: "org.openrewrite.rewrite"

rewrite {
activeRecipe("org.junit.jupiter.openrewrite.SanityCheck")
exportDatatables = true
failOnDryRunResults = true
}

dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.15.0"))
rewrite("org.openrewrite.recipe:rewrite-java-security:3.19.0")
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.18.0")
rewrite("org.openrewrite.recipe:rewrite-rewrite:0.13.0")
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.18.0")
rewrite("org.openrewrite.recipe:rewrite-third-party:0.28.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private UniqueId(UniqueIdFormat uniqueIdFormat, Segment segment) {
}

Optional<Segment> getRoot() {
return this.segments.isEmpty() ? Optional.empty() : Optional.of(this.segments.get(0));
return this.segments.stream().findFirst();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
BigDecimal factor = configurationParameters.get(CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME,
BigDecimal::new).orElse(BigDecimal.ONE);

Preconditions.condition(factor.compareTo(BigDecimal.ZERO) > 0,
Preconditions.condition(factor.signum() == 1,
() -> "Factor '%s' specified via configuration parameter '%s' must be greater than 0".formatted(factor,
CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public FilterResult apply(TestEngine testEngine) {
Preconditions.notBlank(engineId, "TestEngine ID must not be null or blank");

if (this.type == Type.INCLUDE) {
return includedIf(this.engineIds.stream().anyMatch(engineId::equals), //
return includedIf(this.engineIds.contains(engineId), //
() -> "Engine ID [%s] is in included list [%s]".formatted(engineId, this.engineIds), //
() -> "Engine ID [%s] is not in included list [%s]".formatted(engineId, this.engineIds));
}
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 @@ -174,7 +174,7 @@ Collection rawCollectionFactory() {

@TestFactory
Stream<?> unboundStreamFactory() {
return Stream.of();
return Stream.empty();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void convertsStringToURL() throws Exception {
@Test
void convertsStringsToJavaTimeInstances() {
assertConverts("PT1234.5678S", Duration.class, Duration.ofSeconds(1234, 567800000));
assertConverts("1970-01-01T00:00:00Z", Instant.class, Instant.ofEpochMilli(0));
assertConverts("1970-01-01T00:00:00Z", Instant.class, Instant.EPOCH);
assertConverts("2017-03-14", LocalDate.class, LocalDate.of(2017, 3, 14));
assertConverts("2017-03-14T12:34:56.789", LocalDateTime.class,
LocalDateTime.of(2017, 3, 14, 12, 34, 56, 789_000_000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private <T extends Serializable> void assertSerializable(T instance) {
var serialized = serialize(instance);
var deserialized = deserialize(serialized);

assertTrue(type.isAssignableFrom(deserialized.getClass()));
assertTrue(type.isInstance(deserialized));
assertEquals(instance, deserialized);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String toCliArgument() {
@Override
public void close() throws IOException {
try (var files = Files.walk(tempDir)) {
files.sorted(Comparator.<Path> naturalOrder().reversed()) //
files.sorted(Comparator.reverseOrder()) //
.forEach(path -> {
try {
Files.delete(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ 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(Predicate.not(String::isEmpty)).sorted() //
.forEach(out);
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ record OutputDir(Path root) implements AutoCloseable {

@Override
public void close() throws Exception {
try (var stream = Files.walk(root).sorted(Comparator.<Path> naturalOrder().reversed())) {
try (var stream = Files.walk(root).sorted(Comparator.reverseOrder())) {
stream.forEach(path -> {
try {
Files.delete(path);
Expand Down
50 changes: 50 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.junit.jupiter.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.java.security.JavaSecurityBestPractices
- org.openrewrite.staticanalysis.NoFinalizer
- org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods
- tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes
- tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes
- tech.picnic.errorprone.refasterrules.ClassRulesRecipes
- tech.picnic.errorprone.refasterrules.CollectionRulesRecipes
- tech.picnic.errorprone.refasterrules.ComparatorRulesRecipes
- tech.picnic.errorprone.refasterrules.FileRulesRecipes
- tech.picnic.errorprone.refasterrules.MicrometerRulesRecipes
- tech.picnic.errorprone.refasterrules.PatternRulesRecipes
- tech.picnic.errorprone.refasterrules.PreconditionsRulesRecipes
- tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes
- tech.picnic.errorprone.refasterrules.StreamRulesRecipes
- tech.picnic.errorprone.refasterrules.TimeRulesRecipes
# - org.openrewrite.staticanalysis.EqualsAvoidsNull
Copy link
Author

Choose a reason for hiding this comment

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

this does change alot despite the initial effort. Every tool has its benefits making it win to the community.

# - org.openrewrite.staticanalysis.ModifierOrder
# - org.checkstyle.CheckstyleAutoFix # await release
# - org.openrewrite.gradle.GradleBestPractices
# - org.openrewrite.java.RemoveUnusedImports
# - org.openrewrite.java.format.RemoveTrailingWhitespace
# - org.openrewrite.java.migrate.UpgradeToJava17
# - org.openrewrite.java.recipes.JavaRecipeBestPractices
# - org.openrewrite.java.recipes.RecipeTestingBestPractices
# - org.openrewrite.staticanalysis.CodeCleanup # bug
# - org.openrewrite.staticanalysis.CommonStaticAnalysis
# - org.openrewrite.staticanalysis.JavaApiBestPractices
# - org.openrewrite.staticanalysis.LowercasePackage
# - org.openrewrite.staticanalysis.MissingOverrideAnnotation
# - org.openrewrite.staticanalysis.NoToStringOnStringType
# - org.openrewrite.staticanalysis.NoValueOfOnStringType
# - org.openrewrite.staticanalysis.RemoveUnusedLocalVariables
# - org.openrewrite.staticanalysis.RemoveUnusedPrivateFields
# - org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources
# - org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments
# - org.openrewrite.staticanalysis.UnnecessaryParentheses
# - org.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement
# - org.openrewrite.staticanalysis.UnnecessaryThrows # bug
---