Skip to content

Commit

Permalink
fix: Improve report structure, fix template issue
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov committed Oct 4, 2024
1 parent 7c0e849 commit 78e1dd4
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 97 deletions.
204 changes: 126 additions & 78 deletions src/main/java/com/lpvs/entity/report/LPVSReportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ private String generateLicenseTableMD(
.append("|License Type / Explanation")
.append("|License SPDX ID")
.append("|Vendor / Component")
.append("|Version")
.append("|Repository File Path")
.append("|Component Version")
.append("|Component File Path")
.append("|Matched Lines")
.append("|Match Value|")
Expand Down Expand Up @@ -451,36 +451,49 @@ private void addBlockOfTableForLicenseTypeMD(
Map<String, GroupInfo<?>> componentAndVendor =
(Map<String, GroupInfo<?>>) licenseSpdxIds.get(licenseSpdxId).elements;
for (String componentInfo : componentAndVendor.keySet()) {
// file info
List<LPVSFile> fileInfos =
(List<LPVSFile>) componentAndVendor.get(componentInfo).elements;
for (LPVSFile fileInfo : fileInfos) {
mdBuilder
.append("|")
.append(type)
.append(" / ")
.append(getExplanationForLicenseType(type))
.append("|")
.append(licenseSpdxId)
.append("|")
.append(componentInfo.split(":::")[0])
.append(" (")
.append(componentInfo.split(":::")[1])
.append(")")
.append("|")
.append(fileInfo.getComponentVersion())
.append("|")
.append(fileInfo.getFilePath())
.append("|")
.append(fileInfo.getComponentFilePath())
.append("|")
.append(
LPVSCommentUtil.getMatchedLinesAsLink(
webhookConfig, fileInfo, vcs))
.append("|")
.append(fileInfo.getSnippetMatch())
.append("|")
.append("\n");
// file path
Map<String, GroupInfo<?>> filePath =
(Map<String, GroupInfo<?>>)
componentAndVendor.get(componentInfo).elements;
for (String filePathInfo : filePath.keySet()) {
List<LPVSFile> fileInfos =
(List<LPVSFile>) filePath.get(filePathInfo).elements;
for (LPVSFile fileInfo : fileInfos) {
mdBuilder
.append("|")
.append(type)
.append(" / ")
.append(getExplanationForLicenseType(type))
.append("|")
.append(licenseSpdxId)
.append("|")
.append(componentInfo)
.append("|")
.append(filePathInfo)
.append("|")
.append("[")
.append(fileInfo.getComponentVersion())
.append("](")
.append(fileInfo.getComponentUrl())
.append(")")
.append("|")
.append(
!StringUtils.isBlank(fileInfo.getComponentFileUrl())
? "["
+ fileInfo.getComponentFilePath()
+ "]("
+ fileInfo.getComponentFileUrl()
+ ")"
: fileInfo.getComponentFilePath())
.append("|")
.append(
LPVSCommentUtil.getMatchedLinesAsLink(
webhookConfig, fileInfo, vcs))
.append("|")
.append(fileInfo.getSnippetMatch())
.append("|")
.append("\n");
}
}
}
}
Expand Down Expand Up @@ -552,8 +565,8 @@ private String generateLicenseTableHTML(
.append("<th>License Type / Explanation</th>")
.append("<th>License SPDX ID</th>")
.append("<th>Vendor / Component</th>")
.append("<th>Version</th>")
.append("<th>Repository File Path</th>")
.append("<th>Component Version</th>")
.append("<th>Component File Path</th>")
.append("<th>Matched Lines</th>")
.append("<th>Match Value</th>")
Expand Down Expand Up @@ -652,51 +665,65 @@ private void addBlockOfTableForLicenseTypeHTML(
htmlBuilder
.append("<td rowspan=\"")
.append(componentAndVendor.get(componentInfo).getCount())
.append("\">");
htmlBuilder
.append("<a href=\"")
.append(componentInfo.split(":::")[1])
.append("\">")
.append(componentInfo.split(":::")[0])
.append("</a>");
htmlBuilder.append("</td>");

// file info
List<LPVSFile> fileInfos =
(List<LPVSFile>) componentAndVendor.get(componentInfo).elements;
for (LPVSFile fileInfo : fileInfos) {
.append(componentInfo)
.append("</td>");

// file path
Map<String, GroupInfo<?>> filePath =
(Map<String, GroupInfo<?>>)
componentAndVendor.get(componentInfo).elements;
for (String filePathInfo : filePath.keySet()) {
if (!isNewRow) {
htmlBuilder.append("<tr>");
isNewRow = true;
}
htmlBuilder
.append("<td>")
.append(fileInfo.getComponentVersion())
.append("</td><td>")
.append(fileInfo.getFilePath())
.append("</td><td>");
.append("<td rowspan=\"")
.append(filePath.get(filePathInfo).getCount())
.append("\">")
.append(filePathInfo)
.append("</td>");

if (!StringUtils.isBlank(fileInfo.getComponentFileUrl())) {
// version + file info + match info
List<LPVSFile> fileInfos =
(List<LPVSFile>) filePath.get(filePathInfo).elements;
for (LPVSFile fileInfo : fileInfos) {
if (!isNewRow) {
htmlBuilder.append("<tr>");
}
htmlBuilder
.append("<td>")
.append("<a href=\"")
.append(fileInfo.getComponentFileUrl())
.append(fileInfo.getComponentUrl())
.append("\">")
.append(fileInfo.getComponentFilePath())
.append("</a>");
} else {
htmlBuilder.append(fileInfo.getComponentFilePath());
}

htmlBuilder
.append("</td><td>")
.append(
LPVSCommentUtil.getMatchedLinesAsLink(
webhookConfig, fileInfo, vcs))
.append("</td><td>")
.append(fileInfo.getSnippetMatch())
.append("</td>");
.append(fileInfo.getComponentVersion())
.append("</a>")
.append("</td><td>");

if (!StringUtils.isBlank(fileInfo.getComponentFileUrl())) {
htmlBuilder
.append("<a href=\"")
.append(fileInfo.getComponentFileUrl())
.append("\">")
.append(fileInfo.getComponentFilePath())
.append("</a>");
} else {
htmlBuilder.append(fileInfo.getComponentFilePath());
}

htmlBuilder.append("</tr>");
isNewRow = false;
htmlBuilder
.append("</td><td>")
.append(
LPVSCommentUtil.getMatchedLinesAsLink(
webhookConfig, fileInfo, vcs))
.append("</td><td>")
.append(fileInfo.getSnippetMatch())
.append("</td>");

htmlBuilder.append("</tr>");
isNewRow = false;
}
}
}
}
Expand Down Expand Up @@ -791,18 +818,30 @@ private Map<String, GroupInfo<?>> groupScanResultsForLicenseTable(List<LPVSFile>
Collectors.collectingAndThen(
Collectors.groupingBy(
this::getLicenseSpdxId,
TreeMap::new,
Collectors.collectingAndThen(
Collectors.groupingBy(
this::getComponentKey,
TreeMap::new,
Collectors
.collectingAndThen(
Collectors
.toList(),
files ->
new GroupInfo<>(
files
.size(),
files))),
.groupingBy(
this
::getFilePathKey,
TreeMap
::new,
Collectors
.collectingAndThen(
Collectors
.toList(),
files ->
new GroupInfo<>(
files
.size(),
files))),
this
::sumGroupInfo)),
this::sumGroupInfo)),
this::sumGroupInfo)));
}
Expand All @@ -829,11 +868,20 @@ private GroupInfo<Object> sumGroupInfo(Map<String, GroupInfo<Object>> groupedBy)
* @return the component key that contains component name, vendor name and component URL
*/
private String getComponentKey(LPVSFile lpvsFile) {
return lpvsFile.getComponentVendor()
+ " / "
+ lpvsFile.getComponentName()
+ ":::"
+ lpvsFile.getComponentUrl();
return lpvsFile.getComponentVendor() + " / " + lpvsFile.getComponentName();
}

/**
* Grouping criteria for the file path
*
* @param lpvsFile the LPVSFile whose file path is to be retrieved
* @return the component key that contains component path
*/
private String getFilePathKey(LPVSFile lpvsFile) {
if (lpvsFile.getFilePath().startsWith("/")) {
return lpvsFile.getFilePath().substring(1);
}
return lpvsFile.getFilePath();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/report_single_scan.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ <h3 class="ml-30">Detected License Conflicts</h3>
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
panel.style.maxHeight = "none";
}
});
}
Expand Down
Loading

0 comments on commit 78e1dd4

Please sign in to comment.