From e3d5cca4eb9d9b7178467f20ec85167fe3f1ad5e Mon Sep 17 00:00:00 2001 From: Oleg Kopysov Date: Wed, 9 Oct 2024 19:45:35 +0300 Subject: [PATCH] feat: Generate PDF report for single scan mode Signed-off-by: Oleg Kopysov --- doc/docs/user-guide/cli/cli_file.md | 11 ++-- doc/docs/user-guide/cli/cli_pr.md | 11 ++-- doc/docs/user-guide/config/options.md | 3 ++ pom.xml | 10 ++++ .../lpvs/entity/report/LPVSReportBuilder.java | 51 +++++++++++++++---- .../lpvs/service/scan/LPVSDetectService.java | 51 ++++++++++++++----- .../templates/report_single_scan.html | 20 +++++--- .../entity/report/LPVSReportBuilderTest.java | 19 ++++++- .../lpvs/service/LPVSGitHubServiceTest.java | 22 ++++---- .../service/scan/LPVSDetectServiceTest.java | 11 +++- 10 files changed, 160 insertions(+), 49 deletions(-) diff --git a/doc/docs/user-guide/cli/cli_file.md b/doc/docs/user-guide/cli/cli_file.md index b0b878d5..60cf4c8a 100644 --- a/doc/docs/user-guide/cli/cli_file.md +++ b/doc/docs/user-guide/cli/cli_file.md @@ -44,12 +44,15 @@ Example: java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path= ``` -* Optionally, generate an HTML report and save it in a specified folder using flag `--build.html.report`. - Replace `path/to/your/folder` with the full path to the folder where you want to save the HTML report, - and `your_report_filename.html` with the desired filename for the report. +* Optionally, generate an HTML report and save it in a specified folder using flag `--build.html.report`, + or PDF report using flag `--build.pdf.report`. + Replace `path/to/your/folder` with the full path to the folder where you want to save the HTML/PDF report, + and `your_report_filename.html` or `your_report_filename.pdf` with the desired filename for the report. ```bash java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path= --build.html.report= +java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path= --build.pdf.report= +java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path= --build.html.report= --build.pdf.report= ``` !!! warning @@ -61,4 +64,6 @@ Examples of the command: ```bash java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path=test.c java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path=test_folder --build.html.report=test/report.html +java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path=test_folder --build.pdf.report=test/report.pdf +java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --local.path=test_folder --build.html.report=test/report.html --build.pdf.report=test/report.pdf ``` diff --git a/doc/docs/user-guide/cli/cli_pr.md b/doc/docs/user-guide/cli/cli_pr.md index 9fa63262..c994e50e 100644 --- a/doc/docs/user-guide/cli/cli_pr.md +++ b/doc/docs/user-guide/cli/cli_pr.md @@ -44,12 +44,15 @@ Example: java -jar -Dspring.profiles.active=singlescan -Dgithub.token= lpvs-*.jar --github.pull.request= ``` -* Optionally, generate an HTML report and save it in a specified folder using flag `--build.html.report`. -Replace `path/to/your/folder` with the full path to the folder where you want to save the HTML report, -and `your_report_filename.html` with the desired filename for the report. +* Optionally, generate an HTML report and save it in a specified folder using flag `--build.html.report`, +or PDF report using flag `--build.pdf.report`. +Replace `path/to/your/folder` with the full path to the folder where you want to save the HTML/PDF report, +and `your_report_filename.html` or `your_report_filename.pdf` with the desired filename for the report. ```bash java -jar -Dspring.profiles.active=singlescan -Dgithub.token= lpvs-*.jar --github.pull.request= --build.html.report= +java -jar -Dspring.profiles.active=singlescan -Dgithub.token= lpvs-*.jar --github.pull.request= --build.pdf.report= +java -jar -Dspring.profiles.active=singlescan -Dgithub.token= lpvs-*.jar --github.pull.request= --build.html.report= --build.pdf.report= ``` !!! warning @@ -61,4 +64,6 @@ Examples of the command: ```bash java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --github.pull.request=https://github.com/Samsung/LPVS/pull/2 java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --github.pull.request=https://github.com/Samsung/LPVS/pull/2 --build.html.report=report.html +java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --github.pull.request=https://github.com/Samsung/LPVS/pull/2 --build.pdf.report=report.pdf +java -jar -Dspring.profiles.active=singlescan lpvs-*.jar --github.pull.request=https://github.com/Samsung/LPVS/pull/2 --build.html.report=report.html --build.pdf.report=report.pdf ``` diff --git a/doc/docs/user-guide/config/options.md b/doc/docs/user-guide/config/options.md index e5a5039d..28ee2973 100644 --- a/doc/docs/user-guide/config/options.md +++ b/doc/docs/user-guide/config/options.md @@ -104,6 +104,9 @@ The following command line options are available: - `--build.html.report`: This setting specifies the path to the HTML report file which will be generated after the scan. If it is not specified, no HTML report will be generated and result of the scan will be displayed in the console. +- `--build.pdf.report`: This setting specifies the path to the PDF report file which will be generated after the scan. +If it is not specified, no PDF report will be generated and result of the scan will be displayed in the console. + - `--github.pull.request`: This setting specifies the pull request URL which should be scanned by the LPVS application. - `--local.path`: This setting specifies the path to the local file or folder which should be scanned by the LPVS application. diff --git a/pom.xml b/pom.xml index b4b4ae8f..c26a40c4 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,16 @@ + + com.openhtmltopdf + openhtmltopdf-core + 1.0.10 + + + com.openhtmltopdf + openhtmltopdf-pdfbox + 1.0.10 + org.springframework.boot spring-boot-starter-web diff --git a/src/main/java/com/lpvs/entity/report/LPVSReportBuilder.java b/src/main/java/com/lpvs/entity/report/LPVSReportBuilder.java index a2fe14a7..0edd577d 100644 --- a/src/main/java/com/lpvs/entity/report/LPVSReportBuilder.java +++ b/src/main/java/com/lpvs/entity/report/LPVSReportBuilder.java @@ -12,6 +12,8 @@ import com.lpvs.entity.enums.LPVSVcs; import com.lpvs.entity.LPVSConflict; import com.lpvs.util.LPVSCommentUtil; +import com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder; +import com.openhtmltopdf.pdfboxout.PdfRendererBuilder; import io.micrometer.common.util.StringUtils; import lombok.AllArgsConstructor; import lombok.Getter; @@ -22,10 +24,7 @@ import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; @@ -245,6 +244,32 @@ public static void saveHTMLToFile(String htmlContent, String filePath) { } } + /** + * Saves PDF report to given location. + * + * @param htmlContent The string, containing report in HTML format. + * @param filePath The path to expected pdf report file. + */ + public static void generatePdfFromHtml(String htmlContent, String filePath) { + String report = + htmlContent + .replaceAll(" class=\"panel\"", "") + .replaceAll("", "") + .replaceAll("", "") + .replaceAll("body [\\s\\S]*?}", ""); + try (FileOutputStream os = new FileOutputStream(filePath)) { + PdfRendererBuilder builder = new PdfRendererBuilder(); + builder.withHtmlContent(report, new File(filePath).toURI().toString()) + // Size for the standard A4 landscape page + .useDefaultPageSize(11.7f, 8.3f, BaseRendererBuilder.PageSizeUnits.INCHES) + .toStream(os) + .run(); + log.info("LPVS report saved to: " + filePath); + } catch (IOException ex) { + log.error("Error during saving PDF report: " + ex.getMessage()); + } + } + /** * Generates a comment to the pull request for publication to the VCS. * @@ -508,12 +533,14 @@ private void addBlockOfTableForLicenseTypeMD( */ private String generateLicenseConflictsTableHTML(List> conflicts) { StringBuilder htmlBuilder = new StringBuilder(); - htmlBuilder.append(""); + htmlBuilder.append("
").append(""); htmlBuilder .append("") .append("") .append("") - .append(""); + .append("") + .append("") + .append(""); for (LPVSConflict conflict : conflicts) { htmlBuilder @@ -528,7 +555,7 @@ private String generateLicenseConflictsTableHTML(List") .append(""); } - htmlBuilder.append("
ConflictExplanation
"); + htmlBuilder.append("").append(""); return htmlBuilder.toString(); } @@ -559,8 +586,9 @@ private String getExplanationForLicenseConflict(String lic1, String lic2) { private String generateLicenseTableHTML( Map> detectedLicenseInfo, LPVSQueue webhookConfig, LPVSVcs vcs) { StringBuilder htmlBuilder = new StringBuilder(); - htmlBuilder.append(""); htmlBuilder + .append("
") + .append("") .append("") .append("") .append("") @@ -570,7 +598,10 @@ private String generateLicenseTableHTML( .append("") .append("") .append("") - .append(""); + .append("") + .append("") + .append(""); + // Prohibited licenses addBlockOfTableForLicenseTypeHTML( htmlBuilder, detectedLicenseInfo, prohibited, webhookConfig, vcs); @@ -584,7 +615,7 @@ private String generateLicenseTableHTML( addBlockOfTableForLicenseTypeHTML( htmlBuilder, detectedLicenseInfo, permitted, webhookConfig, vcs); - htmlBuilder.append("
License Type / ExplanationLicense SPDX IDComponent File PathMatched LinesMatch Value
"); + htmlBuilder.append("").append(""); return htmlBuilder.toString(); } diff --git a/src/main/java/com/lpvs/service/scan/LPVSDetectService.java b/src/main/java/com/lpvs/service/scan/LPVSDetectService.java index f9c14836..92937843 100644 --- a/src/main/java/com/lpvs/service/scan/LPVSDetectService.java +++ b/src/main/java/com/lpvs/service/scan/LPVSDetectService.java @@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j; +import static com.lpvs.entity.report.LPVSReportBuilder.generatePdfFromHtml; import static com.lpvs.entity.report.LPVSReportBuilder.saveHTMLToFile; /** @@ -85,6 +86,12 @@ public class LPVSDetectService { @Value("${build.html.report:}") private String htmlReport; + /** + * Optional parameter to save pdf report to specified location. + */ + @Value("${build.pdf.report:}") + private String pdfReport; + /** * Spring application context. */ @@ -192,20 +199,19 @@ public void runSingleScan() { // Report generation // 1. HTML format - if (generateReport && !StringUtils.isBlank(htmlReport)) { - File report = new File(HtmlUtils.htmlEscape(htmlReport)); - String folderPath = report.getParent(); - if (folderPath == null) { - folderPath = "."; + if (generateReport + && (!StringUtils.isBlank(htmlReport) || !StringUtils.isBlank(pdfReport))) { + String reportContent = + reportBuilder.generateHtmlReportSingleScan( + path, scanResult, detectedConflicts, null, null); + if (!StringUtils.isBlank(htmlReport) && checkFolderForReport(htmlReport)) { + saveHTMLToFile( + reportContent, + new File(HtmlUtils.htmlEscape(htmlReport)).getAbsolutePath()); } - File folder = new File(folderPath); - if (folder.exists() && folder.isDirectory()) { - String reportFile = - reportBuilder.generateHtmlReportSingleScan( - path, scanResult, detectedConflicts, null, null); - saveHTMLToFile(reportFile, report.getAbsolutePath()); - } else { - log.error("Error: The parent directory '" + folder.getPath() + "' does not exist."); + if (!StringUtils.isBlank(pdfReport) && checkFolderForReport(pdfReport)) { + generatePdfFromHtml( + reportContent, new File(HtmlUtils.htmlEscape(pdfReport)).getAbsolutePath()); } SpringApplication.exit(ctx, () -> 0); } else if (generateReport) { @@ -219,6 +225,25 @@ public void runSingleScan() { } } + /** + * Checks if the folder exists where the report will be saved. + * @param reportPath the path to the report file + * @return {@code true} if the folder exists and is a directory, otherwise {@code false} + */ + private boolean checkFolderForReport(String reportPath) { + File report = new File(HtmlUtils.htmlEscape(reportPath)); + String folderPath = report.getParent(); + if (folderPath == null) { + folderPath = "."; + } + File folder = new File(folderPath); + if (folder.exists() && folder.isDirectory()) { + return true; + } + log.error("Error: The parent directory '" + folder.getPath() + "' does not exist."); + return false; + } + /** * Creates a new LPVSQueue object with default values for a local scan. * diff --git a/src/main/resources/templates/report_single_scan.html b/src/main/resources/templates/report_single_scan.html index 63ecd5f9..1aa429c8 100644 --- a/src/main/resources/templates/report_single_scan.html +++ b/src/main/resources/templates/report_single_scan.html @@ -1,9 +1,9 @@ - - - + + + title @@ -55,15 +55,23 @@ transition: max-height 0.2s ease-out; } table { - border-collapse: separate; + border-collapse: collapse; width: 100%; padding: 20px; + table-layout: fixed; } table td, table th { padding: 8px; text-align: left; border: 1px solid black; width: auto; + word-wrap: break-words; + } + table thead { + display: table-header-group; + } + table tbody { + display: table-row-group; } .mt-30 { margin-top: 30px; @@ -87,7 +95,7 @@

Report - License Pre-Validation Service ( Used scanner: usedScanner
Version of LPVS: lpvsVersion
-
+

Detected Licenses

Potential license issues detected: licenseDetected @@ -107,7 +115,7 @@

Detected Licenses

-
+

Detected License Conflicts

Potential license conflict(s) detected: licenseConflicts diff --git a/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java b/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java index f7f1d5d6..b1ffab91 100644 --- a/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java +++ b/src/test/java/com/lpvs/entity/report/LPVSReportBuilderTest.java @@ -30,6 +30,7 @@ import java.text.SimpleDateFormat; import java.util.*; +import static com.lpvs.entity.report.LPVSReportBuilder.generatePdfFromHtml; import static com.lpvs.entity.report.LPVSReportBuilder.saveHTMLToFile; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; @@ -297,11 +298,27 @@ void testSaveHTMLToFile() throws IOException { } @Test - void saveHTMLToFile_CatchBlock_N() { + void testSavePDFToFile() throws IOException { + String htmlContent = "

Test HTML

"; + String filePath = "test-output.pdf"; + + generatePdfFromHtml(htmlContent, filePath); + + Path path = Paths.get(filePath); + assertTrue(Files.exists(path)); + + // Clean up: delete the created file + Files.deleteIfExists(path); + } + + @Test + void saveHTMLandPDFtoFile_CatchBlock_N() { String htmlContent = ""; Path invalidPath = tempDir.resolve("invalid/path/with/special/characters"); saveHTMLToFile(htmlContent, invalidPath.toString()); assertFalse(Files.exists(invalidPath)); + generatePdfFromHtml(htmlContent, invalidPath.toString()); + assertFalse(Files.exists(invalidPath)); } private LPVSFile createSampleFile( diff --git a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java index d7c0f169..b65a6420 100644 --- a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java @@ -2169,7 +2169,7 @@ class TestCommentResults__ProhibitedPresentConflictsPresent { + "
\n" + "Detailed description of detected licenses\n" + "\n" - + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PROHIBITED / This license prohibits the use of the licensed code in certain contexts, such as commercial software development.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 15%
\n" + + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PROHIBITED / This license prohibits the use of the licensed code in certain contexts, such as commercial software development.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 15%
\n" + "
\n" + "\n" + "**Detected License Conflicts:**\n" @@ -2179,7 +2179,7 @@ class TestCommentResults__ProhibitedPresentConflictsPresent { + "
\n" + "Detailed description of detected license conflicts\n" + "\n" - + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + "
\n" + "\n"; @@ -2457,7 +2457,7 @@ class TestCommentResults__ProhibitedPresentConflictsPresentWithHubLink { + "
\n" + "Detailed description of detected licenses\n" + "\n" - + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PROHIBITED / This license prohibits the use of the licensed code in certain contexts, such as commercial software development.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 15%
\n" + + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PROHIBITED / This license prohibits the use of the licensed code in certain contexts, such as commercial software development.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 15%
\n" + "
\n" + "\n" + "**Detected License Conflicts:**\n" @@ -2467,7 +2467,7 @@ class TestCommentResults__ProhibitedPresentConflictsPresentWithHubLink { + "
\n" + "Detailed description of detected license conflicts\n" + "\n" - + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + "
\n" + "\n\n\n" + "######

Check the validation details on the [website](http://test.com)

"; @@ -2672,7 +2672,7 @@ class TestCommentResults__EmptyPresentConflictsPresent { + "
\n" + "Detailed description of detected licenses\n" + "\n" - + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PERMITTED / This license permits free usage, modification, and distribution of the licensed code without any restrictions.MITvendor1 / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javaversion_1src/main/java/com/lpvs/service/LPVSGitHubService.java1-6 30%
\n" + + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PERMITTED / This license permits free usage, modification, and distribution of the licensed code without any restrictions.MITvendor1 / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javaversion_1src/main/java/com/lpvs/service/LPVSGitHubService.java1-6 30%
\n" + "
\n" + "\n" + "**Detected License Conflicts:**\n" @@ -2682,7 +2682,7 @@ class TestCommentResults__EmptyPresentConflictsPresent { + "
\n" + "Detailed description of detected license conflicts\n" + "\n" - + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + "
\n" + "\n"; @@ -3004,7 +3004,7 @@ class TestCommentResults__UnreviewedPresentConflictsPresent { + "
\n" + "Detailed description of detected licenses\n" + "\n" - + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
UNREVIEWED / This license has not been reviewed thoroughly and may contain unknown risks or limitations. It is recommended to review these licenses carefully before using the licensed code.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 50%
\n" + + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
UNREVIEWED / This license has not been reviewed thoroughly and may contain unknown risks or limitations. It is recommended to review these licenses carefully before using the licensed code.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 50%
\n" + "
\n" + "\n" + "**Detected License Conflicts:**\n" @@ -3014,7 +3014,7 @@ class TestCommentResults__UnreviewedPresentConflictsPresent { + "
\n" + "Detailed description of detected license conflicts\n" + "\n" - + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + "
\n" + "\n"; @@ -3338,7 +3338,7 @@ class TestCommentResults__RestrictedPresentConflictsPresent { + "
\n" + "Detailed description of detected licenses\n" + "\n" - + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
RESTRICTED / This license required compliance with specific obligations. It is crucial to carefully review and adhere to these obligations before using the licensed code.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 40%
\n" + + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
RESTRICTED / This license required compliance with specific obligations. It is crucial to carefully review and adhere to these obligations before using the licensed code.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 40%
\n" + "
\n" + "\n" + "**Detected License Conflicts:**\n" @@ -3348,7 +3348,7 @@ class TestCommentResults__RestrictedPresentConflictsPresent { + "
\n" + "Detailed description of detected license conflicts\n" + "\n" - + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + + "
ConflictExplanation
MIT and Apache-1.0These two licenses are incompatible due to their conflicting terms and conditions. It is recommended to resolve this conflict by choosing either MIT or Apache-1.0 for the affected components.
\n" + "
\n" + "\n"; @@ -3656,7 +3656,7 @@ class TestCommentResults__ProhibitedAbsentConflictsAbsent { + "
\n" + "Detailed description of detected licenses\n" + "\n" - + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PERMITTED / This license permits free usage, modification, and distribution of the licensed code without any restrictions.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 10%
\n" + + "
License Type / ExplanationLicense SPDX IDVendor / ComponentRepository File PathComponent VersionComponent File PathMatched LinesMatch Value
PERMITTED / This license permits free usage, modification, and distribution of the licensed code without any restrictions.MITnull / LPVS::Servicessrc/main/java/com/lpvs/service/LPVSGitHubService.javanullsrc/main/java/com/lpvs/service/LPVSGitHubService.java1-6 10%
\n" + "
\n" + "\n" + "**Detected License Conflicts:**\n" diff --git a/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java index bfd07d6c..d2f27ebc 100644 --- a/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java +++ b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java @@ -298,12 +298,14 @@ void testRunOneScan_PullRequest_Branch2() setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); setPrivateField(detectService, "htmlReport", null); + setPrivateField(detectService, "pdfReport", null); setPrivateField(detectService, "ctx", mockApplicationContext); setPrivateField(detectService, "scanService", scanoss_mock); assertDoesNotThrow(() -> detectService.runSingleScan()); setPrivateField(detectService, "htmlReport", ""); + setPrivateField(detectService, "pdfReport", ""); assertDoesNotThrow(() -> detectService.runSingleScan()); } @@ -328,6 +330,7 @@ void testRunOneScan_Branch3() setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); setPrivateField(detectService, "htmlReport", "build"); + setPrivateField(detectService, "pdfReport", "build.pdf"); setPrivateField(detectService, "ctx", mockApplicationContext); setPrivateField(detectService, "scanService", scanoss_mock); @@ -360,6 +363,7 @@ void testRunOneScan_Branch3() assertDoesNotThrow(() -> detectService.runSingleScan()); deleteFile("build"); + deleteFile("build.pdf"); } @Test @@ -424,6 +428,7 @@ void testRunOneScan_LocalFiles_WithHtmlReport() setPrivateField(detectService, "ctx", mockApplicationContext); setPrivateField(detectService, "scanService", scanoss_mock); setPrivateField(detectService, "htmlReport", "report/test.html"); + setPrivateField(detectService, "pdfReport", ""); new File("report").mkdir(); @@ -522,7 +527,7 @@ void testRunOneScan_TriggerNotNull() throws Exception { List> expected = List.of(conflict_1, conflict_1); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "htmlReport", "report/test.html"); + setPrivateField(detectService, "pdfReport", "report/test.pdf"); setPrivateField(detectService, "ctx", mockApplicationContext); setPrivateField(detectService, "scanService", scanoss_mock); @@ -568,6 +573,7 @@ void testRunOneScan_TriggerNotNull_Branch2() throws Exception { setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); setPrivateField(detectService, "htmlReport", "report/test.html"); + setPrivateField(detectService, "pdfReport", "report/test.pdf"); setPrivateField(detectService, "ctx", mockApplicationContext); setPrivateField(detectService, "scanService", scanoss_mock); @@ -657,7 +663,8 @@ void testRunOneScan_TriggerNotNull_NoDirectory() throws Exception { List> expected = List.of(conflict_1, conflict_1); setPrivateField(detectService, "trigger", "github/owner/repo/branch/123"); - setPrivateField(detectService, "htmlReport", "report/test.html"); + setPrivateField(detectService, "htmlReport", ""); + setPrivateField(detectService, "pdfReport", "report/test.pdf"); setPrivateField(detectService, "ctx", mockApplicationContext); setPrivateField(detectService, "scanService", scanoss_mock);