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);
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations