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

fix(spoon): Improve logging for spoon based analyzer #809

Merged
merged 1 commit into from
Jul 9, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,6 +20,7 @@

public class SpoonAnalyzer {

private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final List<LocalAnalyzer> localAnalyzers;

public SpoonAnalyzer() {
Expand All @@ -41,7 +43,7 @@ public List<BadSmell> analyze(String path) {
try {
List<Path> 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) {
Expand All @@ -53,7 +55,7 @@ public List<BadSmell> 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);
Expand All @@ -63,7 +65,7 @@ public List<BadSmell> analyze(String path) {
}
}
} catch (Exception e) {
e.printStackTrace();
logger.atSevere().withCause(e).log("Error while analyzing.");
}
return badSmells;
}
Expand Down