Search in sources :

Example 26 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class GemspecParseExtractor method extract.

public Extraction extract(File gemspec) {
    try (InputStream inputStream = new FileInputStream(gemspec)) {
        DependencyGraph dependencyGraph = gemspecParser.parse(inputStream);
        CodeLocation codeLocation = new CodeLocation(dependencyGraph);
        return new Extraction.Builder().success(codeLocation).build();
    } catch (IOException e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 27 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PipInspectorExtractor method extract.

public Extraction extract(File directory, ExecutableTarget pythonExe, ExecutableTarget pipExe, File pipInspector, File setupFile, List<Path> requirementFilePaths, String providedProjectName) {
    toolVersionLogger.log(directory, pythonExe);
    toolVersionLogger.log(directory, pipExe);
    Extraction extractionResult;
    try {
        String projectName = getProjectName(directory, pythonExe, setupFile, providedProjectName);
        List<CodeLocation> codeLocations = new ArrayList<>();
        String projectVersion = null;
        List<Path> requirementsPaths = new ArrayList<>();
        if (requirementFilePaths.isEmpty()) {
            requirementsPaths.add(null);
        } else {
            requirementsPaths.addAll(requirementFilePaths);
        }
        for (Path requirementFilePath : requirementsPaths) {
            List<String> inspectorOutput = runInspector(directory, pythonExe, pipInspector, projectName, requirementFilePath);
            Optional<NameVersionCodeLocation> result = pipInspectorTreeParser.parse(inspectorOutput, directory.toString());
            if (result.isPresent()) {
                codeLocations.add(result.get().getCodeLocation());
                String potentialProjectVersion = result.get().getProjectVersion();
                if (projectVersion == null && StringUtils.isNotBlank(potentialProjectVersion)) {
                    projectVersion = potentialProjectVersion;
                }
            }
        }
        if (codeLocations.isEmpty()) {
            extractionResult = new Extraction.Builder().failure("The Pip Inspector tree parse failed to produce output.").build();
        } else {
            extractionResult = new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
        }
    } catch (Exception e) {
        extractionResult = new Extraction.Builder().exception(e).build();
    }
    return extractionResult;
}
Also used : Path(java.nio.file.Path) NameVersionCodeLocation(com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) ArrayList(java.util.ArrayList) ExecutableRunnerException(com.synopsys.integration.executable.ExecutableRunnerException) Extraction(com.synopsys.integration.detectable.extraction.Extraction) NameVersionCodeLocation(com.synopsys.integration.detectable.detectables.pip.inspector.model.NameVersionCodeLocation)

Example 28 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PackageJsonExtractorFunctionalTest method extractWithDevDependencies.

@Test
void extractWithDevDependencies() {
    Extraction extraction = createExtractor(NpmDependencyType.PEER).extract(packageJsonInputStream);
    assertEquals(1, extraction.getCodeLocations().size());
    CodeLocation codeLocation = extraction.getCodeLocations().get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
    graphAssert.hasRootDependency(testDep1);
    graphAssert.hasRootDependency(testDep2);
    graphAssert.hasRootDependency(testDevDep1);
    graphAssert.hasRootDependency(testDevDep2);
    graphAssert.hasNoDependency(testPeerDep1);
    graphAssert.hasNoDependency(testPeerDep2);
    graphAssert.hasRootSize(4);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 29 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PackageJsonExtractorFunctionalTest method extractWithNoDevDependencies.

@Test
void extractWithNoDevDependencies() {
    Extraction extraction = createExtractor(NpmDependencyType.PEER, NpmDependencyType.DEV).extract(packageJsonInputStream);
    assertEquals(1, extraction.getCodeLocations().size());
    CodeLocation codeLocation = extraction.getCodeLocations().get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
    graphAssert.hasRootDependency(testDep1);
    graphAssert.hasRootDependency(testDep2);
    graphAssert.hasNoDependency(testDevDep1);
    graphAssert.hasNoDependency(testDevDep2);
    graphAssert.hasNoDependency(testPeerDep1);
    graphAssert.hasNoDependency(testPeerDep2);
    graphAssert.hasRootSize(2);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Test(org.junit.jupiter.api.Test) FunctionalTest(com.synopsys.integration.detectable.annotations.FunctionalTest)

Example 30 with Extraction

use of com.synopsys.integration.detectable.extraction.Extraction in project synopsys-detect by blackducksoftware.

the class PackageJsonExtractorTest method extractWithNoDevOrPeerDependencies.

@Test
void extractWithNoDevOrPeerDependencies() {
    PackageJson packageJson = createPackageJson();
    Extraction extraction = createExtractor(NpmDependencyType.DEV, NpmDependencyType.PEER).extract(packageJson);
    assertEquals(1, extraction.getCodeLocations().size());
    CodeLocation codeLocation = extraction.getCodeLocations().get(0);
    DependencyGraph dependencyGraph = codeLocation.getDependencyGraph();
    GraphAssert graphAssert = new GraphAssert(Forge.RUBYGEMS, dependencyGraph);
    graphAssert.hasRootDependency(testDep1);
    graphAssert.hasRootDependency(testDep2);
    graphAssert.hasNoDependency(testDevDep1);
    graphAssert.hasNoDependency(testDevDep2);
    graphAssert.hasRootSize(2);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) GraphAssert(com.synopsys.integration.detectable.util.graph.GraphAssert) Extraction(com.synopsys.integration.detectable.extraction.Extraction) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) PackageJson(com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

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