com.synopsys.integration.blackduck.codelocation.signaturescanner.command.ScanCommandRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blackduck-common Show documentation
Show all versions of blackduck-common Show documentation
A library for using various capabilities of Black Duck, notably the REST API and signature scanning.
/**
* blackduck-common
*
* Copyright (c) 2019 Synopsys, Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.synopsys.integration.blackduck.codelocation.signaturescanner.command;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
import com.synopsys.integration.blackduck.exception.ScanFailedException;
import com.synopsys.integration.log.IntLogger;
import com.synopsys.integration.util.IntEnvironmentVariables;
import com.synopsys.integration.util.NoThreadExecutorService;
public class ScanCommandRunner {
private final IntLogger logger;
private final IntEnvironmentVariables intEnvironmentVariables;
private final ScanPathsUtility scanPathsUtility;
private final ExecutorService executorService;
/**
* @deprecated Please provide an ExecutorService - for no change, you can provide an instance of NoThreadExecutorService
*/
@Deprecated
public ScanCommandRunner(final IntLogger logger, final IntEnvironmentVariables intEnvironmentVariables, final ScanPathsUtility scanPathsUtility) {
this(logger, intEnvironmentVariables, scanPathsUtility, new NoThreadExecutorService());
}
public ScanCommandRunner(final IntLogger logger, final IntEnvironmentVariables intEnvironmentVariables, final ScanPathsUtility scanPathsUtility, final ExecutorService executorService) {
this.logger = logger;
this.intEnvironmentVariables = intEnvironmentVariables;
this.scanPathsUtility = scanPathsUtility;
this.executorService = executorService;
}
public List executeScans(final List scanCommands, final boolean cleanupOutput) throws ScanFailedException {
logger.info("Starting the Black Duck Signature Scan commands.");
final List scanCommandOutputs = executeCommands(scanCommands, cleanupOutput);
logger.info("Completed the Black Duck Signature Scan commands.");
return scanCommandOutputs;
}
private List executeCommands(final List scanCommands, final boolean cleanupOutput) throws ScanFailedException {
final List scanCommandOutputs = new ArrayList<>();
try {
final List callables = createCallables(scanCommands, cleanupOutput);
final List> submitted = new ArrayList<>();
for (final ScanCommandCallable callable : callables) {
submitted.add(executorService.submit(callable));
}
for (final Future future : submitted) {
final ScanCommandOutput scanCommandOutput = future.get();
if (scanCommandOutput != null) {
scanCommandOutputs.add(scanCommandOutput);
}
}
} catch (final Exception e) {
throw new ScanFailedException(String.format("Encountered a problem waiting for a scan to finish. %s", e.getMessage()), e);
}
return scanCommandOutputs;
}
private List createCallables(final List scanCommands, final boolean cleanupOutput) {
final List callables = scanCommands.stream().map(scanCommand -> new ScanCommandCallable(logger, scanPathsUtility, intEnvironmentVariables, scanCommand, cleanupOutput)).collect(Collectors.toList());
return callables;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy