Search in sources :

Example 41 with Extraction

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);
    }
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Detectable(com.synopsys.integration.detectable.Detectable) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation)

Example 42 with Extraction

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();
    }
}
Also used : Extraction(com.synopsys.integration.detectable.extraction.Extraction) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) FileFinder(com.synopsys.integration.common.util.finder.FileFinder) ArrayList(java.util.ArrayList) NameVersion(com.synopsys.integration.util.NameVersion) ExecutableTarget(com.synopsys.integration.detectable.ExecutableTarget) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Map(java.util.Map) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Logger(org.slf4j.Logger) NugetInspectorParser(com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Executable(com.synopsys.integration.executable.Executable) List(java.util.List) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DetectableExecutableRunner(com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner) Optional(java.util.Optional) ExecutableUtils(com.synopsys.integration.detectable.ExecutableUtils) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) IOException(java.io.IOException) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) File(java.io.File)

Example 43 with Extraction

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();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) FileInputStream(java.io.FileInputStream) IntegrationException(com.synopsys.integration.exception.IntegrationException) ExecutableOutput(com.synopsys.integration.executable.ExecutableOutput) PackageDependency(com.synopsys.integration.detectable.detectables.pear.model.PackageDependency) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Example 44 with Extraction

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();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) GemlockParser(com.synopsys.integration.detectable.detectables.rubygems.gemlock.parse.GemlockParser)

Example 45 with Extraction

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();
    }
}
Also used : PackagistParseResult(com.synopsys.integration.detectable.detectables.packagist.model.PackagistParseResult) Extraction(com.synopsys.integration.detectable.extraction.Extraction)

Aggregations

Extraction (com.synopsys.integration.detectable.extraction.Extraction)63 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)38 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)23 IOException (java.io.IOException)19 Test (org.junit.jupiter.api.Test)18 File (java.io.File)17 ArrayList (java.util.ArrayList)14 ExecutableOutput (com.synopsys.integration.executable.ExecutableOutput)13 DetectableExecutableRunner (com.synopsys.integration.detectable.detectable.executable.DetectableExecutableRunner)12 NameVersion (com.synopsys.integration.util.NameVersion)12 Executable (com.synopsys.integration.executable.Executable)11 ExecutableRunnerException (com.synopsys.integration.executable.ExecutableRunnerException)9 List (java.util.List)9 ExecutableTarget (com.synopsys.integration.detectable.ExecutableTarget)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)7 Collectors (java.util.stream.Collectors)7 ExecutableFailedException (com.synopsys.integration.detectable.detectable.executable.ExecutableFailedException)6 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)6