Search in sources :

Example 41 with CodeLocation

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());
    }
}
Also used : DetectExtractionEnvironment(com.synopsys.integration.detect.tool.detector.DetectExtractionEnvironment) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)

Example 42 with CodeLocation

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();
    }
}
Also used : ExecutableFailedException(com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) IntegrationException(com.synopsys.integration.exception.IntegrationException) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) BitbakeGraph(com.synopsys.integration.detectable.detectables.bitbake.model.BitbakeGraph)

Example 43 with CodeLocation

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();
    }
}
Also used : Logger(org.slf4j.Logger) Forge(com.synopsys.integration.bdio.model.Forge) PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ClangPackageManagerRunner(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManagerRunner) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ClangPackageDetailsTransformer(com.synopsys.integration.detectable.detectables.clang.dependencyfile.ClangPackageDetailsTransformer) File(java.io.File) ArrayList(java.util.ArrayList) CompileCommandDatabaseParser(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommandDatabaseParser) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) ClangPackageManager(com.synopsys.integration.detectable.detectables.clang.packagemanager.ClangPackageManager) DependencyFileDetailGenerator(com.synopsys.integration.detectable.detectables.clang.dependencyfile.DependencyFileDetailGenerator) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Forge(com.synopsys.integration.bdio.model.Forge) IOException(java.io.IOException) CompileCommand(com.synopsys.integration.detectable.detectables.clang.compilecommand.CompileCommand) Extraction(com.synopsys.integration.detectable.extraction.Extraction) PackageDetailsResult(com.synopsys.integration.detectable.detectables.clang.packagemanager.PackageDetailsResult) File(java.io.File)

Example 44 with CodeLocation

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();
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) ArrayList(java.util.ArrayList) CargoLockData(com.synopsys.integration.detectable.detectables.cargo.data.CargoLockData) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Toml(com.moandjiezana.toml.Toml) CargoLockPackage(com.synopsys.integration.detectable.detectables.cargo.model.CargoLockPackage)

Example 45 with CodeLocation

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();
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) IOException(java.io.IOException) MissingExternalIdException(com.synopsys.integration.bdio.graph.builder.MissingExternalIdException)

Aggregations

CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)104 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)60 Extraction (com.synopsys.integration.detectable.extraction.Extraction)41 File (java.io.File)24 ArrayList (java.util.ArrayList)23 Test (org.junit.jupiter.api.Test)22 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)21 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)20 NameVersion (com.synopsys.integration.util.NameVersion)19 IOException (java.io.IOException)19 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)16 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)16 List (java.util.List)14 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)13 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10