-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
647 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
...tractor/src/main/java/org/jfrog/build/extractor/buildScanTable/BuildScanTableElement.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ractor/src/main/java/org/jfrog/build/extractor/buildScanTable/LicenseViolationsTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.jfrog.build.extractor.buildScanTable; | ||
|
||
import org.jfrog.build.api.util.Log; | ||
import org.jfrog.build.client.artifactoryXrayResponse.InfectedFile; | ||
import org.jfrog.build.client.artifactoryXrayResponse.Issue; | ||
|
||
import java.util.Objects; | ||
|
||
public class LicenseViolationsTable extends ScanTableBase { | ||
public static final String LICENSE_VIOLATIONS_TABLE_HEADLINE = "License Compliance Violations"; | ||
|
||
protected LicenseViolationsTable(Log log) { | ||
super(log); | ||
} | ||
|
||
protected String getHeadline() { | ||
return LICENSE_VIOLATIONS_TABLE_HEADLINE; | ||
} | ||
|
||
protected String[] getHeaders() { | ||
return new String[]{"#", "Severity", "Component"}; | ||
} | ||
|
||
protected String getTableFormat() { | ||
return super.getFormatBase(longestDisplayName); | ||
} | ||
|
||
protected String getEmptyTableLine() { | ||
return "No license compliance violations were found"; | ||
} | ||
|
||
protected void addElement(Issue issue, InfectedFile infectedFile) { | ||
// Create table element. | ||
LicenseTableElement element = new LicenseTableElement(infectedFile.getDisplayName(), infectedFile.getSha256(), | ||
issue.getSummary(), issue.getDescription()); | ||
super.addElement(table, issue, element); | ||
// Update the longest display name if longer. | ||
if (infectedFile.getDisplayName() != null && infectedFile.getDisplayName().length() > longestDisplayName) { | ||
longestDisplayName = infectedFile.getDisplayName().length(); | ||
} | ||
} | ||
|
||
protected void printTable() { | ||
super.printTable(table); | ||
} | ||
|
||
private static class LicenseTableElement extends TableElementBase { | ||
LicenseTableElement(String fileDisplayName, String fileSha256, | ||
String issueSummary, String issueDescription) { | ||
super(fileDisplayName, fileSha256, issueSummary, issueDescription); | ||
} | ||
|
||
@Override | ||
protected Object[] getLineArgs(int line, String severityName) { | ||
return new Object[]{line, severityName, this.getFileDisplayName()}; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
LicenseTableElement that = (LicenseTableElement) o; | ||
return Objects.equals(fileDisplayName, that.fileDisplayName) && | ||
Objects.equals(fileSha256, that.fileSha256) && | ||
Objects.equals(issueSummary, that.issueSummary) && | ||
Objects.equals(issueDescription, that.issueDescription); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fileDisplayName, fileSha256, issueSummary, issueDescription); | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...-info-extractor/src/main/java/org/jfrog/build/extractor/buildScanTable/ScanTableBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package org.jfrog.build.extractor.buildScanTable; | ||
|
||
import org.jfrog.build.api.util.Log; | ||
import org.jfrog.build.client.artifactoryXrayResponse.Issue; | ||
import org.jfrog.build.extractor.scan.Severity; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Base class for violations tables printed by {@link BuildScanTableHelper} | ||
*/ | ||
abstract class ScanTableBase { | ||
private final Log log; | ||
protected int longestDisplayName = 0; | ||
protected final Map<Severity, Set<TableElementBase>> table = new HashMap<>(); | ||
|
||
protected ScanTableBase(Log log) { | ||
this.log = log; | ||
} | ||
|
||
protected abstract String getHeadline(); | ||
|
||
protected abstract String[] getHeaders(); | ||
|
||
protected abstract String getTableFormat(); | ||
|
||
protected abstract String getEmptyTableLine(); | ||
|
||
protected String getFormatBase(int longestDisplayName) { | ||
// Index (assuming 5 digits is sufficient). | ||
return "%-6s" | ||
// Severity (Longest is 'Information'). | ||
+ "%-14s" | ||
// Display name (plus space). | ||
+ "%-" + (longestDisplayName + 3) + "s"; | ||
} | ||
|
||
private void printFormattedLine(Object... args) { | ||
log.info(String.format(getTableFormat(), args)); | ||
} | ||
|
||
protected void addElement(Map<Severity, Set<TableElementBase>> table, Issue issue, TableElementBase element) { | ||
Severity severity = Severity.fromString(issue.getSeverity()); | ||
Set<TableElementBase> elements = table.get(severity); | ||
if (elements == null) { | ||
elements = new HashSet<>(); | ||
} | ||
elements.add(element); | ||
table.put(severity, elements); | ||
} | ||
|
||
protected void printTable(Map<Severity, Set<TableElementBase>> table) { | ||
int line = 1; | ||
Severity[] severities = Severity.values(); | ||
|
||
// Print table headline. | ||
log.info(getHeadline()); | ||
|
||
// If table is empty, print the no violations found line and return. | ||
if (table.isEmpty()) { | ||
log.info(getEmptyTableLine()); | ||
log.info(""); | ||
return; | ||
} | ||
|
||
// Print column headers. | ||
printFormattedLine((Object[]) getHeaders()); | ||
|
||
// Print lines of violations by descending severity. | ||
for (int i = severities.length - 1; i >= 0; i--) { | ||
Severity severity = severities[i]; | ||
Set<TableElementBase> elements = table.get(severity); | ||
if (elements == null) { | ||
continue; | ||
} | ||
for (TableElementBase element : elements) { | ||
printFormattedLine(element.getLineArgs(line, severity.getSeverityName())); | ||
line++; | ||
} | ||
} | ||
log.info(""); | ||
} | ||
|
||
/** | ||
* Base class for elements of the violations tables | ||
*/ | ||
protected abstract static class TableElementBase { | ||
protected final String fileDisplayName; | ||
// Following fields are for the set's uniqueness only: | ||
protected final String fileSha256; | ||
protected final String issueSummary; | ||
protected final String issueDescription; | ||
|
||
protected TableElementBase(String fileDisplayName, String fileSha256, | ||
String issueSummary, String issueDescription) { | ||
this.fileDisplayName = fileDisplayName; | ||
this.fileSha256 = fileSha256; | ||
this.issueSummary = issueSummary; | ||
this.issueDescription = issueDescription; | ||
} | ||
|
||
protected String getFileDisplayName() { | ||
return fileDisplayName == null ? "" : fileDisplayName; | ||
} | ||
|
||
protected abstract Object[] getLineArgs(int line, String severityName); | ||
} | ||
} |
Oops, something went wrong.