Search in sources :

Example 76 with CodeLocation

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

the class NugetInspectorParser method createDetectCodeLocationFromNugetContainer.

private Optional<NugetParseResult> createDetectCodeLocationFromNugetContainer(NugetContainer nugetContainer) {
    NugetParseResult parseResult;
    String projectName = "";
    String projectVersionName = "";
    if (nugetContainer == null) {
        return Optional.empty();
    }
    if (NugetContainerType.SOLUTION == nugetContainer.type) {
        projectName = nugetContainer.name;
        projectVersionName = nugetContainer.version;
        List<CodeLocation> codeLocations = new ArrayList<>();
        for (NugetContainer container : nugetContainer.children) {
            if (container == null)
                continue;
            NugetDependencyNodeBuilder builder = new NugetDependencyNodeBuilder();
            builder.addPackageSets(container.packages);
            DependencyGraph children = builder.createDependencyGraph(container.dependencies);
            if (StringUtils.isBlank(projectVersionName)) {
                projectVersionName = container.version;
            }
            CodeLocation codeLocation = new CodeLocation(children, externalIdFactory.createNameVersionExternalId(Forge.NUGET, projectName, projectVersionName), convertSourcePath(container.sourcePath));
            codeLocations.add(codeLocation);
        }
        parseResult = new NugetParseResult(projectName, projectVersionName, codeLocations);
    } else if (NugetContainerType.PROJECT == nugetContainer.type) {
        projectName = nugetContainer.name;
        projectVersionName = nugetContainer.version;
        NugetDependencyNodeBuilder builder = new NugetDependencyNodeBuilder();
        builder.addPackageSets(nugetContainer.packages);
        DependencyGraph children = builder.createDependencyGraph(nugetContainer.dependencies);
        CodeLocation codeLocation = new CodeLocation(children, externalIdFactory.createNameVersionExternalId(Forge.NUGET, projectName, projectVersionName), convertSourcePath(nugetContainer.sourcePath));
        parseResult = new NugetParseResult(projectName, projectVersionName, codeLocation);
    } else {
        parseResult = null;
    }
    return Optional.ofNullable(parseResult);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NugetContainer(com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph)

Example 77 with CodeLocation

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

the class NugetInspectorParser method createCodeLocation.

public NugetParseResult createCodeLocation(String dependencyFileText) {
    NugetInspection nugetInspection = gson.fromJson(dependencyFileText, NugetInspection.class);
    List<CodeLocation> codeLocations = new ArrayList<>();
    String projectName = "";
    String projectVersion = "";
    for (NugetContainer it : nugetInspection.containers) {
        Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it);
        if (possibleParseResult.isPresent()) {
            NugetParseResult result = possibleParseResult.get();
            if (StringUtils.isNotBlank(result.getProjectName())) {
                projectName = result.getProjectName();
                projectVersion = result.getProjectVersion();
            }
            codeLocations.addAll(result.getCodeLocations());
        }
    }
    return new NugetParseResult(projectName, projectVersion, codeLocations);
}
Also used : NugetInspection(com.synopsys.integration.detectable.detectables.nuget.model.NugetInspection) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NugetContainer(com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer) ArrayList(java.util.ArrayList)

Example 78 with CodeLocation

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

the class PnpmLockYamlParser method createCodeLocationsFromImports.

private List<CodeLocation> createCodeLocationsFromImports(File sourcePath, PnpmLockYaml pnpmLockYaml, PnpmLinkedPackageResolver linkedPackageResolver, @Nullable NameVersion projectNameVersion) throws IntegrationException {
    if (MapUtils.isEmpty(pnpmLockYaml.importers)) {
        return Collections.emptyList();
    }
    List<CodeLocation> codeLocations = new LinkedList<>();
    for (Map.Entry<String, PnpmProjectPackage> projectPackageInfo : pnpmLockYaml.importers.entrySet()) {
        String projectKey = projectPackageInfo.getKey();
        PnpmProjectPackage projectPackage = projectPackageInfo.getValue();
        NameVersion extractedNameVersion = extractProjectInfo(projectPackageInfo, linkedPackageResolver, projectNameVersion);
        String reportingProjectPackagePath = null;
        if (!isNodeRoot.evaluate(projectKey)) {
            reportingProjectPackagePath = projectKey;
        }
        File generatedSourcePath = generateCodeLocationSourcePath(sourcePath, reportingProjectPackagePath);
        codeLocations.add(pnpmTransformer.generateCodeLocation(generatedSourcePath, projectPackage, reportingProjectPackagePath, extractedNameVersion, pnpmLockYaml.packages, linkedPackageResolver));
    }
    return codeLocations;
}
Also used : PnpmProjectPackage(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmProjectPackage) CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) NameVersion(com.synopsys.integration.util.NameVersion) Map(java.util.Map) File(java.io.File) LinkedList(java.util.LinkedList)

Example 79 with CodeLocation

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

the class PnpmYamlTransformer method generateCodeLocation.

public CodeLocation generateCodeLocation(File sourcePath, PnpmProjectPackage projectPackage, @Nullable String reportingProjectPackagePath, @Nullable NameVersion projectNameVersion, @Nullable Map<String, PnpmPackageInfo> packageMap, PnpmLinkedPackageResolver linkedPackageResolver) throws IntegrationException {
    DependencyGraph dependencyGraph = new BasicDependencyGraph();
    List<String> rootPackageIds = extractRootPackageIds(projectPackage, reportingProjectPackagePath, linkedPackageResolver);
    buildGraph(dependencyGraph, rootPackageIds, packageMap, linkedPackageResolver, reportingProjectPackagePath);
    if (projectNameVersion != null) {
        return new CodeLocation(dependencyGraph, ExternalId.FACTORY.createNameVersionExternalId(Forge.NPMJS, projectNameVersion.getName(), projectNameVersion.getVersion()), sourcePath);
    }
    return new CodeLocation(dependencyGraph, sourcePath);
}
Also used : CodeLocation(com.synopsys.integration.detectable.detectable.codelocation.CodeLocation) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph)

Example 80 with CodeLocation

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

the class PoetryExtractor method extract.

public Extraction extract(File poetryLock, @Nullable TomlTable toolDotPoetrySection) {
    try {
        DependencyGraph graph = poetryLockParser.parseLockFile(FileUtils.readFileToString(poetryLock, StandardCharsets.UTF_8));
        CodeLocation codeLocation = new CodeLocation(graph);
        Optional<NameVersion> poetryNameVersion = extractNameVersionFromToolDotPoetrySection(toolDotPoetrySection);
        if (poetryNameVersion.isPresent()) {
            return new Extraction.Builder().success(codeLocation).projectName(poetryNameVersion.get().getName()).projectVersion(poetryNameVersion.get().getVersion()).build();
        }
        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) NameVersion(com.synopsys.integration.util.NameVersion) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) Extraction(com.synopsys.integration.detectable.extraction.Extraction) IOException(java.io.IOException)

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