use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class PolarisTool method runPolaris.
public void runPolaris(final IntLogger logger, File projectDirectory) throws DetectUserFriendlyException {
logger.info("Checking if Polaris can run.");
PolarisEnvironmentCheck polarisEnvironmentCheck = new PolarisEnvironmentCheck();
if (!polarisEnvironmentCheck.canRun(directoryManager.getUserHome())) {
logger.info("Polaris determined it should not run.");
logger.debug("Checked the following user directory: " + directoryManager.getUserHome().getAbsolutePath());
return;
}
logger.info("Polaris determined it should attempt to run.");
IntHttpClient restConnection = connectionManager.createUnauthenticatedRestConnection(PolarisDownloadUtility.DEFAULT_POLARIS_SERVER_URL);
CleanupZipExpander cleanupZipExpander = new CleanupZipExpander(logger);
File toolsDirectory = directoryManager.getPermanentDirectory();
PolarisDownloadUtility polarisDownloadUtility = new PolarisDownloadUtility(logger, restConnection, cleanupZipExpander, PolarisDownloadUtility.DEFAULT_POLARIS_SERVER_URL, toolsDirectory);
Optional<String> swipCliPath = polarisDownloadUtility.retrievePolarisCliExecutablePath();
if (swipCliPath.isPresent()) {
Map<String, String> environmentVariables = new HashMap<>();
environmentVariables.put("COVERITY_UNSUPPORTED", "1");
environmentVariables.put("SWIP_USER_INPUT_TIMEOUT_MINUTES", "1");
logger.info("Found polaris cli: " + swipCliPath.get());
List<String> arguments = new ArrayList<>();
arguments.add("analyze");
arguments.add("-w");
Executable swipExecutable = new Executable(projectDirectory, environmentVariables, swipCliPath.get(), arguments);
try {
ExecutableOutput output = executableRunner.execute(swipExecutable);
if (output.getReturnCode() == 0) {
eventSystem.publishEvent(Event.StatusSummary, new Status("POLARIS", StatusType.SUCCESS));
} else {
logger.error("Polaris returned a non-zero exit code.");
eventSystem.publishEvent(Event.StatusSummary, new Status("POLARIS", StatusType.FAILURE));
}
} catch (ExecutableRunnerException e) {
eventSystem.publishEvent(Event.StatusSummary, new Status("POLARIS", StatusType.FAILURE));
logger.error("Couldn't run the executable: " + e.getMessage());
}
} else {
logger.error("Check the logs - the Polaris CLI could not be found.");
}
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class BazelExternalIdGenerator method executeDependencyDetailsQuery.
private Optional<String> executeDependencyDetailsQuery(final BazelExternalIdExtractionFullRule xPathRule, final List<String> dependencyDetailsQueryArgs) {
ExecutableOutput dependencyDetailsXmlQueryResults = null;
try {
dependencyDetailsXmlQueryResults = executableRunner.executeQuietly(workspaceDir, bazelExe, dependencyDetailsQueryArgs);
} catch (ExecutableRunnerException e) {
logger.debug(String.format("Error executing bazel with args: %s: %s", xPathRule.getDependencyDetailsXmlQueryBazelCmdArguments(), e.getMessage()));
exceptionsGenerated.put(xPathRule, e);
return Optional.empty();
}
final int dependencyDetailsXmlQueryReturnCode = dependencyDetailsXmlQueryResults.getReturnCode();
final String dependencyDetailsXmlQueryOutput = dependencyDetailsXmlQueryResults.getStandardOutput();
logger.debug(String.format("Bazel targetDependenciesQuery returned %d; output: %s", dependencyDetailsXmlQueryReturnCode, dependencyDetailsXmlQueryOutput));
final String xml = dependencyDetailsXmlQueryResults.getStandardOutput();
logger.debug(String.format("Bazel query returned %d; output: %s", dependencyDetailsXmlQueryReturnCode, xml));
return Optional.of(xml);
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class BazelExternalIdGenerator method executeDependencyListQuery.
private Optional<String[]> executeDependencyListQuery(final BazelExternalIdExtractionFullRule xPathRule, final List<String> dependencyListQueryArgs) {
ExecutableOutput targetDependenciesQueryResults = null;
try {
targetDependenciesQueryResults = executableRunner.executeQuietly(workspaceDir, bazelExe, dependencyListQueryArgs);
} catch (ExecutableRunnerException e) {
logger.debug(String.format("Error executing bazel with args: %s: %s", dependencyListQueryArgs, e.getMessage()));
exceptionsGenerated.put(xPathRule, e);
return Optional.empty();
}
final int targetDependenciesQueryReturnCode = targetDependenciesQueryResults.getReturnCode();
if (targetDependenciesQueryReturnCode != 0) {
String msg = String.format("Error executing bazel with args: %s: Return code: %d; stderr: %s", dependencyListQueryArgs, targetDependenciesQueryReturnCode, targetDependenciesQueryResults.getErrorOutput());
logger.debug(msg);
exceptionsGenerated.put(xPathRule, new IntegrationException(msg));
return Optional.empty();
}
final String targetDependenciesQueryOutput = targetDependenciesQueryResults.getStandardOutput();
logger.debug(String.format("Bazel targetDependenciesQuery returned %d; output: %s", targetDependenciesQueryReturnCode, targetDependenciesQueryOutput));
if (StringUtils.isBlank(targetDependenciesQueryOutput)) {
logger.debug("Bazel targetDependenciesQuery found no dependencies");
return Optional.empty();
}
final String[] rawDependencies = targetDependenciesQueryOutput.split("\\s+");
return Optional.of(rawDependencies);
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class YarnLockExtractor method extract.
public Extraction extract(final File directory, final File yarnlock, final String yarnExe) {
try {
final List<String> yarnLockText = Files.readAllLines(yarnlock.toPath(), StandardCharsets.UTF_8);
final List<String> exeArgs = Stream.of("list", "--emoji", "false").collect(Collectors.toCollection(ArrayList::new));
if (detectConfiguration.getBooleanProperty(DetectProperty.DETECT_YARN_PROD_ONLY, PropertyAuthority.None)) {
exeArgs.add("--prod");
}
final Executable yarnListExe = new Executable(directory, yarnExe, exeArgs);
final ExecutableOutput executableOutput = executableRunner.execute(yarnListExe);
if (executableOutput.getReturnCode() != 0) {
final Extraction.Builder builder = new Extraction.Builder().failure(String.format("Executing command '%s' returned a non-zero exit code %s", String.join(" ", exeArgs), executableOutput.getReturnCode()));
return builder.build();
}
final DependencyGraph dependencyGraph = yarnListParser.parseYarnList(yarnLockText, executableOutput.getStandardOutputAsList());
final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.NPM, directory.getCanonicalPath());
final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.YARN, directory.getCanonicalPath(), externalId, dependencyGraph).build();
return new Extraction.Builder().success(detectCodeLocation).build();
} catch (final Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput in project hub-detect by blackducksoftware.
the class DotNetCoreNugetInspector method execute.
@Override
public ExecutableOutput execute(File workingDirectory, List<String> arguments) throws ExecutableRunnerException {
List<String> dotnetArguments = new ArrayList<String>();
dotnetArguments.add(inspectorDll);
dotnetArguments.addAll(arguments);
final Executable hubNugetInspectorExecutable = new Executable(workingDirectory, dotnetExe, dotnetArguments);
final ExecutableOutput executableOutput = executableRunner.execute(hubNugetInspectorExecutable);
return executableOutput;
}
Aggregations