Search in sources :

Example 51 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class SbtResolutionCacheExtractor method extract.

public Extraction extract(File directory, SbtResolutionCacheOptions sbtResolutionCacheOptions) {
    // TODO: Extractor should not use DetectableOptions
    try {
        // TODO: Handle null better.
        List<String> included = sbtResolutionCacheOptions.getIncludedConfigurations();
        List<String> excluded = sbtResolutionCacheOptions.getExcludedConfigurations();
        int depth = sbtResolutionCacheOptions.getReportDepth();
        SbtProject project = extractProject(directory, sbtResolutionCacheOptions.isFollowSymLinks(), depth, included, excluded);
        List<CodeLocation> codeLocations = new ArrayList<>();
        String projectName = null;
        String projectVersion = null;
        for (SbtDependencyModule module : project.getModules()) {
            CodeLocation codeLocation;
            if (project.getProjectExternalId() != null) {
                codeLocation = new CodeLocation(module.getGraph(), project.getProjectExternalId());
            } else {
                codeLocation = new CodeLocation(module.getGraph());
            }
            if (projectName == null) {
                projectName = project.getProjectName();
                projectVersion = project.getProjectVersion();
            }
            codeLocations.add(codeLocation);
        }
        if (codeLocations.size() > 0) {
            return new Extraction.Builder().success(codeLocations).projectName(projectName).projectVersion(projectVersion).build();
        } else {
            logger.error("Unable to find any dependency information.");
            return new Extraction.Builder().failure("Unable to find any dependency information.").build();
        }
    } catch (Exception e) {
        return new Extraction.Builder().exception(e).build();
    }
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) SbtProject(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtProject) SbtDependencyModule(com.synopsys.integration.detectable.detectables.sbt.parse.model.SbtDependencyModule) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 52 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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 53 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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 54 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation in project synopsys-detect by blackducksoftware.

the class PipfileLockExtractor method extract.

public Extraction extract(File pipfileLockFile) throws IOException {
    String pipfileLockText = FileUtils.readFileToString(pipfileLockFile, StandardCharsets.UTF_8);
    PipfileLock pipfileLock = gson.fromJson(pipfileLockText, PipfileLock.class);
    List<PipfileLockDependency> dependencies = pipfileLockTransformer.transform(pipfileLock);
    DependencyGraph dependencyGraph = pipfileLockDependencyTransformer.transform(dependencies);
    CodeLocation codeLocation = new CodeLocation(dependencyGraph);
    // No project info - hoping git can help with that.
    return Extraction.success(codeLocation);
}
Also used : PipfileLock(com.synopsys.integration.detectable.detectables.pipenv.parse.data.PipfileLock) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) PipfileLockDependency(com.synopsys.integration.detectable.detectables.pipenv.parse.model.PipfileLockDependency) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 55 with CodeLocation

use of com.synopsys.integration.detectable.detectable.codelocation.CodeLocation 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)

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