Skip to content

Commit

Permalink
Merge pull request #404 from blackducksoftware/dev/dterry/IDETECT-389…
Browse files Browse the repository at this point in the history
…3-pass-no-persistence-mode-flag

add no persistent mode flag to scan CLI to support BOM_COMPARE modes for signature scans
  • Loading branch information
dterrybd authored Jul 5, 2023
2 parents 0c926c5 + 6de68c7 commit da3a2b3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public static ScanBatchBuilder newBuilder() {
private final ReducedPersistence reducedPersistence;
@Nullable
private final String correlationId;
private final String bomCompareMode;

public ScanBatch(File outputDirectory, boolean cleanupOutput, int scanMemoryInMegabytes, boolean dryRun, boolean debug, boolean verbose,
String scanCliOpts, String additionalScanArguments, BlackDuckOnlineProperties blackDuckOnlineProperties, IndividualFileMatching individualFileMatching, HttpUrl blackDuckUrl,
String blackDuckUsername, String blackDuckPassword, String blackDuckApiToken, ProxyInfo proxyInfo, boolean runInsecure, String projectName, String projectVersionName,
List<ScanTarget> scanTargets, boolean isRapid, ReducedPersistence reducedPersistence, @Nullable String correlationId) {
List<ScanTarget> scanTargets, boolean isRapid, ReducedPersistence reducedPersistence, @Nullable String correlationId, String bomCompareMode) {
this.outputDirectory = outputDirectory;
this.cleanupOutput = cleanupOutput;
this.scanMemoryInMegabytes = scanMemoryInMegabytes;
Expand All @@ -86,6 +87,7 @@ public ScanBatch(File outputDirectory, boolean cleanupOutput, int scanMemoryInMe
this.isRapid = isRapid;
this.reducedPersistence = reducedPersistence;
this.correlationId = correlationId;
this.bomCompareMode = bomCompareMode;
}

/**
Expand Down Expand Up @@ -126,7 +128,8 @@ private void addToScanCommands(File signatureScannerInstallDirectory, ScanPathsU
File commandOutputDirectory = scanTarget.determineCommandOutputDirectory(scanPathsUtility, outputDirectory);
ScanCommand scanCommand = new ScanCommand(signatureScannerInstallDirectory, commandOutputDirectory, commandDryRun, proxyInfo, scanCliOptsToUse, scanMemoryInMegabytes, commandScheme, commandHost,
blackDuckApiToken, blackDuckUsername, blackDuckPassword, commandPort, runInsecure, scanTarget.getCodeLocationName(), blackDuckOnlineProperties,
individualFileMatching, scanTarget.getExclusionPatterns(), additionalScanArguments, scanTarget.getPath(), verbose, debug, projectName, projectVersionName, isRapid, reducedPersistence, correlationId);
individualFileMatching, scanTarget.getExclusionPatterns(), additionalScanArguments, scanTarget.getPath(), verbose, debug, projectName, projectVersionName, isRapid, reducedPersistence, correlationId,
bomCompareMode);
scanCommands.add(scanCommand);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ public class ScanBatchBuilder extends IntegrationBuilder<ScanBatch> {
private String correlationId;

private List<ScanTarget> scanTargets = new ArrayList<>();

private String bomCompareMode;

@Override
protected ScanBatch buildWithoutValidation() {
BlackDuckOnlineProperties blackDuckOnlineProperties = new BlackDuckOnlineProperties(snippetMatching, uploadSource, licenseSearch, copyrightSearch);
return new ScanBatch(outputDirectory, cleanupOutput, scanMemoryInMegabytes, dryRun, debug, verbose, scanCliOpts, additionalScanArguments,
blackDuckOnlineProperties, individualFileMatching, blackDuckUrl, blackDuckUsername, blackDuckPassword, blackDuckApiToken, proxyInfo, alwaysTrustServerCertificate,
projectName, projectVersionName, scanTargets, isRapid, reducedPersistence, correlationId);
projectName, projectVersionName, scanTargets, isRapid, reducedPersistence, correlationId, bomCompareMode);
}

@Override
Expand Down Expand Up @@ -375,5 +377,9 @@ public ScanBatchBuilder correlationId(String correlationId) {
public String getCorrelationId() {
return correlationId;
}


public ScanBatchBuilder bomCompareMode(String bomCompareMode) {
this.bomCompareMode = bomCompareMode;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public class ScanCommand {
private final ReducedPersistence reducedPersistence;
@Nullable
private final String correlationId;
private final String bomCompareMode;

public ScanCommand(File signatureScannerInstallDirectory, File outputDirectory, boolean dryRun, ProxyInfo proxyInfo, String scanCliOpts, int scanMemoryInMegabytes, String scheme, String host, String blackDuckApiToken,
String blackDuckUsername, String blackDuckPassword, int port, boolean runInsecure, String name, BlackDuckOnlineProperties blackDuckOnlineProperties, IndividualFileMatching individualFileMatching, Set<String> excludePatterns,
String additionalScanArguments, String targetPath, boolean verbose, boolean debug, String projectName, String versionName, boolean isRapid,
ReducedPersistence reducedPersistence,
@Nullable String correlationId) {
@Nullable String correlationId, String bomCompareMode) {
this.signatureScannerInstallDirectory = signatureScannerInstallDirectory;
this.outputDirectory = outputDirectory;
this.dryRun = dryRun;
Expand All @@ -82,6 +83,7 @@ public ScanCommand(File signatureScannerInstallDirectory, File outputDirectory,
this.isRapid = isRapid;
this.reducedPersistence = reducedPersistence;
this.correlationId = correlationId;
this.bomCompareMode = bomCompareMode;
}

public List<String> createCommandForProcessBuilder(IntLogger logger, ScanPaths scannerPaths, String specificRunOutputDirectoryPath) throws IllegalArgumentException, IntegrationException {
Expand Down Expand Up @@ -138,6 +140,10 @@ public List<String> createCommandForProcessBuilder(IntLogger logger, ScanPaths s

if (isRapid) {
cmd.add("--no-persistence");

// --no-persistence-mode should never be used without --no-persistence so
// only set it in this block.
cmd.add("--no-persistence-mode=" + bomCompareMode);
}

populateReducedPersistence(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,30 @@ public void testDiscardUnmatchedFiles() throws IntegrationException {
List<String> commandList = createCommandList();
assertTrue(commandList.contains("--discard-unmatched-files"));
}

@Test
public void testNoPersistentModeSpecifiedWithRapidModeSpecified() throws IntegrationException {
scanBatchBuilder.rapid(true);
scanBatchBuilder.bomCompareMode("BOM_COMPARE_STRICT");
List<String> commandList = createCommandList();
assertTrue(commandList.contains("--no-persistence-mode=BOM_COMPARE_STRICT"));
}

@Test
public void testNoPersistentModeNotSpecified() throws IntegrationException {
scanBatchBuilder.rapid(false);
List<String> commandList = createCommandList();
assertFalse(commandList.contains("--no-persistence-mode=BOM_COMPARE_STRICT"));
}

@Test
public void testNoPersistentModeSpecifiedWithRapidModeNotSpecified() throws IntegrationException {
scanBatchBuilder.rapid(false);
scanBatchBuilder.bomCompareMode("BOM_COMPARE_STRICT");
List<String> commandList = createCommandList();
assertFalse(commandList.contains("--no-persistence-mode=BOM_COMPARE_STRICT"));
}

private void populateBuilder(ScanBatchBuilder scanBatchBuilder) {
try {
scanBatchBuilder.blackDuckUrl(new HttpUrl("http://fakeserver.com"));
Expand Down

0 comments on commit da3a2b3

Please sign in to comment.