net.adamcin.oakpal.cli.ReportMessage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oakpal-cli Show documentation
Show all versions of oakpal-cli Show documentation
Command Line Interface for OakPAL
package net.adamcin.oakpal.cli;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Set;
import java.util.stream.Collectors;
import javax.json.JsonObject;
import net.adamcin.oakpal.core.CheckReport;
import net.adamcin.oakpal.core.Violation;
import org.apache.jackrabbit.vault.packaging.PackageId;
public class ReportMessage implements StructuredMessage {
private final CheckReport report;
public ReportMessage(final CheckReport report) {
this.report = report;
}
@Override
public String toString() {
StringWriter sw = new StringWriter();
try (PrintWriter writer = new PrintWriter(sw)) {
writer.println(String.format("report: %s", String.valueOf(report.getCheckName())));
for (Violation v : report.getViolations()) {
final Set packageIds = v.getPackages().stream().map(PackageId::getDownloadName)
.collect(Collectors.toSet());
final String violLog = !packageIds.isEmpty()
? String.format(" +- <%s> %s %s", v.getSeverity(), v.getDescription(), packageIds)
: String.format(" +- <%s> %s", v.getSeverity(), v.getDescription());
writer.println(violLog);
}
}
return sw.toString().trim();
}
@Override
public JsonObject toJson() {
return report.toJson();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy