Skip to content

Commit

Permalink
feat: make architecture report log issues (#83460)
Browse files Browse the repository at this point in the history
  • Loading branch information
skiesewetter-intershop authored Sep 22, 2023
1 parent 6ed2f39 commit a490311
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.intershop.tool.architecture.report.common.issue;

import java.util.Comparator;

public class IssueComparator implements Comparator<Issue>
{
private static final Comparator<Issue> DELEGATE = Comparator.comparing(
(Issue a) -> a.getProjectRef().getIdentifier())
.thenComparing(Issue::getKey)
.thenComparing(Issue::getParametersString);

private static final IssueComparator INSTANCE = new IssueComparator();

public static Comparator<Issue> getInstance() {
return INSTANCE;
}

@Override
public int compare(Issue issue1, Issue issue2)
{
return DELEGATE.compare(issue1, issue2);
}
}
Original file line number Diff line number Diff line change
@@ -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<Issue> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Comparator;
import java.util.Formatter;
import java.util.List;

Expand All @@ -15,11 +14,7 @@

public class IssuePrinter
{
private static final Logger logger = LoggerFactory.getLogger(IssuePrinter.class);
private static final Comparator<? super Issue> 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;

Expand All @@ -33,7 +28,7 @@ public IssuePrinter(CommandLineArguments info)
*/
public void printIssues(List<Issue> issues)
{
issues.sort(ISSUE_COMPARATOR);
issues.sort(IssueComparator.getInstance());
ArchitectureReportOutputFolder folderLocations = new ArchitectureReportOutputFolder(
info.getArgument(ArchitectureReportConstants.ARG_OUTPUT_DIRECTORY));
File newIssuesFile = folderLocations.getNewIssuesFile();
Expand All @@ -53,8 +48,8 @@ public void printIssues(List<Issue> 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());
}
}

0 comments on commit a490311

Please sign in to comment.