Skip to content

Commit 22717e6

Browse files
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 <team@moderne.io> * Fix checkstyle violations * Update suppressions as indicated * Restore indentation for locator field * Apply spotless --------- Co-authored-by: Moderne <team@moderne.io>
1 parent 784b5ba commit 22717e6

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

src/config/checkstyle-suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ under the License.
2222
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
2323
<suppressions>
2424
<suppress checks="ParameterNumberCheck" files="CheckstyleReportRenderer.java" />
25-
<suppress checks="MethodLengthCheck" files="DefaultCheckstyleExecutor.java" />
25+
<suppress checks="ConstantName|MethodLengthCheck" files="DefaultCheckstyleExecutor.java" />
2626
</suppressions>

src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,25 @@
5252
import org.apache.maven.artifact.DependencyResolutionRequiredException;
5353
import org.apache.maven.model.Resource;
5454
import org.apache.maven.project.MavenProject;
55-
import org.codehaus.plexus.logging.AbstractLogEnabled;
5655
import org.codehaus.plexus.resource.ResourceManager;
5756
import org.codehaus.plexus.resource.loader.FileResourceCreationException;
5857
import org.codehaus.plexus.resource.loader.FileResourceLoader;
5958
import org.codehaus.plexus.resource.loader.ResourceNotFoundException;
6059
import org.codehaus.plexus.util.FileUtils;
6160
import org.eclipse.sisu.Typed;
61+
import org.slf4j.Logger;
62+
import org.slf4j.LoggerFactory;
6263

6364
/**
6465
* @author Olivier Lamy
6566
* @since 2.5
6667
*/
6768
@Named
6869
@Typed(CheckstyleExecutor.class)
69-
public class DefaultCheckstyleExecutor extends AbstractLogEnabled implements CheckstyleExecutor {
70+
public class DefaultCheckstyleExecutor implements CheckstyleExecutor {
71+
72+
private static final Logger logger = LoggerFactory.getLogger(DefaultCheckstyleExecutor.class);
73+
7074
private final ResourceManager locator;
7175

7276
private final ResourceManager licenseLocator;
@@ -81,8 +85,8 @@ public DefaultCheckstyleExecutor(
8185
@Override
8286
public CheckstyleResults executeCheckstyle(CheckstyleExecutorRequest request)
8387
throws CheckstyleExecutorException, CheckstyleException {
84-
if (getLogger().isDebugEnabled()) {
85-
getLogger().debug("executeCheckstyle start headerLocation : " + request.getHeaderLocation());
88+
if (logger.isDebugEnabled()) {
89+
logger.debug("executeCheckstyle start headerLocation : " + request.getHeaderLocation());
8690
}
8791

8892
MavenProject project = request.getProject();
@@ -220,7 +224,7 @@ public CheckstyleResults executeCheckstyle(CheckstyleExecutorRequest request)
220224
// work regardless of config), but should record this information
221225
throw new CheckstyleExecutorException(message.toString());
222226
} else {
223-
getLogger().info(message.toString());
227+
logger.info(message.toString());
224228
}
225229
}
226230

@@ -255,8 +259,7 @@ protected void addSourceDirectory(
255259
File resourcesDirectory = new File(resource.getDirectory());
256260
if (resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
257261
sinkListener.addSourceDirectory(resourcesDirectory);
258-
getLogger()
259-
.debug("Added '" + resourcesDirectory.getAbsolutePath() + "' as a source directory.");
262+
logger.debug("Added '" + resourcesDirectory.getAbsolutePath() + "' as a source directory.");
260263
}
261264
}
262265
}
@@ -286,9 +289,8 @@ public Configuration getConfiguration(CheckstyleExecutorRequest request) throws
286289
: System.getProperty("file.encoding", "UTF-8");
287290

288291
if (StringUtils.isEmpty(request.getEncoding())) {
289-
getLogger()
290-
.warn("File encoding has not been set, using platform encoding " + effectiveEncoding
291-
+ ", i.e. build is platform dependent!");
292+
logger.warn("File encoding has not been set, using platform encoding " + effectiveEncoding
293+
+ ", i.e. build is platform dependent!");
292294
}
293295

294296
if ("Checker".equals(config.getName())
@@ -298,7 +300,7 @@ public Configuration getConfiguration(CheckstyleExecutorRequest request) throws
298300
addAttributeIfNotExists((DefaultConfiguration) config, "charset", effectiveEncoding);
299301
addAttributeIfNotExists((DefaultConfiguration) config, "cacheFile", request.getCacheFile());
300302
} else {
301-
getLogger().warn("Failed to configure file encoding on module " + config);
303+
logger.warn("Failed to configure file encoding on module " + config);
302304
}
303305
}
304306
return config;
@@ -368,8 +370,8 @@ private Properties getOverridingProperties(CheckstyleExecutorRequest request) th
368370
Properties p = new Properties();
369371
try {
370372
if (request.getPropertiesLocation() != null) {
371-
if (getLogger().isDebugEnabled()) {
372-
getLogger().debug("request.getPropertiesLocation() " + request.getPropertiesLocation());
373+
if (logger.isDebugEnabled()) {
374+
logger.debug("request.getPropertiesLocation() " + request.getPropertiesLocation());
373375
}
374376

375377
File propertiesFile =
@@ -399,8 +401,8 @@ private Properties getOverridingProperties(CheckstyleExecutorRequest request) th
399401
headerLocation = "config/maven-header.txt";
400402
}
401403
}
402-
if (getLogger().isDebugEnabled()) {
403-
getLogger().debug("headerLocation " + headerLocation);
404+
if (logger.isDebugEnabled()) {
405+
logger.debug("headerLocation " + headerLocation);
404406
}
405407

406408
if (headerLocation != null && !headerLocation.isEmpty()) {
@@ -411,8 +413,8 @@ private Properties getOverridingProperties(CheckstyleExecutorRequest request) th
411413
p.setProperty("checkstyle.header.file", headerFile.getAbsolutePath());
412414
}
413415
} catch (FileResourceCreationException | ResourceNotFoundException e) {
414-
getLogger().debug("Unable to process header location: " + headerLocation);
415-
getLogger().debug("Checkstyle will throw exception if ${checkstyle.header.file} is used");
416+
logger.debug("Unable to process header location: " + headerLocation);
417+
logger.debug("Checkstyle will throw exception if ${checkstyle.header.file} is used");
416418
}
417419
}
418420

@@ -486,7 +488,7 @@ private List<File> getFilesToProcess(CheckstyleExecutorRequest request) throws I
486488
request.getTestSourceDirectories());
487489
}
488490

489-
getLogger().debug("Added " + files.size() + " files to process.");
491+
logger.debug("Added " + files.size() + " files to process.");
490492

491493
return new ArrayList<>(files);
492494
}
@@ -505,9 +507,8 @@ private void addFilesToProcess(
505507
final List<File> sourceFiles =
506508
FileUtils.getFiles(sourceDirectory, request.getIncludes(), request.getExcludes());
507509
files.addAll(sourceFiles);
508-
getLogger()
509-
.debug("Added " + sourceFiles.size() + " source files found in '"
510-
+ sourceDirectory.getAbsolutePath() + "'.");
510+
logger.debug("Added " + sourceFiles.size() + " source files found in '"
511+
+ sourceDirectory.getAbsolutePath() + "'.");
511512
}
512513
}
513514
}
@@ -519,23 +520,22 @@ private void addFilesToProcess(
519520
FileUtils.getFiles(testSourceDirectory, request.getIncludes(), request.getExcludes());
520521

521522
files.addAll(testSourceFiles);
522-
getLogger()
523-
.debug("Added " + testSourceFiles.size() + " test source files found in '"
524-
+ testSourceDirectory.getAbsolutePath() + "'.");
523+
logger.debug("Added " + testSourceFiles.size() + " test source files found in '"
524+
+ testSourceDirectory.getAbsolutePath() + "'.");
525525
}
526526
}
527527
}
528528

529529
if (resources != null && request.isIncludeResources()) {
530530
addResourceFilesToProcess(request, resources, files);
531531
} else {
532-
getLogger().debug("No resources found in this project.");
532+
logger.debug("No resources found in this project.");
533533
}
534534

535535
if (testResources != null && request.isIncludeTestResources()) {
536536
addResourceFilesToProcess(request, testResources, files);
537537
} else {
538-
getLogger().debug("No test resources found in this project.");
538+
logger.debug("No test resources found in this project.");
539539
}
540540
}
541541

@@ -569,13 +569,11 @@ private void addResourceFilesToProcess(
569569

570570
List<File> resourceFiles = FileUtils.getFiles(resourcesDirectory, includes, excludes);
571571
files.addAll(resourceFiles);
572-
getLogger()
573-
.debug("Added " + resourceFiles.size() + " resource files found in '"
574-
+ resourcesDirectory.getAbsolutePath() + "'.");
572+
logger.debug("Added " + resourceFiles.size() + " resource files found in '"
573+
+ resourcesDirectory.getAbsolutePath() + "'.");
575574
} else {
576-
getLogger()
577-
.debug("The resources directory '" + resourcesDirectory.getAbsolutePath()
578-
+ "' does not exist or is not a directory.");
575+
logger.debug("The resources directory '" + resourcesDirectory.getAbsolutePath()
576+
+ "' does not exist or is not a directory.");
579577
}
580578
}
581579
}
@@ -613,8 +611,8 @@ private String getSuppressionsFilePath(final CheckstyleExecutorRequest request)
613611

614612
private String getConfigFile(CheckstyleExecutorRequest request) throws CheckstyleExecutorException {
615613
try {
616-
if (getLogger().isDebugEnabled()) {
617-
getLogger().debug("request.getConfigLocation() " + request.getConfigLocation());
614+
if (logger.isDebugEnabled()) {
615+
logger.debug("request.getConfigLocation() " + request.getConfigLocation());
618616
}
619617

620618
File configFile = locator.getResourceAsFile(request.getConfigLocation(), "checkstyle-checker.xml");

0 commit comments

Comments
 (0)