Skip to content

Commit

Permalink
fix: Update unit tests and fix the build process
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Kopysov <o.kopysov@samsung.com>
  • Loading branch information
o-kopysov committed Aug 6, 2024
1 parent a0cada0 commit dc1381e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion doc/quick-start-guide-and-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ _LPVS_ is now built and running. You can create a new pull request or update an

Alternatively, you can perform a one-time scan on a specific pull request or local files using the single scan mode. Follow these steps:

4.2.1 Install and navigate to the target directory as described in step 4.1.1 and 4.1.2:
4.2.1 Install and navigate to the target directory as described in step 4.1.1 and 4.1.2:

```bash
mvn clean install
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/lpvs/service/LPVSLicenseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.lpvs.util.LPVSExitHandler;

import com.lpvs.util.LPVSPayloadUtil;
import io.micrometer.common.util.StringUtils;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -230,7 +231,7 @@ protected LPVSLicense findLicenseByName(String name) {
if (license.getLicenseName().equalsIgnoreCase(name)) {
return license;
}
if (license.getAlternativeNames() != null && !license.getAlternativeNames().isBlank()) {
if (!StringUtils.isBlank(license.getAlternativeNames())) {
String[] names = license.getAlternativeNames().split(",");
for (String n : names) {
if (n.trim().equalsIgnoreCase(name)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.lpvs.service;

import com.lpvs.entity.LPVSQueue;
import io.micrometer.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -62,7 +63,7 @@ protected void queueProcessor() throws Exception {
queueService.checkForQueue();

// Process LPVSQueue elements until the trigger is set.
while (trigger.isBlank() && localPath.isBlank()) {
while (StringUtils.isBlank(trigger) && StringUtils.isBlank(localPath)) {
// Get the first element from the LPVSQueue.
LPVSQueue webhookConfig = queueService.getQueueFirstElement();
log.info("PROCESS Webhook id = " + webhookConfig.getId());
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/lpvs/service/scan/LPVSDetectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.lpvs.service.LPVSGitHubService;
import com.lpvs.service.LPVSLicenseService;
import com.lpvs.util.LPVSFileUtil;
import io.micrometer.common.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -118,13 +119,13 @@ public void runSingleScan() {
List<LPVSLicenseService.Conflict<String, String>> detectedConflicts = null;

// Error case when both pull request scan and local files scan are set to true
if (!trigger.isBlank() && !localPath.isBlank()) {
if (!StringUtils.isBlank(trigger) && !StringUtils.isBlank(localPath)) {
log.error(
"Incorrect settings: both pull request scan and local files scan are set to true.");
SpringApplication.exit(ctx, () -> 0);

// Scan option - single pull request scan
} else if (trigger != null && !HtmlUtils.htmlEscape(trigger).isBlank()) {
} else if (!StringUtils.isBlank(trigger)) {
log.info("Triggered single scan of pull request.");
try {
licenseService.reloadFromTables();
Expand All @@ -144,10 +145,11 @@ public void runSingleScan() {
}

// Scan option - single scan of local file or folder
} else if (localPath != null && !HtmlUtils.htmlEscape(localPath).isEmpty()) {
} else if (!StringUtils.isBlank(localPath)) {
log.info("Triggered single scan of local file(s).");
try {
licenseService.reloadFromTables();
localPath = HtmlUtils.htmlEscape(localPath);
File localFile = new File(localPath);
if (localFile.exists()) {
// 1. Generate webhook config
Expand Down Expand Up @@ -176,8 +178,8 @@ public void runSingleScan() {

// Report generation
// 1. HTML format
if (generateReport && htmlReport != null && !HtmlUtils.htmlEscape(htmlReport).isEmpty()) {
File report = new File(htmlReport);
if (generateReport && !StringUtils.isBlank(htmlReport)) {
File report = new File(HtmlUtils.htmlEscape(htmlReport));
String folderPath = report.getParent();
if (folderPath == null) {
folderPath = ".";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/lpvs/util/LPVSFileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.extern.slf4j.Slf4j;
import org.kohsuke.github.GHPullRequestFileDetail;
import org.springframework.util.FileSystemUtils;
import org.springframework.web.util.HtmlUtils;
import io.micrometer.common.util.StringUtils;

import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -214,11 +216,10 @@ public static String getLocalDirectoryPath(LPVSQueue webhookConfig) {
*/
public static String getScanResultsJsonFilePath(LPVSQueue webhookConfig) {
String fileName = null;
if (webhookConfig.getHeadCommitSHA() == null
|| webhookConfig.getHeadCommitSHA().isBlank()) {
if (StringUtils.isBlank(webhookConfig.getHeadCommitSHA())) {
fileName = LPVSPayloadUtil.getPullRequestId(webhookConfig);
} else {
fileName = webhookConfig.getHeadCommitSHA();
fileName = HtmlUtils.htmlEscape(webhookConfig.getHeadCommitSHA());
}

return System.getProperty("user.home")
Expand Down

0 comments on commit dc1381e

Please sign in to comment.