use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class ExtractionEvaluator method extractionEvaluation.
public void extractionEvaluation(DetectorEvaluationTree detectorEvaluationTree) {
logger.trace("Extracting detectors in the directory: {}", detectorEvaluationTree.getDirectory());
for (DetectorEvaluation detectorEvaluation : detectorEvaluationTree.getOrderedEvaluations()) {
if (detectorEvaluation.isExtractable() && detectorEvaluation.getExtractionEnvironment() != null) {
logger.trace("Detector was searchable, applicable and extractable, will perform extraction: {}", detectorEvaluation.getDetectorRule().getDescriptiveName());
Detectable detectable = detectorEvaluation.getDetectable();
getDetectorEvaluatorListener().ifPresent(it -> it.extractionStarted(detectorEvaluation));
try {
Extraction extraction = detectable.extract(detectorEvaluation.getExtractionEnvironment());
detectorEvaluation.setExtraction(extraction);
} catch (Exception e) {
detectorEvaluation.setExtraction(new Extraction.Builder().exception(e).build());
}
getDetectorEvaluatorListener().ifPresent(it -> it.extractionEnded(detectorEvaluation));
logger.trace("Extraction result: {}", detectorEvaluation.wasExtractionSuccessful());
}
}
for (DetectorEvaluationTree childDetectorEvaluationTree : detectorEvaluationTree.getChildren()) {
extractionEvaluation(childDetectorEvaluationTree);
}
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class NugetInspectorExtractor method extract.
public Extraction extract(List<File> targets, File outputDirectory, ExecutableTarget inspector, NugetInspectorOptions nugetInspectorOptions) {
try {
List<NugetTargetResult> results = new ArrayList<>();
for (int i = 0; i < targets.size(); i++) {
File targetDirectory = new File(outputDirectory, "inspection-" + i);
results.add(executeTarget(inspector, targets.get(i), targetDirectory, nugetInspectorOptions));
}
List<CodeLocation> codeLocations = results.stream().flatMap(it -> it.codeLocations.stream()).collect(Collectors.toList());
Map<File, CodeLocation> codeLocationsBySource = new HashMap<>();
codeLocations.forEach(codeLocation -> {
File sourcePathFile = codeLocation.getSourcePath().orElse(null);
if (codeLocationsBySource.containsKey(sourcePathFile)) {
logger.debug("Combined code location for: " + sourcePathFile);
CodeLocation destination = codeLocationsBySource.get(sourcePathFile);
// TODO: I don't like this casting, perhaps this doesn't have to happen here in 8.0.0. JM-04/2022
destination.getDependencyGraph().copyGraphToRoot((BasicDependencyGraph) codeLocation.getDependencyGraph());
} else {
codeLocationsBySource.put(sourcePathFile, codeLocation);
}
});
Optional<NameVersion> nameVersion = results.stream().filter(it -> it.nameVersion != null).map(it -> it.nameVersion).findFirst();
List<CodeLocation> uniqueCodeLocations = new ArrayList<>(codeLocationsBySource.values());
return new Extraction.Builder().success(uniqueCodeLocations).nameVersionIfPresent(nameVersion).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class PearCliExtractor method extract.
public Extraction extract(ExecutableTarget pearExe, File packageXmlFile, File workingDirectory) {
try {
ExecutableOutput pearListOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "list"));
ExecutableOutput packageDependenciesOutput = executableRunner.execute(ExecutableUtils.createFromTarget(workingDirectory, pearExe, "package-dependencies", PACKAGE_XML_FILENAME));
assertValidExecutableOutput(pearListOutput, packageDependenciesOutput);
Map<String, String> dependencyNameVersionMap = pearListParser.parse(pearListOutput.getStandardOutputAsList());
List<PackageDependency> packageDependencies = pearPackageDependenciesParser.parse(packageDependenciesOutput.getStandardOutputAsList());
DependencyGraph dependencyGraph = pearDependencyGraphTransformer.buildDependencyGraph(dependencyNameVersionMap, packageDependencies);
try (InputStream packageXmlInputStream = new FileInputStream(packageXmlFile)) {
NameVersion projectNameVersion = pearPackageXmlParser.parse(packageXmlInputStream);
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.PEAR, projectNameVersion.getName(), projectNameVersion.getVersion());
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, externalId);
return new Extraction.Builder().success(detectCodeLocation).projectName(projectNameVersion.getName()).projectVersion(projectNameVersion.getVersion()).build();
}
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class GemlockExtractor method extract.
public Extraction extract(File gemlock) {
try {
List<String> gemlockText = Files.readAllLines(gemlock.toPath(), StandardCharsets.UTF_8);
GemlockParser gemlockParser = new GemlockParser(externalIdFactory);
DependencyGraph dependencyGraph = gemlockParser.parseProjectDependencies(gemlockText);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.
the class ComposerLockExtractor method extract.
public Extraction extract(File composerJson, File composerLock) {
try {
String composerJsonText = FileUtils.readFileToString(composerJson, StandardCharsets.UTF_8);
String composerLockText = FileUtils.readFileToString(composerLock, StandardCharsets.UTF_8);
logger.debug(composerJsonText);
logger.debug(composerLockText);
PackagistParseResult result = packagistParser.getDependencyGraphFromProject(composerJsonText, composerLockText);
return new Extraction.Builder().success(result.getCodeLocation()).projectName(result.getProjectName()).projectVersion(result.getProjectVersion()).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
Aggregations