Search in sources :

Example 6 with Extraction

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

Example 7 with Extraction

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

the class CpanCliExtractor method extract.

public Extraction extract(final File directory, final File cpanExe, final File cpanmExe, ExtractionId extractionId) {
    try {
        File workingDirectory = directoryManager.getExtractionOutputDirectory(extractionId);
        final ExecutableOutput cpanListOutput = executableRunner.execute(workingDirectory, cpanExe, "-l");
        final List<String> listText = cpanListOutput.getStandardOutputAsList();
        final ExecutableOutput showdepsOutput = executableRunner.execute(workingDirectory, cpanmExe, "--showdeps", ".");
        final List<String> showdeps = showdepsOutput.getStandardOutputAsList();
        final DependencyGraph dependencyGraph = cpanListParser.parse(listText, showdeps);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.CPAN, directory.toString());
        final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CPAN, 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 : 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) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 8 with Extraction

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

the class PackratLockExtractor method extract.

public Extraction extract(final File directory, final File packratlock) {
    try {
        String projectName = "";
        String projectVersion = "";
        if (detectFileFinder.containsAllFiles(directory, "DESCRIPTION")) {
            final File descriptionFile = new File(directory, "DESCRIPTION");
            final List<String> descriptionText = Files.readAllLines(descriptionFile.toPath(), StandardCharsets.UTF_8);
            logger.debug(descriptionText.stream().collect(Collectors.joining("\n")));
            projectName = packratPackager.getProjectName(descriptionText);
            projectVersion = packratPackager.getVersion(descriptionText);
        }
        final List<String> packratLockText = Files.readAllLines(packratlock.toPath(), StandardCharsets.UTF_8);
        final DependencyGraph dependencyGraph = packratPackager.extractProjectDependencies(packratLockText);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.CRAN, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.CRAN, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(codeLocation).projectName(projectName).projectVersion(projectVersion).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 9 with Extraction

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

the class GoVndrExtractor method extract.

public Extraction extract(final File directory, final File vndrConfig) {
    try {
        final VndrParser vndrParser = new VndrParser(externalIdFactory);
        final List<String> venderConfContents = Files.readAllLines(vndrConfig.toPath(), StandardCharsets.UTF_8);
        logger.debug(venderConfContents.stream().collect(Collectors.joining("\n")));
        final DependencyGraph dependencyGraph = vndrParser.parseVendorConf(venderConfContents);
        final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.GOLANG, directory.toString());
        final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GO_VNDR, directory.toString(), externalId, dependencyGraph).build();
        return new Extraction.Builder().success(codeLocation).build();
    } catch (final Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)

Example 10 with Extraction

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

the class PodlockExtractor method extract.

public Extraction extract(final File directory, final File podlock) {
    String podLockText;
    try {
        logger.trace(String.format("Reading from the pod lock file %s", podlock.getAbsolutePath()));
        podLockText = FileUtils.readFileToString(podlock, StandardCharsets.UTF_8);
        logger.debug(podLockText);
        logger.trace("Finished reading from the pod lock file.");
    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
    DependencyGraph dependencyGraph;
    try {
        logger.trace("Attempting to create the dependency graph from the pod lock file.");
        dependencyGraph = podlockParser.extractDependencyGraph(podLockText);
        logger.trace("Finished creating the dependency graph from the pod lock file.");
    } catch (final IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
    final ExternalId externalId = externalIdFactory.createPathExternalId(Forge.COCOAPODS, directory.toString());
    final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.COCOAPODS, directory.toString(), externalId, dependencyGraph).build();
    return new Extraction.Builder().success(codeLocation).build();
}
Also used : 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) IOException(java.io.IOException)

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