use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class CodeLocationReporter method writeBomToolEvaluationDetails.
private void writeBomToolEvaluationDetails(ReportWriter writer, DetectorEvaluation evaluation, Map<DetectCodeLocation, Integer> dependencyCounts, Map<CodeLocation, DetectCodeLocation> detectCodeLocationMap, Map<DetectCodeLocation, String> codeLocationNameMap) {
for (CodeLocation codeLocation : evaluation.getExtraction().getCodeLocations()) {
DetectExtractionEnvironment detectExtractionEnvironment = (DetectExtractionEnvironment) evaluation.getExtractionEnvironment();
DetectCodeLocation detectCodeLocation = detectCodeLocationMap.get(codeLocation);
writeCodeLocationDetails(writer, detectCodeLocation, dependencyCounts.get(detectCodeLocation), codeLocationNameMap.get(detectCodeLocation), detectExtractionEnvironment.getExtractionId().toUniqueString());
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class BitbakeExtractor method generateCodeLocationForTargetPackage.
private Optional<CodeLocation> generateCodeLocationForTargetPackage(String targetPackage, File sourceDirectory, ExecutableTarget bashExecutable, File buildEnvironmentFile, File buildDirectory, ShowRecipesResults showRecipesResults, BitbakeEnvironment bitbakeEnvironment) {
try {
BitbakeGraph bitbakeGraph = generateBitbakeGraph(sourceDirectory, bashExecutable, buildEnvironmentFile, buildDirectory, targetPackage, showRecipesResults.getLayerNames());
Map<String, String> imageRecipes = null;
if (dependencyTypeFilter.shouldExclude(BitbakeDependencyType.BUILD)) {
imageRecipes = readImageRecipes(buildDirectory, targetPackage, bitbakeEnvironment);
}
DependencyGraph dependencyGraph = bitbakeDependencyGraphTransformer.transform(bitbakeGraph, showRecipesResults.getRecipesWithLayers(), imageRecipes);
return Optional.of(new CodeLocation(dependencyGraph));
} catch (ExecutableFailedException | IntegrationException | IOException e) {
logger.error("Failed to extract a Code Location while running Bitbake against package '{}': {}", targetPackage, e.getMessage());
logger.debug(e.getMessage(), e);
return Optional.empty();
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class ClangExtractor method extract.
public Extraction extract(ClangPackageManager currentPackageManager, ClangPackageManagerRunner packageManagerRunner, File sourceDirectory, File outputDirectory, File jsonCompilationDatabaseFile, boolean cleanup) {
try {
logger.debug(String.format("Analyzing %s", jsonCompilationDatabaseFile.getAbsolutePath()));
logger.debug(String.format("extract() called; compileCommandsJsonFilePath: %s", jsonCompilationDatabaseFile.getAbsolutePath()));
List<CompileCommand> compileCommands = compileCommandDatabaseParser.parseCompileCommandDatabase(jsonCompilationDatabaseFile);
Set<File> dependencyFileDetails = dependencyFileDetailGenerator.fromCompileCommands(compileCommands, outputDirectory, cleanup);
PackageDetailsResult results = packageManagerRunner.getAllPackages(currentPackageManager, sourceDirectory, executableRunner, dependencyFileDetails);
logger.trace("Found : " + results.getFoundPackages() + " packages.");
logger.trace("Found : " + results.getUnRecognizedDependencyFiles() + " non-package files.");
List<Forge> packageForges = forgeChooser.determineForges(currentPackageManager);
CodeLocation codeLocation = clangPackageDetailsTransformer.toCodeLocation(packageForges, results.getFoundPackages());
logFileCollection("Unrecognized dependency files (all)", results.getUnRecognizedDependencyFiles());
List<File> unrecognizedIncludeFiles = results.getUnRecognizedDependencyFiles().stream().filter(file -> !isFileUnderDir(sourceDirectory, file)).collect(Collectors.toList());
logFileCollection(String.format("Unrecognized dependency files that are outside the compile_commands.json directory (%s) and will be collected", sourceDirectory), unrecognizedIncludeFiles);
return new Extraction.Builder().unrecognizedPaths(unrecognizedIncludeFiles).success(codeLocation).build();
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class CargoExtractor method extract.
public Extraction extract(File cargoLockFile, @Nullable File cargoTomlFile) throws IOException, DetectableException, MissingExternalIdException {
CargoLockData cargoLockData = new Toml().read(cargoLockFile).to(CargoLockData.class);
List<CargoLockPackage> packages = cargoLockData.getPackages().orElse(new ArrayList<>()).stream().map(cargoLockPackageDataTransformer::transform).collect(Collectors.toList());
DependencyGraph graph = cargoLockPackageTransformer.transformToGraph(packages);
Optional<NameVersion> projectNameVersion = Optional.empty();
if (cargoTomlFile != null) {
String cargoTomlContents = FileUtils.readFileToString(cargoTomlFile, StandardCharsets.UTF_8);
projectNameVersion = cargoTomlParser.parseNameVersionFromCargoToml(cargoTomlContents);
}
// TODO: Consider for 8.0.0 providing an external ID.
CodeLocation codeLocation = new CodeLocation(graph);
return new Extraction.Builder().success(codeLocation).nameVersionIfPresent(projectNameVersion).build();
}
use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.
the class PodlockExtractor method extract.
public Extraction extract(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.trace("Finished reading from the pod lock file.");
} catch (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 (IOException | MissingExternalIdException e) {
return new Extraction.Builder().exception(e).build();
}
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return new Extraction.Builder().success(codeLocation).build();
}
Aggregations