Skip to content

Commit

Permalink
refactor: Replace Plexus AbstractLogEnabled with SLF4J (#157)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
timtebeek and TeamModerne authored Dec 14, 2024
1 parent 784b5ba commit 22717e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/config/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,25 @@
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
* @since 2.5
*/
@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;
Expand All @@ -81,8 +85,8 @@ public DefaultCheckstyleExecutor(
@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();
Expand Down Expand Up @@ -220,7 +224,7 @@ public CheckstyleResults executeCheckstyle(CheckstyleExecutorRequest request)
// work regardless of config), but should record this information
throw new CheckstyleExecutorException(message.toString());
} else {
getLogger().info(message.toString());
logger.info(message.toString());
}
}

Expand Down Expand Up @@ -255,8 +259,7 @@ protected void addSourceDirectory(
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.");
}
}
}
Expand Down Expand Up @@ -286,9 +289,8 @@ public Configuration getConfiguration(CheckstyleExecutorRequest request) throws
: 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())
Expand All @@ -298,7 +300,7 @@ public Configuration getConfiguration(CheckstyleExecutorRequest request) throws
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;
Expand Down Expand Up @@ -368,8 +370,8 @@ private Properties getOverridingProperties(CheckstyleExecutorRequest request) th
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 =
Expand Down Expand Up @@ -399,8 +401,8 @@ private Properties getOverridingProperties(CheckstyleExecutorRequest request) th
headerLocation = "config/maven-header.txt";
}
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("headerLocation " + headerLocation);
if (logger.isDebugEnabled()) {
logger.debug("headerLocation " + headerLocation);
}

if (headerLocation != null && !headerLocation.isEmpty()) {
Expand All @@ -411,8 +413,8 @@ private Properties getOverridingProperties(CheckstyleExecutorRequest request) th
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");
}
}

Expand Down Expand Up @@ -486,7 +488,7 @@ private List<File> getFilesToProcess(CheckstyleExecutorRequest request) throws I
request.getTestSourceDirectories());
}

getLogger().debug("Added " + files.size() + " files to process.");
logger.debug("Added " + files.size() + " files to process.");

return new ArrayList<>(files);
}
Expand All @@ -505,9 +507,8 @@ private void addFilesToProcess(
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() + "'.");
}
}
}
Expand All @@ -519,23 +520,22 @@ private void addFilesToProcess(
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() + "'.");
}
}
}

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.");
}
}

Expand Down Expand Up @@ -569,13 +569,11 @@ private void addResourceFilesToProcess(

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.");
}
}
}
Expand Down Expand Up @@ -613,8 +611,8 @@ private String getSuppressionsFilePath(final CheckstyleExecutorRequest request)

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");
Expand Down

0 comments on commit 22717e6

Please sign in to comment.