Search in sources :

Example 26 with ExecutableOutput

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.");
    }
}
Also used : Status(com.blackducksoftware.integration.hub.detect.workflow.status.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException) CleanupZipExpander(com.synopsys.integration.util.CleanupZipExpander) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) PolarisDownloadUtility(com.synopsys.integration.polaris.common.PolarisDownloadUtility) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Example 27 with ExecutableOutput

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);
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 28 with ExecutableOutput

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);
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 29 with ExecutableOutput

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();
    }
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 30 with ExecutableOutput

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;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ArrayList(java.util.ArrayList) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Aggregations

ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)30 File (java.io.File)16 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)14 ArrayList (java.util.ArrayList)12 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)10 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)9 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)8 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)7 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 Test (org.junit.Test)6 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)5 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)4 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)4 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)4 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)3 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)3 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3