This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 22717e6 refactor: Replace Plexus AbstractLogEnabled with SLF4J (#157)
22717e6 is described below
commit 22717e62bf92123c1ae19a90f7bda3112295c0e3
Author: Tim te Beek <[email protected]>
AuthorDate: Sat Dec 14 20:53:16 2024 +0100
refactor: Replace Plexus AbstractLogEnabled with SLF4J (#157)
* refactor: Replace Plexus AbstractLogEnabled with SLF4J
Use this link to re-run the recipe:
https://app.moderne.io/builder/P4zH7djn6?organizationId=QXBhY2hlIE1hdmVu
Co-authored-by: Moderne <[email protected]>
* Fix checkstyle violations
* Update suppressions as indicated
* Restore indentation for locator field
* Apply spotless
---------
Co-authored-by: Moderne <[email protected]>
---
src/config/checkstyle-suppressions.xml | 2 +-
.../checkstyle/exec/DefaultCheckstyleExecutor.java | 66 +++++++++++-----------
2 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/src/config/checkstyle-suppressions.xml
b/src/config/checkstyle-suppressions.xml
index 308814e..ed960fd 100644
--- a/src/config/checkstyle-suppressions.xml
+++ b/src/config/checkstyle-suppressions.xml
@@ -22,5 +22,5 @@ under the License.
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
<suppressions>
<suppress checks="ParameterNumberCheck"
files="CheckstyleReportRenderer.java" />
- <suppress checks="MethodLengthCheck" files="DefaultCheckstyleExecutor.java"
/>
+ <suppress checks="ConstantName|MethodLengthCheck"
files="DefaultCheckstyleExecutor.java" />
</suppressions>
diff --git
a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
index 588372c..bd30668 100644
---
a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
+++
b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
@@ -52,13 +52,14 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.resource.ResourceManager;
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
import org.codehaus.plexus.resource.loader.FileResourceLoader;
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.sisu.Typed;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Olivier Lamy
@@ -66,7 +67,10 @@ import org.eclipse.sisu.Typed;
*/
@Named
@Typed(CheckstyleExecutor.class)
-public class DefaultCheckstyleExecutor extends AbstractLogEnabled implements
CheckstyleExecutor {
+public class DefaultCheckstyleExecutor implements CheckstyleExecutor {
+
+ private static final Logger logger =
LoggerFactory.getLogger(DefaultCheckstyleExecutor.class);
+
private final ResourceManager locator;
private final ResourceManager licenseLocator;
@@ -81,8 +85,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
@Override
public CheckstyleResults executeCheckstyle(CheckstyleExecutorRequest
request)
throws CheckstyleExecutorException, CheckstyleException {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("executeCheckstyle start headerLocation : " +
request.getHeaderLocation());
+ if (logger.isDebugEnabled()) {
+ logger.debug("executeCheckstyle start headerLocation : " +
request.getHeaderLocation());
}
MavenProject project = request.getProject();
@@ -220,7 +224,7 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
// work regardless of config), but should record this
information
throw new CheckstyleExecutorException(message.toString());
} else {
- getLogger().info(message.toString());
+ logger.info(message.toString());
}
}
@@ -255,8 +259,7 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
File resourcesDirectory = new
File(resource.getDirectory());
if (resourcesDirectory.exists() &&
resourcesDirectory.isDirectory()) {
sinkListener.addSourceDirectory(resourcesDirectory);
- getLogger()
- .debug("Added '" +
resourcesDirectory.getAbsolutePath() + "' as a source directory.");
+ logger.debug("Added '" +
resourcesDirectory.getAbsolutePath() + "' as a source directory.");
}
}
}
@@ -286,9 +289,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
: System.getProperty("file.encoding", "UTF-8");
if (StringUtils.isEmpty(request.getEncoding())) {
- getLogger()
- .warn("File encoding has not been set, using platform
encoding " + effectiveEncoding
- + ", i.e. build is platform dependent!");
+ logger.warn("File encoding has not been set, using platform
encoding " + effectiveEncoding
+ + ", i.e. build is platform dependent!");
}
if ("Checker".equals(config.getName())
@@ -298,7 +300,7 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
addAttributeIfNotExists((DefaultConfiguration) config,
"charset", effectiveEncoding);
addAttributeIfNotExists((DefaultConfiguration) config,
"cacheFile", request.getCacheFile());
} else {
- getLogger().warn("Failed to configure file encoding on
module " + config);
+ logger.warn("Failed to configure file encoding on module "
+ config);
}
}
return config;
@@ -368,8 +370,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
Properties p = new Properties();
try {
if (request.getPropertiesLocation() != null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("request.getPropertiesLocation() " +
request.getPropertiesLocation());
+ if (logger.isDebugEnabled()) {
+ logger.debug("request.getPropertiesLocation() " +
request.getPropertiesLocation());
}
File propertiesFile =
@@ -399,8 +401,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
headerLocation = "config/maven-header.txt";
}
}
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("headerLocation " + headerLocation);
+ if (logger.isDebugEnabled()) {
+ logger.debug("headerLocation " + headerLocation);
}
if (headerLocation != null && !headerLocation.isEmpty()) {
@@ -411,8 +413,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
p.setProperty("checkstyle.header.file",
headerFile.getAbsolutePath());
}
} catch (FileResourceCreationException |
ResourceNotFoundException e) {
- getLogger().debug("Unable to process header location: " +
headerLocation);
- getLogger().debug("Checkstyle will throw exception if
${checkstyle.header.file} is used");
+ logger.debug("Unable to process header location: " +
headerLocation);
+ logger.debug("Checkstyle will throw exception if
${checkstyle.header.file} is used");
}
}
@@ -486,7 +488,7 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
request.getTestSourceDirectories());
}
- getLogger().debug("Added " + files.size() + " files to process.");
+ logger.debug("Added " + files.size() + " files to process.");
return new ArrayList<>(files);
}
@@ -505,9 +507,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
final List<File> sourceFiles =
FileUtils.getFiles(sourceDirectory,
request.getIncludes(), request.getExcludes());
files.addAll(sourceFiles);
- getLogger()
- .debug("Added " + sourceFiles.size() + " source
files found in '"
- + sourceDirectory.getAbsolutePath() +
"'.");
+ logger.debug("Added " + sourceFiles.size() + " source
files found in '"
+ + sourceDirectory.getAbsolutePath() + "'.");
}
}
}
@@ -519,9 +520,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
FileUtils.getFiles(testSourceDirectory,
request.getIncludes(), request.getExcludes());
files.addAll(testSourceFiles);
- getLogger()
- .debug("Added " + testSourceFiles.size() + " test
source files found in '"
- + testSourceDirectory.getAbsolutePath() +
"'.");
+ logger.debug("Added " + testSourceFiles.size() + " test
source files found in '"
+ + testSourceDirectory.getAbsolutePath() + "'.");
}
}
}
@@ -529,13 +529,13 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
if (resources != null && request.isIncludeResources()) {
addResourceFilesToProcess(request, resources, files);
} else {
- getLogger().debug("No resources found in this project.");
+ logger.debug("No resources found in this project.");
}
if (testResources != null && request.isIncludeTestResources()) {
addResourceFilesToProcess(request, testResources, files);
} else {
- getLogger().debug("No test resources found in this project.");
+ logger.debug("No test resources found in this project.");
}
}
@@ -569,13 +569,11 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
List<File> resourceFiles =
FileUtils.getFiles(resourcesDirectory, includes, excludes);
files.addAll(resourceFiles);
- getLogger()
- .debug("Added " + resourceFiles.size() + "
resource files found in '"
- + resourcesDirectory.getAbsolutePath() +
"'.");
+ logger.debug("Added " + resourceFiles.size() + " resource
files found in '"
+ + resourcesDirectory.getAbsolutePath() + "'.");
} else {
- getLogger()
- .debug("The resources directory '" +
resourcesDirectory.getAbsolutePath()
- + "' does not exist or is not a
directory.");
+ logger.debug("The resources directory '" +
resourcesDirectory.getAbsolutePath()
+ + "' does not exist or is not a directory.");
}
}
}
@@ -613,8 +611,8 @@ public class DefaultCheckstyleExecutor extends
AbstractLogEnabled implements Che
private String getConfigFile(CheckstyleExecutorRequest request) throws
CheckstyleExecutorException {
try {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("request.getConfigLocation() " +
request.getConfigLocation());
+ if (logger.isDebugEnabled()) {
+ logger.debug("request.getConfigLocation() " +
request.getConfigLocation());
}
File configFile =
locator.getResourceAsFile(request.getConfigLocation(),
"checkstyle-checker.xml");