Search in sources :

Example 1 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.

the class PearCliExtractor method extract.

public Extraction extract(final File directory, final File pearExe, final ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final ExecutableOutput pearListing = executableRunner.execute(workingDirectory, pearExe, "list");
        final ExecutableOutput pearDependencies = executableRunner.execute(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME);
        // TODO: Why is this done here?
        final File packageFile = detectFileFinder.findFile(directory, PACKAGE_XML_FILENAME);
        final PearParseResult result = pearParser.parse(packageFile, pearListing, pearDependencies);
        final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PEAR, result.name, result.version);
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PEAR, directory.toString(), id, result.dependencyGraph).build();
        return new Extraction.Builder().success(detectCodeLocation).projectName(result.name).projectVersion(result.version).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) File(java.io.File)

Example 2 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.

the class PipenvExtractor method extract.

public Extraction extract(final File directory, final String pythonExe, final String pipenvExe, final File setupFile) {
    Extraction extraction;
    try {
        final String projectName = getProjectName(directory, pythonExe, setupFile);
        final String projectVersionName = getProjectVersionName(directory, pythonExe, setupFile);
        final PipParseResult result;
        final Executable pipenvRunPipFreeze = new Executable(directory, pipenvExe, Arrays.asList("run", "pip", "freeze"));
        final ExecutableOutput pipFreezeOutput = executableRunner.execute(pipenvRunPipFreeze);
        final Executable pipenvGraph = new Executable(directory, pipenvExe, Arrays.asList("graph", "--bare"));
        final ExecutableOutput graphOutput = executableRunner.execute(pipenvGraph);
        result = pipenvTreeParser.parse(projectName, projectVersionName, pipFreezeOutput.getStandardOutputAsList(), graphOutput.getStandardOutputAsList(), directory.toString());
        if (result != null) {
            extraction = new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
        } else {
            extraction = new Extraction.Builder().failure("Pipenv graph could not successfully be parsed").build();
        }
    } catch (final Exception e) {
        extraction = new Extraction.Builder().exception(e).build();
    }
    return extraction;
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 3 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.

the class NpmCliExtractor method extract.

public Extraction extract(final File directory, final String npmExe, final ExtractionId extractionId) {
    final boolean includeDevDeps = detectConfiguration.getBooleanProperty(DetectProperty.DETECT_NPM_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None);
    final List<String> exeArgs = new ArrayList<>();
    exeArgs.add("ls");
    exeArgs.add("-json");
    if (!includeDevDeps) {
        exeArgs.add("-prod");
    }
    final String additionalArguments = detectConfiguration.getProperty(DetectProperty.DETECT_NPM_ARGUMENTS, PropertyAuthority.None);
    if (StringUtils.isNotBlank(additionalArguments)) {
        exeArgs.addAll(Arrays.asList(additionalArguments.split(" ")));
    }
    final Executable npmLsExe = new Executable(directory, npmExe, exeArgs);
    ExecutableOutput executableOutput;
    try {
        executableOutput = executableRunner.execute(npmLsExe);
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
    final String standardOutput = executableOutput.getStandardOutput();
    final String errorOutput = executableOutput.getErrorOutput();
    if (StringUtils.isNotBlank(errorOutput)) {
        logger.error("Error when running npm ls -json command");
        logger.error(errorOutput);
        return new Extraction.Builder().failure("Npm wrote to stderr while running npm ls.").build();
    } else if (StringUtils.isNotBlank(standardOutput)) {
        logger.debug("Parsing npm ls file.");
        logger.debug(standardOutput);
        try {
            final NpmParseResult result = npmCliParser.generateCodeLocation(directory.getCanonicalPath(), standardOutput);
            return new Extraction.Builder().success(result.codeLocation).projectName(result.projectName).projectVersion(result.projectVersion).build();
        } catch (final IOException e) {
            return new Extraction.Builder().exception(e).build();
        }
    } else {
        logger.error("Nothing returned from npm ls -json command");
        return new Extraction.Builder().failure("Npm returned error after running npm ls.").build();
    }
}
Also used : ExecutableOutput(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput) ArrayList(java.util.ArrayList) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) IOException(java.io.IOException) Executable(com.blackducksoftware.integration.hub.detect.util.executable.Executable) IOException(java.io.IOException)

Example 4 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction in project hub-detect by blackducksoftware.

the class PipInspectorExtractor method extract.

public Extraction extract(final File directory, final String pythonExe, final File pipInspector, final File setupFile, final String requirementFilePath) {
    Extraction extractionResult;
    try {
        final String projectName = getProjectName(directory, pythonExe, setupFile);
        final Optional<PipParseResult> result;
        final List<String> inspectorOutput = runInspector(directory, pythonExe, pipInspector, projectName, requirementFilePath);
        result = pipInspectorTreeParser.parse(inspectorOutput, directory.toString());
        if (!result.isPresent()) {
            extractionResult = new Extraction.Builder().failure("The Pip Inspector tree parser failed to produce output").build();
        } else {
            extractionResult = new Extraction.Builder().success(result.get().getCodeLocation()).projectName(result.get().getProjectName()).projectVersion(result.get().getProjectVersion()).build();
        }
    } catch (final Exception e) {
        extractionResult = new Extraction.Builder().exception(e).build();
    }
    return extractionResult;
}
Also used : Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 5 with Extraction

use of com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction 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)

Aggregations

Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)29 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)17 File (java.io.File)17 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)14 ArrayList (java.util.ArrayList)12 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)11 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)11 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)8 DetectFileFinder (com.blackducksoftware.integration.hub.detect.workflow.file.DetectFileFinder)7 ExecutableRunner (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunner)6 ExtractionId (com.blackducksoftware.integration.hub.detect.detector.ExtractionId)5 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)5 IOException (java.io.IOException)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 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)3 DirectoryManager (com.blackducksoftware.integration.hub.detect.workflow.file.DirectoryManager)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3