Skip to content

Commit

Permalink
Migrate to slf4j (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reamer authored Jan 17, 2024
1 parent 7bcb1cb commit 0909abd
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.SensorDescriptor;
import org.sonar.api.notifications.AnalysisWarnings;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.scanner.sensor.ProjectSensor;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.api.utils.log.Profiler;
import org.sonar.dependencycheck.base.DependencyCheckMetrics;
import org.sonar.dependencycheck.base.DependencyCheckUtils;
import org.sonar.dependencycheck.parser.JsonReportParserHelper;
Expand All @@ -48,7 +47,7 @@

public class DependencyCheckSensor implements ProjectSensor {

private static final Logger LOGGER = Loggers.get(DependencyCheckSensor.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DependencyCheckSensor.class);
private static final String SENSOR_NAME = "Dependency-Check";

private final FileSystem fileSystem;
Expand Down Expand Up @@ -123,11 +122,10 @@ public void describe(SensorDescriptor sensorDescriptor) {

@Override
public void execute(SensorContext sensorContext) {
Profiler profiler = Profiler.create(LOGGER);
profiler.startInfo("Process Dependency-Check report");
if (DependencyCheckUtils.skipPlugin(sensorContext.config())) {
LOGGER.info("Dependency-Check skipped");
} else {
LOGGER.info("Dependency-Check - Start");
Optional<Analysis> analysis = parseAnalysis(sensorContext);
if (analysis.isPresent()) {
DependencyReasonSearcher dependencyReasonSearcher = new DependencyReasonSearcher(sensorContext);
Expand All @@ -137,7 +135,8 @@ public void execute(SensorContext sensorContext) {
}
}
uploadHTMLReport(sensorContext);
LOGGER.info("Dependency-Check - End");
}
profiler.stopInfo();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
*/
package org.sonar.dependencycheck.base;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.issue.impact.Severity;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;

import edu.umd.cs.findbugs.annotations.NonNull;

public class DependencyCheckMetric {

private static final Logger LOGGER = Loggers.get(DependencyCheckMetric.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DependencyCheckMetric.class);
private final InputComponent inputcomponent;

private int totalDependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.dependencycheck.base.DependencyCheckUtils;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand All @@ -37,7 +37,7 @@
@JsonIgnoreProperties({"notes", "references", "vulnerableSoftware", "unscored", "knownExploitedVulnerability"})
public class Vulnerability {

private static final Logger LOGGER = Loggers.get(Vulnerability.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Vulnerability.class);

private final String name;
private final String source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
Expand All @@ -30,8 +32,6 @@
import org.sonar.api.issue.impact.Severity;
import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.dependencycheck.base.DependencyCheckConstants;
import org.sonar.dependencycheck.base.DependencyCheckMetric;
import org.sonar.dependencycheck.base.DependencyCheckUtils;
Expand All @@ -43,7 +43,7 @@

public abstract class DependencyReason {

private static final Logger LOGGER = Loggers.get(DependencyReason.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DependencyReason.class);

private final DependencyCheckMetric metrics;
private final Language language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import java.util.List;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.batch.sensor.issue.NewIssueLocation;
import org.sonar.api.issue.impact.Severity;
import org.sonar.api.issue.impact.SoftwareQuality;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.dependencycheck.base.DependencyCheckConstants;
import org.sonar.dependencycheck.base.DependencyCheckMetric;
import org.sonar.dependencycheck.base.DependencyCheckUtils;
Expand All @@ -44,7 +44,7 @@

public class DependencyReasonSearcher {

private static final Logger LOGGER = Loggers.get(DependencyReasonSearcher.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DependencyReasonSearcher.class);
private final DependencyCheckMetric projectMetric;

private final Collection<DependencyReason> dependencyReasons;
Expand Down Expand Up @@ -103,7 +103,7 @@ private Optional<DependencyReason> getBestDependencyReason(Dependency dependency
LOGGER.debug("Get the best DependencyReason out of {} for {}", dependencyReasons.size(), dependency.getFileName());
// Prefer root configuration file
Optional<DependencyReason> dependencyReasonWinner = DependencyCheckUtils.getBestDependencyReason(dependency, dependencyReasons);
dependencyReasonWinner.ifPresent(dependencyReason -> LOGGER.debug("DependencyReasonWinner: " + dependencyReason.getInputComponent()));
dependencyReasonWinner.ifPresent(dependencyReason -> LOGGER.debug("DependencyReasonWinner: {}", dependencyReason.getInputComponent()));
return dependencyReasonWinner;
}

Expand All @@ -115,12 +115,12 @@ public void addDependenciesToInputComponents(@NonNull Analysis analysis,@NonNull
if (dependencyReasons.isEmpty()) {
LOGGER.info("No project configuration file, e.g. pom.xml, *.gradle, *.gradle.kts, package-lock.json found, therefore it isn't possible to correctly link dependencies with files.");
linkIssues(analysis.getDependencies(), context);
LOGGER.debug("Saving Metrics to project {}", projectMetric.toString());
LOGGER.debug("Saving Metrics to project {}", projectMetric);
projectMetric.saveMeasures(context);
} else {
linkIssues(analysis.getDependencies(), context);
for (DependencyReason reason : dependencyReasons) {
LOGGER.debug("Saving Metrics to reason file {} ", reason.getMetrics().toString());
LOGGER.debug("Saving Metrics to reason file {} ", reason.getMetrics());
reason.getMetrics().saveMeasures(context);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import java.util.Scanner;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.dependencycheck.base.DependencyCheckUtils;
import org.sonar.dependencycheck.parser.element.Confidence;
import org.sonar.dependencycheck.parser.element.Dependency;
Expand All @@ -46,7 +46,7 @@ public class GradleDependencyReason extends DependencyReason {
private String content;
private final Map<Dependency, TextRangeConfidence> dependencyMap;

private static final Logger LOGGER = Loggers.get(GradleDependencyReason.class);
private static final Logger LOGGER = LoggerFactory.getLogger(GradleDependencyReason.class);

public GradleDependencyReason(@NonNull InputFile buildGradle) {
super(buildGradle, Language.JAVA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.dependencycheck.base.DependencyCheckUtils;
import org.sonar.dependencycheck.parser.PomParserHelper;
import org.sonar.dependencycheck.parser.ReportParserException;
Expand All @@ -49,7 +49,7 @@ public class MavenDependencyReason extends DependencyReason {
private final Map<Dependency, TextRangeConfidence> dependencyMap;
private MavenPomModel pomModel;

private static final Logger LOGGER = Loggers.get(MavenDependencyReason.class);
private static final Logger LOGGER = LoggerFactory.getLogger(MavenDependencyReason.class);

public MavenDependencyReason(@NonNull InputFile pom) {
super(pom, Language.JAVA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.sonar.dependencycheck.base.DependencyCheckUtils;
import org.sonar.dependencycheck.parser.PackageLockParserHelper;
import org.sonar.dependencycheck.parser.ReportParserException;
Expand All @@ -47,7 +47,7 @@ public class NPMDependencyReason extends DependencyReason {
private PackageLockModel packageLockModel;
private final Map<Dependency, TextRangeConfidence> dependencyMap;

private static final Logger LOGGER = Loggers.get(NPMDependencyReason.class);
private static final Logger LOGGER = LoggerFactory.getLogger(NPMDependencyReason.class);

public NPMDependencyReason(InputFile packageLock) {
super(packageLock, Language.JAVASCRIPT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.Nullable;

public abstract class ReportFile {
private static final Logger LOGGER = Loggers.get(ReportFile.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ReportFile.class);

protected final ReportFormat reportFormat;
protected final String property;
Expand Down

0 comments on commit 0909abd

Please sign in to comment.