Search in sources :

Example 6 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class PipInspectorExtractor method getProjectName.

private String getProjectName(final File directory, final String pythonExe, final File setupFile) throws ExecutableRunnerException {
    String projectName = detectConfiguration.getProperty(DetectProperty.DETECT_PIP_PROJECT_NAME, PropertyAuthority.None);
    if (setupFile != null && setupFile.exists() && StringUtils.isBlank(projectName)) {
        final Executable findProjectNameExecutable = new Executable(directory, pythonExe, Arrays.asList(setupFile.getAbsolutePath(), "--name"));
        final List<String> output = executableRunner.execute(findProjectNameExecutable).getStandardOutputAsList();
        projectName = output.get(output.size() - 1).replace('_', '-').trim();
    }
    return projectName;
}
Also used : Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable)

Example 7 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class DockerExtractor method importTars.

private void importTars(final File inspectorJar, final List<File> importTars, final File directory, final Map<String, String> environmentVariables, final File bashExe) {
    try {
        for (final File imageToImport : importTars) {
            // The -c is a bash option, the following String is the command we want to run
            final List<String> dockerImportArguments = Arrays.asList("-c", "docker load -i \"" + imageToImport.getCanonicalPath() + "\"");
            final Executable dockerImportImageExecutable = new Executable(directory, environmentVariables, bashExe.toString(), dockerImportArguments);
            executableRunner.execute(dockerImportImageExecutable);
        }
    } catch (final Exception e) {
        logger.debug("Exception encountered when resolving paths for docker air gap, running in online mode instead");
        logger.debug(e.getMessage());
    }
}
Also used : Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File) IOException(java.io.IOException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 8 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class DockerExtractor method executeDocker.

private Extraction executeDocker(File outputDirectory, final String imageArgument, final String imagePiece, final String dockerTarFilePath, final File directory, final File javaExe, final File bashExe, final DockerInspectorInfo dockerInspectorInfo) throws IOException, ExecutableRunnerException {
    final File dockerPropertiesFile = new File(outputDirectory, "application.properties");
    dockerProperties.populatePropertiesFile(dockerPropertiesFile, outputDirectory);
    final Map<String, String> environmentVariables = new HashMap<>(0);
    final List<String> dockerArguments = new ArrayList<>();
    dockerArguments.add("-jar");
    dockerArguments.add(dockerInspectorInfo.getDockerInspectorJar().getAbsolutePath());
    dockerArguments.add("--spring.config.location");
    dockerArguments.add("file:" + dockerPropertiesFile.getCanonicalPath());
    dockerArguments.add(imageArgument);
    if (dockerInspectorInfo.hasAirGapImageFiles()) {
        importTars(dockerInspectorInfo.getDockerInspectorJar(), dockerInspectorInfo.getAirGapInspectorImageTarfiles(), outputDirectory, environmentVariables, bashExe);
    }
    final Executable dockerExecutable = new Executable(outputDirectory, environmentVariables, javaExe.getAbsolutePath(), dockerArguments);
    executableRunner.execute(dockerExecutable);
    final File producedTarFile = detectFileFinder.findFile(outputDirectory, TAR_FILENAME_PATTERN);
    File scanFile = null;
    if (null != producedTarFile && producedTarFile.isFile()) {
        scanFile = producedTarFile;
    } else {
        logger.debug(String.format("No files found matching pattern [%s]. Expected docker-inspector to produce file in %s", TAR_FILENAME_PATTERN, outputDirectory.getCanonicalPath()));
        if (StringUtils.isNotBlank(dockerTarFilePath)) {
            final File dockerTarFile = new File(dockerTarFilePath);
            if (dockerTarFile.isFile()) {
                logger.debug(String.format("Will scan the provided Docker tar file %s", dockerTarFile.getCanonicalPath()));
                scanFile = dockerTarFile;
            }
        }
    }
    Extraction.Builder extractionBuilder = findCodeLocations(outputDirectory, directory, imagePiece);
    extractionBuilder.metaData(DOCKER_TAR_META_DATA_KEY, scanFile);
    return extractionBuilder.build();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Example 9 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class BitbakeExtractor method runBitbake.

private ExecutableOutput runBitbake(final File outputDirectory, final File buildEnvScript, final String bitbakeCommand, File bash) {
    final List<String> arguments = new ArrayList<>();
    arguments.add("-c");
    arguments.add(". " + buildEnvScript + "; " + bitbakeCommand);
    final Executable sourceExecutable = new Executable(outputDirectory, bash, arguments);
    ExecutableOutput executableOutput = null;
    try {
        executableOutput = executableRunner.execute(sourceExecutable);
    } catch (final ExecutableRunnerException e) {
        logger.error(String.format("Failed executing command '%s'", sourceExecutable.getExecutableDescription()));
        logger.debug(e.getMessage(), e);
    }
    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) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 10 with Executable

use of com.blackducksoftware.integration.hub.detect.util.executable.Executable in project hub-detect by blackducksoftware.

the class CondaCliExtractor method extract.

public Extraction extract(final File directory, final File condaExe, ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final List<String> condaListOptions = new ArrayList<>();
        condaListOptions.add("list");
        final String condaEnvironmentName = detectConfiguration.getProperty(DetectProperty.DETECT_CONDA_ENVIRONMENT_NAME, PropertyAuthority.None);
        if (StringUtils.isNotBlank(condaEnvironmentName)) {
            condaListOptions.add("-n");
            condaListOptions.add(condaEnvironmentName);
        }
        condaListOptions.add("--json");
        final Executable condaListExecutable = new Executable(directory, condaExe, condaListOptions);
        final ExecutableOutput condaListOutput = executableRunner.execute(condaListExecutable);
        final String listJsonText = condaListOutput.getStandardOutput();
        final ExecutableOutput condaInfoOutput = executableRunner.execute(workingDirectory, condaExe, "info", "--json");
        final String infoJsonText = condaInfoOutput.getStandardOutput();
        final DependencyGraph dependencyGraph = condaListParser.parse(listJsonText, infoJsonText);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.ANACONDA, directory.toString());
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CONDA, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(detectCodeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) File(java.io.File)

Aggregations

Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)22 ArrayList (java.util.ArrayList)13 File (java.io.File)11 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)10 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)8 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)6 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 DetectConfiguration (com.blackducksoftware.integration.hub.detect.configuration.DetectConfiguration)2 DetectProperty (com.blackducksoftware.integration.hub.detect.configuration.DetectProperty)2 PropertyAuthority (com.blackducksoftware.integration.hub.detect.configuration.PropertyAuthority)2 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)2 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Optional (java.util.Optional)2 StringUtils (org.apache.commons.lang3.StringUtils)2 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)1