Search in sources :

Example 6 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class ExtractionManager method performExtractions.

public ExtractionResult performExtractions(final List<DetectorEvaluation> results) {
    final List<DetectorEvaluation> extractable = results.stream().filter(result -> result.isExtractable()).collect(Collectors.toList());
    for (int i = 0; i < extractable.size(); i++) {
        final DetectorEvaluation detectorEvaluation = extractable.get(i);
        final String progress = Integer.toString((int) Math.floor((i * 100.0f) / extractable.size()));
        logger.info(String.format("Extracting %d of %d (%s%%)", i + 1, extractable.size(), progress));
        logger.info(ReportConstants.SEPERATOR);
        final ExtractionId extractionId = new ExtractionId(detectorEvaluation.getDetector().getDetectorType(), Integer.toString(i));
        detectorEvaluation.setExtractionId(extractionId);
        extract(extractable.get(i));
    }
    final Set<DetectorType> succesfulBomToolGroups = extractable.stream().filter(it -> it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final Set<DetectorType> failedBomToolGroups = extractable.stream().filter(it -> !it.wasExtractionSuccessful()).map(it -> it.getDetector().getDetectorType()).collect(Collectors.toSet());
    final List<DetectCodeLocation> codeLocations = extractable.stream().filter(it -> it.wasExtractionSuccessful()).flatMap(it -> it.getExtraction().codeLocations.stream()).collect(Collectors.toList());
    return new ExtractionResult(codeLocations, succesfulBomToolGroups, failedBomToolGroups);
}
Also used : DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) ExtractionResultType(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction.ExtractionResultType) Logger(org.slf4j.Logger) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId) InfoLogReportWriter(com.blackducksoftware.integration.hub.detect.workflow.report.writer.InfoLogReportWriter) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) ReportConstants(com.blackducksoftware.integration.hub.detect.workflow.report.util.ReportConstants) ObjectPrinter(com.blackducksoftware.integration.hub.detect.workflow.report.util.ObjectPrinter) DetectorType(com.blackducksoftware.integration.hub.detect.detector.DetectorType) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) DetectorEvaluation(com.blackducksoftware.integration.hub.detect.workflow.search.result.DetectorEvaluation) ExtractionId(com.blackducksoftware.integration.hub.detect.detector.ExtractionId)

Example 7 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation in project hub-detect by blackducksoftware.

the class CodeLocationDependencyCounter method aggregateCountsByGroup.

public Map<DetectCodeLocationType, Integer> aggregateCountsByGroup(final Map<DetectCodeLocation, Integer> codeLocations) {
    final Map<DetectCodeLocationType, Integer> dependencyCounts = new HashMap<>();
    for (final Entry<DetectCodeLocation, Integer> countEntry : codeLocations.entrySet()) {
        final DetectCodeLocationType group = countEntry.getKey().getCodeLocationType();
        if (!dependencyCounts.containsKey(group)) {
            dependencyCounts.put(group, 0);
        }
        dependencyCounts.put(group, dependencyCounts.get(group) + countEntry.getValue());
    }
    return dependencyCounts;
}
Also used : HashMap(java.util.HashMap) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) DetectCodeLocationType(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocationType)

Example 8 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation 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 9 with DetectCodeLocation

use of com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation 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 10 with DetectCodeLocation

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

Aggregations

DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)44 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)22 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)18 File (java.io.File)17 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)15 ArrayList (java.util.ArrayList)10 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)9 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)9 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)8 MutableMapDependencyGraph (com.synopsys.integration.bdio.graph.MutableMapDependencyGraph)8 ExecutableOutput (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableOutput)7 Test (org.junit.Test)7 Executable (com.blackducksoftware.integration.hub.detect.util.executable.Executable)5 List (java.util.List)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4