diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java index 61acecbcb..db78f8c72 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/mining/PeriodicMiner.java @@ -140,7 +140,10 @@ private void mineRandomRepo() { } private CodeAnalyzerResult analyzeProjectWithSpoon(Success success) { - return spoonAnalyzerService.analyze(new AnalyzerRequest.WithProject(success.project())); + logger.atInfo().log("Analyzing project %s with spoon", success.project()); + CodeAnalyzerResult analyze = spoonAnalyzerService.analyze(new AnalyzerRequest.WithProject(success.project())); + logger.atInfo().log("Successfully analyzed project %s with spoon", success.project()); + return analyze; } private boolean isAlreadyMined(ProjectResult.Success success, String commitHash) { diff --git a/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/SpoonAnalyzerService.java b/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/SpoonAnalyzerService.java index 3c45ced64..0be1c8477 100644 --- a/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/SpoonAnalyzerService.java +++ b/github-bot/src/main/java/io/github/martinwitt/laughing_train/services/SpoonAnalyzerService.java @@ -47,6 +47,7 @@ public CodeAnalyzerResult analyze(AnalyzerRequest request) { return new CodeAnalyzerResult.Failure("Unknown request type"); } } catch (Exception e) { + logger.atSevere().withCause(e).log("Error while analyzing code"); return new CodeAnalyzerResult.Failure(Strings.nullToEmpty(e.getMessage())); } } diff --git a/spoon-analyzer/src/main/java/io/github/martinwitt/spoon_analyzer/SpoonAnalyzer.java b/spoon-analyzer/src/main/java/io/github/martinwitt/spoon_analyzer/SpoonAnalyzer.java index 3000691c5..4e6561e96 100644 --- a/spoon-analyzer/src/main/java/io/github/martinwitt/spoon_analyzer/SpoonAnalyzer.java +++ b/spoon-analyzer/src/main/java/io/github/martinwitt/spoon_analyzer/SpoonAnalyzer.java @@ -1,5 +1,6 @@ package io.github.martinwitt.spoon_analyzer; +import com.google.common.flogger.FluentLogger; import io.github.martinwitt.spoon_analyzer.badsmells.Index_off_replaceable_by_contains.IndexOfReplaceableByContainsAnalyzer; import io.github.martinwitt.spoon_analyzer.badsmells.access_static_via_instance.AccessStaticViaInstanceAnalyzer; import io.github.martinwitt.spoon_analyzer.badsmells.array_can_be_replaced_with_enum_values.ArrayCanBeReplacedWithEnumValuesAnalyzer; @@ -19,6 +20,7 @@ public class SpoonAnalyzer { + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private final List localAnalyzers; public SpoonAnalyzer() { @@ -41,7 +43,7 @@ public List analyze(String path) { try { List files = Files.walk(Path.of(path)).filter(v -> Files.isDirectory(v)).toList(); - files = PathUtils.removeRedundantPaths(PathUtils.filterResourcePaths(files)); + files = PathUtils.filterResourcePaths(files); Launcher launcher = new Launcher(); for (Path p : files) { @@ -53,7 +55,7 @@ public List analyze(String path) { launcher.getEnvironment().setComplianceLevel(17); launcher.getEnvironment().setIgnoreSyntaxErrors(true); var model = launcher.buildModel(); - System.out.println("Found " + model.getAllTypes().size() + " types."); + logger.atInfo().log("Found %s types.", model.getAllTypes().size()); for (CtType type : model.getAllTypes()) { for (LocalAnalyzer analyzer : localAnalyzers) { var badSmell = analyzer.analyze(type); @@ -63,7 +65,7 @@ public List analyze(String path) { } } } catch (Exception e) { - e.printStackTrace(); + logger.atSevere().withCause(e).log("Error while analyzing."); } return badSmells; }