Skip to content

Commit

Permalink
refactor: Group artifacts to LPVS folder, apply small fixes (#557)
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kopysov <[email protected]>
  • Loading branch information
o-kopysov authored Jul 29, 2024
1 parent af27e74 commit dccafc6
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 37 deletions.
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/lpvs/service/scan/LPVSDetectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -119,7 +119,7 @@ public void runOneScan() {
List<LPVSLicenseService.Conflict<String, String>> 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();

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/lpvs/util/LPVSFileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -180,6 +184,8 @@ public static String getScanResultsJsonFilePath(LPVSQueue webhookConfig) {
}

return System.getProperty("user.home")
+ File.separator
+ "LPVS"
+ File.separator
+ "Results"
+ File.separator
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/test/java/com/lpvs/service/LPVSGitHubServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ public PagedIterator<GHPullRequestFileDetail> _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
Expand Down Expand Up @@ -332,7 +333,8 @@ public PagedIterator<GHPullRequestFileDetail> _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
Expand Down Expand Up @@ -479,7 +481,8 @@ public PagedIterator<GHPullRequestFileDetail> _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
Expand Down Expand Up @@ -1052,7 +1055,8 @@ public PagedIterator<GHPullRequestFileDetail> _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
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/lpvs/service/LPVSQueueServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
28 changes: 14 additions & 14 deletions src/test/java/com/lpvs/service/scan/LPVSDetectServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -235,7 +235,7 @@ void testRunOneScan_trigerInternalQueueException()
setPrivateField(detectService, "trigger", "fake-trigger-value");
setPrivateField(detectService, "ctx", mockApplicationContext);

assertDoesNotThrow(() -> detectService.runOneScan());
assertDoesNotThrow(() -> detectService.runSingleScan());
}

@Test
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/lpvs/util/LPVSFileUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public void testSaveFileWithEmptyPatchedLines() {

private static String getExpectedProjectsPathWithCommitSHA() {
return System.getProperty("user.home")
+ File.separator
+ "LPVS"
+ File.separator
+ "Projects"
+ File.separator
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dccafc6

Please sign in to comment.