diff --git a/.github/ISSUE_TEMPLATE/additional_static_rule.md b/.github/ISSUE_TEMPLATE/additional_static_rule.md index e1e1abf14..e3c88da1d 100644 --- a/.github/ISSUE_TEMPLATE/additional_static_rule.md +++ b/.github/ISSUE_TEMPLATE/additional_static_rule.md @@ -11,7 +11,7 @@ assignees: '' If existing, a reference to the rule from the external system : - https://rules.sonarsource.com/java/RSPEC-1116 -- https://pmd.github.io/latest/pmd_rules_java_codestyle.html#emptycontrolstatement +- https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#emptycontrolstatement - https://javadoc.io/static/com.puppycrawl.tools/checkstyle/8.37/com/puppycrawl/tools/checkstyle/checks/coding/EmptyStatementCheck.html Please also provide code examples `before` -> `after`. diff --git a/CHANGES.MD b/CHANGES.MD index a79711b77..24d3577bf 100644 --- a/CHANGES.MD +++ b/CHANGES.MD @@ -2,6 +2,12 @@ This document is intended for CleanThat developers and users (e.g. through [Spot We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format +## [2.24] + +* `UseUnderscoresInNumericLiterals` has now homogeneous behavior between both floating number legs, following PMD expectation. https://github.com/solven-eu/cleanthat/issues/896 +* `ModifierOrder` may corrupt code by lack of whitespaces due to JavaParser bug. https://github.com/solven-eu/cleanthat/issues/897 +* `JavaParser` is updated to `3.27.0` to fix https://github.com/solven-eu/cleanthat/issues/899 + ## [2.23] * `UnnecessaryModifier` is reworked for simplification. It includes further management of `record`. (https://github.com/solven-eu/cleanthat/pull/848) diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD index 9f14d3a0e..ef0601f5d 100644 --- a/CONTRIBUTING.MD +++ b/CONTRIBUTING.MD @@ -11,6 +11,17 @@ Once done (or re-done after a release), you can simply: # Note for `mutator` contributors +## Bug with JavaParser + +We regularly encounter bugs with `JavaParser` upstream dependency. In such case, with or without a workaround, it would be beneficial to report the case to JavaParser. + +Many issues are related with `LexicalPreservingPrinter`. + +Typical cases are: + +- https://github.com/javaparser/javaparser/issues/3924 +- https://github.com/javaparser/javaparser/issues/3936 + ## Unit-tests Mutators are subject to many edge-cases, due to the complexity of syntaxes (including Java). @@ -65,6 +76,14 @@ A given rule can be tested against a large set of codebases with https://github. # Notes for maintainers +## Additional mutator + +Add you rule in `eu.solven.cleanthat.engine.java.refactorer.mutators.scanner.MutatorsScanner`. + +## Generate documentation + +Run `TestGenerateDocumentation`. + ## Deploy into Production (AWS Lambda): git push origin master:deploy-prd diff --git a/MUTATORS.generated.MD b/MUTATORS.generated.MD index bc186b8b4..566e72375 100644 --- a/MUTATORS.generated.MD +++ b/MUTATORS.generated.MD @@ -54,7 +54,7 @@ languageLevel: jdk1.2 ### [ComparisonWithNaN](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ComparisonWithNaN.java) -PMD: [ComparisonWithNaN](https://pmd.github.io/latest/pmd_rules_java_errorprone.html#comparisonwithnan) +PMD: [ComparisonWithNaN](https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#comparisonwithnan) Cleanthat own ID: ComparisonWithNaN @@ -62,7 +62,7 @@ languageLevel: jdk11 ### [LiteralsFirstInComparisons](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LiteralsFirstInComparisons.java) -PMD: [LiteralsFirstInComparisons](https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#literalsfirstincomparisons) +PMD: [LiteralsFirstInComparisons](https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#literalsfirstincomparisons) Cleanthat own ID: LiteralsFirstInComparisons @@ -110,7 +110,7 @@ languageLevel: jdk1.8 ### [SimplifyStartsWith](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyStartsWith.java) -PMD: [SimplifyStartsWith](https://pmd.github.io/latest/pmd_rules_java_performance.html#simplifystartswith) +PMD: [SimplifyStartsWith](https://pmd.github.io/pmd-doc-6.55.0/pmd_rules_java_performance.html#simplifystartswith) Cleanthat own ID: SimplifyStartsWith @@ -134,7 +134,7 @@ languageLevel: jdk1.4 ### [StringToString](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java) -PMD: [StringToString](https://pmd.github.io/latest/pmd_rules_java_performance.html#stringtostring) +PMD: [StringToString](https://pmd.github.io/pmd/pmd_rules_java_performance.html#stringtostring) jSparrow: [RemoveToStringOnString](https://jsparrow.github.io/rules/remove-to-string-on-string.html) @@ -152,7 +152,7 @@ languageLevel: jdk1.1 ### [UnnecessaryModifier](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java) -PMD: [UnnecessaryModifier](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessarymodifier) +PMD: [UnnecessaryModifier](https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessarymodifier) CheckStyle: [RedundantModifier](https://checkstyle.sourceforge.io/config_modifier.html#RedundantModifier) @@ -166,7 +166,7 @@ languageLevel: jdk1 ### [UseCollectionIsEmpty](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseCollectionIsEmpty.java) -PMD: [UseCollectionIsEmpty](https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#usecollectionisempty) +PMD: [UseCollectionIsEmpty](https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#usecollectionisempty) Sonar: [RSPEC-1155](https://rules.sonarsource.com/java/RSPEC-1155) @@ -178,7 +178,7 @@ languageLevel: jdk1.2 ### [UseIndexOfChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java) -PMD: [UseIndexOfChar](https://pmd.github.io/latest/pmd_rules_java_performance.html#useindexofchar) +PMD: [UseIndexOfChar](https://pmd.github.io/pmd/pmd_rules_java_performance.html#useindexofchar) Sonar: [RSPEC-1155](https://rules.sonarsource.com/java/RSPEC-1155) @@ -194,7 +194,7 @@ languageLevel: jdk1.6 ### [UseUnderscoresInNumericLiterals](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseUnderscoresInNumericLiterals.java) -PMD: [UseUnderscoresInNumericLiterals](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#useunderscoresinnumericliterals) +PMD: [UseUnderscoresInNumericLiterals](https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#useunderscoresinnumericliterals) Sonar: [RSPEC-2148](https://rules.sonarsource.com/java/RSPEC-2148) @@ -204,6 +204,16 @@ languageLevel: jdk1.7 ## Single Mutators (DRAFTs) +### [AppendCharacterWithChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java) + +PMD: [AppendCharacterWithChar](https://pmd.github.io/pmd/pmd_rules_java_performance.html#appendcharacterwithchar) + +Cleanthat own ID: AppendCharacterWithChar + +isDraft + +languageLevel: jdk1.5 + ### [ArithmeticOverFloats](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArithmeticOverFloats.java) Sonar: [RSPEC-2164](https://rules.sonarsource.com/java/RSPEC-2164) @@ -216,7 +226,7 @@ languageLevel: jdk1 ### [AvoidFileStream](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java) -PMD: [AvoidFileStream](https://pmd.github.io/latest/pmd_rules_java_performance.html#avoidfilestream) +PMD: [AvoidFileStream](https://pmd.github.io/pmd/pmd_rules_java_performance.html#avoidfilestream) Cleanthat own ID: AvoidFileStream @@ -226,7 +236,7 @@ languageLevel: jdk1.7 ### [AvoidUncheckedExceptionsInSignatures](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java) -PMD: [AvoidUncheckedExceptionsInSignatures](https://pmd.github.io/latest/pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures) +PMD: [AvoidUncheckedExceptionsInSignatures](https://pmd.github.io/pmd/pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures) Cleanthat own ID: AvoidUncheckedExceptionsInSignatures @@ -472,7 +482,7 @@ languageLevel: jdk1.8 ### [PrimitiveWrapperInstantiation](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java) -PMD: [PrimitiveWrapperInstantiation](https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#primitivewrapperinstantiation) +PMD: [PrimitiveWrapperInstantiation](https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#primitivewrapperinstantiation) Cleanthat own ID: PrimitiveWrapperInstantiation @@ -586,9 +596,19 @@ isDraft languageLevel: jdk1 +### [UnnecessaryCaseChange](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java) + +PMD: [UnnecessaryCaseChange](https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#unnecessarycasechange) + +Cleanthat own ID: UnnecessaryCaseChange + +isDraft + +languageLevel: jdk1 + ### [UnnecessaryFullyQualifiedName](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java) -PMD: [UnnecessaryFullyQualifiedName](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname) +PMD: [UnnecessaryFullyQualifiedName](https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname) Cleanthat own ID: UnnecessaryFullyQualifiedName @@ -618,7 +638,7 @@ languageLevel: jdk1.8 ### [UnnecessarySemicolon](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessarySemicolon.java) -PMD: [UnnecessarySemicolon](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessarysemicolon) +PMD: [UnnecessarySemicolon](https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessarysemicolon) Sonar: [RSPEC-2959](https://rules.sonarsource.com/java/RSPEC-2959) @@ -630,7 +650,7 @@ languageLevel: jdk1 ### [UseDiamondOperator](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseDiamondOperator.java) -PMD: [UseDiamondOperator](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#usediamondoperator) +PMD: [UseDiamondOperator](https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#usediamondoperator) Sonar: [RSPEC-2293](https://rules.sonarsource.com/java/RSPEC-2293) @@ -642,7 +662,7 @@ languageLevel: jdk1.7 ### [UseDiamondOperatorJdk8](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseDiamondOperatorJdk8.java) -PMD: [UseDiamondOperator](https://pmd.github.io/latest/pmd_rules_java_codestyle.html#usediamondoperator) +PMD: [UseDiamondOperator](https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#usediamondoperator) Sonar: [RSPEC-2293](https://rules.sonarsource.com/java/RSPEC-2293) diff --git a/MUTATORS_BY_TAG.generated.MD b/MUTATORS_BY_TAG.generated.MD index 2d668dc2e..27d20692b 100644 --- a/MUTATORS_BY_TAG.generated.MD +++ b/MUTATORS_BY_TAG.generated.MD @@ -21,6 +21,7 @@ ## Draft +- [AppendCharacterWithChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java) - [ArithmeticOverFloats](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArithmeticOverFloats.java) - [AvoidFileStream](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java) - [AvoidUncheckedExceptionsInSignatures](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java) @@ -61,6 +62,7 @@ - [StringFromString](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringFromString.java) - [StringReplaceAllWithQuotableInput](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringReplaceAllWithQuotableInput.java) - [ThreadRunToThreadStart](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ThreadRunToThreadStart.java) +- [UnnecessaryCaseChange](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java) - [UnnecessaryFullyQualifiedName](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java) - [UnnecessaryImport](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java) - [UnnecessaryLambdaEnclosingParameters](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryLambdaEnclosingParameters.java) @@ -151,6 +153,7 @@ ## PMD +- [AppendCharacterWithChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java) - [AvoidFileStream](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java) - [AvoidMultipleUnaryOperators](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidMultipleUnaryOperators.java) - [AvoidUncheckedExceptionsInSignatures](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java) @@ -159,6 +162,7 @@ - [PrimitiveWrapperInstantiation](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java) - [SimplifyStartsWith](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyStartsWith.java) - [StringToString](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java) +- [UnnecessaryCaseChange](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java) - [UnnecessaryFullyQualifiedName](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java) - [UnnecessaryModifier](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java) - [UnnecessarySemicolon](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessarySemicolon.java) @@ -258,6 +262,7 @@ - [StringIndexOfToContains](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringIndexOfToContains.java) - [StringReplaceAllWithQuotableInput](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringReplaceAllWithQuotableInput.java) - [StringToString](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java) +- [UnnecessaryCaseChange](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java) - [UseIndexOfChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java) - [UseStringIsEmpty](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseStringIsEmpty.java) - [UseTextBlocks](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseTextBlocks.java) @@ -286,6 +291,7 @@ - [SimplifyBooleanExpression](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyBooleanExpression.java) - [StringToString](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java) - [ThreadRunToThreadStart](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ThreadRunToThreadStart.java) +- [UnnecessaryCaseChange](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java) - [UnnecessaryFullyQualifiedName](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java) - [UnnecessaryImport](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java) - [UnnecessaryModifier](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java) @@ -311,6 +317,7 @@ ## With JDK 1.5 +- [AppendCharacterWithChar](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java) - [EnumsWithoutEquals](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EnumsWithoutEquals.java) - [PrimitiveWrapperInstantiation](java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java) diff --git a/annotations/pom.xml b/annotations/pom.xml index 697966876..667448365 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT annotations diff --git a/any-language/pom.xml b/any-language/pom.xml index 1ad22c19e..4fcab9715 100644 --- a/any-language/pom.xml +++ b/any-language/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT any-language diff --git a/any-language/src/main/java/eu/solven/cleanthat/engine/EngineAndLinters.java b/any-language/src/main/java/eu/solven/cleanthat/engine/EngineAndLinters.java index 6e16345e4..b9e160943 100644 --- a/any-language/src/main/java/eu/solven/cleanthat/engine/EngineAndLinters.java +++ b/any-language/src/main/java/eu/solven/cleanthat/engine/EngineAndLinters.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,13 @@ import java.util.List; import java.util.stream.IntStream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.MoreObjects; import eu.solven.cleanthat.formatter.ILintFixer; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; /** * Computed processors, to be applicable to any file of a given repository @@ -32,25 +32,14 @@ * @author Benoit Lacelle * */ +@Slf4j +@Getter +@RequiredArgsConstructor public class EngineAndLinters implements AutoCloseable { - private static final Logger LOGGER = LoggerFactory.getLogger(EngineAndLinters.class); final IEngineProperties engineProperties; final List linters; - public EngineAndLinters(IEngineProperties engineProperties, List linters) { - this.engineProperties = engineProperties; - this.linters = linters; - } - - public IEngineProperties getEngineProperties() { - return engineProperties; - } - - public List getLinters() { - return linters; - } - @Override public String toString() { var builder = MoreObjects.toStringHelper(this).add("engine", engineProperties.getEngine()); diff --git a/any-language/src/main/java/eu/solven/cleanthat/formatter/CodeFormatterApplier.java b/any-language/src/main/java/eu/solven/cleanthat/formatter/CodeFormatterApplier.java index 7ee33d634..dd14e188b 100644 --- a/any-language/src/main/java/eu/solven/cleanthat/formatter/CodeFormatterApplier.java +++ b/any-language/src/main/java/eu/solven/cleanthat/formatter/CodeFormatterApplier.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,22 +20,19 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.solven.cleanthat.config.IDocumentationConstants; import eu.solven.cleanthat.engine.EngineAndLinters; import eu.solven.cleanthat.engine.ICodeFormatterApplier; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * Abstract class for language formatters * * @author Benoit Lacelle */ +@Slf4j public class CodeFormatterApplier implements ICodeFormatterApplier { - private static final Logger LOGGER = LoggerFactory.getLogger(CodeFormatterApplier.class); - public static final AtomicInteger NB_EXCEPTIONS = new AtomicInteger(); @Override diff --git a/code-cleaners/pom.xml b/code-cleaners/pom.xml index e1dd8a534..0c38c294c 100644 --- a/code-cleaners/pom.xml +++ b/code-cleaners/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT code-cleaners @@ -42,14 +42,6 @@ jackson-dataformat-yaml - - - - org.projectlombok - lombok - provided - - io.github.solven-eu.cleanthat test-helpers diff --git a/code-cleaners/src/main/java/eu/solven/cleanthat/any_language/ACodeCleaner.java b/code-cleaners/src/main/java/eu/solven/cleanthat/any_language/ACodeCleaner.java index ee77770fc..3d0100863 100644 --- a/code-cleaners/src/main/java/eu/solven/cleanthat/any_language/ACodeCleaner.java +++ b/code-cleaners/src/main/java/eu/solven/cleanthat/any_language/ACodeCleaner.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.Map; import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.databind.ObjectMapper; import eu.solven.cleanthat.codeprovider.CodeProviderDecoratingWriter; @@ -38,15 +35,15 @@ import eu.solven.cleanthat.github.CleanthatConfigHelper; import eu.solven.cleanthat.utils.ResultOrError; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * Asbtract for {@link ICodeCleaner} * * @author Benoit Lacelle */ +@Slf4j public abstract class ACodeCleaner implements ICodeCleaner { - private static final Logger LOGGER = LoggerFactory.getLogger(ACodeCleaner.class); - final Collection objectMappers; final ICleanthatConfigInitializer configInitializer; final ICodeProviderFormatter formatterProvider; diff --git a/code-cleaners/src/main/java/eu/solven/cleanthat/code_provider/github/CodeCleanerSpringConfig.java b/code-cleaners/src/main/java/eu/solven/cleanthat/code_provider/github/CodeCleanerSpringConfig.java index 36c22a3d8..f63de06a1 100644 --- a/code-cleaners/src/main/java/eu/solven/cleanthat/code_provider/github/CodeCleanerSpringConfig.java +++ b/code-cleaners/src/main/java/eu/solven/cleanthat/code_provider/github/CodeCleanerSpringConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import java.util.Map; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -40,6 +38,7 @@ import eu.solven.cleanthat.formatter.CodeFormatterApplier; import eu.solven.cleanthat.formatter.CodeProviderFormatter; import eu.solven.cleanthat.formatter.ICodeProviderFormatter; +import lombok.extern.slf4j.Slf4j; /** * The {@link Configuration} enabling {@link GitHub} @@ -47,11 +46,10 @@ * @author Benoit Lacelle * */ +@Slf4j @Configuration @Import({ ConfigSpringConfig.class }) public class CodeCleanerSpringConfig { - private static final Logger LOGGER = LoggerFactory.getLogger(CodeCleanerSpringConfig.class); - @Bean public ICodeFormatterApplier codeFormatterApplier() { return new CodeFormatterApplier(); diff --git a/code-cleaners/src/main/java/eu/solven/cleanthat/config/GenerateInitialConfig.java b/code-cleaners/src/main/java/eu/solven/cleanthat/config/GenerateInitialConfig.java index 18818ffb8..557f4cbaf 100644 --- a/code-cleaners/src/main/java/eu/solven/cleanthat/config/GenerateInitialConfig.java +++ b/code-cleaners/src/main/java/eu/solven/cleanthat/config/GenerateInitialConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,6 @@ import java.util.Map; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.Function; import com.google.common.util.concurrent.AtomicLongMap; @@ -36,6 +33,7 @@ import eu.solven.cleanthat.config.pojo.CleanthatRepositoryProperties; import eu.solven.cleanthat.engine.IEngineLintFixerFactory; import eu.solven.cleanthat.engine.IEngineStep; +import lombok.extern.slf4j.Slf4j; /** * Helps generating a default {@link CleanthatRepositoryProperties} @@ -43,8 +41,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GenerateInitialConfig { - private static final Logger LOGGER = LoggerFactory.getLogger(GenerateInitialConfig.class); final Collection factories; diff --git a/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/CodeProviderFormatter.java b/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/CodeProviderFormatter.java index 86398febd..946d63158 100644 --- a/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/CodeProviderFormatter.java +++ b/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/CodeProviderFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.slf4j.Logger; - import com.google.common.base.Strings; import com.google.common.util.concurrent.AtomicLongMap; import com.google.common.util.concurrent.MoreExecutors; @@ -56,17 +54,17 @@ import eu.solven.cleanthat.engine.IEngineFormatterFactory; import eu.solven.cleanthat.language.IEngineProperties; import eu.solven.pepper.thread.PepperExecutorsHelper; +import lombok.extern.slf4j.Slf4j; /** * Unclear what is the point of this class * * @author Benoit Lacelle */ +@Slf4j public class CodeProviderFormatter implements ICodeProviderFormatter { private static final String KEY_NB_FILES_FORMATTED = "nb_files_formatted"; - private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(CodeProviderFormatter.class); - public static final String EOL = "\r\n"; private static final int MAX_LOG_MANY_FILES = 128; diff --git a/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/SourceCodeFormatterHelper.java b/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/SourceCodeFormatterHelper.java index b5be6c666..b69e15adb 100644 --- a/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/SourceCodeFormatterHelper.java +++ b/code-cleaners/src/main/java/eu/solven/cleanthat/formatter/SourceCodeFormatterHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,11 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.solven.cleanthat.config.pojo.CleanthatStepProperties; import eu.solven.cleanthat.engine.EngineAndLinters; import eu.solven.cleanthat.engine.IEngineLintFixerFactory; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * Helps compiling CodeProcessors in the context of a repository @@ -33,8 +31,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class SourceCodeFormatterHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(SourceCodeFormatterHelper.class); public EngineAndLinters compile(IEngineProperties engineProperties, CleanthatSession cleanthatSession, diff --git a/code-providers/pom.xml b/code-providers/pom.xml index 57665bc3e..67f653743 100644 --- a/code-providers/pom.xml +++ b/code-providers/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT code-providers diff --git a/code-providers/src/main/java/eu/solven/cleanthat/code_provider/inmemory/FileSystemCodeProvider.java b/code-providers/src/main/java/eu/solven/cleanthat/code_provider/inmemory/FileSystemCodeProvider.java index 45c684145..39e27fbde 100644 --- a/code-providers/src/main/java/eu/solven/cleanthat/code_provider/inmemory/FileSystemCodeProvider.java +++ b/code-providers/src/main/java/eu/solven/cleanthat/code_provider/inmemory/FileSystemCodeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,6 @@ import java.util.function.Consumer; import java.util.function.Predicate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.jimfs.Jimfs; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -46,14 +43,15 @@ import eu.solven.cleanthat.codeprovider.ICodeProviderFile; import eu.solven.cleanthat.codeprovider.ICodeProviderWriter; import eu.solven.cleanthat.codeprovider.ICodeWritingMetadata; +import lombok.extern.slf4j.Slf4j; /** * An {@link ICodeProvider} for {@link FileSystem} * * @author Benoit Lacelle */ +@Slf4j public class FileSystemCodeProvider implements ICodeProviderWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(FileSystemCodeProvider.class); final FileSystem fs; final Path root; diff --git a/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderDecoratingWriter.java b/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderDecoratingWriter.java index a210f1ab5..1fec93a4c 100644 --- a/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderDecoratingWriter.java +++ b/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderDecoratingWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * Typically used to be able to read from one {@link ICodeProvider} and write into a different @@ -33,8 +32,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CodeProviderDecoratingWriter implements ICodeProviderWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(CodeProviderDecoratingWriter.class); protected final ICodeProvider codeProvider; protected final Supplier writerLogicSupplier; diff --git a/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderHelpers.java b/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderHelpers.java index e9b3c312a..b2dba34e2 100644 --- a/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderHelpers.java +++ b/code-providers/src/main/java/eu/solven/cleanthat/codeprovider/CodeProviderHelpers.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,6 @@ import java.util.Map; import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Maps; @@ -33,6 +30,7 @@ import eu.solven.cleanthat.code_provider.CleanthatPathHelpers; import eu.solven.cleanthat.config.ConfigHelpers; import eu.solven.cleanthat.config.ICleanthatConfigConstants; +import lombok.extern.slf4j.Slf4j; /** * Helpers working for any {@link ICodeProvider} @@ -40,8 +38,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CodeProviderHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(CodeProviderHelpers.class); protected Collection objectMappers; diff --git a/config/pom.xml b/config/pom.xml index d31a1c10e..222c4baf4 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -4,7 +4,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT config @@ -31,13 +31,6 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml - - - - org.projectlombok - lombok - provided - io.github.solven-eu.cleanthat test-helpers diff --git a/config/src/main/java/eu/solven/cleanthat/config/ConfigHelpers.java b/config/src/main/java/eu/solven/cleanthat/config/ConfigHelpers.java index 13477a42d..3b924e3cb 100644 --- a/config/src/main/java/eu/solven/cleanthat/config/ConfigHelpers.java +++ b/config/src/main/java/eu/solven/cleanthat/config/ConfigHelpers.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -45,14 +43,15 @@ import eu.solven.cleanthat.language.IEngineProperties; import eu.solven.cleanthat.language.ISourceCodeProperties; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * Helps working with configuration files * * @author Benoit Lacelle */ +@Slf4j public class ConfigHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(ConfigHelpers.class); private static final String KEY_EXCLUDES = "excludes"; private static final String KEY_INCLUDES = "includes"; diff --git a/config/src/main/java/eu/solven/cleanthat/config/GitService.java b/config/src/main/java/eu/solven/cleanthat/config/GitService.java index b615990e5..bfa437a6f 100644 --- a/config/src/main/java/eu/solven/cleanthat/config/GitService.java +++ b/config/src/main/java/eu/solven/cleanthat/config/GitService.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import java.io.UncheckedIOException; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.core.io.ClassPathResource; @@ -28,6 +26,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * Helps providing information about Git through a REST api. It implements {@link BeanFactoryPostProcessor} to ensure @@ -36,8 +35,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GitService implements IGitService, InitializingBean { - protected static final Logger LOGGER = LoggerFactory.getLogger(GitService.class); private static final String KEY_GIT_COMMIT_ID = "git.commit.id"; diff --git a/config/src/main/java/eu/solven/cleanthat/config/IncludeExcludeHelpers.java b/config/src/main/java/eu/solven/cleanthat/config/IncludeExcludeHelpers.java index 98402462e..ab0dce787 100644 --- a/config/src/main/java/eu/solven/cleanthat/config/IncludeExcludeHelpers.java +++ b/config/src/main/java/eu/solven/cleanthat/config/IncludeExcludeHelpers.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * Helpers related to include and exclude rules @@ -34,8 +33,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class IncludeExcludeHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(IncludeExcludeHelpers.class); // It is good to know that '/' will be interpreted as folder separator even under Windows // https://stackoverflow.com/questions/9148528/how-do-i-use-directory-globbing-in-jdk7 diff --git a/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRefFilterProperties.java b/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRefFilterProperties.java index 5c992939a..6b19f2142 100644 --- a/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRefFilterProperties.java +++ b/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRefFilterProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.PropertyNamingStrategy; import com.fasterxml.jackson.databind.annotation.JsonNaming; @@ -31,6 +28,7 @@ import lombok.AccessLevel; import lombok.Data; import lombok.Setter; +import lombok.extern.slf4j.Slf4j; /** * The configuration of which ref are concerned by CleanThat or not. @@ -43,8 +41,8 @@ @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) @JsonIgnoreProperties({ "branches" }) @Data +@Slf4j public final class CleanthatRefFilterProperties implements IGitRefsConstants { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanthatRefFilterProperties.class); // By default, we clean a set of standard default branch names // https://docs.github.com/en/github/administering-a-repository/managing-branches-in-your-repository/changing-the-default-branch diff --git a/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRepositoryProperties.java b/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRepositoryProperties.java index 817f70de2..7742a3d3f 100644 --- a/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRepositoryProperties.java +++ b/config/src/main/java/eu/solven/cleanthat/config/pojo/CleanthatRepositoryProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public final class CleanthatRepositoryProperties implements IHasSourceCodeProper public static final String PREVIOUS_SYNTAX_VERSION = "2021-08-02"; public static final String LATEST_SYNTAX_VERSION = "2023-01-09"; - // Not named 'config_version' else it may be unclear if it applies to that config_syntax or the the user_config + // Not named 'config_version' else it may be unclear if it applies to that config_syntax or to the user_config // version // AWS IAM policy relies on a field named 'Version' with a localDate as value: it is a source of inspiration @Builder.Default diff --git a/config/src/test/java/eu/solven/cleanthat/config/RunConvertToYml.java b/config/src/test/java/eu/solven/cleanthat/config/RunConvertToYml.java index 18e9729a8..5b8b4267f 100644 --- a/config/src/test/java/eu/solven/cleanthat/config/RunConvertToYml.java +++ b/config/src/test/java/eu/solven/cleanthat/config/RunConvertToYml.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,15 @@ import java.io.IOException; import java.util.Arrays; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.FileSystemResource; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class RunConvertToYml { - private static final Logger LOGGER = LoggerFactory.getLogger(RunConvertToYml.class); public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { var jsonObjectMapper = ConfigHelpers.makeJsonObjectMapper(); diff --git a/config/src/test/java/eu/solven/cleanthat/config/TestConfigHelpers.java b/config/src/test/java/eu/solven/cleanthat/config/TestConfigHelpers.java index 0dc1cf062..c84280b32 100644 --- a/config/src/test/java/eu/solven/cleanthat/config/TestConfigHelpers.java +++ b/config/src/test/java/eu/solven/cleanthat/config/TestConfigHelpers.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.util.StreamUtils; @@ -37,11 +35,11 @@ import eu.solven.cleanthat.config.pojo.SourceCodeProperties; import eu.solven.cleanthat.formatter.LineEnding; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class TestConfigHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(TestConfigHelpers.class); - private static final String EOL = System.lineSeparator(); @Test diff --git a/git/pom.xml b/git/pom.xml index 7358bf515..fffbff442 100644 --- a/git/pom.xml +++ b/git/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT git diff --git a/git/src/main/java/eu/solven/cleanthat/jgit/JGitCodeProvider.java b/git/src/main/java/eu/solven/cleanthat/jgit/JGitCodeProvider.java index 5b1ec4ffa..b2d89779b 100644 --- a/git/src/main/java/eu/solven/cleanthat/jgit/JGitCodeProvider.java +++ b/git/src/main/java/eu/solven/cleanthat/jgit/JGitCodeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,8 +45,6 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.treewalk.TreeWalk; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Strings; @@ -56,15 +54,16 @@ import eu.solven.cleanthat.codeprovider.ICodeProviderFile; import eu.solven.cleanthat.codeprovider.ICodeProviderWriter; import eu.solven.cleanthat.codeprovider.ICodeWritingMetadata; +import lombok.extern.slf4j.Slf4j; /** * An {@link ICodeProvider} for Github pull-requests * * @author Benoit Lacelle */ +@Slf4j @SuppressWarnings("PMD.GodClass") public class JGitCodeProvider implements ICodeProviderWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(JGitCodeProvider.class); final boolean commitPush; final Path workingDir; diff --git a/github/pom.xml b/github/pom.xml index d0a16cac9..ffce09719 100644 --- a/github/pom.xml +++ b/github/pom.xml @@ -4,7 +4,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT github diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/GithubHelper.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/GithubHelper.java index b62d7db40..f6982fa9f 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/GithubHelper.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/GithubHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,13 +29,12 @@ import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Strings; import eu.solven.cleanthat.config.pojo.CleanthatRefFilterProperties; import eu.solven.cleanthat.github.ICleanthatGitRefsConstants; +import lombok.extern.slf4j.Slf4j; /** * Helps working with Github @@ -43,8 +42,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GithubHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubHelper.class); protected GithubHelper() { // hidden diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubCodeProvider.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubCodeProvider.java index 82cbd196f..448adacf6 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubCodeProvider.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubCodeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ * @author Benoit Lacelle */ public abstract class AGithubCodeProvider implements ICodeProvider { - // private static final Logger LOGGER = LoggerFactory.getLogger(AGithubCodeProvider.class); final Path repositoryRoot; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubSha1CodeProvider.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubSha1CodeProvider.java index 39aef508a..0f82ff330 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubSha1CodeProvider.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/AGithubSha1CodeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,21 +24,20 @@ import org.kohsuke.github.GHFileNotFoundException; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHTree; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.CleanthatPathHelpers; import eu.solven.cleanthat.codeprovider.DummyCodeProviderFile; import eu.solven.cleanthat.codeprovider.ICodeProvider; import eu.solven.cleanthat.codeprovider.ICodeProviderFile; +import lombok.extern.slf4j.Slf4j; /** * An {@link ICodeProvider} for Github pull-requests * * @author Benoit Lacelle */ +@Slf4j public abstract class AGithubSha1CodeProvider extends AGithubCodeProvider implements IGithubSha1CodeProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(AGithubSha1CodeProvider.class); final String token; final GHRepository repo; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/GithubSha1CodeProviderHelper.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/GithubSha1CodeProviderHelper.java index e5f6a6fee..e850f3ba3 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/GithubSha1CodeProviderHelper.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/code_provider/GithubSha1CodeProviderHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,8 +31,6 @@ import org.eclipse.jgit.api.Git; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.util.FileSystemUtils; import com.google.common.collect.Iterables; @@ -42,14 +40,15 @@ import eu.solven.cleanthat.codeprovider.ICodeProviderFile; import eu.solven.cleanthat.jgit.JGitCodeProvider; import eu.solven.pepper.logging.PepperLogHelper; +import lombok.extern.slf4j.Slf4j; /** * Helper for Github sha1 * * @author Benoit Lacelle */ +@Slf4j public class GithubSha1CodeProviderHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubSha1CodeProviderHelper.class); // To be compared with the limit of 5000 calls per hour per installation private static final int MAX_FILE_BEFORE_CLONING = 512; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/CheckGithubEventHasValidConfig.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/CheckGithubEventHasValidConfig.java index 388d6b927..83f6eb4e7 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/CheckGithubEventHasValidConfig.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/CheckGithubEventHasValidConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,6 @@ import org.kohsuke.github.GHFileNotFoundException; import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.github.GithubHelper; import eu.solven.cleanthat.code_provider.github.decorator.GithubDecoratorHelper; @@ -44,6 +42,7 @@ import eu.solven.cleanthat.git_abstraction.GithubFacade; import eu.solven.cleanthat.git_abstraction.GithubRepositoryFacade; import eu.solven.cleanthat.utils.ResultOrError; +import lombok.extern.slf4j.Slf4j; /** * Relates to verifying an Event can trigger a cleaning or not @@ -51,8 +50,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CheckGithubEventHasValidConfig { - private static final Logger LOGGER = LoggerFactory.getLogger(CheckGithubEventHasValidConfig.class); final Path root; final ICodeCleanerFactory cleanerFactory; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubAppFactory.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubAppFactory.java index 68c47decd..0a5d0802b 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubAppFactory.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubAppFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,6 @@ import org.kohsuke.github.connector.GitHubConnector; import org.kohsuke.github.extras.authorization.JWTTokenProvider; import org.kohsuke.github.extras.okhttp3.OkHttpGitHubConnector; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import com.google.common.base.Ascii; @@ -46,6 +44,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import eu.solven.cleanthat.code_provider.github.event.pojo.WebhookRelevancyResult; import eu.solven.cleanthat.utils.ResultOrError; +import lombok.extern.slf4j.Slf4j; import okhttp3.OkHttpClient; /** @@ -55,12 +54,11 @@ * */ // https://github.com/spotbugs/spotbugs/issues/2695 +@Slf4j @SuppressFBWarnings("CT_CONSTRUCTOR_THROW") public class GithubAppFactory implements IGithubAppFactory { private static final int PUBLIC_CHARS_IN_TOKEN = 10; - private static final Logger LOGGER = LoggerFactory.getLogger(GithubAppFactory.class); - public static final String ENV_GITHUB_APP_PRIVATE_JWK = "github.app.private-jwk"; // https://github.com/organizations/solven-eu/settings/apps/cleanthat diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCheckRunManager.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCheckRunManager.java index 8ab1c85cb..b8b73f65e 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCheckRunManager.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCheckRunManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,14 +26,13 @@ import org.kohsuke.github.GHCheckRunBuilder.Output; import org.kohsuke.github.GHPermissionType; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Ascii; import com.google.common.base.Throwables; import eu.solven.cleanthat.config.IDocumentationConstants; import eu.solven.cleanthat.config.IGitService; +import lombok.extern.slf4j.Slf4j; /** * manages CheckRun in GitHub API @@ -42,8 +41,8 @@ * */ // https://stackoverflow.com/questions/67919168/github-checks-api-vs-check-runs-vs-check-suites +@Slf4j public class GithubCheckRunManager { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubCheckRunManager.class); private static final String ID_CLEANTHAT = "Cleanthat"; private static final int LIMIT_IDENTIFIER = 20; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCodeCleaner.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCodeCleaner.java index 2425aeed4..e1715815a 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCodeCleaner.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubCodeCleaner.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import org.kohsuke.github.GHBranch; import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.github.decorator.GithubDecoratorHelper; import eu.solven.cleanthat.code_provider.github.event.pojo.WebhookRelevancyResult; @@ -38,6 +36,7 @@ import eu.solven.cleanthat.formatter.CodeFormatResult; import eu.solven.cleanthat.git_abstraction.GithubRepositoryFacade; import eu.solven.cleanthat.github.ICleanthatGitRefsConstants; +import lombok.extern.slf4j.Slf4j; /** * Relates to actually cleaning code in Github @@ -45,8 +44,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GithubCodeCleaner { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubCodeCleaner.class); final Path root; final IGitRefCleaner cleaner; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubEventHelper.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubEventHelper.java index b11338bf7..cc0c8caa0 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubEventHelper.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubEventHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import org.kohsuke.github.GHCommit; import org.kohsuke.github.GHRef; import org.kohsuke.github.GHUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.github.decorator.GithubDecoratorHelper; import eu.solven.cleanthat.code_provider.github.event.pojo.WebhookRelevancyResult; @@ -37,6 +35,7 @@ import eu.solven.cleanthat.formatter.CodeFormatResult; import eu.solven.cleanthat.git_abstraction.GithubRepositoryFacade; import eu.solven.pepper.resource.PepperResourceHelper; +import lombok.extern.slf4j.Slf4j; /** * Helps executing logic on GithubEvents @@ -44,8 +43,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GithubEventHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubEventHelper.class); protected GithubEventHelper() { // hidden diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubNoApiWebhookHandler.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubNoApiWebhookHandler.java index 8d3813b50..170ad8811 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubNoApiWebhookHandler.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubNoApiWebhookHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.Map; import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -36,6 +33,7 @@ import eu.solven.cleanthat.lambda.step0_checkwebhook.I3rdPartyWebhookEvent; import eu.solven.pepper.collection.PepperMapHelper; import eu.solven.pepper.jvm.GCInspector; +import lombok.extern.slf4j.Slf4j; /** * Default implementation for IGithubWebhookHandler @@ -43,9 +41,9 @@ * @author Benoit Lacelle */ // https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads +@Slf4j @SuppressWarnings("PMD.GodClass") public class GithubNoApiWebhookHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubNoApiWebhookHandler.class); final List objectMappers; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubWebhookHandler.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubWebhookHandler.java index 8b6f78934..1ecc9d561 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubWebhookHandler.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/GithubWebhookHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,6 @@ import org.kohsuke.github.GHRateLimit; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; @@ -51,6 +49,7 @@ import eu.solven.cleanthat.utils.ResultOrError; import eu.solven.pepper.collection.PepperMapHelper; import eu.solven.pepper.logging.PepperLogHelper; +import lombok.extern.slf4j.Slf4j; /** * Default implementation for IGithubWebhookHandler @@ -58,12 +57,11 @@ * @author Benoit Lacelle */ // https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads +@Slf4j @SuppressWarnings("PMD.GodClass") public final class GithubWebhookHandler implements IGithubWebhookHandler { private static final String EOL = "\r\n"; - private static final Logger LOGGER = LoggerFactory.getLogger(GithubWebhookHandler.class); - final IGithubAppFactory githubAppFactory; final GHApp githubApp; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/pojo/GithubWebhookEvent.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/pojo/GithubWebhookEvent.java index 17dc61e99..5260fdb58 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/pojo/GithubWebhookEvent.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/event/pojo/GithubWebhookEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,14 +18,12 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.base.Strings; import eu.solven.cleanthat.lambda.step0_checkwebhook.I3rdPartyWebhookEvent; import eu.solven.cleanthat.lambda.step0_checkwebhook.IWebhookEvent; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * a POJO holding details about Github webhooks @@ -33,8 +31,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GithubWebhookEvent implements I3rdPartyWebhookEvent { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubWebhookEvent.class); public static final String KEY_BODY = "body"; public static final String KEY_HEADERS = "headers"; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/AGithubDiffCodeProvider.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/AGithubDiffCodeProvider.java index 8e984649d..6fa067272 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/AGithubDiffCodeProvider.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/AGithubDiffCodeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,6 @@ import org.kohsuke.github.GHCompare; import org.kohsuke.github.GHFileNotFoundException; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; @@ -41,14 +39,15 @@ import eu.solven.cleanthat.codeprovider.ICodeProviderFile; import eu.solven.cleanthat.codeprovider.IListOnlyModifiedFiles; import eu.solven.pepper.logging.PepperLogHelper; +import lombok.extern.slf4j.Slf4j; /** * An {@link ICodeProvider} for Github pull-requests * * @author Benoit Lacelle */ +@Slf4j public abstract class AGithubDiffCodeProvider extends AGithubCodeProvider implements IListOnlyModifiedFiles { - private static final Logger LOGGER = LoggerFactory.getLogger(AGithubDiffCodeProvider.class); private static final int LIMIT_COMMIT_IN_COMPARE = 250; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubPRCodeProvider.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubPRCodeProvider.java index 286bbabc1..13820bdbe 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubPRCodeProvider.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubPRCodeProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.CleanthatPathHelpers; import eu.solven.cleanthat.code_provider.github.code_provider.AGithubSha1CodeProvider; @@ -40,15 +38,16 @@ import eu.solven.cleanthat.codeprovider.IListOnlyModifiedFiles; import eu.solven.cleanthat.git_abstraction.GithubRepositoryFacade; import eu.solven.cleanthat.github.IGitRefsConstants; +import lombok.extern.slf4j.Slf4j; /** * An {@link ICodeProvider} for Github pull-requests * * @author Benoit Lacelle */ +@Slf4j public class GithubPRCodeProvider extends AGithubSha1CodeProvider implements IListOnlyModifiedFiles, ICodeProviderWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubPRCodeProvider.class); final String eventKey; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefCleaner.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefCleaner.java index 7bab3dbdb..f52329909 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefCleaner.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefCleaner.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,6 @@ import org.kohsuke.github.GHTree; import org.kohsuke.github.GHTreeBuilder; import org.kohsuke.github.GHUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Strings; @@ -80,15 +78,16 @@ import eu.solven.cleanthat.github.ICleanthatGitRefsConstants; import eu.solven.cleanthat.github.IGitRefsConstants; import eu.solven.cleanthat.utils.ResultOrError; +import lombok.extern.slf4j.Slf4j; /** * Default for {@link IGitRefCleaner} * * @author Benoit Lacelle */ +@Slf4j @SuppressWarnings("PMD.GodClass") public class GithubRefCleaner extends ACodeCleaner implements IGitRefCleaner, ICleanthatGitRefsConstants { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubRefCleaner.class); public static final String ENV_TEMPORARY_BRANCH_SUFFIX = "cleanthat.temporary_branch_suffix"; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefWriterLogic.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefWriterLogic.java index c4a0d6368..d71e752a3 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefWriterLogic.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/GithubRefWriterLogic.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,13 +33,12 @@ import org.kohsuke.github.GHRepository; import org.kohsuke.github.GHTree; import org.kohsuke.github.GHTreeBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.CleanthatPathHelpers; import eu.solven.cleanthat.codeprovider.ICodeProviderWriterLogic; import eu.solven.cleanthat.codeprovider.ICodeWritingMetadata; import eu.solven.cleanthat.formatter.CodeProviderFormatter; +import lombok.extern.slf4j.Slf4j; /** * Default {@link ICodeProviderWriterLogic} @@ -47,8 +46,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GithubRefWriterLogic implements ICodeProviderWriterLogic { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubRefWriterLogic.class); final String eventKey; diff --git a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/all_files/GithubRefCodeReadWriter.java b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/all_files/GithubRefCodeReadWriter.java index fbc465d25..4007b2d77 100644 --- a/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/all_files/GithubRefCodeReadWriter.java +++ b/github/src/main/java/eu/solven/cleanthat/code_provider/github/refs/all_files/GithubRefCodeReadWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,19 +20,18 @@ import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.github.code_provider.AGithubSha1CodeProviderWriter; import eu.solven.cleanthat.codeprovider.ICodeProvider; +import lombok.extern.slf4j.Slf4j; /** * An {@link ICodeProvider} for Github pull-requests * * @author Benoit Lacelle */ +@Slf4j public class GithubRefCodeReadWriter extends AGithubSha1CodeProviderWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubRefCodeReadWriter.class); final GHRef ref; final String sha1; diff --git a/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubFacade.java b/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubFacade.java index 1221d5eab..66be7de0b 100644 --- a/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubFacade.java +++ b/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubFacade.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,10 @@ import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.codeprovider.git.GitRepoBranchSha1; import eu.solven.cleanthat.config.pojo.CleanthatRefFilterProperties; +import lombok.extern.slf4j.Slf4j; /** * Enable a Facade over RewiewRequestProvider @@ -36,8 +35,8 @@ * @author Benoit Lacelle * */ +@Slf4j public final class GithubFacade { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubFacade.class); final GitHub github; final String repoName; diff --git a/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubRepositoryFacade.java b/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubRepositoryFacade.java index 2a3984280..4e931e7f1 100644 --- a/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubRepositoryFacade.java +++ b/github/src/main/java/eu/solven/cleanthat/git_abstraction/GithubRepositoryFacade.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,13 +27,12 @@ import org.kohsuke.github.GHPullRequest; import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.code_provider.github.decorator.GithubDecoratorHelper; import eu.solven.cleanthat.codeprovider.decorator.IGitRepository; import eu.solven.cleanthat.codeprovider.git.GitRepoBranchSha1; import eu.solven.cleanthat.config.pojo.CleanthatRefFilterProperties; +import lombok.extern.slf4j.Slf4j; /** * Enable a Facade over RewiewRequestProvider @@ -41,8 +40,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class GithubRepositoryFacade { - private static final Logger LOGGER = LoggerFactory.getLogger(GithubRepositoryFacade.class); final GHRepository repository; diff --git a/github/src/test/java/eu/solven/cleanthat/github/run/RunGithubMonitoring.java b/github/src/test/java/eu/solven/cleanthat/github/run/RunGithubMonitoring.java index f59d27565..fde219616 100644 --- a/github/src/test/java/eu/solven/cleanthat/github/run/RunGithubMonitoring.java +++ b/github/src/test/java/eu/solven/cleanthat/github/run/RunGithubMonitoring.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,6 @@ import org.kohsuke.github.GitHubBuilder; import org.kohsuke.github.GitHubClientUtil; import org.kohsuke.github.PagedSearchIterable; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; @@ -55,6 +53,7 @@ import eu.solven.cleanthat.formatter.CleanthatSession; import eu.solven.cleanthat.formatter.ILintFixer; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * This helps showing insights about installations @@ -62,12 +61,11 @@ * @author Benoit Lacelle * @see https://github.com/marketplace/cleanthat/insights */ +@Slf4j @SpringBootApplication(scanBasePackages = "none") @Import({ GithubSpringConfig.class }) public class RunGithubMonitoring { - private static final Logger LOGGER = LoggerFactory.getLogger(RunGithubMonitoring.class); - public static void main(String[] args) { new SpringApplicationBuilder(RunGithubMonitoring.class).web(WebApplicationType.NONE).run(args); } diff --git a/github/src/test/java/eu/solven/cleanthat/it/ITGithub.java b/github/src/test/java/eu/solven/cleanthat/it/ITGithub.java index a2dc27f5f..177b7de4e 100644 --- a/github/src/test/java/eu/solven/cleanthat/it/ITGithub.java +++ b/github/src/test/java/eu/solven/cleanthat/it/ITGithub.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,6 @@ import org.junit.Test; import org.kohsuke.github.GHApp; import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.mock.env.MockEnvironment; @@ -57,11 +55,11 @@ import eu.solven.cleanthat.config.IGitService; import eu.solven.cleanthat.git_abstraction.GithubFacade; import eu.solven.cleanthat.github.IGitRefsConstants; +import lombok.extern.slf4j.Slf4j; //https://github-api.kohsuke.org/githubappjwtauth.html +@Slf4j public class ITGithub { - private static final Logger LOGGER = LoggerFactory.getLogger(ITGithub.class); - private static final String SOLVEN_EU_MITRUST_DATASHARING = "solven-eu/mitrust-datasharing"; private static final String SOLVEN_EU_CLEANTHAT = "solven-eu/cleanthat"; private static final String SOLVEN_EU_CLEANTHAT_ITS = "solven-eu/cleanthat-integrationtests"; diff --git a/gitlab/pom.xml b/gitlab/pom.xml index f37694b94..ff3a03b32 100644 --- a/gitlab/pom.xml +++ b/gitlab/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT gitlab diff --git a/java-eclipse/pom.xml b/java-eclipse/pom.xml index a7ff30d12..d21f7c7c2 100644 --- a/java-eclipse/pom.xml +++ b/java-eclipse/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT java-eclipse @@ -37,13 +37,6 @@ ${project.version} - - - org.projectlombok - lombok - provided - - com.google.code.findbugs diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatter.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatter.java index fb6adbfbf..6be6600e2 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatter.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatter.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,12 +27,11 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.text.edits.MalformedTreeException; import org.eclipse.text.edits.TextEdit; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.formatter.ILintFixerWithId; import eu.solven.cleanthat.formatter.LineEnding; import eu.solven.pepper.logging.PepperLogHelper; +import lombok.extern.slf4j.Slf4j; /** * Bridges to Eclipse formatting engine @@ -43,8 +42,8 @@ // Example configurations: // https://raw.githubusercontent.com/spring-io/spring-javaformat/master/.eclipse/eclipse-code-formatter.xml // https://raw.githubusercontent.com/solven-eu/pepper/master/static/src/main/resources/eclipse/eclipse_java_code_formatter.xml +@Slf4j public class EclipseJavaFormatter implements ILintFixerWithId { - private static final Logger LOGGER = LoggerFactory.getLogger(EclipseJavaFormatter.class); public static final String ID = "eclipse_formatter"; diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatterConfiguration.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatterConfiguration.java index 4c1634935..9e1b5168b 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatterConfiguration.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/EclipseJavaFormatterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import java.util.TreeMap; import org.eclipse.jdt.core.JavaCore; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.xml.sax.SAXException; @@ -39,6 +37,7 @@ import eu.solven.cleanthat.engine.java.eclipse.config.ConfigReader; import eu.solven.cleanthat.language.IEngineProperties; import lombok.Data; +import lombok.extern.slf4j.Slf4j; /** * Load the configuration. It is useful to be cached, as it may rely on an external {@link URL} @@ -46,9 +45,8 @@ * @author Benoit Lacelle */ @Data +@Slf4j public class EclipseJavaFormatterConfiguration { - private static final Logger LOGGER = LoggerFactory.getLogger(EclipseJavaFormatterConfiguration.class); - private static final String KEY_URL = "url"; private final Map settings; diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfigWriter.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfigWriter.java index 4af350cf1..c6df6eb18 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfigWriter.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfigWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 Benoit Lacelle - SOLVEN + * Copyright 2009-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * Class for writing a new eclipse-configuration-file. Gets used by class Transformer. Two eclipse-formatter-profile @@ -37,8 +37,8 @@ * @author Lars Ködderitzsch */ // https://github.com/checkstyle/eclipse-cs/blob/master/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/transformer/FormatterConfigWriter.java +@Slf4j public class FormatterConfigWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(FormatterConfigWriter.class); /** Constant for show generated code. */ private static final String CS_GENERATED = "CheckStyle-Generated "; diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfiguration.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfiguration.java index b8c1e1ae0..94bf0aa72 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfiguration.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/FormatterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 Benoit Lacelle - SOLVEN + * Copyright 2009-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,18 +20,16 @@ import java.util.Iterator; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import lombok.extern.slf4j.Slf4j; /** * Class containing all configurations for a eclipse-formatter-profile. * * @author Lukas Frena */ +@Slf4j public class FormatterConfiguration { - private static final Logger LOGGER = LoggerFactory.getLogger(FormatterConfiguration.class); /** Map containing all eclipse editor-settings. */ private final Map mCleanupSettings = new HashMap<>(); diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/XmlProfileWriter.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/XmlProfileWriter.java index 4c631b776..c9b1e809d 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/XmlProfileWriter.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/checkstyle/XmlProfileWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 Benoit Lacelle - SOLVEN + * Copyright 2002-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,10 +30,8 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import lombok.extern.slf4j.Slf4j; /** * Utility class to write eclipse formatter/cleanup profile XML files. @@ -41,8 +39,8 @@ * @author Alexandros Karypidis * */ +@Slf4j public final class XmlProfileWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(XmlProfileWriter.class); private static final String XML_NODE_ROOT = "profiles"; private static final String XML_NODE_PROFILE = "profile"; diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/cleanup/EclipseCleanupProcessor.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/cleanup/EclipseCleanupProcessor.java index 5c6750ac6..24c69ce35 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/cleanup/EclipseCleanupProcessor.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/cleanup/EclipseCleanupProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,8 @@ import org.eclipse.jdt.core.refactoring.CompilationUnitChange; import org.eclipse.jdt.internal.ui.fix.PlainReplacementCleanUpCore; import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * Process code with standard Eclipse clean-up rules. @@ -42,9 +42,9 @@ // https://help.eclipse.org/latest/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Fguide%2Fjdt_api_contributing_a_cleanup.htm // https://stackoverflow.com/questions/10120072/how-to-invoke-a-eclipse-clean-up-profile-programmatically // https://stackoverflow.com/questions/11166862/eclipse-create-compilationunit-from-java-file +@Slf4j @Deprecated(since = "TODO") public class EclipseCleanupProcessor { - private static final Logger LOGGER = LoggerFactory.getLogger(EclipseCleanupProcessor.class); public CleanUpContextCore makeContext(ICompilationUnit unit, CompilationUnit ast) { return new CleanUpContextCore(unit, ast); diff --git a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/generator/EclipseStylesheetGenerator.java b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/generator/EclipseStylesheetGenerator.java index 6c4a31f96..398a1cc72 100644 --- a/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/generator/EclipseStylesheetGenerator.java +++ b/java-eclipse/src/main/java/eu/solven/cleanthat/engine/java/eclipse/generator/EclipseStylesheetGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,6 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import com.google.common.annotations.VisibleForTesting; @@ -53,6 +51,7 @@ import eu.solven.cleanthat.engine.java.eclipse.EclipseJavaFormatter; import eu.solven.cleanthat.engine.java.eclipse.EclipseJavaFormatterConfiguration; import eu.solven.pepper.logging.PepperLogHelper; +import lombok.extern.slf4j.Slf4j; /** * Default implementation for {@link IEclipseStylesheetGenerator} @@ -62,9 +61,9 @@ */ // Convert from Checkstyle // https://github.com/checkstyle/eclipse-cs/blob/master/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/jobs/TransformCheckstyleRulesJob.java +@Slf4j @SuppressWarnings("PMD.GodClass") public class EclipseStylesheetGenerator implements IEclipseStylesheetGenerator { - private static final Logger LOGGER = LoggerFactory.getLogger(EclipseStylesheetGenerator.class); private static final String SETTING_TABULATION_CHAR = "org.eclipse.jdt.core.formatter.tabulation.char"; diff --git a/java-eclipse/src/test/java/eu/solven/cleanthat/engine/java/eclipse/generator/RunGenerateEclipseStylesheet.java b/java-eclipse/src/test/java/eu/solven/cleanthat/engine/java/eclipse/generator/RunGenerateEclipseStylesheet.java index 211f97ad6..dc3f658ac 100644 --- a/java-eclipse/src/test/java/eu/solven/cleanthat/engine/java/eclipse/generator/RunGenerateEclipseStylesheet.java +++ b/java-eclipse/src/test/java/eu/solven/cleanthat/engine/java/eclipse/generator/RunGenerateEclipseStylesheet.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,6 @@ import javax.xml.transform.TransformerException; import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import com.github.difflib.patch.PatchFailedException; @@ -40,14 +38,15 @@ import eu.solven.cleanthat.engine.java.eclipse.EclipseJavaFormatter; import eu.solven.cleanthat.engine.java.eclipse.EclipseJavaFormatterConfiguration; import eu.solven.cleanthat.engine.java.eclipse.checkstyle.XmlProfileWriter; +import lombok.extern.slf4j.Slf4j; /** * Execute the procedure to generate a minimizing Eclipse Formatter configuration * * @author Benoit Lacelle */ +@Slf4j public class RunGenerateEclipseStylesheet { - private static final Logger LOGGER = LoggerFactory.getLogger(RunGenerateEclipseStylesheet.class); protected RunGenerateEclipseStylesheet() { // hidden diff --git a/java-eclipse/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java b/java-eclipse/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java index fab582c96..53697c0d7 100644 --- a/java-eclipse/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java +++ b/java-eclipse/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java @@ -13,6 +13,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,8 +28,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class LocaleHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(LocaleHelper.class); private static final Supplier> ISO_LANGUAGES = Suppliers.memoize(() -> ImmutableSet.copyOf(Locale.getISOLanguages())); diff --git a/java/pom.xml b/java/pom.xml index dc1e0cc14..307f8e473 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT java @@ -37,14 +37,7 @@ com.github.javaparser javaparser-symbol-solver-core - 3.26.2 - - - - - org.projectlombok - lombok - provided + 3.27.0 diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/JavaFormattersFactory.java b/java/src/main/java/eu/solven/cleanthat/engine/java/JavaFormattersFactory.java index 4f78d61e5..9aa8a7d11 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/JavaFormattersFactory.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/JavaFormattersFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.Map; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.solven.cleanthat.config.ConfigHelpers; import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties; import eu.solven.cleanthat.config.pojo.CleanthatStepProperties; @@ -35,14 +32,15 @@ import eu.solven.cleanthat.formatter.ILintFixer; import eu.solven.cleanthat.formatter.ILintFixerWithId; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * Formatter for Java * * @author Benoit Lacelle */ +@Slf4j public class JavaFormattersFactory extends ASourceCodeFormatterFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(JavaFormattersFactory.class); public JavaFormattersFactory(ConfigHelpers configHelpers) { super(configHelpers); diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserAstMutator.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserAstMutator.java index 0ceba7034..b5c47218c 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserAstMutator.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserAstMutator.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; @@ -32,15 +29,16 @@ import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.pepper.logging.PepperLogHelper; +import lombok.extern.slf4j.Slf4j; /** * Enables common behavior to JavaParser-based rules * * @author Benoit Lacelle */ +@Slf4j @SuppressWarnings("PMD.GodClass") public abstract class AJavaparserAstMutator implements IJavaparserAstMutator, ICountMutatorIssues { - private static final Logger LOGGER = LoggerFactory.getLogger(AJavaparserAstMutator.class); // Some mutator may edit thr input Node, before cancelling the operation: it would leave the input Node in an // inconsistent state. To workaround this, we tried first simulating the operation on a cloned Node, but it led to diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserNodeMutator.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserNodeMutator.java index 8edf99a78..b426d5a98 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserNodeMutator.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AJavaparserNodeMutator.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; @@ -34,6 +31,7 @@ import eu.solven.cleanthat.engine.java.refactorer.function.OnMethodName; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserNodeMutator; +import lombok.extern.slf4j.Slf4j; /** * A single-node (i.e. not the recursive AST) mutator. @@ -41,8 +39,8 @@ * @author Benoit Lacelle * */ +@Slf4j public abstract class AJavaparserNodeMutator extends AJavaparserAstMutator implements IJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(AJavaparserNodeMutator.class); private final AtomicInteger nbReplaceIssues = new AtomicInteger(); private final AtomicInteger nbRemoveIssues = new AtomicInteger(); diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/ATodoJavaParserMutator.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/ATodoJavaParserMutator.java index 1b652da8d..5e3061498 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/ATodoJavaParserMutator.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/ATodoJavaParserMutator.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,20 +15,18 @@ */ package eu.solven.cleanthat.engine.java.refactorer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import eu.solven.cleanthat.engine.java.IJdkVersionConstants; +import lombok.extern.slf4j.Slf4j; /** * Helps preparing rules * * @author Benoit Lacelle */ +@Slf4j public abstract class ATodoJavaParserMutator extends AJavaparserNodeMutator implements IDisabledMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(ATodoJavaParserMutator.class); @Override public boolean isDraft() { diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/JavaRefactorer.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/JavaRefactorer.java index c65a4981d..9185933a1 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/JavaRefactorer.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/JavaRefactorer.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,6 @@ import java.util.stream.Collectors; import org.codehaus.plexus.languages.java.version.JavaVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.github.difflib.DiffUtils; import com.github.difflib.patch.AbstractDelta; @@ -52,6 +50,7 @@ import eu.solven.cleanthat.formatter.LineEnding; import eu.solven.cleanthat.formatter.PathAndContent; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * This class is dedicated to refactoring. Most mutators will refactor code to a better (e.g. shorter, faster, safer, @@ -60,8 +59,8 @@ * @author Benoit Lacelle */ // https://github.com/revelc/formatter-maven-plugin/blob/master/src/main/java/net/revelc/code/formatter/java/JavaFormatter.java +@Slf4j public class JavaRefactorer extends AAstRefactorer { - private static final Logger LOGGER = LoggerFactory.getLogger(JavaRefactorer.class); // It is ambiguous to give access to access on the classLoader, as it would give insights to custom classes public static final boolean JAVAPARSER_JRE_ONLY = true; diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/MethodCallExprHelpers.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/MethodCallExprHelpers.java index 9e016c5fa..c8de0cea0 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/MethodCallExprHelpers.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/MethodCallExprHelpers.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.function.Predicate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; import com.github.javaparser.resolution.SymbolResolver; @@ -28,6 +25,7 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import lombok.extern.slf4j.Slf4j; /** * Helps working with {@link MethodCallExpr} @@ -35,8 +33,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class MethodCallExprHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(MethodCallExprHelpers.class); protected MethodCallExprHelpers() { // hidden diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/ResolvedTypeHelpers.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/ResolvedTypeHelpers.java index 90bdaefd5..018f33f4a 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/ResolvedTypeHelpers.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/helpers/ResolvedTypeHelpers.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,6 @@ import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.type.Type; import com.github.javaparser.resolution.UnsolvedSymbolException; import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; @@ -30,6 +27,7 @@ import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; +import lombok.extern.slf4j.Slf4j; /** * Helps working with {@link ResolvedType} @@ -37,8 +35,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class ResolvedTypeHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(ResolvedTypeHelpers.class); protected ResolvedTypeHelpers() { // hidden diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AUseXIsEmpty.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AUseXIsEmpty.java index ade8564b2..0b05f27ef 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AUseXIsEmpty.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AUseXIsEmpty.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.ast.expr.Expression; @@ -33,6 +30,7 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import lombok.extern.slf4j.Slf4j; /** * Migrate from 'm.size() == 0’ to ’m.isEmpty()'. Works with {@link Collection}, {@link Map} and {@link String}. @@ -40,8 +38,8 @@ * @author Benoit Lacelle */ // https://jsparrow.github.io/rules/use-is-empty-on-collections.html +@Slf4j public abstract class AUseXIsEmpty extends AJavaparserExprMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(AUseXIsEmpty.class); private static final IntegerLiteralExpr ZERO_EXPR = new IntegerLiteralExpr("0"); diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java new file mode 100644 index 000000000..81e8a51c8 --- /dev/null +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AppendCharacterWithChar.java @@ -0,0 +1,102 @@ +/* + * Copyright 2025 Benoit Lacelle - SOLVEN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.solven.cleanthat.engine.java.refactorer.mutators; + +import java.util.Optional; +import java.util.Set; + +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.CharLiteralExpr; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.utils.StringEscapeUtils; +import com.google.common.collect.ImmutableSet; + +import eu.solven.cleanthat.engine.java.IJdkVersionConstants; +import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator; +import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; + +/** + * Turns `stringBuilder.append("c")` into `stringBuilder.append('c')` + *

+ * Works with classes implementing {@link Appendable}. + * + * @author Balazs Glatz + */ +public class AppendCharacterWithChar extends AJavaparserExprMutator { + + public static final String APOSTROPHE = "'"; + public static final String METHOD_APPEND = "append"; + + @Override + public String minimalJavaVersion() { + return IJdkVersionConstants.JDK_5; + } + + @Override + public Set getTags() { + return ImmutableSet.of("String"); + } + + @Override + public Optional getPmdId() { + return Optional.of("AppendCharacterWithChar"); + } + + @Override + public String pmdUrl() { + return "https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#appendcharacterwithchar"; + } + + @Override + protected boolean processExpression(NodeAndSymbolSolver expression) { + if (!(expression.getNode() instanceof MethodCallExpr)) { + return false; + } + + var methodCall = expression.getNode().asMethodCallExpr(); + var methodName = methodCall.getNameAsString(); + if (!METHOD_APPEND.equals(methodName) || methodCall.getArguments().size() != 1) { + return false; + } + + Expression argument = methodCall.getArgument(0); + if (!argument.isStringLiteralExpr()) { + return false; + } + + Optional scope = methodCall.getScope(); + if (!MethodCallExprHelpers.scopeHasRequiredType(expression.editNode(scope), Appendable.class)) { + return false; + } + + var argumentAsString = argument.asStringLiteralExpr().getValue(); + if (APOSTROPHE.equals(argumentAsString) || !couldBeCharacter(argumentAsString)) { + return false; + } + + CharLiteralExpr character = new CharLiteralExpr(argumentAsString); + var replacement = new MethodCallExpr(scope.get(), METHOD_APPEND, NodeList.nodeList(character)); + + return tryReplace(methodCall, replacement); + } + + private static boolean couldBeCharacter(String argumentAsString) { + return StringEscapeUtils.unescapeJava(argumentAsString).length() == 1; + } + +} diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArithmeticOverFloats.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArithmeticOverFloats.java index cee7517ae..7f02667b6 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArithmeticOverFloats.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArithmeticOverFloats.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.ast.expr.CastExpr; @@ -39,14 +36,15 @@ import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; import eu.solven.cleanthat.engine.java.refactorer.helpers.OptionalOrRejection; import eu.solven.cleanthat.engine.java.refactorer.helpers.ResolvedTypeHelpers; +import lombok.extern.slf4j.Slf4j; /** * Turns '1F + 0.1F` into `(double) 1F + 0.1F` * * @author Benoit Lacelle */ +@Slf4j public class ArithmeticOverFloats extends AJavaparserExprMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(ArithmeticOverFloats.class); private static final Set MATH_FLOAT_OPERATORS = Set.of(BinaryExpr.Operator.PLUS, BinaryExpr.Operator.MINUS, diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArraysDotStream.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArraysDotStream.java index f00de1648..62ed6c4ad 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArraysDotStream.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ArraysDotStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.Set; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; @@ -35,6 +32,7 @@ import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.ImportDeclarationHelpers; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import lombok.extern.slf4j.Slf4j; /** * Turns 'Arrays.asList("1", 2).stream()' into 'Arrays.stream("1", 2)' @@ -42,8 +40,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class ArraysDotStream extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(StreamAnyMatch.class); private static final String METHOD_ASLIST = "asList"; private static final String METHOD_STREAM = "stream"; diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java index 46553fd80..712025f9f 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidFileStream.java @@ -52,7 +52,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_performance.html#avoidfilestream"; + return "https://pmd.github.io/pmd/pmd_rules_java_performance.html#avoidfilestream"; } } diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidInlineConditionals.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidInlineConditionals.java index 6bf9eaa00..9cc46a125 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidInlineConditionals.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidInlineConditionals.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.VariableDeclarator; @@ -40,6 +37,7 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import lombok.extern.slf4j.Slf4j; /** * Turns 'boolean b = (x > 1 ) ? true : callback.doIt() || true' into 'if (x > 1) { ... } else { ...}' @@ -47,8 +45,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class AvoidInlineConditionals extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(AvoidInlineConditionals.class); @Override public boolean isDraft() { diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java index 79a9c458e..f45e0819b 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/AvoidUncheckedExceptionsInSignatures.java @@ -50,7 +50,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures"; + return "https://pmd.github.io/pmd/pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ComparisonWithNaN.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ComparisonWithNaN.java index 46dd65849..3f246427b 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ComparisonWithNaN.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ComparisonWithNaN.java @@ -64,7 +64,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_errorprone.html#comparisonwithnan"; + return "https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#comparisonwithnan"; } @SuppressWarnings({ "PMD.CognitiveComplexity", "PMD.NPathComplexity" }) diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/CreateTempFilesUsingNio.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/CreateTempFilesUsingNio.java index ec832dc4d..128966bf5 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/CreateTempFilesUsingNio.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/CreateTempFilesUsingNio.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.ast.expr.BinaryExpr.Operator; @@ -41,16 +38,16 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import lombok.extern.slf4j.Slf4j; /** * cases inspired from #description * * @author Sébastien Collard */ +@Slf4j public class CreateTempFilesUsingNio extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(UseCollectionIsEmpty.class); - @Override public String minimalJavaVersion() { // java.nio.Files has been introduced in JDK7 diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EmptyControlStatement.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EmptyControlStatement.java index 0037013b5..6b615567c 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EmptyControlStatement.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EmptyControlStatement.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.body.InitializerDeclaration; import com.github.javaparser.ast.stmt.BlockStmt; @@ -29,6 +26,7 @@ import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import lombok.extern.slf4j.Slf4j; /** * Turns '{}' into '' @@ -36,8 +34,8 @@ * @author Benoit Lacelle */ // https://github.com/openrewrite/rewrite/blob/main/rewrite-java/src/main/java/org/openrewrite/java/cleanup/EmptyBlockVisitor.java +@Slf4j public class EmptyControlStatement extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(EmptyControlStatement.class); @Override public String minimalJavaVersion() { @@ -56,7 +54,7 @@ public Set getPmdIds() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#emptycontrolstatement"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#emptycontrolstatement"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EnumsWithoutEquals.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EnumsWithoutEquals.java index 68105ef14..f50003f5d 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EnumsWithoutEquals.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/EnumsWithoutEquals.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.BinaryExpr; import com.github.javaparser.ast.expr.UnaryExpr; @@ -30,6 +27,7 @@ import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import lombok.extern.slf4j.Slf4j; /** * Prevent relying .equals on {@link Enum} types @@ -38,8 +36,8 @@ */ // see https://jsparrow.github.io/rules/enums-without-equals.html#properties // https://stackoverflow.com/questions/1750435/comparing-java-enum-members-or-equals +@Slf4j public class EnumsWithoutEquals extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(EnumsWithoutEquals.class); @Override public String minimalJavaVersion() { diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/JUnit4ToJUnit5.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/JUnit4ToJUnit5.java index 8b28f7543..a3dafabe9 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/JUnit4ToJUnit5.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/JUnit4ToJUnit5.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; @@ -42,6 +39,7 @@ import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.ImportDeclarationHelpers; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import lombok.extern.slf4j.Slf4j; /** * Migrate from JUnit4 to JUnit5/Jupiter. @@ -54,8 +52,8 @@ // https://jsparrow.github.io/tags/#junit // https://www.baeldung.com/junit-5-migration // https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-from-junit-4-to-junit-5 +@Slf4j public class JUnit4ToJUnit5 extends AJavaparserNodeMutator implements IDisabledMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(JUnit4ToJUnit5.class); private final Map fromTo = ImmutableMap.builder() .put("org.junit.Before", "org.junit.jupiter.api.BeforeEach") diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LambdaReturnsSingleStatement.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LambdaReturnsSingleStatement.java index 512430177..b04c3d6cb 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LambdaReturnsSingleStatement.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LambdaReturnsSingleStatement.java @@ -57,7 +57,7 @@ public boolean isDraft() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LiteralsFirstInComparisons.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LiteralsFirstInComparisons.java index 8ea224749..a6fea411a 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LiteralsFirstInComparisons.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LiteralsFirstInComparisons.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.FieldAccessExpr; @@ -40,7 +37,9 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import eu.solven.cleanthat.engine.java.refactorer.meta.ApplyBeforeMe; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutatorDescriber; +import lombok.extern.slf4j.Slf4j; /** * Switch o.equals("someString") to "someString".equals(o) @@ -48,8 +47,9 @@ * @author Benoit Lacelle */ @SuppressWarnings("PMD.GodClass") +@Slf4j +@ApplyBeforeMe(UnnecessaryCaseChange.class) public class LiteralsFirstInComparisons extends AJavaparserNodeMutator implements IMutatorDescriber { - private static final Logger LOGGER = LoggerFactory.getLogger(LiteralsFirstInComparisons.class); private static final String METHOD_EQUALS = "equals"; @@ -70,7 +70,7 @@ public boolean isDraft() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#literalsfirstincomparisons"; + return "https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#literalsfirstincomparisons"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LocalVariableTypeInference.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LocalVariableTypeInference.java index 8d2335368..e731cac97 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LocalVariableTypeInference.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/LocalVariableTypeInference.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.body.VariableDeclarator; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.VariableDeclarationExpr; @@ -38,6 +35,7 @@ import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; import eu.solven.cleanthat.engine.java.refactorer.helpers.ResolvedTypeHelpers; +import lombok.extern.slf4j.Slf4j; /** * Turns 'int i = 10;' into 'var i = 10'. @@ -50,8 +48,8 @@ // https://github.com/openrewrite/rewrite/issues/1656 // https://stackoverflow.com/questions/49210591/restrictions-on-using-local-variable-type-inference-in-java-10 // https://openjdk.org/projects/amber/guides/lvti-style-guide +@Slf4j public class LocalVariableTypeInference extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(LocalVariableTypeInference.class); @Override public String minimalJavaVersion() { diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ModifierOrder.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ModifierOrder.java index d76abcce4..fd5924e5e 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ModifierOrder.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/ModifierOrder.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,12 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Modifier; import com.github.javaparser.ast.Modifier.Keyword; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations; import com.github.javaparser.ast.nodeTypes.NodeWithModifiers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -37,17 +36,18 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.meta.ApplyBeforeMe; +import lombok.extern.slf4j.Slf4j; /** - * Order modifiers according the the Java specification. + * Order modifiers according to the Java specification. * * @author Benoit Lacelle * @see https://github.com/checkstyle/checkstyle/blob/master/src/xdocs/checks/modifier/modifierorder.xml * @see */ +@Slf4j @ApplyBeforeMe(UnnecessaryModifier.class) public class ModifierOrder extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(ModifierOrder.class); private static final List ORDERED_MODIFIERS = ImmutableList.of("public", "protected", @@ -154,6 +154,16 @@ private boolean applyModifiers(NodeWithModifiers nodeWithModifiers, return false; } + // https://github.com/solven-eu/cleanthat/issues/897 + if (nodeWithModifiers instanceof NodeWithAnnotations) { + var nodeWithAnnotations = (NodeWithAnnotations) nodeWithModifiers; + NodeList annotations = nodeWithAnnotations.getAnnotations(); + if (annotations.isNonEmpty()) { + nodeWithAnnotations.setAnnotations(new NodeList<>()); + nodeWithAnnotations.setAnnotations(annotations); + } + } + // https://github.com/javaparser/javaparser/issues/3935 nodeWithModifiers.setModifiers(); diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/NullCheckToOptionalOfNullable.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/NullCheckToOptionalOfNullable.java index acf1ef7cf..1aa873057 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/NullCheckToOptionalOfNullable.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/NullCheckToOptionalOfNullable.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.body.MethodDeclaration; @@ -45,6 +42,7 @@ import eu.solven.cleanthat.engine.java.refactorer.helpers.ImportDeclarationHelpers; import eu.solven.cleanthat.engine.java.refactorer.helpers.LambdaExprHelpers; import eu.solven.cleanthat.engine.java.refactorer.meta.ApplyAfterMe; +import lombok.extern.slf4j.Slf4j; /** * Turns `if (s != null) {...}` into `Optional.ofNullable(s).ifPresent(...)` @@ -55,9 +53,9 @@ * @author Benoit Lacelle */ // https://community.sonarsource.com/t/java-optional-used-as-replacement-for-local-null-check/43842 +@Slf4j @ApplyAfterMe({ OptionalWrappedIfToFilter.class, OptionalWrappedVariableToMap.class }) public class NullCheckToOptionalOfNullable extends AJavaparserStmtMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(NullCheckToOptionalOfNullable.class); final NullLiteralExpr nullLiteralExpr = new NullLiteralExpr(); diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java index 0cecc7a26..77ef0c470 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/PrimitiveWrapperInstantiation.java @@ -61,7 +61,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#primitivewrapperinstantiation"; + return "https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#primitivewrapperinstantiation"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyBooleanInitialization.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyBooleanInitialization.java index faf2ef37f..9c9487675 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyBooleanInitialization.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyBooleanInitialization.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.expr.AssignExpr; import com.github.javaparser.ast.expr.EnclosedExpr; import com.github.javaparser.ast.expr.Expression; @@ -37,6 +34,7 @@ import eu.solven.cleanthat.engine.java.refactorer.helpers.VariableDeclarationExprHepers; import eu.solven.cleanthat.engine.java.refactorer.meta.ApplyBeforeMe; import eu.solven.cleanthat.engine.java.refactorer.meta.RepeatOnSuccess; +import lombok.extern.slf4j.Slf4j; /** * Turns `boolean b=false; if(X) b=true;` into `boolean b=X;` @@ -46,10 +44,10 @@ * * @author Benoit Lacelle */ +@Slf4j @RepeatOnSuccess @ApplyBeforeMe({ RedundantLogicalComplementsInStream.class }) public class SimplifyBooleanInitialization extends ARefactorConsecutiveStatements { - private static final Logger LOGGER = LoggerFactory.getLogger(SimplifyBooleanInitialization.class); @Override public String minimalJavaVersion() { diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyStartsWith.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyStartsWith.java index 9d2701583..15513a7f7 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyStartsWith.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/SimplifyStartsWith.java @@ -59,7 +59,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_performance.html#simplifystartswith"; + return "https://pmd.github.io/pmd-doc-6.55.0/pmd_rules_java_performance.html#simplifystartswith"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StreamForEachNestingForLoopToFlatMap.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StreamForEachNestingForLoopToFlatMap.java index f127e377c..6620e3d8a 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StreamForEachNestingForLoopToFlatMap.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StreamForEachNestingForLoopToFlatMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,6 @@ import java.util.stream.LongStream; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.LambdaExpr; @@ -41,6 +38,7 @@ import eu.solven.cleanthat.engine.java.refactorer.meta.ApplyAfterMe; import eu.solven.cleanthat.engine.java.refactorer.meta.IReApplyUntilNoop; import eu.solven.cleanthat.engine.java.refactorer.meta.RepeatOnSuccess; +import lombok.extern.slf4j.Slf4j; /** * Turns `stream.forEach(value -> { value.forEach(user -> { System.out.println(user); }); });` @@ -49,10 +47,10 @@ * * @author Benoit Lacelle */ +@Slf4j @ApplyAfterMe({ LambdaIsMethodReference.class }) @RepeatOnSuccess public class StreamForEachNestingForLoopToFlatMap extends AJavaparserExprMutator implements IReApplyUntilNoop { - private static final Logger LOGGER = LoggerFactory.getLogger(StreamForEachNestingForLoopToFlatMap.class); private static final Map, String> TYPE_TO_FLATMAP = Map.of(Stream.class, "flatMap", diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringReplaceAllWithQuotableInput.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringReplaceAllWithQuotableInput.java index 56b6543b4..9709466ad 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringReplaceAllWithQuotableInput.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringReplaceAllWithQuotableInput.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.LiteralStringValueExpr; import com.google.common.collect.ImmutableSet; @@ -31,15 +28,15 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import lombok.extern.slf4j.Slf4j; /** * Turns `s.replaceAll("abc", "")` into `s.replace("abc", "")` * * @author Benoit Lacelle */ +@Slf4j public class StringReplaceAllWithQuotableInput extends AJavaparserExprMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(StringReplaceAllWithQuotableInput.class); - // https://stackoverflow.com/questions/5105143/list-of-all-characters-that-should-be-escaped-before-put-in-to-regex private static final String IS_REGEX_SPECIAL_CHAR = ".\\+*?[^]$(){}=!<>|:-"; private static final String IS_NOT_REGEX = IS_REGEX_SPECIAL_CHAR.chars() diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java index 7f6982daa..4a74ff6ee 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/StringToString.java @@ -57,7 +57,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_performance.html#stringtostring"; + return "https://pmd.github.io/pmd/pmd_rules_java_performance.html#stringtostring"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryBoxing.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryBoxing.java index dc405fbd7..d012f878f 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryBoxing.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryBoxing.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.NodeList; import com.github.javaparser.ast.expr.Expression; import com.github.javaparser.ast.expr.MethodCallExpr; @@ -34,6 +31,7 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; +import lombok.extern.slf4j.Slf4j; /** * Turns `Integer i = Integer.valueOf(2)` into `Integer i = 2` @@ -42,8 +40,8 @@ * * @author Benoit Lacelle */ +@Slf4j public class UnnecessaryBoxing extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(UnnecessaryBoxing.class); @Override public boolean isDraft() { @@ -67,7 +65,7 @@ public String jSparrowUrl() { @Override public String pmdUrl() { - // "https://pmd.github.io/latest/pmd_rules_java_performance.html#unnecessarywrapperobjectcreation"; + // "https://pmd.github.io/pmd-doc-6.55.0/pmd_rules_java_performance.html#unnecessarywrapperobjectcreation"; return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessaryboxing"; } diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java new file mode 100644 index 000000000..7a837b8f2 --- /dev/null +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryCaseChange.java @@ -0,0 +1,212 @@ +/* + * Copyright 2025 Benoit Lacelle - SOLVEN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package eu.solven.cleanthat.engine.java.refactorer.mutators; + +import java.util.Optional; +import java.util.Set; + +import com.github.javaparser.ast.NodeList; +import com.github.javaparser.ast.expr.Expression; +import com.github.javaparser.ast.expr.MethodCallExpr; +import com.github.javaparser.ast.expr.StringLiteralExpr; +import com.google.common.collect.ImmutableSet; + +import eu.solven.cleanthat.engine.java.refactorer.AJavaparserExprMutator; +import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import eu.solven.cleanthat.engine.java.refactorer.helpers.MethodCallExprHelpers; + +/** + * Switch o.toLowerCase().equals("some_string") to o.equalsIgnoreCase("some_string") + * + * @author Balazs Glatz + */ +public class UnnecessaryCaseChange extends AJavaparserExprMutator { + + private static final String METHOD_EQUALS = "equals"; + private static final String METHOD_EQUALS_IGNORE_CASE = "equalsIgnoreCase"; + + @Override + public Set getTags() { + return ImmutableSet.of("String"); + } + + @Override + public Optional getPmdId() { + return Optional.of("UnnecessaryCaseChange"); + } + + @Override + public String pmdUrl() { + return "https://pmd.github.io/pmd/pmd_rules_java_errorprone.html#unnecessarycasechange"; + } + + @Override + @SuppressWarnings("PMD.NPathComplexity") + protected boolean processExpression(NodeAndSymbolSolver expression) { + if (!(expression.getNode() instanceof MethodCallExpr)) { + return false; + } + + var methodCall = expression.getNode().asMethodCallExpr(); + + var methodName = methodCall.getNameAsString(); + boolean equals = METHOD_EQUALS.equals(methodName); + boolean equalsIgnoreCase = METHOD_EQUALS_IGNORE_CASE.equals(methodName); + + if (isNotSingleArgumentEqualsOrEqualsIgnoreCase(equals, equalsIgnoreCase, methodCall)) { + return false; + } + + Expression originalScope = methodCall.getScope().orElse(null); + if (!isCalledOnString(expression, originalScope)) { + return false; + } + + Expression originalArgument = methodCall.getArgument(0); + + UnnecessaryCaseChangeExpression scope; + UnnecessaryCaseChangeExpression argument; + try { + scope = new UnnecessaryCaseChangeExpression(originalScope); + argument = new UnnecessaryCaseChangeExpression(originalArgument); + } catch (IllegalStateException exception) { + return false; + } + + // left.toLowerCase().equals(right.toLowerCase()) || left.toUpperCase().equals(right.toUpperCase()) + if (scope.isToLowerCase && argument.isToLowerCase || scope.isToUpperCase && argument.isToUpperCase) { + Expression newScope = getScope(scope.methodCall); + Expression newArg = getScope(argument.methodCall); + + var replacement = getReplacement(newScope, newArg); + + return tryReplace(methodCall, replacement); + } + + // left.toLowerCase().equals("lowercase") || left.toUpperCase().equals("UPPERCASE") + if (scope.isToLowerCase && argument.isLowercase || scope.isToUpperCase && argument.isUppercase) { + Expression newScope = getScope(scope.methodCall); + + var replacement = getReplacement(newScope, argument.stringLiteral); + + return tryReplace(methodCall, replacement); + } + + // "lowercase".equals(right.toLowerCase()) || "UPPERCASE".equals(right.toUpperCase()) + if (scope.isLowercase && argument.isToLowerCase || scope.isUppercase && argument.isToUpperCase) { + Expression newArg = getScope(argument.methodCall); + + var replacement = getReplacement(scope.stringLiteral, newArg); + + return tryReplace(methodCall, replacement); + } + + // left.toLowerCase().equalsIgnoreCase(right.toLowerCase()) + if (equalsIgnoreCase && scope.isMethodCall && argument.isMethodCall) { + Expression newScope = getScope(scope.methodCall); + Expression newArg = getScope(argument.methodCall); + + var replacement = getReplacement(newScope, newArg); + + return tryReplace(methodCall, replacement); + } + + // left.toLowerCase().equalsIgnoreCase(right) + if (equalsIgnoreCase && scope.isMethodCall) { + Expression newScope = getScope(scope.methodCall); + + var replacement = getReplacement(newScope, originalArgument); + + return tryReplace(methodCall, replacement); + } + + // left.equalsIgnoreCase(right.toLowerCase()) + if (equalsIgnoreCase && argument.isMethodCall) { + Expression newArg = getScope(argument.methodCall); + + var replacement = getReplacement(originalScope, newArg); + + return tryReplace(methodCall, replacement); + } + + return false; + } + + private static boolean isNotSingleArgumentEqualsOrEqualsIgnoreCase(boolean equals, + boolean equalsIgnoreCase, + MethodCallExpr methodCall) { + return !(equals || equalsIgnoreCase) || methodCall.getArguments().size() != 1; + } + + private static boolean isCalledOnString(NodeAndSymbolSolver expression, Expression originalScope) { + return originalScope != null + && MethodCallExprHelpers.scopeHasRequiredType(expression.editNode(originalScope), String.class); + } + + private static Expression getScope(MethodCallExpr scope) { + return scope.getScope().get().clone(); + } + + private static MethodCallExpr getReplacement(Expression scope, Expression argument) { + return new MethodCallExpr(scope, METHOD_EQUALS_IGNORE_CASE, NodeList.nodeList(argument)); + } + + @SuppressWarnings("PMD.ImmutableField") + private static final class UnnecessaryCaseChangeExpression { + private boolean isMethodCall; + private MethodCallExpr methodCall; + private StringLiteralExpr stringLiteral; + + private boolean isToLowerCase; + private boolean isToUpperCase; + + private boolean isLowercase; + private boolean isUppercase; + + /** + * @param expression + * either the scope or the argument of an equals/equalsIgnoreCase method call + * + * @throws IllegalStateException + * when the expression is neither a String literal nor a toLowerCase/toUpperCase method call + */ + @SuppressWarnings({ "PMD.UnnecessaryCaseChange", "PMD.UseLocaleWithCaseConversions" }) + private UnnecessaryCaseChangeExpression(Expression expression) { + if (expression instanceof MethodCallExpr) { + isMethodCall = true; + methodCall = expression.asMethodCallExpr(); + + if (!methodCall.getArguments().isEmpty()) { + throw new IllegalStateException(); + } + + var methodName = methodCall.getNameAsString(); + isToLowerCase = "toLowerCase".equals(methodName); + isToUpperCase = "toUpperCase".equals(methodName); + + if (!isToLowerCase && !isToUpperCase) { + throw new IllegalStateException(); + } + } else if (expression.isStringLiteralExpr()) { + stringLiteral = expression.asStringLiteralExpr(); + String literal = stringLiteral.getValue(); + isLowercase = literal.equals(literal.toLowerCase()); + isUppercase = literal.equals(literal.toUpperCase()); + } + } + } + +} diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java index cc3044fb6..2630eb813 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryFullyQualifiedName.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; import com.github.javaparser.ast.nodeTypes.NodeWithType; @@ -33,6 +30,7 @@ import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; +import lombok.extern.slf4j.Slf4j; /** * This will remove unnecessary fully qualified type reference, typically because given type if imported. @@ -44,8 +42,8 @@ * * @author Benoit Lacelle */ +@Slf4j public class UnnecessaryFullyQualifiedName extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(UnnecessaryFullyQualifiedName.class); @Override public String minimalJavaVersion() { @@ -64,7 +62,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessaryfullyqualifiedname"; } /** diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java index beeb8b9ee..346db4fad 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryImport.java @@ -76,8 +76,8 @@ public Set getPmdIds() { @Override public String pmdUrl() { - // https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#unusedimports - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessaryimport"; + // https://pmd.github.io/pmd-doc-6.55.0/pmd_rules_java_bestpractices.html#unusedimports + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessaryimport"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryLambdaEnclosingParameters.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryLambdaEnclosingParameters.java index 8b0dac9f5..c107b9a97 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryLambdaEnclosingParameters.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryLambdaEnclosingParameters.java @@ -43,7 +43,7 @@ public Set getTags() { @Override public boolean isDraft() { - // see UnnecessaryLambdaEnclosingParametersCases.CaseFunction + // see TestUnnecessaryLambdaEnclosingParametersCases.CaseFunction return true; } @@ -54,13 +54,18 @@ protected boolean processNotRecursively(NodeAndSymbolSolver node) { } var lambdaExpr = (LambdaExpr) node.getNode(); + if (lambdaExpr.getParameters().size() != 1 || !lambdaExpr.isEnclosingParameters()) { + return false; + } - if (lambdaExpr.getParameters().size() == 1 && lambdaExpr.isEnclosingParameters()) { - var newLambdaExpr = lambdaExpr.clone(); - newLambdaExpr.setEnclosingParameters(false); - return tryReplace(lambdaExpr, newLambdaExpr); - } + var param = lambdaExpr.getParameters().get(0); + if (param.getType() != null) { + return false; + } - return false; - } + var newLambdaExpr = lambdaExpr.clone(); + newLambdaExpr.setEnclosingParameters(false); + return tryReplace(lambdaExpr, newLambdaExpr); + + } } diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java index 49b313533..bfbcfef84 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessaryModifier.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,14 +36,12 @@ import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; -import lombok.extern.slf4j.Slf4j; /** * Turns 'public static final someMethod();' into 'someMethod();' in interfaces * * @author Benoit Lacelle */ -@Slf4j public class UnnecessaryModifier extends AJavaparserNodeMutator { @Override @@ -68,7 +66,7 @@ public Optional getPmdId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessarymodifier"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessarymodifier"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessarySemicolon.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessarySemicolon.java index 3c68b742d..d064d91ec 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessarySemicolon.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UnnecessarySemicolon.java @@ -52,7 +52,7 @@ public Set getPmdIds() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#unnecessarysemicolon"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#unnecessarysemicolon"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseCollectionIsEmpty.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseCollectionIsEmpty.java index caaee5449..bbed1816e 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseCollectionIsEmpty.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseCollectionIsEmpty.java @@ -50,7 +50,7 @@ public String minimalJavaVersion() { @Override public String pmdUrl() { // https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java - return "https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#usecollectionisempty"; + return "https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#usecollectionisempty"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseDiamondOperator.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseDiamondOperator.java index 7cb3b2986..f0814bf19 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseDiamondOperator.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseDiamondOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,6 @@ import java.util.Optional; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.javaparser.ast.Node; import com.github.javaparser.ast.expr.ObjectCreationExpr; import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments; @@ -31,6 +28,7 @@ import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; import eu.solven.cleanthat.engine.java.refactorer.helpers.ResolvedTypeHelpers; +import lombok.extern.slf4j.Slf4j; /** * Use the diamond operation {@code <>} whenever possible. @@ -38,9 +36,9 @@ * @author Benoit Lacelle */ // see org.openrewrite.java.cleanup.UseDiamondOperator +@Slf4j @Deprecated(since = "Not-ready") public class UseDiamondOperator extends AJavaparserNodeMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(UseDiamondOperator.class); @Override public String minimalJavaVersion() { @@ -59,7 +57,7 @@ public Optional getSonarId() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#usediamondoperator"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#usediamondoperator"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java index b17de7b5e..12ada3977 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseIndexOfChar.java @@ -54,7 +54,7 @@ public boolean isDraft() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_performance.html#useindexofchar"; + return "https://pmd.github.io/pmd/pmd_rules_java_performance.html#useindexofchar"; } @Override diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseTextBlocks.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseTextBlocks.java index e478923c2..199dd095f 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseTextBlocks.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseTextBlocks.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.AJavaparserNodeMutator; import eu.solven.cleanthat.engine.java.refactorer.NodeAndSymbolSolver; -import lombok.extern.slf4j.Slf4j; /** * Turns '"a\r\n" + "b\r\n"’ into ’"""aEOLbEOL"""' @@ -43,7 +42,6 @@ // https://www.baeldung.com/java-text-blocks // https://stackoverflow.com/questions/878573/does-java-have-support-for-multiline-strings/50155171#50155171 // TODO Handle intermediate parenthesis -@Slf4j public class UseTextBlocks extends AJavaparserNodeMutator { @Override public String minimalJavaVersion() { diff --git a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseUnderscoresInNumericLiterals.java b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseUnderscoresInNumericLiterals.java index f251a4e07..390064f28 100644 --- a/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseUnderscoresInNumericLiterals.java +++ b/java/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/UseUnderscoresInNumericLiterals.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ public String minimalJavaVersion() { @Override public String pmdUrl() { - return "https://pmd.github.io/latest/pmd_rules_java_codestyle.html#useunderscoresinnumericliterals"; + return "https://pmd.github.io/pmd/pmd_rules_java_codestyle.html#useunderscoresinnumericliterals"; } @Override @@ -136,13 +136,25 @@ protected boolean processNotRecursively(NodeAndSymbolSolver node) { var totalNbDigits = noUnderscore.length() - 1; sb = new StringBuilder(totalNbDigits + 1 + totalNbDigits / BLOCK_SIZE); - { - var beforeDot = noUnderscore.substring(0, indexOfDot); + var beforeDot = noUnderscore.substring(0, indexOfDot); + var afterDot = noUnderscore.substring(indexOfDot + 1, lastIndex); + + // Simulate each legs in a temporary StringBuilder to know if they would add an `_` + StringBuilder tmpSB = new StringBuilder(); + boolean hasBeforeUnderscore = appendWithUnderscores(beforeDot, tmpSB); + boolean hasAfterUnderscore = appendWithUnderscores(afterDot, tmpSB, true); + + // https://www.baeldung.com/java-xor-operator + if (hasBeforeUnderscore ^ hasAfterUnderscore) { + // https://github.com/solven-eu/cleanthat/issues/896 + // We need both legs to have underscores, following PMD expectation + doAppendWithUnderscores(beforeDot, sb, false); + sb.append('.'); + doAppendWithUnderscores(afterDot, sb, true); + } else { + // Treat each legs independantly appendWithUnderscores(beforeDot, sb); - } - sb.append('.'); - { - var afterDot = noUnderscore.substring(indexOfDot + 1, lastIndex); + sb.append('.'); appendWithUnderscores(afterDot, sb, true); } } @@ -175,26 +187,49 @@ protected boolean processNotRecursively(NodeAndSymbolSolver node) { } } - private void appendWithUnderscores(String noUnderscore, StringBuilder sb) { - appendWithUnderscores(noUnderscore, sb, false); + private boolean appendWithUnderscores(String noUnderscore, StringBuilder sb) { + return appendWithUnderscores(noUnderscore, sb, false); } - private void appendWithUnderscores(String noUnderscore, StringBuilder sb, boolean reverseForDecimals) { + /** + * + * @param noUnderscore + * @param sb + * @param reverseForDecimals + * @return true if at least one underscore is added + */ + private boolean appendWithUnderscores(String noUnderscore, StringBuilder sb, boolean reverseForDecimals) { if (noUnderscore.length() <= getAcceptableDecimalLength()) { sb.append(noUnderscore); - return; + return false; } + return doAppendWithUnderscores(noUnderscore, sb, reverseForDecimals); + } + + /** + * Force adding `_` in proper locations. Even if the number is smaller than + * {@link UseUnderscoresInNumericLiterals#getAcceptableDecimalLength()}. + * + * @param noUnderscore + * @param sb + * @param reverseForDecimals + * @return true if at least one underscore is added + */ + private boolean doAppendWithUnderscores(String noUnderscore, StringBuilder sb, boolean reverseForDecimals) { assert noUnderscore.matches("\\d+"); var nbDigits = noUnderscore.length(); var position = 0; var nbDigitsLeft = nbDigits; + + boolean hasUnderscore = false; while (nbDigitsLeft > 0) { if (position != 0) { sb.append('_'); + hasUnderscore = true; } int nextBlockSize; @@ -209,6 +244,8 @@ private void appendWithUnderscores(String noUnderscore, StringBuilder sb, boolea nbDigitsLeft -= nextBlockSize; position = nextPosition; } + + return hasUnderscore; } } diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation.java index 7854d70a0..b6c4aff94 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import org.codehaus.plexus.languages.java.version.JavaVersion; import org.junit.Test; import org.junit.jupiter.params.provider.Arguments; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.util.ClassUtils; import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; @@ -40,10 +38,11 @@ import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.AllIncludingDraftSingleMutators; import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.CompositeMutator; import eu.solven.cleanthat.engine.java.refactorer.test.LocalClassTestHelper; +import lombok.extern.slf4j.Slf4j; // BEWARE: This will generate a versioned file: It may lead to unexpected result. However, it will also make sure this file is often up-to-date +@Slf4j public class TestGenerateDocumentation { - private static final Logger LOGGER = LoggerFactory.getLogger(TestGenerateDocumentation.class); static final String EOL = System.lineSeparator(); diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation_Tags.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation_Tags.java index 1e2b8c5a0..7a27b557d 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation_Tags.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/TestGenerateDocumentation_Tags.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,18 +25,17 @@ import org.codehaus.plexus.languages.java.version.JavaVersion; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.engine.java.IJdkVersionConstants; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.AllIncludingDraftSingleMutators; import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.CompositeMutator; import eu.solven.cleanthat.engine.java.refactorer.test.LocalClassTestHelper; +import lombok.extern.slf4j.Slf4j; // BEWARE: This will generate a versioned file: It may lead to unexpected result. However, it will also make sure this file is often up-to-date +@Slf4j public class TestGenerateDocumentation_Tags { - private static final Logger LOGGER = LoggerFactory.getLogger(TestGenerateDocumentation_Tags.class); static final String EOL = System.lineSeparator(); diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestAllMutators.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestAllMutators.java index 4b75aec7d..6b3d0673a 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestAllMutators.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestAllMutators.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import org.codehaus.plexus.languages.java.version.JavaVersion; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -33,9 +31,10 @@ import eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryBoxing; import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.AllIncludingDraftSingleMutators; import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserTestCases; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class TestAllMutators extends AJavaparserTestCases { - private static final Logger LOGGER = LoggerFactory.getLogger(TestAllMutators.class); final IJavaparserAstMutator mutator = new UnnecessaryBoxing(); diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestLocalVariableTypeInferenceCustom.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestLocalVariableTypeInferenceCustom.java index 7e2af1fba..aa36ab67d 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestLocalVariableTypeInferenceCustom.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/TestLocalVariableTypeInferenceCustom.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; @@ -32,9 +30,10 @@ import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.LocalVariableTypeInference; import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserTestCases; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class TestLocalVariableTypeInferenceCustom extends AJavaparserTestCases { - private static final Logger LOGGER = LoggerFactory.getLogger(TestLocalVariableTypeInferenceCustom.class); final IJavaparserAstMutator mutator = new LocalVariableTypeInference(); diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestAppendCharacterWithCharCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestAppendCharacterWithCharCases.java new file mode 100644 index 000000000..71f9ea698 --- /dev/null +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestAppendCharacterWithCharCases.java @@ -0,0 +1,159 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import eu.solven.cleanthat.engine.java.refactorer.annotations.CompareMethods; +import eu.solven.cleanthat.engine.java.refactorer.annotations.UnmodifiedMethod; +import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; +import eu.solven.cleanthat.engine.java.refactorer.mutators.AppendCharacterWithChar; +import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserRefactorerCases; + +import java.io.CharArrayWriter; +import java.io.StringWriter; + +public class TestAppendCharacterWithCharCases extends AJavaparserRefactorerCases { + + @Override + public IJavaparserAstMutator getTransformer() { + return new AppendCharacterWithChar(); + } + + private static final class CustomStringBuilder { + private CustomStringBuilder append(String string) { + return this; + } + } + + @UnmodifiedMethod + public static class CaseCustomStringBuilder { + public Object pre() { + return new CustomStringBuilder().append("a"); + } + } + + @CompareMethods + public static class CaseCharArrayWriter { + public Object pre() { + return new CharArrayWriter().append("a"); + } + + public Object post() { + return new CharArrayWriter().append('a'); + } + } + + @CompareMethods + public static class CaseStringWriter { + public Object pre() { + return new StringWriter().append("a"); + } + + public Object post() { + return new StringWriter().append('a'); + } + } + + @CompareMethods + public static class CaseStringBuffer { + public Object pre() { + return new StringBuffer().append("a"); + } + + public Object post() { + return new StringBuffer().append('a'); + } + } + + @CompareMethods + public static class CaseStringBuilder { + public Object pre() { + return new StringBuilder().append("a"); + } + + public Object post() { + return new StringBuilder().append('a'); + } + } + + @CompareMethods + public static class CaseCharChain { + public Object pre() { + return new StringBuilder().append("a").append("b"); + } + + public Object post() { + return new StringBuilder().append('a').append('b'); + } + } + + @UnmodifiedMethod + public static class CaseString { + public Object pre() { + return new StringBuilder().append("aa"); + } + } + + @UnmodifiedMethod + public static class CaseStringChain { + public Object pre() { + return new StringBuilder().append("aa").append("bb"); + } + } + + @CompareMethods + public static class CaseMixedChain { + public Object pre() { + return new StringBuilder().append("a").append("bb"); + } + + public Object post() { + return new StringBuilder().append('a').append("bb"); + } + } + + @CompareMethods + public static class CaseMixedChainFlipped { + public Object pre() { + return new StringBuilder().append("aa").append("b"); + } + + public Object post() { + return new StringBuilder().append("aa").append('b'); + } + } + + @UnmodifiedMethod + public static class CaseEmptyString { + public Object pre() { + return new StringBuilder().append(""); + } + } + + @UnmodifiedMethod + public static class CaseApostrophe { + public Object pre() { + return new StringBuilder().append("'"); + } + } + + @CompareMethods + public static class CaseTab { + public Object pre() { + return new StringBuilder().append("\t"); + } + + public Object post() { + return new StringBuilder().append('\t'); + } + } + + @CompareMethods + public static class CaseDelete { + public Object pre() { + return new StringBuilder().append("\u007F"); + } + + public Object post() { + return new StringBuilder().append('\u007F'); + } + } + +} diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestEmptyControlStatementCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestEmptyControlStatementCases.java index c43e24459..2078c1703 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestEmptyControlStatementCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestEmptyControlStatementCases.java @@ -60,7 +60,7 @@ public void post() { // In edgy-cases, one would consider this as a feature (e.g. if one wants a custom class) @Ignore("This may deserve a dedicated mutator") - // https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#doublebraceinitialization + // https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#doublebraceinitialization @CompareMethods public static class AnonymousClass { public Object pre() { diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestLiteralsFirstInComparisonsCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestLiteralsFirstInComparisonsCases.java index 59ba7257b..94ee77144 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestLiteralsFirstInComparisonsCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestLiteralsFirstInComparisonsCases.java @@ -121,7 +121,7 @@ public Object post(Object input) { } } - // https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#literalsfirstincomparisons + // https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#literalsfirstincomparisons @CompareMethods public static class CasePMD_stringEquals { boolean pre(String x) { diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderCases.java index 7bb3b0808..5b41841cf 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderCases.java @@ -116,4 +116,11 @@ public static class Issue_SealedClass_rightOrder { post = "public sealed interface IUpdatePortCommand permits UpdateScheduleCommand, UpdateStateCommand {}") public static class Issue_SealedClass_wrongOrder { } + + // https://github.com/solven-eu/cleanthat/issues/897 + @CompareCompilationUnitsAsStrings( + pre = "public class A { private transient final @Deprecated String ANNOTATED; }", + post = "public class A { @Deprecated private final transient String ANNOTATED; }") + public static class Issue_MissingWhiteSpaceBetweenAnnotationAndFirstModifier { + } } diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderThenUnnecessaryModifierCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderThenUnnecessaryModifierCases.java index 19288fc32..292839e95 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderThenUnnecessaryModifierCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestModifierOrderThenUnnecessaryModifierCases.java @@ -20,7 +20,7 @@ public IJavaparserAstMutator getTransformer() { // https://github.com/solven-eu/cleanthat/issues/802 @CompareCompilationUnitsAsStrings(pre = "interface TopLevelInterface { public final static int i = 0; }", - post = "interface TopLevelInterface {\n" + "\n" + " int i = 0;\n" + "}\n") + post = "interface TopLevelInterface { int i = 0; }") public static class Issue802 { } diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestObjectEqualsForPrimitivesCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestObjectEqualsForPrimitivesCases.java index 4050b89b1..4414967e5 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestObjectEqualsForPrimitivesCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestObjectEqualsForPrimitivesCases.java @@ -36,19 +36,23 @@ public boolean post(double a, double b) { } } - @UnmodifiedMethod - public static class CaseIntLong { - public boolean pre(int a, long b) { - return Objects.equals(a, b); - } - } + // Commented until the following is fixed (NOK with Eclipse 3.36.0 (June 2025)) + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3870 + // @UnmodifiedMethod + // public static class CaseIntLong { + // public boolean pre(int a, long b) { + // return Objects.equals(a, b); + // } + // } - @UnmodifiedMethod - public static class CaseIntDouble { - public boolean pre(int a, double b) { - return Objects.equals(a, b); - } - } + // Commented until the following is fixed (NOK with Eclipse 3.36.0 (June 2025)) + // https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3870 + // @UnmodifiedMethod + // public static class CaseIntDouble { + // public boolean pre(int a, double b) { + // return Objects.equals(a, b); + // } + // } @UnmodifiedMethod public static class CaseObject { diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryCaseChangeCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryCaseChangeCases.java new file mode 100644 index 000000000..e011048c1 --- /dev/null +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryCaseChangeCases.java @@ -0,0 +1,427 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import eu.solven.cleanthat.engine.java.refactorer.annotations.CompareMethods; +import eu.solven.cleanthat.engine.java.refactorer.annotations.UnmodifiedMethod; +import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; +import eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryCaseChange; +import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserRefactorerCases; + +import java.util.Locale; + +public class TestUnnecessaryCaseChangeCases extends AJavaparserRefactorerCases { + + @Override + public IJavaparserAstMutator getTransformer() { + return new UnnecessaryCaseChange(); + } + + private static final class CustomClass { + private CustomClass equalsIgnoreCase(String string) { + return this; + } + + private CustomClass toLowerCase() { + return this; + } + } + + @UnmodifiedMethod + public static class CaseCustomClassWithEqualsIgnoreCase { + public Object pre() { + return new CustomClass().toLowerCase().equalsIgnoreCase("lowercase"); + } + } + + // Cases that should be replaced with equalsIgnoreCase + + @CompareMethods + public static class CaseToLowerCaseWithLiteralEmpty { + public Object pre(String string) { + return string.toLowerCase().equals(""); + } + + public Object post(String string) { + return string.equalsIgnoreCase(""); + } + } + + @CompareMethods + public static class CaseToUpperCaseWithLiteralEmpty { + public Object pre(String string) { + return string.toUpperCase().equals(""); + } + + public Object post(String string) { + return string.equalsIgnoreCase(""); + } + } + + @CompareMethods + public static class CaseToLowerCaseWithLiteralLowercase { + public Object pre(String string) { + return string.toLowerCase().equals("lowercase"); + } + + public Object post(String string) { + return string.equalsIgnoreCase("lowercase"); + } + } + + @CompareMethods + public static class CaseToUpperCaseWithLiteralUppercase { + public Object pre(String string) { + return string.toUpperCase().equals("UPPERCASE"); + } + + public Object post(String string) { + return string.equalsIgnoreCase("UPPERCASE"); + } + } + + @CompareMethods + public static class CaseLiteralEmptyWithToLowerCaseWith { + public Object pre(String string) { + return "".equals(string.toLowerCase()); + } + + public Object post(String string) { + return "".equalsIgnoreCase(string); + } + } + + @CompareMethods + public static class CaseLiteralEmptyWithToUpperCase { + public Object pre(String string) { + return "".equals(string.toUpperCase()); + } + + public Object post(String string) { + return "".equalsIgnoreCase(string); + } + } + + @CompareMethods + public static class CaseLiteralLowercaseWithToLowerCaseWith { + public Object pre(String string) { + return "lowercase".equals(string.toLowerCase()); + } + + public Object post(String string) { + return "lowercase".equalsIgnoreCase(string); + } + } + + @CompareMethods + public static class CaseLiteralUppercaseWithToUpperCase { + public Object pre(String string) { + return "UPPERCASE".equals(string.toUpperCase()); + } + + public Object post(String string) { + return "UPPERCASE".equalsIgnoreCase(string); + } + } + + @CompareMethods + public static class CaseToLowerCaseWithToLowerCase { + public Object pre(String left, String right) { + return left.toLowerCase().equals(right.toLowerCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseToUpperCaseWithToUpperCase { + public Object pre(String left, String right) { + return left.toUpperCase().equals(right.toUpperCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + // Cases where case change should be omitted + + @CompareMethods + public static class CaseToLowerCaseWithEqualsIgnoreCaseToLowerCase { + public Object pre(String left, String right) { + return left.toLowerCase().equalsIgnoreCase(right.toLowerCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseToUpperCaseWithEqualsIgnoreCaseToUpperCase { + public Object pre(String left, String right) { + return left.toUpperCase().equalsIgnoreCase(right.toUpperCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseToLowerCaseWithEqualsIgnoreCaseToUpperCase { + public Object pre(String left, String right) { + return left.toLowerCase().equalsIgnoreCase(right.toUpperCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseToUpperCaseWithEqualsIgnoreCaseToLowerCase { + public Object pre(String left, String right) { + return left.toUpperCase().equalsIgnoreCase(right.toLowerCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseToLowerCaseWithEqualsIgnoreCase { + public Object pre(String left, String right) { + return left.toLowerCase().equalsIgnoreCase(right); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseToUpperCaseWithEqualsIgnoreCase { + public Object pre(String left, String right) { + return left.toUpperCase().equalsIgnoreCase(right); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseVariableWithEqualsIgnoreCaseToLowerCase { + public Object pre(String left, String right) { + return left.equalsIgnoreCase(right.toLowerCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + @CompareMethods + public static class CaseVariableWithEqualsIgnoreCaseToUpperCase { + public Object pre(String left, String right) { + return left.equalsIgnoreCase(right.toUpperCase()); + } + + public Object post(String left, String right) { + return left.equalsIgnoreCase(right); + } + } + + // Cases that could be replaced, but are ignored for now + + @UnmodifiedMethod + public static class CaseToLowerCaseWithNull { + public Object pre(String string) { + return string.toLowerCase().equals(null); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithNull { + public Object pre(String string) { + return string.toUpperCase().equals(null); + } + } + + // Cases that should be ignored as the replacement WOULD change execution behavior + + @UnmodifiedMethod + public static class CaseToLowerCaseWithLiteralUppercase { + public Object pre(String string) { + return string.toLowerCase().equals("UPPERCASE"); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithLiteralLowercase { + public Object pre(String string) { + return string.toUpperCase().equals("lowercase"); + } + } + + @UnmodifiedMethod + public static class CaseToLowerCaseWithLiteralMixedCase { + public Object pre(String string) { + return string.toLowerCase().equals("MixedCase"); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithLiteralMixedCase { + public Object pre(String string) { + return string.toUpperCase().equals("MixedCase"); + } + } + + @UnmodifiedMethod + public static class CaseLiteralUppercaseWithToLowerCase { + public Object pre(String string) { + return "UPPERCASE".equals(string.toLowerCase()); + } + } + + @UnmodifiedMethod + public static class CaseLiteralLowercaseWithToUpperCase { + public Object pre(String string) { + return "lowercase".equals(string.toUpperCase()); + } + } + + @UnmodifiedMethod + public static class CaseLiteralMixedCaseWithToLowerCase { + public Object pre(String string) { + return "MixedCase".equals(string.toLowerCase()); + } + } + + @UnmodifiedMethod + public static class CaseLiteralMixedCaseWithToUpperCase { + public Object pre(String string) { + return "MixedCase".equals(string.toUpperCase()); + } + } + + @UnmodifiedMethod + public static class CaseToLowerCaseWithToUpperCase { + public Object pre(String left, String right) { + return left.toLowerCase().equals(right.toUpperCase()); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithToLowerCase { + public Object pre(String left, String right) { + return left.toUpperCase().equals(right.toLowerCase()); + } + } + + // Cases that should be ignored as the replacement COULD change execution behavior + + @UnmodifiedMethod + public static class CaseToLowerCaseWithLocaleAndEqualsIgnoreCase { + public Object pre(String string) { + return string.toLowerCase(Locale.ENGLISH).equalsIgnoreCase("lowercase"); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithLocaleAndEqualsIgnoreCase { + public Object pre(String string) { + return string.toUpperCase(Locale.ENGLISH).equalsIgnoreCase("UPPERCASE"); + } + } + + @UnmodifiedMethod + public static class CaseAndEqualsIgnoreCaseWithToLowerCaseAndLocale { + public Object pre(String string) { + return "lowercase".equalsIgnoreCase(string.toLowerCase(Locale.ENGLISH)); + } + } + + @UnmodifiedMethod + public static class CaseAndEqualsIgnoreCaseWithToUpperCaseAndLocale { + public Object pre(String string) { + return "UPPERCASE".equalsIgnoreCase(string.toUpperCase(Locale.ENGLISH)); + } + } + + @UnmodifiedMethod + public static class CaseToLowerCaseWithLocale { + public Object pre(String string) { + return string.toLowerCase(Locale.ENGLISH).equals("lowercase"); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithLocale { + public Object pre(String string) { + return string.toUpperCase(Locale.ENGLISH).equals("UPPERCASE"); + } + } + + @UnmodifiedMethod + public static class CaseToLowerCaseWithLocaleFlipped { + public Object pre(String string) { + return "lowercase".equals(string.toLowerCase(Locale.ENGLISH)); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithLocaleFlipped { + public Object pre(String string) { + return "UPPERCASE".equals(string.toUpperCase(Locale.ENGLISH)); + } + } + + @UnmodifiedMethod + public static class CaseVariableWithToLowerCase { + public Object pre(String left, String right) { + return left.equals(right.toLowerCase()); + } + } + + @UnmodifiedMethod + public static class CaseVariableWithToUpperCase { + public Object pre(String left, String right) { + return left.equals(right.toUpperCase()); + } + } + + @UnmodifiedMethod + public static class CaseToLowerCaseWithVariable { + public Object pre(String left, String right) { + return left.toLowerCase().equals(right); + } + } + + @UnmodifiedMethod + public static class CaseToUpperCaseWithVariable { + public Object pre(String left, String right) { + return left.toUpperCase().equals(right); + } + } + + // Cases that should be ignored as there is no case change involved + + @UnmodifiedMethod + public static class CaseLiteralEqualsLiteral { + public Object pre() { + return "lowercase".equals("lowercase"); + } + } + + @UnmodifiedMethod + public static class CaseLiteralEqualsIgnoreCaseLiteral { + public Object pre() { + return "lowercase".equalsIgnoreCase("lowercase"); + } + } + +} diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryLambdaEnclosingParametersCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryLambdaEnclosingParametersCases.java index e86106ddd..73b4f5ede 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryLambdaEnclosingParametersCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUnnecessaryLambdaEnclosingParametersCases.java @@ -23,7 +23,6 @@ public static class CaseRunnable { public Runnable pre() { return () -> System.out.print("ok"); } - } @Ignore("TODO") @@ -38,6 +37,13 @@ public Function post() { } } + @UnmodifiedMethod + public static class CaseTypedFunction { + public Function pre() { + return (Integer a) -> a % 5; + } + } + @UnmodifiedMethod public static class CaseBiFunction { public BiFunction pre() { @@ -45,4 +51,11 @@ public BiFunction pre() { } } + @UnmodifiedMethod + public static class CaseTypedBiFunction { + public BiFunction pre() { + return (Integer a, Integer b) -> a + b; + } + } + } diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUseUnderscoresInNumericLiteralsCases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUseUnderscoresInNumericLiteralsCases.java index 618522c92..312d63d50 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUseUnderscoresInNumericLiteralsCases.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/TestUseUnderscoresInNumericLiteralsCases.java @@ -4,6 +4,7 @@ import eu.solven.cleanthat.engine.java.refactorer.annotations.CompareInnerClasses; import eu.solven.cleanthat.engine.java.refactorer.annotations.CompareMethods; import eu.solven.cleanthat.engine.java.refactorer.annotations.UnmodifiedInnerClass; +import eu.solven.cleanthat.engine.java.refactorer.annotations.UnmodifiedMethod; import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.UseUnderscoresInNumericLiterals; import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserRefactorerCases; @@ -103,4 +104,37 @@ public interface Pre { double d_hex = 0x4.5p1f; } } + + // https://github.com/solven-eu/cleanthat/issues/896 + @CompareMethods + public static class Case896 { + public Object pre() { + return 1234.12345; + } + + public Object post() { + return 1_234.123_45; + } + } + + // https://github.com/solven-eu/cleanthat/issues/896 + @CompareMethods + public static class Case896_LongerPrefixThanSuffix { + public Object pre() { + return 12345.1234; + } + + public Object post() { + return 12_345.123_4; + } + } + + // This is invalid due to `The literal 36e-11234 of type double is out of range ` + @UnmodifiedMethod + public static class LargeExponent { + public int pre() { + // double binary = 36e-11234; + return 0; + } + } } diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/multiple/TestLiteralsFirstInComparisons_UnnecessaryCaseChange_Cases.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/multiple/TestLiteralsFirstInComparisons_UnnecessaryCaseChange_Cases.java new file mode 100644 index 000000000..f5c6c1530 --- /dev/null +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/cases/do_not_format_me/multiple/TestLiteralsFirstInComparisons_UnnecessaryCaseChange_Cases.java @@ -0,0 +1,33 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me.multiple; + +import eu.solven.cleanthat.engine.java.refactorer.annotations.CompareMethods; +import eu.solven.cleanthat.engine.java.refactorer.meta.CompositeJavaparserMutator; +import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; +import eu.solven.cleanthat.engine.java.refactorer.mutators.LiteralsFirstInComparisons; +import eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryCaseChange; +import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserRefactorerCases; + +import java.util.Arrays; + +public class TestLiteralsFirstInComparisons_UnnecessaryCaseChange_Cases extends AJavaparserRefactorerCases { + + @Override + public IJavaparserAstMutator getTransformer() { + return new CompositeJavaparserMutator(Arrays.asList( + new LiteralsFirstInComparisons(), + new UnnecessaryCaseChange() + )); + } + + @CompareMethods + public static class CaseToLowerCaseWithHardcodedLowercase { + public Object pre(String string) { + return string.toLowerCase().equals("lowercase"); + } + + public Object post(String string) { + return "lowercase".equalsIgnoreCase(string); + } + } + +} diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITAnonymousClass.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITAnonymousClass.java index bf07921a7..49115fa89 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITAnonymousClass.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITAnonymousClass.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import java.util.function.Function; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.github.javaparser.JavaParser; import com.github.javaparser.ast.Node; @@ -37,9 +35,10 @@ import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class ITAnonymousClass { - private static final Logger LOGGER = LoggerFactory.getLogger(ITAnonymousClass.class); private static final String eol = System.lineSeparator(); public static class CaseAnonymousClass_HashMap { diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITCheckNotModified.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITCheckNotModified.java index ca7a0e076..29acdbd7b 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITCheckNotModified.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITCheckNotModified.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,16 +23,16 @@ import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.github.javaparser.StaticJavaParser; import com.google.common.collect.ImmutableMap; +import lombok.extern.slf4j.Slf4j; + // TODO Move this to somewhere not specific to lambda? // https://github.com/javaparser/javaparser/issues/3317 +@Slf4j public class ITCheckNotModified { - private static final Logger LOGGER = LoggerFactory.getLogger(ITCheckNotModified.class); protected Map ShouldNotMutate() { // Before diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestLocalFile.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestLocalFile.java index c1347b3e7..f823d43bd 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestLocalFile.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestLocalFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,13 @@ import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import eu.solven.cleanthat.config.pojo.CleanthatEngineProperties; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer; import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; import eu.solven.cleanthat.engine.java.refactorer.meta.IJavaparserAstMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.LiteralsFirstInComparisons; +import lombok.extern.slf4j.Slf4j; /** * This is useful to investigate a misbehavior over current project file @@ -37,8 +36,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class ITTestLocalFile { - private static final Logger LOGGER = LoggerFactory.getLogger(ITTestLocalFile.class); final String path = // "./config/src/main/java/" + "eu.solven.cleanthat.config.ConfigHelpers".replace('.', '/') + ".java" diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestRemoteFile.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestRemoteFile.java index 4bbaf9373..542ab6cf7 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestRemoteFile.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/it/ITTestRemoteFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch; import org.bitbucket.cowwoc.diffmatchpatch.DiffMatchPatch.Operation; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.io.ByteStreams; @@ -39,6 +37,7 @@ import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties; import eu.solven.cleanthat.engine.java.refactorer.mutators.LiteralsFirstInComparisons; import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators; +import lombok.extern.slf4j.Slf4j; /** * This is useful to investigate a misbehavior over current project file @@ -46,8 +45,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class ITTestRemoteFile { - private static final Logger LOGGER = LoggerFactory.getLogger(ITTestRemoteFile.class); final String hashMapPath = "https://raw.githubusercontent.com/openjdk/jdk/master/src/java.base/share/classes/java/util/HashMap.java"; diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestJavaParserParsing.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestJavaParserParsing.java index a364706e1..3c400a560 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestJavaParserParsing.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestJavaParserParsing.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -30,9 +28,10 @@ import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.LocalVariableTypeInference; import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserTestCases; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class TestJavaParserParsing extends AJavaparserTestCases { - private static final Logger LOGGER = LoggerFactory.getLogger(TestJavaParserParsing.class); final IMutator mutator = new LocalVariableTypeInference(); diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestMutatorOnFiles.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestMutatorOnFiles.java index 589cf5eff..490d5e111 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestMutatorOnFiles.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/javaparser/TestMutatorOnFiles.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -50,6 +48,7 @@ import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.AllIncludingDraftSingleMutators; import eu.solven.cleanthat.engine.java.refactorer.mutators.scanner.MutatorsScanner; import eu.solven.cleanthat.engine.java.refactorer.test.AJavaparserTestCases; +import lombok.extern.slf4j.Slf4j; /** * This is some sort of integration tests. it will process any resource in `/source/do_not_format_me/XXX` where XXX is @@ -58,9 +57,9 @@ * @author Benoit Lacelle * */ +@Slf4j @RunWith(Parameterized.class) public class TestMutatorOnFiles extends AJavaparserTestCases { - private static final Logger LOGGER = LoggerFactory.getLogger(TestMutatorOnFiles.class); private static final String DIR = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/source/do_not_format_me/"; diff --git a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/mutators/composite/TestSafeAndConsensualMutators.java b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/mutators/composite/TestSafeAndConsensualMutators.java index d4c4fecd2..cc6053ee7 100644 --- a/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/mutators/composite/TestSafeAndConsensualMutators.java +++ b/java/src/test/java/eu/solven/cleanthat/engine/java/refactorer/mutators/composite/TestSafeAndConsensualMutators.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.Sets; @@ -32,9 +30,10 @@ import eu.solven.cleanthat.engine.java.refactorer.ATodoJavaParserMutator; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.scanner.MutatorsScanner; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class TestSafeAndConsensualMutators { - private static final Logger LOGGER = LoggerFactory.getLogger(TestSafeAndConsensualMutators.class); final JavaVersion last = JavaVersion.parse(IJdkVersionConstants.LAST); diff --git a/java/src/test/resources/source/do_not_format_me/LocalVariableTypeInference/CodeProviderHelpers.java b/java/src/test/resources/source/do_not_format_me/LocalVariableTypeInference/CodeProviderHelpers.java index ab16f0b47..262065744 100644 --- a/java/src/test/resources/source/do_not_format_me/LocalVariableTypeInference/CodeProviderHelpers.java +++ b/java/src/test/resources/source/do_not_format_me/LocalVariableTypeInference/CodeProviderHelpers.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Optional; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,8 +41,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CodeProviderHelpers { - private static final Logger LOGGER = LoggerFactory.getLogger(CodeProviderHelpers.class); protected Collection objectMappers; diff --git a/java/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java b/java/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java index fab582c96..53697c0d7 100644 --- a/java/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java +++ b/java/src/test/resources/source/do_not_format_me/MiTrust/LocaleHelper.java @@ -13,6 +13,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,8 +28,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class LocaleHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(LocaleHelper.class); private static final Supplier> ISO_LANGUAGES = Suppliers.memoize(() -> ImmutableSet.copyOf(Locale.getISOLanguages())); diff --git a/kotlin/src/main/java/eu/solven/cleanthat/kotlin/JavaService.java b/kotlin/src/main/java/eu/solven/cleanthat/kotlin/JavaService.java index 6d81e3fd2..481415861 100644 --- a/kotlin/src/main/java/eu/solven/cleanthat/kotlin/JavaService.java +++ b/kotlin/src/main/java/eu/solven/cleanthat/kotlin/JavaService.java @@ -23,8 +23,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class JavaService { - private static final Logger LOGGER = LoggerFactory.getLogger(JavaService.class); public void sayHello() { LOGGER.info("Java says 'Hello World!'"); diff --git a/lambda/pom.xml b/lambda/pom.xml index 96332fe01..f02def789 100644 --- a/lambda/pom.xml +++ b/lambda/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT lambda diff --git a/lambda/src/main/java/eu/solven/cleanthat/lambda/AWebhooksLambdaFunction.java b/lambda/src/main/java/eu/solven/cleanthat/lambda/AWebhooksLambdaFunction.java index 575c46839..3d1e1d041 100644 --- a/lambda/src/main/java/eu/solven/cleanthat/lambda/AWebhooksLambdaFunction.java +++ b/lambda/src/main/java/eu/solven/cleanthat/lambda/AWebhooksLambdaFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @@ -43,6 +41,7 @@ import eu.solven.cleanthat.lambda.jackson.CustomSnakeCase; import eu.solven.cleanthat.lambda.step0_checkwebhook.IWebhookEvent; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * The main used by AWS Lambda. This is a {@link SpringBootApplication} which is quite fat. There is lighter @@ -53,8 +52,8 @@ // https://github.com/spring-cloud/spring-cloud-function // https://cloud.spring.io/spring-cloud-static/spring-cloud-function/2.1.1.RELEASE/spring-cloud-function.html // https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#logsV2:log-groups/log-group/$252Faws$252Flambda$252FupperCase +@Slf4j public abstract class AWebhooksLambdaFunction extends ACleanThatXxxFunction { - private static final Logger LOGGER = LoggerFactory.getLogger(AWebhooksLambdaFunction.class); private static final String KEY_BODY = "body"; private static final String KEY_HEADERS = "headers"; diff --git a/lambda/src/main/java/eu/solven/cleanthat/lambda/dynamodb/SaveToDynamoDb.java b/lambda/src/main/java/eu/solven/cleanthat/lambda/dynamodb/SaveToDynamoDb.java index 499d156f3..2d6969a2a 100644 --- a/lambda/src/main/java/eu/solven/cleanthat/lambda/dynamodb/SaveToDynamoDb.java +++ b/lambda/src/main/java/eu/solven/cleanthat/lambda/dynamodb/SaveToDynamoDb.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,9 +21,6 @@ import java.util.Map; import java.util.UUID; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.regions.Regions; @@ -37,6 +34,7 @@ import eu.solven.cleanthat.code_provider.github.event.pojo.GithubWebhookEvent; import eu.solven.cleanthat.lambda.step0_checkwebhook.IWebhookEvent; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * Helps saving into DynamoDB @@ -44,8 +42,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class SaveToDynamoDb { - private static final Logger LOGGER = LoggerFactory.getLogger(SaveToDynamoDb.class); protected SaveToDynamoDb() { // hidden diff --git a/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/CheckWebhooksLambdaFunction.java b/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/CheckWebhooksLambdaFunction.java index 160aa3dae..bcdc07fe1 100644 --- a/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/CheckWebhooksLambdaFunction.java +++ b/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/CheckWebhooksLambdaFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ import java.util.Map; import java.util.Optional; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; @@ -36,6 +34,7 @@ import eu.solven.cleanthat.lambda.AWebhooksLambdaFunction; import eu.solven.cleanthat.lambda.dynamodb.SaveToDynamoDb; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * Used to filter relevant webhooks for useless webhooks. @@ -47,8 +46,8 @@ * */ // https://docs.github.com/en/developers/github-marketplace/using-the-github-marketplace-api-in-your-app/webhook-events-for-the-github-marketplace-api +@Slf4j public class CheckWebhooksLambdaFunction extends AWebhooksLambdaFunction { - private static final Logger LOGGER = LoggerFactory.getLogger(CheckWebhooksLambdaFunction.class); public static void main(String[] args) { SpringApplication.run(CheckWebhooksLambdaFunction.class, args); diff --git a/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/MarketPlaceEventManager.java b/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/MarketPlaceEventManager.java index 3e5ceffbb..d5cc8af4d 100644 --- a/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/MarketPlaceEventManager.java +++ b/lambda/src/main/java/eu/solven/cleanthat/lambda/step0_checkwebhook/MarketPlaceEventManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ import java.util.Map; import org.apache.http.HttpStatus; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import com.fasterxml.jackson.core.JsonProcessingException; @@ -37,6 +35,7 @@ import com.google.common.base.Strings; import eu.solven.pepper.collection.PepperMapHelper; +import lombok.extern.slf4j.Slf4j; /** * Manages marketPlace events for Github @@ -44,8 +43,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class MarketPlaceEventManager { - private static final Logger LOGGER = LoggerFactory.getLogger(MarketPlaceEventManager.class); protected MarketPlaceEventManager() { // hidden diff --git a/lambda/src/main/java/eu/solven/cleanthat/lambda/step1_checkconfiguration/CheckConfigWebhooksLambdaFunction.java b/lambda/src/main/java/eu/solven/cleanthat/lambda/step1_checkconfiguration/CheckConfigWebhooksLambdaFunction.java index 81085ea2c..c924ae076 100644 --- a/lambda/src/main/java/eu/solven/cleanthat/lambda/step1_checkconfiguration/CheckConfigWebhooksLambdaFunction.java +++ b/lambda/src/main/java/eu/solven/cleanthat/lambda/step1_checkconfiguration/CheckConfigWebhooksLambdaFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; @@ -36,6 +34,7 @@ import eu.solven.cleanthat.lambda.AWebhooksLambdaFunction; import eu.solven.cleanthat.lambda.dynamodb.SaveToDynamoDb; import eu.solven.cleanthat.lambda.step0_checkwebhook.IWebhookEvent; +import lombok.extern.slf4j.Slf4j; /** * Used to check if given webhook is associated to a valid configuration (e.g. to filter irrelevant repositories). @@ -43,8 +42,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CheckConfigWebhooksLambdaFunction extends AWebhooksLambdaFunction { - private static final Logger LOGGER = LoggerFactory.getLogger(CheckConfigWebhooksLambdaFunction.class); public AmazonDynamoDB makeDynamoDbClient() { return SaveToDynamoDb.makeDynamoDbClient(); diff --git a/lambda/src/main/java/eu/solven/cleanthat/lambda/step2_executeclean/ExecuteCleaningWebhooksLambdaFunction.java b/lambda/src/main/java/eu/solven/cleanthat/lambda/step2_executeclean/ExecuteCleaningWebhooksLambdaFunction.java index d7aac5860..cdfab5e07 100644 --- a/lambda/src/main/java/eu/solven/cleanthat/lambda/step2_executeclean/ExecuteCleaningWebhooksLambdaFunction.java +++ b/lambda/src/main/java/eu/solven/cleanthat/lambda/step2_executeclean/ExecuteCleaningWebhooksLambdaFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,6 @@ * */ public class ExecuteCleaningWebhooksLambdaFunction extends AWebhooksLambdaFunction { - // private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteCleaningWebhooksLambdaFunction.class); @Override protected Map unsafeProcessOneEvent(IWebhookEvent input) { diff --git a/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/AProcessLocallyDynamoDbEvent_ExecuteClean.java b/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/AProcessLocallyDynamoDbEvent_ExecuteClean.java index b3d65f7da..a548906db 100644 --- a/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/AProcessLocallyDynamoDbEvent_ExecuteClean.java +++ b/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/AProcessLocallyDynamoDbEvent_ExecuteClean.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ import org.kohsuke.github.AbstractGitHubWireMockTest; import org.kohsuke.github.GitHub; import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -45,6 +43,7 @@ import eu.solven.cleanthat.lambda.AWebhooksLambdaFunction; import eu.solven.cleanthat.lambda.step2_executeclean.ExecuteCleaningWebhooksLambdaFunction; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * This enables re-processing an event locally. Very useful to reproduce an issue, or test a know workload over a @@ -53,11 +52,11 @@ * @author Benoit Lacelle * */ +@Slf4j @RunWith(SpringRunner.class) @ContextConfiguration(classes = { ExecuteCleaningWebhooksLambdaFunction.class, AProcessLocallyDynamoDbEvent_ExecuteClean.CleanthatWiremockSpringConfigContext.class }) public abstract class AProcessLocallyDynamoDbEvent_ExecuteClean extends AbstractGitHubWireMockTest { - private static final Logger LOGGER = LoggerFactory.getLogger(AProcessLocallyDynamoDbEvent_ExecuteClean.class); public static final String ENV_GITHUB_DO_RECORD = "github.do_record"; public static final String ENV_GITHUB_DO_REPLAY = "github.do_replay"; diff --git a/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/ITProcessLocallyOverPushBranch.java b/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/ITProcessLocallyOverPushBranch.java index 7c5206f86..b0a0f01dc 100644 --- a/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/ITProcessLocallyOverPushBranch.java +++ b/lambda/src/test/java/eu/solven/cleanthat/aws/dynamodb/it/ITProcessLocallyOverPushBranch.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -32,6 +30,7 @@ import eu.solven.cleanthat.lambda.step0_checkwebhook.CheckWebhooksLambdaFunction; import eu.solven.cleanthat.lambda.step1_checkconfiguration.CheckConfigWebhooksLambdaFunction; import eu.solven.cleanthat.lambda.step2_executeclean.ExecuteCleaningWebhooksLambdaFunction; +import lombok.extern.slf4j.Slf4j; /** * This enables processing similarly that on a push event over given branch @@ -39,13 +38,13 @@ * @author Benoit Lacelle * */ +@Slf4j @Deprecated(since = "NotReady: it is complicated to craft GitHub events manually (installation.id, after.sha1, ...)") @RunWith(SpringRunner.class) @ContextConfiguration(classes = { CheckWebhooksLambdaFunction.class, CheckConfigWebhooksLambdaFunction.class, ExecuteCleaningWebhooksLambdaFunction.class }) public class ITProcessLocallyOverPushBranch { - private static final Logger LOGGER = LoggerFactory.getLogger(ITProcessLocallyOverPushBranch.class); @Autowired CheckWebhooksLambdaFunction checkEvent; diff --git a/lambda/src/test/java/eu/solven/cleanthat/recorded/TestExecuteClean_Record_PushProtectedBranch.java b/lambda/src/test/java/eu/solven/cleanthat/recorded/TestExecuteClean_Record_PushProtectedBranch.java index 901a38f81..93809e950 100644 --- a/lambda/src/test/java/eu/solven/cleanthat/recorded/TestExecuteClean_Record_PushProtectedBranch.java +++ b/lambda/src/test/java/eu/solven/cleanthat/recorded/TestExecuteClean_Record_PushProtectedBranch.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import org.junit.runner.RunWith; import org.kohsuke.github.junit.GitHubWireMockRule; import org.kohsuke.github.junit.WireMockMultiServerRule; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; @@ -45,6 +43,7 @@ import eu.solven.cleanthat.code_provider.github.event.IGithubAppFactory; import eu.solven.cleanthat.code_provider.github.refs.GithubRefCleaner; import eu.solven.cleanthat.lambda.AWebhooksLambdaFunction; +import lombok.extern.slf4j.Slf4j; /** * This case represents a push of multiple commits to a branch. It leads to cleanthat receive one `push` events per @@ -53,11 +52,11 @@ * @author Benoit Lacelle * */ +@Slf4j @RunWith(SpringRunner.class) @ActiveProfiles(resolver = TestExecuteClean_Record_PushProtectedBranch.class) public class TestExecuteClean_Record_PushProtectedBranch extends AProcessLocallyDynamoDbEvent_ExecuteClean implements ActiveProfilesResolver { - private static final Logger LOGGER = LoggerFactory.getLogger(TestExecuteClean_Record_PushProtectedBranch.class); // Please make a first run with this set to true, then keep it to false; public static boolean DO_RECORD = false; diff --git a/lambda/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java b/lambda/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java index 7401c1664..ab33a2d1e 100644 --- a/lambda/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java +++ b/lambda/src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -244,11 +244,11 @@ protected GHRepository getTempRepository() throws IOException { * Creates a temporary repository that will be deleted at the end of the test. * * @param name - * string name of the the repository + * string name of the repository * * @return a temporary repository * @throws IOException - * if repository could not be created or retrieved. + * if the repository could not be created or retrieved. */ protected GHRepository getTempRepository(String name) throws IOException { var fullName = getOrganization() + '/' + name; diff --git a/lambda/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java b/lambda/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java index f83d38835..f82d13248 100644 --- a/lambda/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java +++ b/lambda/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,6 @@ import javax.annotation.Nonnull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.common.FileSource; import com.github.tomakehurst.wiremock.core.WireMockConfiguration; @@ -52,6 +49,8 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import lombok.extern.slf4j.Slf4j; + // TODO: Auto-generated Javadoc /** * The standard WireMockRule eagerly initializes a WireMockServer. This version suptakes a laze approach allowing us to @@ -60,8 +59,8 @@ * @author Liam Newman */ // https://github.com/hub4j/github-api/blob/main/src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java +@Slf4j public class GitHubWireMockRule extends WireMockMultiServerRule { - private static final Logger LOGGER = LoggerFactory.getLogger(GitHubWireMockRule.class); public static final String KEY_TAKE_SNAPSHOT = "test.github.takeSnapshot"; // By default the wiremock tests will run without proxy or taking a snapshot. diff --git a/local/pom.xml b/local/pom.xml index 746570f38..0591c054d 100644 --- a/local/pom.xml +++ b/local/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT local diff --git a/local/src/main/java/eu/solven/cleanthat/git/GitIgnoreParser.java b/local/src/main/java/eu/solven/cleanthat/git/GitIgnoreParser.java index 4e949bcd5..6a3de39e4 100644 --- a/local/src/main/java/eu/solven/cleanthat/git/GitIgnoreParser.java +++ b/local/src/main/java/eu/solven/cleanthat/git/GitIgnoreParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; /** * A very limitted implementation of a .gitgnore parser. It is very limitted as it handles only a very small subset of @@ -34,8 +33,8 @@ */ // Inspired by https://github.com/codemix/gitignore-parser/blob/master/lib/index.js // https://git-scm.com/docs/gitignore +@Slf4j public class GitIgnoreParser { - private static final Logger LOGGER = LoggerFactory.getLogger(GitIgnoreParser.class); protected GitIgnoreParser() { // hidden diff --git a/lombok.config b/lombok.config new file mode 100644 index 000000000..2cd439fd8 --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.log.fieldName = LOGGER diff --git a/maven/pom.xml b/maven/pom.xml index 7e8f7dca2..9688fbe01 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -4,7 +4,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT cleanthat-maven-plugin diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatMojo.java b/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatMojo.java index 035f47e28..3bd0ca390 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatMojo.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +26,12 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import eu.solven.cleanthat.config.ICleanthatConfigConstants; +import lombok.extern.slf4j.Slf4j; /** * The mojo of the mvn plugin @@ -41,8 +40,8 @@ * */ // https://maven.apache.org/guides/plugin/guide-java-plugin-development.html +@Slf4j public abstract class ACleanThatMojo extends AbstractMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanThatInitMojo.class); // To be synced with CodeProviderHelpers.PATHES_CLEANTHAT.get(0) public static final String MARKER_ANY_PARENT_DOTCLEANTHAT = diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatSpringMojo.java b/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatSpringMojo.java index f3c135c58..2bf9e4753 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatSpringMojo.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/ACleanThatSpringMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,6 @@ import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RemoteRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -44,6 +42,7 @@ import eu.solven.cleanthat.spotless.mvn.ArtifactResolver; import eu.solven.cleanthat.spotless.mvn.MavenProvisioner; import io.sentry.IHub; +import lombok.extern.slf4j.Slf4j; /** * Mojo relying on a Spring {@link ApplicationContext} @@ -52,8 +51,8 @@ * */ // https://maven.apache.org/guides/plugin/guide-java-plugin-development.html +@Slf4j public abstract class ACleanThatSpringMojo extends ACleanThatMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(ACleanThatSpringMojo.class); protected static final AtomicReference CURRENT_MOJO = new AtomicReference<>(); diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatApplyMojo.java b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatApplyMojo.java index e29def4d0..958b38d2f 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatApplyMojo.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatApplyMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import com.fasterxml.jackson.core.JsonProcessingException; @@ -49,6 +47,7 @@ import eu.solven.cleanthat.language.cleanthat.CleanthatForIntegrators; import eu.solven.cleanthat.language.javaparser.ICleanthatJavaparserConstants; import eu.solven.cleanthat.mvn.codeprovider.OverlayCodeProviderWrite; +import lombok.extern.slf4j.Slf4j; /** * This {@link org.apache.maven.plugin.Mojo} enables applying a single {@link IMutator} over current directory. @@ -57,6 +56,7 @@ * */ // https://maven.apache.org/guides/plugin/guide-java-plugin-development.html +@Slf4j @Mojo(name = CleanThatApplyMojo.MOJO_SINGLE, defaultPhase = LifecyclePhase.PROCESS_SOURCES, threadSafe = true, @@ -66,7 +66,6 @@ requiresProject = false) @SuppressWarnings("PMD.ImmutableField") public class CleanThatApplyMojo extends ACleanThatSpringMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanThatApplyMojo.class); public static final String MOJO_SINGLE = "apply"; diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatCheckMojo.java b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatCheckMojo.java index 7d27d3331..cb4624c12 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatCheckMojo.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatCheckMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import eu.solven.cleanthat.any_language.ICodeCleaner; @@ -31,6 +29,7 @@ import eu.solven.cleanthat.codeprovider.CodeProviderHelpers; import eu.solven.cleanthat.codeprovider.ICodeProviderWriter; import eu.solven.cleanthat.lambda.AllEnginesSpringConfig; +import lombok.extern.slf4j.Slf4j; /** * The mojo checking the code is clean @@ -45,11 +44,10 @@ // SpotBugs is VERIFY: https://spotbugs.github.io/spotbugs-maven-plugin/check-mojo.html // Revelc is VALIDATE: https://code.revelc.net/formatter-maven-plugin/validate-mojo.html @Mojo(name = CleanThatCheckMojo.MOJO_CHECK, defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) +@Slf4j public class CleanThatCheckMojo extends ACleanThatSpringMojo { public static final String MOJO_CHECK = "check"; - private static final Logger LOGGER = LoggerFactory.getLogger(CleanThatCheckMojo.class); - @Override protected List> springClasses() { List> classes = new ArrayList<>(); diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatGenerateEclipseStylesheetMojo.java b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatGenerateEclipseStylesheetMojo.java index 05c176ff0..6e4e18763 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatGenerateEclipseStylesheetMojo.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatGenerateEclipseStylesheetMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +46,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import org.springframework.core.io.FileSystemResource; @@ -81,14 +79,16 @@ import eu.solven.cleanthat.spotless.pojo.SpotlessStepParametersProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepProperties; import eu.solven.cleanthat.utils.ResultOrError; +import lombok.extern.slf4j.Slf4j; /** - * The mojo generates an Eclipse formatter stylesheet minimyzing modifications over existing codebase. + * The mojo generates an Eclipse formatter stylesheet minimizing modifications over the existing codebase. * * @author Benoit Lacelle * */ // https://maven.apache.org/guides/plugin/guide-java-plugin-development.html +@Slf4j @SuppressWarnings("PMD.GodClass") @Mojo(name = CleanThatGenerateEclipseStylesheetMojo.GOAL_ECLIPSE, defaultPhase = LifecyclePhase.NONE, @@ -96,7 +96,6 @@ aggregator = true, requiresProject = false) public class CleanThatGenerateEclipseStylesheetMojo extends ACleanThatSpringMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanThatCleanThatMojo.class); // ".*/src/[main|test]/java/.*/.*\\.java" public static final String DEFAULT_JAVA_REGEX = ".*\\.java"; diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatInitMojo.java b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatInitMojo.java index b20d54aaf..35e1a1313 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatInitMojo.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatInitMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,6 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.project.MavenProject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import com.fasterxml.jackson.core.JsonProcessingException; @@ -47,6 +45,7 @@ import eu.solven.cleanthat.config.spring.ConfigSpringConfig; import eu.solven.cleanthat.engine.IEngineLintFixerFactory; import eu.solven.cleanthat.lambda.AllEnginesSpringConfig; +import lombok.extern.slf4j.Slf4j; /** * This mojo will generate a relevant cleanthat configuration in current folder @@ -56,6 +55,7 @@ * */ // https://maven.apache.org/guides/plugin/guide-java-plugin-development.html +@Slf4j @Mojo(name = CleanThatInitMojo.MOJO_INIT, // This would be called once and for all defaultPhase = LifecyclePhase.NONE, @@ -63,7 +63,6 @@ // One may rely on the mvn plugin to initialize a configuration, even if no pom.xml is available requiresProject = false) public class CleanThatInitMojo extends ACleanThatSpringMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanThatInitMojo.class); public static final String MOJO_INIT = "init"; diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatMavenHelper.java b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatMavenHelper.java index d69bcd572..7870cfe55 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatMavenHelper.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/CleanThatMavenHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import java.nio.file.Path; import java.util.Collection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import com.fasterxml.jackson.databind.ObjectMapper; @@ -29,6 +27,7 @@ import eu.solven.cleanthat.codeprovider.ICodeProviderWriter; import eu.solven.cleanthat.config.ICleanthatConfigInitializer; import eu.solven.cleanthat.formatter.ICodeProviderFormatter; +import lombok.extern.slf4j.Slf4j; /** * Helper methods in the context of a mvn plugin @@ -36,8 +35,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CleanThatMavenHelper { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanThatMavenHelper.class); protected CleanThatMavenHelper() { // hidden diff --git a/maven/src/main/java/eu/solven/cleanthat/mvn/codeprovider/OverlayCodeProviderWrite.java b/maven/src/main/java/eu/solven/cleanthat/mvn/codeprovider/OverlayCodeProviderWrite.java index ab608d27c..5a912cb6e 100644 --- a/maven/src/main/java/eu/solven/cleanthat/mvn/codeprovider/OverlayCodeProviderWrite.java +++ b/maven/src/main/java/eu/solven/cleanthat/mvn/codeprovider/OverlayCodeProviderWrite.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,6 @@ import java.util.Set; import java.util.function.Consumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.collect.Sets; import com.google.common.collect.Sets.SetView; @@ -33,6 +30,7 @@ import eu.solven.cleanthat.codeprovider.ICodeProviderFile; import eu.solven.cleanthat.codeprovider.ICodeProviderWriter; import eu.solven.cleanthat.codeprovider.ICodeWritingMetadata; +import lombok.extern.slf4j.Slf4j; /** * This {@link ICodeProviderWriter} enables considering some files with a specific read-only content. @@ -40,8 +38,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class OverlayCodeProviderWrite implements ICodeProviderWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(OverlayCodeProviderWrite.class); final ICodeProviderWriter underlying; diff --git a/maven/src/test/java/eu/solven/cleanthat/mvn/TestACleanThatMojo.java b/maven/src/test/java/eu/solven/cleanthat/mvn/TestACleanThatMojo.java index f93d95efe..afa575689 100644 --- a/maven/src/test/java/eu/solven/cleanthat/mvn/TestACleanThatMojo.java +++ b/maven/src/test/java/eu/solven/cleanthat/mvn/TestACleanThatMojo.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,12 +24,12 @@ import org.assertj.core.api.Assertions; import org.junit.Test; import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class TestACleanThatMojo { - private static final Logger LOGGER = LoggerFactory.getLogger(TestACleanThatMojo.class); final ACleanThatMojo mojo = new ACleanThatMojo() { diff --git a/meta-tests/pom.xml b/meta-tests/pom.xml index 5111d0621..3c96ac26e 100644 --- a/meta-tests/pom.xml +++ b/meta-tests/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT meta-tests @@ -145,11 +145,6 @@ ${project.version} test - - org.projectlombok - lombok - provided - diff --git a/openrewrite/pom.xml b/openrewrite/pom.xml index 57575e28d..216055cf7 100644 --- a/openrewrite/pom.xml +++ b/openrewrite/pom.xml @@ -4,7 +4,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT openrewrite @@ -68,13 +68,6 @@ runtime - - - org.projectlombok - lombok - provided - - io.github.solven-eu.cleanthat test-helpers diff --git a/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteMutator.java b/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteMutator.java index b51b8fe80..5668da880 100644 --- a/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteMutator.java +++ b/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteMutator.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,13 +28,12 @@ import org.openrewrite.Result; import org.openrewrite.SourceFile; import org.openrewrite.internal.InMemoryLargeSourceSet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.Iterables; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.engine.java.refactorer.meta.IWalkingMutator; +import lombok.extern.slf4j.Slf4j; /** * A {@link IMutator} configuring over an OpenRewrite {@link Recipe} @@ -42,8 +41,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class OpenrewriteMutator implements IWalkingMutator { - private static final Logger LOGGER = LoggerFactory.getLogger(OpenrewriteMutator.class); final Recipe recipe; diff --git a/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteRefactorer.java b/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteRefactorer.java index 2eb01c58c..c4383eb29 100644 --- a/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteRefactorer.java +++ b/openrewrite/src/main/java/eu/solven/cleanthat/engine/java/refactorer/OpenrewriteRefactorer.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,13 +31,12 @@ import org.openrewrite.Result; import org.openrewrite.SourceFile; import org.openrewrite.java.JavaParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.Iterables; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.formatter.PathAndContent; +import lombok.extern.slf4j.Slf4j; /** * A {@link IMutator} configuring over an OpenRewrite {@link Recipe} @@ -45,8 +44,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class OpenrewriteRefactorer extends AAstRefactorer { - private static final Logger LOGGER = LoggerFactory.getLogger(OpenrewriteRefactorer.class); // Is this threadsafe/stateless? final ExecutionContext ctx = new InMemoryExecutionContext(Throwable::printStackTrace); diff --git a/openrewrite/src/main/java/eu/solven/cleanthat/language/openrewrite/OpenrewriteFormattersFactory.java b/openrewrite/src/main/java/eu/solven/cleanthat/language/openrewrite/OpenrewriteFormattersFactory.java index 516845819..af4c82cb8 100644 --- a/openrewrite/src/main/java/eu/solven/cleanthat/language/openrewrite/OpenrewriteFormattersFactory.java +++ b/openrewrite/src/main/java/eu/solven/cleanthat/language/openrewrite/OpenrewriteFormattersFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import org.openrewrite.Recipe; import org.openrewrite.config.Environment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableList; @@ -39,14 +37,15 @@ import eu.solven.cleanthat.formatter.ILintFixer; import eu.solven.cleanthat.formatter.ILintFixerWithId; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * Formatter for OpenRewrite Engine * * @author Benoit Lacelle */ +@Slf4j public class OpenrewriteFormattersFactory extends ASourceCodeFormatterFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(OpenrewriteFormattersFactory.class); public OpenrewriteFormattersFactory(ConfigHelpers configHelpers) { super(configHelpers); diff --git a/parent/pom.xml b/parent/pom.xml index a5fb431f4..8a60b16f4 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -15,7 +15,7 @@ io.github.solven-eu.cleanthat parent - 2.24-SNAPSHOT + 2.25-SNAPSHOT pom ${project.groupId}:${project.artifactId} @@ -288,7 +288,7 @@ - + org.apache.maven.plugins maven-pmd-plugin @@ -355,7 +355,7 @@ io.github.solven-eu.cleanthat cleanthat-maven-plugin - 2.24-SNAPSHOT + 2.25-SNAPSHOT Clean the code diff --git a/pom.xml b/pom.xml index c92bf8e50..fd875a2cd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.solven-eu.cleanthat parent - 2.24-SNAPSHOT + 2.25-SNAPSHOT parent aggregator-cleanthat @@ -206,8 +206,20 @@ ${maven-resolver.version} + + org.projectlombok + lombok + ${lombok.version} + provided + + + + org.projectlombok + lombok + + diff --git a/refactorer-test-helpers/pom.xml b/refactorer-test-helpers/pom.xml index b4d60aff6..df0a7fa3b 100644 --- a/refactorer-test-helpers/pom.xml +++ b/refactorer-test-helpers/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT refactorer-test-helpers @@ -24,7 +24,7 @@ com.github.javaparser javaparser-symbol-solver-core - 3.26.2 + 3.27.0 diff --git a/refactorer-test-helpers/src/main/java/eu/solven/cleanthat/engine/java/refactorer/test/OneMutatorCase.java b/refactorer-test-helpers/src/main/java/eu/solven/cleanthat/engine/java/refactorer/test/OneMutatorCase.java index 0dc164d4f..b6e4868ac 100644 --- a/refactorer-test-helpers/src/main/java/eu/solven/cleanthat/engine/java/refactorer/test/OneMutatorCase.java +++ b/refactorer-test-helpers/src/main/java/eu/solven/cleanthat/engine/java/refactorer/test/OneMutatorCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,6 @@ import org.assertj.core.api.Assertions; import org.junit.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.github.javaparser.JavaParser; import com.github.javaparser.ParseResult; @@ -46,6 +44,7 @@ import eu.solven.cleanthat.engine.java.refactorer.meta.IReApplyUntilNoop; import eu.solven.cleanthat.engine.java.refactorer.meta.IWalkingMutator; import eu.solven.pepper.resource.PepperResourceHelper; +import lombok.extern.slf4j.Slf4j; /** * Base class for Cleanthat testing framework @@ -55,9 +54,9 @@ * @param * @param */ +@Slf4j @SuppressWarnings({ "PMD.CouplingBetweenObjects", "PMD.GodClass" }) public class OneMutatorCase { - private static final Logger LOGGER = LoggerFactory.getLogger(OneMutatorCase.class); private static final String PRE_METHOD = "pre"; private static final String PRE_CLASS = "Pre"; diff --git a/refactorer/pom.xml b/refactorer/pom.xml index 004847734..cbb9aa201 100644 --- a/refactorer/pom.xml +++ b/refactorer/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT refactorer @@ -36,13 +36,6 @@ 1.3.0 - - - org.projectlombok - lombok - provided - - com.google.code.findbugs diff --git a/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AAstRefactorer.java b/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AAstRefactorer.java index 41d26f995..e1aad429d 100644 --- a/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AAstRefactorer.java +++ b/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AAstRefactorer.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,6 @@ import java.util.stream.Stream; import org.codehaus.plexus.languages.java.version.JavaVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; @@ -44,6 +42,7 @@ import eu.solven.cleanthat.formatter.ILintFixerWithPath; import eu.solven.cleanthat.formatter.PathAndContent; import eu.solven.cleanthat.language.IEngineProperties; +import lombok.extern.slf4j.Slf4j; /** * This class is dedicated to refactoring. Most mutators will refactor code to a better (e.g. shorter, faster, safer, @@ -52,10 +51,10 @@ * @author Benoit Lacelle */ // https://github.com/revelc/formatter-maven-plugin/blob/master/src/main/java/net/revelc/code/formatter/java/JavaFormatter.java +@Slf4j @SuppressWarnings("PMD.GenericsNaming") public abstract class AAstRefactorer> implements ILintFixerWithId, ILintFixerWithPath { - private static final Logger LOGGER = LoggerFactory.getLogger(AAstRefactorer.class); private static final int MAX_REAPPLY = 10; diff --git a/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AstRefactorerInstance.java b/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AstRefactorerInstance.java index fa8ddd504..0b01f76ca 100644 --- a/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AstRefactorerInstance.java +++ b/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/AstRefactorerInstance.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,20 +20,18 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.engine.java.refactorer.meta.IWalkingMutator; +import lombok.extern.slf4j.Slf4j; /** * This hold the logic of applying a single {@link IMutator} * * @author Benoit Lacelle */ +@Slf4j @SuppressWarnings("PMD.GenericsNaming") class AstRefactorerInstance { - private static final Logger LOGGER = LoggerFactory.getLogger(AstRefactorerInstance.class); final AAstRefactorer> astRefactorer; final P parser; diff --git a/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/scanner/MutatorsScanner.java b/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/scanner/MutatorsScanner.java index dfc77cf8a..f0eeb2454 100644 --- a/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/scanner/MutatorsScanner.java +++ b/refactorer/src/main/java/eu/solven/cleanthat/engine/java/refactorer/mutators/scanner/MutatorsScanner.java @@ -22,8 +22,6 @@ import java.util.stream.Collectors; import org.codehaus.plexus.languages.java.version.JavaVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.annotations.VisibleForTesting; @@ -31,6 +29,7 @@ import eu.solven.cleanthat.engine.java.refactorer.meta.IConstructorNeedsJdkVersion; import eu.solven.cleanthat.engine.java.refactorer.meta.IMutator; import eu.solven.cleanthat.engine.java.refactorer.mutators.composite.CompositeMutator; +import lombok.extern.slf4j.Slf4j; /** * Scans dynamically for available rules @@ -39,8 +38,11 @@ * */ // https://stackoverflow.com/questions/520328/can-you-find-all-classes-in-a-package-using-reflection +@Slf4j public final class MutatorsScanner { - private static final Logger LOGGER = LoggerFactory.getLogger(MutatorsScanner.class); + + private static final String PACKAGE_MUTATORS = "eu.solven.cleanthat.engine.java.refactorer.mutators."; + private static final String PACKAGE_COMPOSITE_MUTATORS = PACKAGE_MUTATORS + "composite."; private static final AtomicInteger ERROR_COUNTS = new AtomicInteger(); @@ -50,146 +52,82 @@ public final class MutatorsScanner { try { // noinspection unchecked SINGLE_MUTATORS = Set.of( - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ArithmethicAssignment"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ArithmeticOverFloats"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ArraysDotStream"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.AvoidFileStream"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.AvoidInlineConditionals"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.AvoidMultipleUnaryOperators"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.AvoidUncheckedExceptionsInSignatures"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.CastMathOperandsBeforeAssignement"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.CollectionIndexOfToContains"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.CollectionToOptional"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ComparisonWithNaN"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.CreateTempFilesUsingNio"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.EmptyControlStatement"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.EnumsWithoutEquals"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.ForEachAddToStreamCollectToCollection"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.ForEachIfBreakElseToStreamTakeWhile"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.ForEachIfBreakToStreamFindFirst"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ForEachIfToIfStreamAnyMatch"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ForEachToIterableForEach"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.GuavaImmutableMapBuilderOverVarargs"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.GuavaInlineStringsRepeat"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.GuavaStringsIsNullOrEmpty"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ImportQualifiedTokens"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.JUnit4ToJUnit5"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.LambdaIsMethodReference"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.LambdaReturnsSingleStatement"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.LiteralsFirstInComparisons"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.LocalVariableTypeInference"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.LoopIntRangeToIntStreamForEach"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ModifierOrder"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.NullCheckToOptionalOfNullable"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ObjectEqualsForPrimitives"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ObjectsHashCodePrimitive"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.OptionalMapIdentity"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.OptionalNotEmpty"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.OptionalWrappedIfToFilter"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.OptionalWrappedVariableToMap"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.PrimitiveWrapperInstantiation"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.RedundantLogicalComplementsInStream"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.RemoveAllToClearCollection"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.RemoveExplicitCallToSuper"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.SimplifyBooleanExpression"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.SimplifyBooleanInitialization"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.SimplifyStartsWith"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StreamAnyMatch"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.StreamFlatMapStreamToFlatMap"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.StreamForEachNestingForLoopToFlatMap"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StreamMapIdentity"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StreamWrappedIfToFilter"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StreamWrappedMethodRefToMap"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StreamWrappedVariableToMap"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StringFromString"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StringIndexOfToContains"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.StringReplaceAllWithQuotableInput"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.StringToString"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.ThreadRunToThreadStart"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryBoxing"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryFullyQualifiedName"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryImport"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryLambdaEnclosingParameters"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessaryModifier"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UnnecessarySemicolon"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UseCollectionIsEmpty"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UseDiamondOperator"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UseDiamondOperatorJdk8"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UseIndexOfChar"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.UsePredefinedStandardCharset"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UseStringIsEmpty"), - (Class) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.UseTextBlocks"), - (Class) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.UseUnderscoresInNumericLiterals")); + (Class) Class.forName(PACKAGE_MUTATORS + "AppendCharacterWithChar"), + (Class) Class.forName(PACKAGE_MUTATORS + "ArithmethicAssignment"), + (Class) Class.forName(PACKAGE_MUTATORS + "ArithmeticOverFloats"), + (Class) Class.forName(PACKAGE_MUTATORS + "ArraysDotStream"), + (Class) Class.forName(PACKAGE_MUTATORS + "AvoidFileStream"), + (Class) Class.forName(PACKAGE_MUTATORS + "AvoidInlineConditionals"), + (Class) Class.forName(PACKAGE_MUTATORS + "AvoidMultipleUnaryOperators"), + (Class) Class + .forName(PACKAGE_MUTATORS + "AvoidUncheckedExceptionsInSignatures"), + (Class) Class.forName(PACKAGE_MUTATORS + "CastMathOperandsBeforeAssignement"), + (Class) Class.forName(PACKAGE_MUTATORS + "CollectionIndexOfToContains"), + (Class) Class.forName(PACKAGE_MUTATORS + "CollectionToOptional"), + (Class) Class.forName(PACKAGE_MUTATORS + "ComparisonWithNaN"), + (Class) Class.forName(PACKAGE_MUTATORS + "CreateTempFilesUsingNio"), + (Class) Class.forName(PACKAGE_MUTATORS + "EmptyControlStatement"), + (Class) Class.forName(PACKAGE_MUTATORS + "EnumsWithoutEquals"), + (Class) Class + .forName(PACKAGE_MUTATORS + "ForEachAddToStreamCollectToCollection"), + (Class) Class.forName(PACKAGE_MUTATORS + "ForEachIfBreakElseToStreamTakeWhile"), + (Class) Class.forName(PACKAGE_MUTATORS + "ForEachIfBreakToStreamFindFirst"), + (Class) Class.forName(PACKAGE_MUTATORS + "ForEachIfToIfStreamAnyMatch"), + (Class) Class.forName(PACKAGE_MUTATORS + "ForEachToIterableForEach"), + (Class) Class.forName(PACKAGE_MUTATORS + "GuavaImmutableMapBuilderOverVarargs"), + (Class) Class.forName(PACKAGE_MUTATORS + "GuavaInlineStringsRepeat"), + (Class) Class.forName(PACKAGE_MUTATORS + "GuavaStringsIsNullOrEmpty"), + (Class) Class.forName(PACKAGE_MUTATORS + "ImportQualifiedTokens"), + (Class) Class.forName(PACKAGE_MUTATORS + "JUnit4ToJUnit5"), + (Class) Class.forName(PACKAGE_MUTATORS + "LambdaIsMethodReference"), + (Class) Class.forName(PACKAGE_MUTATORS + "LambdaReturnsSingleStatement"), + (Class) Class.forName(PACKAGE_MUTATORS + "LiteralsFirstInComparisons"), + (Class) Class.forName(PACKAGE_MUTATORS + "LocalVariableTypeInference"), + (Class) Class.forName(PACKAGE_MUTATORS + "LoopIntRangeToIntStreamForEach"), + (Class) Class.forName(PACKAGE_MUTATORS + "ModifierOrder"), + (Class) Class.forName(PACKAGE_MUTATORS + "NullCheckToOptionalOfNullable"), + (Class) Class.forName(PACKAGE_MUTATORS + "ObjectEqualsForPrimitives"), + (Class) Class.forName(PACKAGE_MUTATORS + "ObjectsHashCodePrimitive"), + (Class) Class.forName(PACKAGE_MUTATORS + "OptionalMapIdentity"), + (Class) Class.forName(PACKAGE_MUTATORS + "OptionalNotEmpty"), + (Class) Class.forName(PACKAGE_MUTATORS + "OptionalWrappedIfToFilter"), + (Class) Class.forName(PACKAGE_MUTATORS + "OptionalWrappedVariableToMap"), + (Class) Class.forName(PACKAGE_MUTATORS + "PrimitiveWrapperInstantiation"), + (Class) Class.forName(PACKAGE_MUTATORS + "RedundantLogicalComplementsInStream"), + (Class) Class.forName(PACKAGE_MUTATORS + "RemoveAllToClearCollection"), + (Class) Class.forName(PACKAGE_MUTATORS + "RemoveExplicitCallToSuper"), + (Class) Class.forName(PACKAGE_MUTATORS + "SimplifyBooleanExpression"), + (Class) Class.forName(PACKAGE_MUTATORS + "SimplifyBooleanInitialization"), + (Class) Class.forName(PACKAGE_MUTATORS + "SimplifyStartsWith"), + (Class) Class.forName(PACKAGE_MUTATORS + "StreamAnyMatch"), + (Class) Class.forName(PACKAGE_MUTATORS + "StreamFlatMapStreamToFlatMap"), + (Class) Class + .forName(PACKAGE_MUTATORS + "StreamForEachNestingForLoopToFlatMap"), + (Class) Class.forName(PACKAGE_MUTATORS + "StreamMapIdentity"), + (Class) Class.forName(PACKAGE_MUTATORS + "StreamWrappedIfToFilter"), + (Class) Class.forName(PACKAGE_MUTATORS + "StreamWrappedMethodRefToMap"), + (Class) Class.forName(PACKAGE_MUTATORS + "StreamWrappedVariableToMap"), + (Class) Class.forName(PACKAGE_MUTATORS + "StringFromString"), + (Class) Class.forName(PACKAGE_MUTATORS + "StringIndexOfToContains"), + (Class) Class.forName(PACKAGE_MUTATORS + "StringReplaceAllWithQuotableInput"), + (Class) Class.forName(PACKAGE_MUTATORS + "StringToString"), + (Class) Class.forName(PACKAGE_MUTATORS + "ThreadRunToThreadStart"), + (Class) Class.forName(PACKAGE_MUTATORS + "UnnecessaryBoxing"), + (Class) Class.forName(PACKAGE_MUTATORS + "UnnecessaryCaseChange"), + (Class) Class.forName(PACKAGE_MUTATORS + "UnnecessaryFullyQualifiedName"), + (Class) Class.forName(PACKAGE_MUTATORS + "UnnecessaryImport"), + (Class) Class + .forName(PACKAGE_MUTATORS + "UnnecessaryLambdaEnclosingParameters"), + (Class) Class.forName(PACKAGE_MUTATORS + "UnnecessaryModifier"), + (Class) Class.forName(PACKAGE_MUTATORS + "UnnecessarySemicolon"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseCollectionIsEmpty"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseDiamondOperator"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseDiamondOperatorJdk8"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseIndexOfChar"), + (Class) Class.forName(PACKAGE_MUTATORS + "UsePredefinedStandardCharset"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseStringIsEmpty"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseTextBlocks"), + (Class) Class.forName(PACKAGE_MUTATORS + "UseUnderscoresInNumericLiterals")); } catch (ClassNotFoundException e) { ERROR_COUNTS.incrementAndGet(); throw new IllegalStateException("Cannot load CleanThat mutators", e); @@ -201,36 +139,32 @@ public final class MutatorsScanner { try { // noinspection unchecked COMPOSITE_MUTATORS = Set.of( - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.CompositeWalkingMutator"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.CheckStyleMutators"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.ErrorProneMutators"), (Class>) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.GuavaMutators"), + .forName(PACKAGE_COMPOSITE_MUTATORS + "CompositeWalkingMutator"), + (Class>) Class + .forName(PACKAGE_COMPOSITE_MUTATORS + "CheckStyleMutators"), + (Class>) Class + .forName(PACKAGE_COMPOSITE_MUTATORS + "ErrorProneMutators"), + (Class>) Class.forName(PACKAGE_COMPOSITE_MUTATORS + "GuavaMutators"), + (Class>) Class + .forName(PACKAGE_COMPOSITE_MUTATORS + "JSparrowMutators"), + (Class>) Class.forName(PACKAGE_COMPOSITE_MUTATORS + "PMDMutators"), + (Class>) Class + .forName(PACKAGE_COMPOSITE_MUTATORS + "SafeAndConsensualMutators"), + (Class>) Class + .forName(PACKAGE_COMPOSITE_MUTATORS + "SafeButControversialMutators"), (Class>) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.JSparrowMutators"), + .forName(PACKAGE_COMPOSITE_MUTATORS + "SafeButNotConsensualMutators"), + (Class>) Class.forName(PACKAGE_COMPOSITE_MUTATORS + "SonarMutators"), (Class>) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.PMDMutators"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeButControversialMutators"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeButNotConsensualMutators"), + .forName(PACKAGE_COMPOSITE_MUTATORS + "SpotBugsMutators"), + (Class>) Class.forName(PACKAGE_COMPOSITE_MUTATORS + "StreamMutators"), (Class>) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SonarMutators"), + .forName(PACKAGE_COMPOSITE_MUTATORS + "UnsafeDueToGenerics"), (Class>) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SpotBugsMutators"), + .forName(PACKAGE_COMPOSITE_MUTATORS + "AllIncludingDraftCompositeMutators"), (Class>) Class - .forName("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.StreamMutators"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.UnsafeDueToGenerics"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.AllIncludingDraftCompositeMutators"), - (Class>) Class.forName( - "eu.solven.cleanthat.engine.java.refactorer.mutators.composite.AllIncludingDraftSingleMutators")); + .forName(PACKAGE_COMPOSITE_MUTATORS + "AllIncludingDraftSingleMutators")); } catch (ClassNotFoundException e) { ERROR_COUNTS.incrementAndGet(); diff --git a/runnable/pom.xml b/runnable/pom.xml index c6d65f17b..1a2a5a7d9 100644 --- a/runnable/pom.xml +++ b/runnable/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT runnable diff --git a/runnable/src/main/java/eu/solven/cleanthat/lambda/ACleanThatXxxFunction.java b/runnable/src/main/java/eu/solven/cleanthat/lambda/ACleanThatXxxFunction.java index ff48e20d5..2eafd777d 100644 --- a/runnable/src/main/java/eu/solven/cleanthat/lambda/ACleanThatXxxFunction.java +++ b/runnable/src/main/java/eu/solven/cleanthat/lambda/ACleanThatXxxFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,9 @@ import java.util.List; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import eu.solven.cleanthat.lambda.step0_checkwebhook.IWebhookEvent; import io.sentry.Sentry; +import lombok.extern.slf4j.Slf4j; /** * Based class for Lambda, Functions, etc @@ -31,8 +29,8 @@ * @author Benoit Lacelle * */ +@Slf4j public abstract class ACleanThatXxxFunction extends ACleanThatXxxApplication { - private static final Logger LOGGER = LoggerFactory.getLogger(ACleanThatXxxFunction.class); static { // https://stackoverflow.com/questions/35298616/aws-lambda-and-inaccurate-memory-allocation diff --git a/runnable/src/main/java/eu/solven/cleanthat/logback/LocalDumperAppender.java b/runnable/src/main/java/eu/solven/cleanthat/logback/LocalDumperAppender.java index 64ae362ad..55dcf2dd1 100644 --- a/runnable/src/main/java/eu/solven/cleanthat/logback/LocalDumperAppender.java +++ b/runnable/src/main/java/eu/solven/cleanthat/logback/LocalDumperAppender.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,12 @@ import java.util.ArrayList; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.Appender; import ch.qos.logback.core.AppenderBase; import ch.qos.logback.core.encoder.Encoder; import eu.solven.pepper.memory.IPepperMemoryConstants; +import lombok.extern.slf4j.Slf4j; /** * This LogBack {@link Appender} shall help enabling a log to be produced for each run. @@ -36,8 +34,8 @@ * */ // TODO +@Slf4j public class LocalDumperAppender extends AppenderBase { - private static final Logger LOGGER = LoggerFactory.getLogger(LocalDumperAppender.class); private static final ThreadLocal> TL_LOGS = new ThreadLocal<>() { @Override diff --git a/runnable/src/test/java/eu/solven/cleanthat/config/TestDefaultConfig.java b/runnable/src/test/java/eu/solven/cleanthat/config/TestDefaultConfig.java index 1e026e32e..6c122d261 100644 --- a/runnable/src/test/java/eu/solven/cleanthat/config/TestDefaultConfig.java +++ b/runnable/src/test/java/eu/solven/cleanthat/config/TestDefaultConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ import org.assertj.core.api.Assertions; import org.junit.Assert; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import com.fasterxml.jackson.core.JsonParseException; @@ -34,11 +32,12 @@ import eu.solven.cleanthat.config.pojo.CleanthatStepProperties; import eu.solven.cleanthat.config.pojo.SourceCodeProperties; import eu.solven.cleanthat.language.spotless.CleanthatSpotlessStepParametersProperties; +import lombok.extern.slf4j.Slf4j; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +@Slf4j public class TestDefaultConfig { - private static final Logger LOGGER = LoggerFactory.getLogger(TestDefaultConfig.class); @Test public void testHashcodeEquals() { diff --git a/runnable/src/test/java/eu/solven/cleanthat/it/ITCleanLocalRepository.java b/runnable/src/test/java/eu/solven/cleanthat/it/ITCleanLocalRepository.java index 66753209c..41b42f838 100644 --- a/runnable/src/test/java/eu/solven/cleanthat/it/ITCleanLocalRepository.java +++ b/runnable/src/test/java/eu/solven/cleanthat/it/ITCleanLocalRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,6 @@ import java.util.Optional; import org.eclipse.jgit.api.Git; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.context.event.ContextRefreshedEvent; @@ -42,6 +40,7 @@ import eu.solven.cleanthat.formatter.CodeProviderFormatter; import eu.solven.cleanthat.jgit.JGitCodeProvider; import eu.solven.cleanthat.lambda.ACleanThatXxxApplication; +import lombok.extern.slf4j.Slf4j; /** * This enables easy cleaning of any given folder. Given folder is supposedly the root of a repository. @@ -52,8 +51,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class ITCleanLocalRepository extends ACleanThatXxxApplication { - private static final Logger LOGGER = LoggerFactory.getLogger(ITCleanLocalRepository.class); public static void main(String[] args) { SpringApplication springApp = new SpringApplication(ITCleanLocalRepository.class); diff --git a/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubBranch.java b/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubBranch.java index d9410741a..a86f5119f 100644 --- a/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubBranch.java +++ b/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubBranch.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,6 @@ import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.context.event.ContextRefreshedEvent; @@ -56,6 +54,7 @@ import eu.solven.cleanthat.formatter.CodeFormatResult; import eu.solven.cleanthat.github.run.ICleanThatITConstants; import eu.solven.cleanthat.lambda.ACleanThatXxxApplication; +import lombok.extern.slf4j.Slf4j; /** * This enables running CleanThat cleaning logic directly on given branch @@ -63,8 +62,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class RunCleanGithubBranch extends ACleanThatXxxApplication implements ICleanThatITConstants { - private static final Logger LOGGER = LoggerFactory.getLogger(RunCleanGithubBranch.class); final String repoFullName = SOLVEN_EU_MITRUST_DATASHARING; // If empty, we will process the default branch diff --git a/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubPullRequest.java b/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubPullRequest.java index f66dfb63d..fba40413e 100644 --- a/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubPullRequest.java +++ b/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanGithubPullRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,6 @@ import org.kohsuke.github.GHRef; import org.kohsuke.github.GHRepository; import org.kohsuke.github.GitHub; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.context.event.ContextRefreshedEvent; @@ -51,12 +49,12 @@ import eu.solven.cleanthat.config.pojo.CleanthatRefFilterProperties; import eu.solven.cleanthat.formatter.CodeFormatResult; import eu.solven.cleanthat.lambda.ACleanThatXxxApplication; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Deprecated(since = "DELETEME") public class RunCleanGithubPullRequest extends ACleanThatXxxApplication { - private static final Logger LOGGER = LoggerFactory.getLogger(RunCleanGithubPullRequest.class); - private static final String SOLVEN_EU_MITRUST_DATASHARING = "solven-eu/mitrust-datasharing"; private static final String SOLVEN_EU_CLEANTHAT = "solven-eu/cleanthat"; diff --git a/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanLocalRepository.java b/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanLocalRepository.java index 5f06465c0..c40b3c282 100644 --- a/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanLocalRepository.java +++ b/runnable/src/test/java/eu/solven/cleanthat/it/RunCleanLocalRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.WebApplicationType; import org.springframework.context.event.ContextRefreshedEvent; @@ -36,6 +34,7 @@ import eu.solven.cleanthat.config.ConfigHelpers; import eu.solven.cleanthat.formatter.CodeProviderFormatter; import eu.solven.cleanthat.lambda.ACleanThatXxxApplication; +import lombok.extern.slf4j.Slf4j; /** * This enables easy cleaning of any given folder. Given folder is supposedly the root of a repository. @@ -46,8 +45,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class RunCleanLocalRepository extends ACleanThatXxxApplication { - private static final Logger LOGGER = LoggerFactory.getLogger(RunCleanLocalRepository.class); public static void main(String[] args) { SpringApplication springApp = new SpringApplication(RunCleanLocalRepository.class); diff --git a/spotless/pom.xml b/spotless/pom.xml index e2638938e..783661dd9 100644 --- a/spotless/pom.xml +++ b/spotless/pom.xml @@ -4,7 +4,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT spotless @@ -57,13 +57,6 @@ 2.6.1 - - - org.projectlombok - lombok - provided - - diff --git a/spotless/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings_InMemory.java b/spotless/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings_InMemory.java index 81602e1d0..7ed15423e 100644 --- a/spotless/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings_InMemory.java +++ b/spotless/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings_InMemory.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 Benoit Lacelle - SOLVEN + * Copyright 2016-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +43,6 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; import org.eclipse.jgit.lib.CoreConfig.EOL; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.diffplug.spotless.FileSignature; import com.diffplug.spotless.LazyForwardingEquality; @@ -56,6 +54,7 @@ import eu.solven.cleanthat.codeprovider.ICodeProvider; import eu.solven.cleanthat.spotless.pojo.SpotlessGitProperties; +import lombok.extern.slf4j.Slf4j; /** * Uses .gitattributes to determine the appropriate line ending. @@ -67,9 +66,9 @@ */ // This differs from original GitAttributesLineEndings as it rely on a .gitattributes as a String, and no not try // consider any system git configuration +@Slf4j @SuppressWarnings("checkstyle:TypeName") public final class GitAttributesLineEndings_InMemory { - private static final Logger LOGGER = LoggerFactory.getLogger(GitAttributesLineEndings_InMemory.class); // prevent direct instantiation private GitAttributesLineEndings_InMemory() { diff --git a/spotless/src/main/java/eu/solven/cleanthat/language/cleanthat/CleanthatForIntegrators.java b/spotless/src/main/java/eu/solven/cleanthat/language/cleanthat/CleanthatForIntegrators.java index 4ad00540e..96bf7f61c 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/language/cleanthat/CleanthatForIntegrators.java +++ b/spotless/src/main/java/eu/solven/cleanthat/language/cleanthat/CleanthatForIntegrators.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.List; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.diffplug.common.annotations.VisibleForTesting; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -30,6 +27,7 @@ import eu.solven.cleanthat.config.pojo.ICleanthatStepParametersProperties; import eu.solven.pepper.collection.PepperMapHelper; import eu.solven.pepper.resource.PepperResourceHelper; +import lombok.extern.slf4j.Slf4j; /** * Helps integrating CleanThat @@ -37,8 +35,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class CleanthatForIntegrators { - private static final Logger LOGGER = LoggerFactory.getLogger(CleanthatForIntegrators.class); public static final String ENV_CLEANTHAT_INCLUDE_DRAFT = "cleanthat.include_draft"; diff --git a/spotless/src/main/java/eu/solven/cleanthat/language/spotless/SpotlessFormattersFactory.java b/spotless/src/main/java/eu/solven/cleanthat/language/spotless/SpotlessFormattersFactory.java index 9f5fabbd0..ae8df9646 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/language/spotless/SpotlessFormattersFactory.java +++ b/spotless/src/main/java/eu/solven/cleanthat/language/spotless/SpotlessFormattersFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,6 @@ import java.util.Set; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.diffplug.spotless.Provisioner; import com.fasterxml.jackson.core.JsonProcessingException; import com.google.common.base.Strings; @@ -49,14 +46,15 @@ import eu.solven.cleanthat.spotless.pojo.SpotlessEngineProperties.SpotlessEnginePropertiesBuilder; import eu.solven.cleanthat.spotless.pojo.SpotlessFormatterProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepProperties; +import lombok.extern.slf4j.Slf4j; /** * Formatter for Spotless Engine * * @author Benoit Lacelle */ +@Slf4j public class SpotlessFormattersFactory extends ASourceCodeFormatterFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(SpotlessFormattersFactory.class); final Provisioner provisionner; diff --git a/spotless/src/main/java/eu/solven/cleanthat/spotless/FormatterFactory.java b/spotless/src/main/java/eu/solven/cleanthat/spotless/FormatterFactory.java index c70567c92..bf138e088 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/spotless/FormatterFactory.java +++ b/spotless/src/main/java/eu/solven/cleanthat/spotless/FormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,8 +30,6 @@ import org.apache.maven.resolver.examples.util.Booter; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.diffplug.spotless.FormatExceptionPolicy; import com.diffplug.spotless.FormatExceptionPolicyStrict; @@ -56,6 +54,7 @@ import eu.solven.cleanthat.spotless.pojo.SpotlessEngineProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessFormatterProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepProperties; +import lombok.extern.slf4j.Slf4j; /** * Knows how to instantiate {@link AFormatterStepFactory} @@ -63,8 +62,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class FormatterFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(FormatterFactory.class); // '-Dcleanthat.spotless.m2.repository=/Users/blacelle/.m2/repository' to reuse a local repository public static final String PATH_M2_REPO = "cleanthat.spotless.m2.repository"; diff --git a/spotless/src/main/java/eu/solven/cleanthat/spotless/SpotlessSession.java b/spotless/src/main/java/eu/solven/cleanthat/spotless/SpotlessSession.java index b1a3289ec..e3289f09c 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/spotless/SpotlessSession.java +++ b/spotless/src/main/java/eu/solven/cleanthat/spotless/SpotlessSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,14 +29,13 @@ import java.util.stream.StreamSupport; import org.codehaus.plexus.util.MatchPatterns; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.diffplug.spotless.PaddedCell; import eu.solven.cleanthat.code_provider.CleanthatPathHelpers; import eu.solven.cleanthat.codeprovider.ICodeProvider; import eu.solven.cleanthat.formatter.PathAndContent; +import lombok.extern.slf4j.Slf4j; /** * Trigger Spotless engine @@ -45,8 +44,8 @@ * */ // see com.diffplug.spotless.maven.SpotlessApplyMojo +@Slf4j public class SpotlessSession { - private static final Logger LOGGER = LoggerFactory.getLogger(SpotlessSession.class); final ImpactedFilesTracker filesTracker = new ImpactedFilesTracker(); diff --git a/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterFactory.java b/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterFactory.java index 553dc8178..2a6b8eb18 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterFactory.java +++ b/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,6 @@ import java.util.List; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.diffplug.spotless.pom.SortPomCfg; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -31,6 +28,7 @@ import eu.solven.cleanthat.spotless.pojo.SpotlessFormatterProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepParametersProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepProperties; +import lombok.extern.slf4j.Slf4j; /** * Configure Spotless engine for '.java' files @@ -38,8 +36,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class PomXmlFormatterFactory extends AFormatterFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(PomXmlFormatterFactory.class); /** * CleanThat will call spotless from the root directory: process any 'pom.xml' file from there diff --git a/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterStepFactory.java b/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterStepFactory.java index 44c325044..d386f7fd1 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterStepFactory.java +++ b/spotless/src/main/java/eu/solven/cleanthat/spotless/language/PomXmlFormatterStepFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,6 @@ import java.lang.reflect.Field; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.Provisioner; import com.diffplug.spotless.pom.SortPomCfg; @@ -30,6 +27,7 @@ import eu.solven.cleanthat.spotless.pojo.SpotlessFormatterProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepParametersProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessStepProperties; +import lombok.extern.slf4j.Slf4j; /** * Configure Spotless engine for 'pom.xml' files @@ -37,8 +35,8 @@ * @author Benoit Lacelle * */ +@Slf4j public class PomXmlFormatterStepFactory extends AFormatterStepFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(PomXmlFormatterStepFactory.class); public PomXmlFormatterStepFactory(PomXmlFormatterFactory pomXmlFactory, ICodeProvider codeProvider, diff --git a/spotless/src/main/java/eu/solven/cleanthat/spotless/mvn/ArtifactResolver.java b/spotless/src/main/java/eu/solven/cleanthat/spotless/mvn/ArtifactResolver.java index 74c609922..02c365a1d 100644 --- a/spotless/src/main/java/eu/solven/cleanthat/spotless/mvn/ArtifactResolver.java +++ b/spotless/src/main/java/eu/solven/cleanthat/spotless/mvn/ArtifactResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 Benoit Lacelle - SOLVEN + * Copyright 2016-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ import org.eclipse.aether.resolution.DependencyRequest; import org.eclipse.aether.resolution.DependencyResolutionException; import org.eclipse.aether.resolution.DependencyResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * Duplicates com.diffplug.spotless.maven.ArtifactResolver, as it is difficult to import from a maven-plugin jar. @@ -50,8 +50,8 @@ * @see com.diffplug.spotless.maven.ArtifactResolver * */ +@Slf4j public class ArtifactResolver { - private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactResolver.class); private static final Exclusion EXCLUDE_ALL_TRANSITIVES = new Exclusion("*", "*", "*", "*"); diff --git a/spotless/src/main/java/org/apache/maven/resolver/examples/manual/ManualRepositorySystemFactory.java b/spotless/src/main/java/org/apache/maven/resolver/examples/manual/ManualRepositorySystemFactory.java index 119e843aa..41295bb3a 100644 --- a/spotless/src/main/java/org/apache/maven/resolver/examples/manual/ManualRepositorySystemFactory.java +++ b/spotless/src/main/java/org/apache/maven/resolver/examples/manual/ManualRepositorySystemFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ import org.eclipse.aether.spi.connector.transport.TransporterFactory; import org.eclipse.aether.transport.file.FileTransporterFactory; import org.eclipse.aether.transport.http.HttpTransporterFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * A factory for repository system instances that employs Maven Artifact Resolver's built-in service locator @@ -35,9 +35,9 @@ // CHECKSTYLE:OFF: checkstyle:LineLength // https://github.com/apache/maven-resolver/blob/master/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/manual/ManualRepositorySystemFactory.java // CHECKSTYLE:ON: checkstyle:LineLength +@Slf4j @SuppressWarnings({ "PMD", "checkstyle:HideUtilityClassConstructor" }) public class ManualRepositorySystemFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(ManualRepositorySystemFactory.class); public static RepositorySystem newRepositorySystem() { /* diff --git a/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingRepositoryListener.java b/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingRepositoryListener.java index 7dc490771..f60758d22 100644 --- a/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingRepositoryListener.java +++ b/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingRepositoryListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ import org.eclipse.aether.AbstractRepositoryListener; import org.eclipse.aether.RepositoryEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * A simplistic repository listener that logs events to the console. * * @author https://github.com/apache/maven-resolver/ */ +@Slf4j @SuppressWarnings({ "PMD", "checkstyle:AvoidInlineConditionals" }) public class LoggingRepositoryListener extends AbstractRepositoryListener { - private static final Logger LOGGER = LoggerFactory.getLogger(LoggingRepositoryListener.class); public void artifactDeployed(RepositoryEvent event) { requireNonNull(event, "event cannot be null"); diff --git a/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingTransferListener.java b/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingTransferListener.java index 495bbe246..00401bd24 100644 --- a/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingTransferListener.java +++ b/spotless/src/main/java/org/apache/maven/resolver/examples/util/LoggingTransferListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,17 +27,17 @@ import org.eclipse.aether.transfer.MetadataNotFoundException; import org.eclipse.aether.transfer.TransferEvent; import org.eclipse.aether.transfer.TransferResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import lombok.extern.slf4j.Slf4j; /** * A simplistic transfer listener that logs uploads/downloads to the console. * * @author https://github.com/apache/maven-resolver/ */ +@Slf4j @SuppressWarnings({ "PMD", "checkstyle:JavadocType", "checkstyle:AvoidInlineConditionals", "checkstyle:MagicNumber" }) public class LoggingTransferListener extends AbstractTransferListener { - private static final Logger LOGGER = LoggerFactory.getLogger(LoggingTransferListener.class); private final Map downloads = new ConcurrentHashMap<>(); diff --git a/spotless/src/test/java/eu/solven/cleanthat/config/TestDefaultSpotlessConfig.java b/spotless/src/test/java/eu/solven/cleanthat/config/TestDefaultSpotlessConfig.java index fba6790f0..a331981c1 100644 --- a/spotless/src/test/java/eu/solven/cleanthat/config/TestDefaultSpotlessConfig.java +++ b/spotless/src/test/java/eu/solven/cleanthat/config/TestDefaultSpotlessConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Benoit Lacelle - SOLVEN + * Copyright 2023-2025 Benoit Lacelle - SOLVEN * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,6 @@ import org.assertj.core.api.Assertions; import org.junit.Assert; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import com.fasterxml.jackson.core.JsonParseException; @@ -44,11 +42,12 @@ import eu.solven.cleanthat.config.pojo.CleanthatRepositoryProperties; import eu.solven.cleanthat.spotless.pojo.SpotlessEngineProperties; +import lombok.extern.slf4j.Slf4j; import nl.jqno.equalsverifier.EqualsVerifier; import nl.jqno.equalsverifier.Warning; +@Slf4j public class TestDefaultSpotlessConfig { - private static final Logger LOGGER = LoggerFactory.getLogger(TestDefaultSpotlessConfig.class); @Test public void testHashcodeEquals() { diff --git a/test-helpers/pom.xml b/test-helpers/pom.xml index 1edb2d38b..8bf7e7ff2 100644 --- a/test-helpers/pom.xml +++ b/test-helpers/pom.xml @@ -5,7 +5,7 @@ io.github.solven-eu.cleanthat aggregator-cleanthat - 2.24-SNAPSHOT + 2.25-SNAPSHOT test-helpers