Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace Plexus AbstractLogEnabled with SLF4J #157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading