Skip to content

Commit

Permalink
Fix Scanners execution
Browse files Browse the repository at this point in the history
  • Loading branch information
talarian1 committed Sep 10, 2023
1 parent 9b1092e commit 621654f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ protected List<JFrogSecurityWarning> execute(ScanConfig.Builder inputFileBuilder
inputFileBuilder.scanType(scanType);
ScanConfig inputParams = inputFileBuilder.Build();
args = new ArrayList<>(args);
inputFile = newConfigFormat ? createTempRunInputFile(new NewScanConfig(inputParams)) : createTempRunInputFile(new ScansConfig(List.of(inputParams)));
inputFile = newConfigFormat ? createTempRunInputFile(new NewScansConfig(new NewScanConfig(inputParams))) : createTempRunInputFile(new ScansConfig(List.of(inputParams)));
args.add(inputFile.toString());
if (newConfigFormat) {
args.add(outputFilePath.toString());
}

Logger log = Logger.getInstance();
// The following logging is done outside the commandExecutor because the commandExecutor log level is set to INFO.
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/jfrog/ide/idea/scan/ScanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.jfrog.xray.client.impl.XrayClient;
import com.jfrog.xray.client.impl.util.JFrogInactiveEnvironmentException;
import com.jfrog.xray.client.services.system.Version;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -108,7 +109,7 @@ public void startScan() {
} catch (JFrogInactiveEnvironmentException e) {
handleJfrogInactiveEnvironment(e.getRedirectUrl());
} catch (IOException | RuntimeException | InterruptedException e) {
logError(Logger.getInstance(), "", e, true);
logError(Logger.getInstance(), ExceptionUtils.getRootCauseMessage(e), e, true);
} finally {
executor.shutdownNow();
if (isScanCompleted.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ private void sourceCodeScanAndUpdate(ProgressIndicator indicator, Runnable check
JFrogApplicationsConfig projectConfig = parseJFrogApplicationsConfig();

if (projectConfig != null) {
for (ModuleConfig moduleConfig : projectConfig.getModules())
for (ModuleConfig moduleConfig : projectConfig.getModules()) {
scan(moduleConfig, indicator, checkCanceled, log);
}
} else {
scan(null, indicator, checkCanceled, log);
}
scan(null, indicator, checkCanceled, log);
}

private void scan(ModuleConfig moduleConfig, ProgressIndicator indicator, Runnable checkCanceled, Logger log) {
Expand Down Expand Up @@ -216,18 +218,21 @@ private ScanConfig.Builder createBasicScannerInput(ModuleConfig config, ScannerC
// Scanner's working dirs (roots)
List<String> workingDirs = new ArrayList<>();
String projectBasePath = defaultIfEmpty(config.getSourceRoot(), getProjectBasePath(project).toAbsolutePath().toString());
if (scannerConfig != null && CollectionUtils.isEmpty(scannerConfig.getWorkingDirs())) {
if (scannerConfig != null && !CollectionUtils.isEmpty(scannerConfig.getWorkingDirs())) {
for (String workingDir : scannerConfig.getWorkingDirs()) {
workingDirs.add(Paths.get(projectBasePath).resolve(workingDir).toAbsolutePath().toString());
workingDirs.add(Paths.get(projectBasePath).resolve(workingDir).toString());
}
} else {
// Default: ".", the application's root directory.
workingDirs.add(projectBasePath);
}

// Module exclude patterns
List<String> skippedFolders = new ArrayList<>(config.getExcludePatterns());
if (scannerConfig != null) {
List<String> skippedFolders = new ArrayList<>();
if (config.getExcludePatterns() != null) {
skippedFolders.addAll(config.getExcludePatterns());
}
if (scannerConfig != null && scannerConfig.getExcludePatterns() != null) {
// Adds scanner specific exclude patterns if exists
skippedFolders.addAll(scannerConfig.getExcludePatterns());
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/jfrog/ide/idea/scan/data/ScanConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import com.jfrog.ide.common.nodes.subentities.SourceCodeScanType;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public class ScanConfig {
@JsonProperty("type")
private SourceCodeScanType scanType;

@JsonProperty("language")
private String language;
@JsonProperty("roots")
Expand Down Expand Up @@ -107,6 +107,10 @@ public static class Builder {
private List<String> excludedRules;

public Builder() {
roots = new ArrayList<>();
cves = new ArrayList<>();
skippedFolders = new ArrayList<>();
excludedRules = new ArrayList<>();
}

@SuppressWarnings("UnusedReturnValue")
Expand Down

0 comments on commit 621654f

Please sign in to comment.