From dccafc6620b232c2483c51a010b60612d9bb77bc Mon Sep 17 00:00:00 2001 From: Oleg Kopysov Date: Mon, 29 Jul 2024 16:09:20 +0300 Subject: [PATCH] refactor: Group artifacts to `LPVS` folder, apply small fixes (#557) Signed-off-by: Oleg Kopysov --- .gitignore | 9 ++---- README.md | 1 - .../service/LPVSQueueProcessorService.java | 2 +- .../lpvs/service/scan/LPVSDetectService.java | 6 ++-- src/main/java/com/lpvs/util/LPVSFileUtil.java | 10 ++++++- .../lpvs/service/LPVSGitHubServiceTest.java | 12 +++++--- .../lpvs/service/LPVSQueueServiceTest.java | 6 ++-- .../service/scan/LPVSDetectServiceTest.java | 28 +++++++++---------- .../scanner/LPVSScanossDetectServiceTest.java | 12 ++++++-- .../java/com/lpvs/util/LPVSFileUtilTest.java | 6 ++++ 10 files changed, 55 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index f6bc1906..68b3286c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,11 +25,6 @@ hs_err_pid* src/main/resources/.idea/* .idea/* target/ -Projects/ +LPVS/Projects/ +LPVS/Results/ *.iml - -# DB storage by default -mysql-lpvs-data/ - -# Run results -RESULTS/ diff --git a/README.md b/README.md index 61aed38b..fa198c9d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ [![LICENSE](https://img.shields.io/github/license/samsung/lpvs.svg)](https://github.com/Samsung/LPVS/blob/main/LICENSE) [![codecov](https://codecov.io/gh/Samsung/LPVS/graph/badge.svg?token=XTD749ITNF)](https://codecov.io/gh/Samsung/LPVS) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7127519.svg)](https://doi.org/10.5281/zenodo.7127519) -[![Project Map](https://sourcespy.com/shield.svg)](https://sourcespy.com/github/samsunglpvs/) ## Introduction [Open-source code](https://en.wikipedia.org/wiki/Open-source_software) (that is a software that is freely available for use, study, modification, and distribution) must meet conditions of the respective license(s) of all of its dependencies. Miscompliance may lead to legal disputes, fines, obligation to disclose intellectual property, as well as reputational damage. diff --git a/src/main/java/com/lpvs/service/LPVSQueueProcessorService.java b/src/main/java/com/lpvs/service/LPVSQueueProcessorService.java index cf272cb2..4008e053 100644 --- a/src/main/java/com/lpvs/service/LPVSQueueProcessorService.java +++ b/src/main/java/com/lpvs/service/LPVSQueueProcessorService.java @@ -56,7 +56,7 @@ private void queueProcessor() throws Exception { queueService.checkForQueue(); // Process LPVSQueue elements until the trigger is set. - while (trigger == null || trigger.equals("")) { + while (trigger == null || trigger.isEmpty()) { // Get the first element from the LPVSQueue. LPVSQueue webhookConfig = queueService.getQueueFirstElement(); log.info("PROCESS Webhook id = " + webhookConfig.getId()); diff --git a/src/main/java/com/lpvs/service/scan/LPVSDetectService.java b/src/main/java/com/lpvs/service/scan/LPVSDetectService.java index 59462dc6..7fa3e9ae 100644 --- a/src/main/java/com/lpvs/service/scan/LPVSDetectService.java +++ b/src/main/java/com/lpvs/service/scan/LPVSDetectService.java @@ -104,8 +104,8 @@ public LPVSDetectService( * Event listener method triggered when the application is ready, runs a single license scan if triggered. */ @EventListener(ApplicationReadyEvent.class) - public void runOneScan() { - if (trigger != null && !HtmlUtils.htmlEscape(trigger).equals("")) { + public void runSingleScan() { + if (trigger != null && !HtmlUtils.htmlEscape(trigger).isEmpty()) { log.info("Triggered single scan operation"); try { licenseService.reloadFromTables(); @@ -119,7 +119,7 @@ public void runOneScan() { List> detectedConflicts = licenseService.findConflicts(webhookConfig, scanResult); - if (htmlReport != null && !HtmlUtils.htmlEscape(htmlReport).equals("")) { + if (htmlReport != null && !HtmlUtils.htmlEscape(htmlReport).isEmpty()) { Path buildReportPath = Paths.get(htmlReport); Path parentDirectory = buildReportPath.getParent(); diff --git a/src/main/java/com/lpvs/util/LPVSFileUtil.java b/src/main/java/com/lpvs/util/LPVSFileUtil.java index a8389d9a..06d4b7ad 100644 --- a/src/main/java/com/lpvs/util/LPVSFileUtil.java +++ b/src/main/java/com/lpvs/util/LPVSFileUtil.java @@ -145,8 +145,10 @@ public static void deleteIfExists(String path) { */ public static String getLocalDirectoryPath(LPVSQueue webhookConfig) { if (webhookConfig.getHeadCommitSHA() == null - || webhookConfig.getHeadCommitSHA().equals("")) { + || webhookConfig.getHeadCommitSHA().isEmpty()) { return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Projects" + File.separator @@ -155,6 +157,8 @@ public static String getLocalDirectoryPath(LPVSQueue webhookConfig) { + LPVSPayloadUtil.getPullRequestId(webhookConfig); } else { return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Projects" + File.separator @@ -180,6 +184,8 @@ public static String getScanResultsJsonFilePath(LPVSQueue webhookConfig) { } return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Results" + File.separator @@ -197,6 +203,8 @@ public static String getScanResultsJsonFilePath(LPVSQueue webhookConfig) { */ public static String getScanResultsDirectoryPath(LPVSQueue webhookConfig) { return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Results" + File.separator diff --git a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java index f3f9a720..14b054cc 100644 --- a/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java @@ -195,7 +195,8 @@ public PagedIterator _iterator(int i) { GHPullRequest mocked_pr_2; final String url_pr_1 = "https://github.com/Samsung/LPVS/pull/18"; final String url_pr_2 = "https://github.com/Samsung/LPVS/pull/19"; - final String githubFiles = "Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; + final String githubFiles = + "LPVS/Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; final String commit_sha = "895337e89ae103ff2d18c9e0d93709f743226afa"; @BeforeEach @@ -332,7 +333,8 @@ public PagedIterator _iterator(int i) { final String url_pr_2 = "https://github.com/Samsung/LPVS/pull/19"; final String repo_org = "Samsung"; final String repo_name = "LPVS"; - final String githubFiles = "Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; + final String githubFiles = + "LPVS/Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; final String commit_sha = "895337e89ae103ff2d18c9e0d93709f743226afa"; @BeforeEach @@ -479,7 +481,8 @@ public PagedIterator _iterator(int i) { final String url_pr_2 = "https://github.com/Samsung/LPVS/pull/19"; final String repo_org = "Samsung"; final String repo_name = "LPVS"; - final String githubFiles = "Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; + final String githubFiles = + "LPVS/Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; final String commit_sha = "895337e89ae103ff2d18c9e0d93709f743226afa"; @BeforeEach @@ -1052,7 +1055,8 @@ public PagedIterator _iterator(int i) { final String repo_url = "https://github.com/Samsung/LPVS"; final String repo_org = "Samsung"; final String repo_name = "LPVS"; - final String githubFiles = "Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; + final String githubFiles = + "LPVS/Projects/Samsung/LPVS/895337e89ae103ff2d18c9e0d93709f743226afa"; final String commit_sha = "895337e89ae103ff2d18c9e0d93709f743226afa"; @BeforeEach diff --git a/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java b/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java index 302295fa..48a1a964 100644 --- a/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java +++ b/src/test/java/com/lpvs/service/LPVSQueueServiceTest.java @@ -176,15 +176,15 @@ public void testProcessWebHook__NoPRDownloaded() throws Exception { // case DeletionAbsent static String filePathTestNoDeletion = System.getProperty("user.dir") - + "/Projects/Samsung/LPVS/3c688f5caa42b936cd6bea04c1dc3f732364250b"; + + "/LPVS/Projects/Samsung/LPVS/3c688f5caa42b936cd6bea04c1dc3f732364250b"; // case DeletionPresent static String filePathTestWithDeletion = System.getProperty("user.dir") - + "/Projects/Samsung/LPVS/3c688f5caa42b936cd6bea04c1dc3f732364250b"; + + "/LPVS/Projects/Samsung/LPVS/3c688f5caa42b936cd6bea04c1dc3f732364250b"; static String filePathTestWithDeletionTruncated = System.getProperty("user.dir") - + "/Projects/Samsung/LPVS/3c688f5caa42b936cd6bea04c1dc3f732364250b"; + + "/LPVS/Projects/Samsung/LPVS/3c688f5caa42b936cd6bea04c1dc3f732364250b"; private Path tempFolderPath; diff --git a/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java index 3f51f05c..654ad808 100644 --- a/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java +++ b/src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java @@ -131,11 +131,11 @@ void testRunOneScanWithNullTrigger() throws NoSuchFieldException, IllegalAccessE setPrivateField(lpvsDetectService, "trigger", null); - assertDoesNotThrow(() -> lpvsDetectService.runOneScan()); + assertDoesNotThrow(() -> lpvsDetectService.runSingleScan()); setPrivateField(lpvsDetectService, "trigger", ""); - assertDoesNotThrow(() -> lpvsDetectService.runOneScan()); + assertDoesNotThrow(() -> lpvsDetectService.runSingleScan()); } @Test @@ -149,7 +149,7 @@ void testRunOneScan_Default() throws NoSuchFieldException, IllegalAccessExceptio setPrivateField(lpvsDetectService, "trigger", "fake-trigger-value"); setPrivateField(lpvsDetectService, "ctx", mockApplicationContext); - assertDoesNotThrow(() -> lpvsDetectService.runOneScan()); + assertDoesNotThrow(() -> lpvsDetectService.runSingleScan()); } @Test @@ -184,11 +184,11 @@ void testRunOneScan_Branch2() setPrivateField(detectService, "htmlReport", null); setPrivateField(detectService, "ctx", mockApplicationContext); - detectService.runOneScan(); + detectService.runSingleScan(); setPrivateField(detectService, "htmlReport", ""); - detectService.runOneScan(); + detectService.runSingleScan(); } @Test @@ -223,9 +223,9 @@ void testRunOneScan_Branch3() String expectedPullRequestUrl = "https://example.com/pull/1"; when(mockPullRequest.getHtmlUrl()).thenReturn(new URL(expectedPullRequestUrl)); - detectService.runOneScan(); + detectService.runSingleScan(); - assertDoesNotThrow(() -> detectService.runOneScan()); + assertDoesNotThrow(() -> detectService.runSingleScan()); } @Test @@ -235,7 +235,7 @@ void testRunOneScan_trigerInternalQueueException() setPrivateField(detectService, "trigger", "fake-trigger-value"); setPrivateField(detectService, "ctx", mockApplicationContext); - assertDoesNotThrow(() -> detectService.runOneScan()); + assertDoesNotThrow(() -> detectService.runSingleScan()); } @Test @@ -265,9 +265,9 @@ void testRunOneScan_TriggerNotNull() throws Exception { String expectedPullRequestUrl = "https://example.com/pull/1"; when(mockPullRequest.getHtmlUrl()).thenReturn(new URL(expectedPullRequestUrl)); - detectService.runOneScan(); + detectService.runSingleScan(); - assertDoesNotThrow(() -> detectService.runOneScan()); + assertDoesNotThrow(() -> detectService.runSingleScan()); } @Test @@ -297,9 +297,9 @@ void testRunOneScan_TriggerNotNull_Branch2() throws Exception { String expectedPullRequestUrl = "https://example.com/pull/1"; when(mockPullRequest.getHtmlUrl()).thenReturn(new URL(expectedPullRequestUrl)); - detectService.runOneScan(); + detectService.runSingleScan(); - assertDoesNotThrow(() -> detectService.runOneScan()); + assertDoesNotThrow(() -> detectService.runSingleScan()); } @Test @@ -328,9 +328,9 @@ void testRunOneScan_TriggerNotNull_Branch3() throws Exception { String expectedPullRequestUrl = "https://example.com/pull/1"; when(mockRepository.getHtmlUrl()).thenReturn(new URL(expectedPullRequestUrl)); - detectService.runOneScan(); + detectService.runSingleScan(); - assertDoesNotThrow(() -> detectService.runOneScan()); + assertDoesNotThrow(() -> detectService.runSingleScan()); } @Test diff --git a/src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java b/src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java index 1c291a74..f33b86c0 100644 --- a/src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java +++ b/src/test/java/com/lpvs/service/scan/scanner/LPVSScanossDetectServiceTest.java @@ -52,7 +52,13 @@ public void setUp() throws URISyntaxException, IOException { MockitoAnnotations.openMocks(this); String resourcePath = "A_B.json"; String destinationPath = - System.getProperty("user.home") + File.separator + "Results" + File.separator + "C"; + System.getProperty("user.home") + + File.separator + + "LPVS" + + File.separator + + "Results" + + File.separator + + "C"; if (!(new File(destinationPath).exists())) { new File(destinationPath).mkdirs(); } @@ -69,8 +75,8 @@ public void setUp() throws URISyntaxException, IOException { @AfterEach public void tearDown() { - if ((new File(System.getProperty("user.home") + File.separator + "Results")).exists()) { - new File(System.getProperty("user.home") + File.separator + "Results").delete(); + if ((new File(System.getProperty("user.home") + File.separator + "LPVS")).exists()) { + new File(System.getProperty("user.home") + File.separator + "LPVS").delete(); } } diff --git a/src/test/java/com/lpvs/util/LPVSFileUtilTest.java b/src/test/java/com/lpvs/util/LPVSFileUtilTest.java index d79be4ac..f8abea27 100644 --- a/src/test/java/com/lpvs/util/LPVSFileUtilTest.java +++ b/src/test/java/com/lpvs/util/LPVSFileUtilTest.java @@ -160,6 +160,8 @@ public void testSaveFileWithEmptyPatchedLines() { private static String getExpectedProjectsPathWithCommitSHA() { return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Projects" + File.separator @@ -170,6 +172,8 @@ private static String getExpectedProjectsPathWithCommitSHA() { private static String getExpectedProjectsPathWithPullRequestId() { return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Projects" + File.separator @@ -180,6 +184,8 @@ private static String getExpectedProjectsPathWithPullRequestId() { private static String getExpectedResultsPath() { return System.getProperty("user.home") + + File.separator + + "LPVS" + File.separator + "Results" + File.separator