From a4903114894890bee75e393716da53bbc5442f1c Mon Sep 17 00:00:00 2001 From: skiesewetter-intershop <82586807+skiesewetter-intershop@users.noreply.github.com> Date: Fri, 22 Sep 2023 07:32:43 +0200 Subject: [PATCH] feat: make architecture report log issues (#83460) --- .../report/cmd/ArchitectureReport.java | 5 ++++ .../report/common/issue/IssueComparator.java | 23 ++++++++++++++++ .../report/common/issue/IssueLogger.java | 26 +++++++++++++++++++ .../report/common/issue/IssuePrinter.java | 13 +++------- 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/intershop/tool/architecture/report/common/issue/IssueComparator.java create mode 100644 src/main/java/com/intershop/tool/architecture/report/common/issue/IssueLogger.java diff --git a/src/main/java/com/intershop/tool/architecture/report/cmd/ArchitectureReport.java b/src/main/java/com/intershop/tool/architecture/report/cmd/ArchitectureReport.java index f2ce194..e69f142 100644 --- a/src/main/java/com/intershop/tool/architecture/report/cmd/ArchitectureReport.java +++ b/src/main/java/com/intershop/tool/architecture/report/cmd/ArchitectureReport.java @@ -2,6 +2,7 @@ import java.util.List; +import com.intershop.tool.architecture.report.common.issue.IssueLogger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -60,8 +61,12 @@ public static boolean validateArchitecture(String[] args) logger.info("Architecture report contains no errors."); return false; } + IssuePrinter printer = new IssuePrinter(info); printer.printIssues(filteredIssues); + + new IssueLogger().logIssues(filteredIssues); + return true; } } diff --git a/src/main/java/com/intershop/tool/architecture/report/common/issue/IssueComparator.java b/src/main/java/com/intershop/tool/architecture/report/common/issue/IssueComparator.java new file mode 100644 index 0000000..93bb6f7 --- /dev/null +++ b/src/main/java/com/intershop/tool/architecture/report/common/issue/IssueComparator.java @@ -0,0 +1,23 @@ +package com.intershop.tool.architecture.report.common.issue; + +import java.util.Comparator; + +public class IssueComparator implements Comparator +{ + private static final Comparator DELEGATE = Comparator.comparing( + (Issue a) -> a.getProjectRef().getIdentifier()) + .thenComparing(Issue::getKey) + .thenComparing(Issue::getParametersString); + + private static final IssueComparator INSTANCE = new IssueComparator(); + + public static Comparator getInstance() { + return INSTANCE; + } + + @Override + public int compare(Issue issue1, Issue issue2) + { + return DELEGATE.compare(issue1, issue2); + } +} diff --git a/src/main/java/com/intershop/tool/architecture/report/common/issue/IssueLogger.java b/src/main/java/com/intershop/tool/architecture/report/common/issue/IssueLogger.java new file mode 100644 index 0000000..0917ba3 --- /dev/null +++ b/src/main/java/com/intershop/tool/architecture/report/common/issue/IssueLogger.java @@ -0,0 +1,26 @@ +package com.intershop.tool.architecture.report.common.issue; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +public class IssueLogger +{ + private static final Logger LOGGER = LoggerFactory.getLogger(IssueLogger.class); + + /** + * @param issues List of issues + */ + public void logIssues(List issues) + { + AtomicInteger idx = new AtomicInteger(1); + String renderedIssues = issues.stream().sorted(IssueComparator.getInstance()).map(issue -> + String.format("%d: project=%s, key=%s, parameters=%s", idx.getAndIncrement(), issue.getProjectRef().getIdentifier(), issue.getKey(), issue.getParametersString()) + ).collect(Collectors.joining("\n")); + + LOGGER.error("Architecture report contains the following new errors:\n{}", renderedIssues); + } +} diff --git a/src/main/java/com/intershop/tool/architecture/report/common/issue/IssuePrinter.java b/src/main/java/com/intershop/tool/architecture/report/common/issue/IssuePrinter.java index 537ecbe..484bc67 100644 --- a/src/main/java/com/intershop/tool/architecture/report/common/issue/IssuePrinter.java +++ b/src/main/java/com/intershop/tool/architecture/report/common/issue/IssuePrinter.java @@ -2,7 +2,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.util.Comparator; import java.util.Formatter; import java.util.List; @@ -15,11 +14,7 @@ public class IssuePrinter { - private static final Logger logger = LoggerFactory.getLogger(IssuePrinter.class); - private static final Comparator ISSUE_COMPARATOR = Comparator.comparing( - (Issue a) -> a.getProjectRef().getIdentifier()) - .thenComparing(Issue::getKey) - .thenComparing(Issue::getParametersString); + private static final Logger LOGGER = LoggerFactory.getLogger(IssuePrinter.class); private final CommandLineArguments info; @@ -33,7 +28,7 @@ public IssuePrinter(CommandLineArguments info) */ public void printIssues(List issues) { - issues.sort(ISSUE_COMPARATOR); + issues.sort(IssueComparator.getInstance()); ArchitectureReportOutputFolder folderLocations = new ArchitectureReportOutputFolder( info.getArgument(ArchitectureReportConstants.ARG_OUTPUT_DIRECTORY)); File newIssuesFile = folderLocations.getNewIssuesFile(); @@ -53,8 +48,8 @@ public void printIssues(List issues) } catch(FileNotFoundException e) { - logger.error("Can't write errors at " + newIssuesFile.getAbsolutePath(), e); + LOGGER.error("Can't write errors at " + newIssuesFile.getAbsolutePath(), e); } - logger.error("Architecture report contains new errors, see '{}'.", newIssuesFile.getAbsolutePath()); + LOGGER.error("Architecture report contains new errors, see '{}'.", newIssuesFile.getAbsolutePath()); } }