Search in sources :

Example 1 with NugetContainer

use of com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer 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 2 with NugetContainer

use of com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer 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 3 with NugetContainer

use of com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer in project synopsys-detect by blackducksoftware.

the class NugetParserTest method handlesNullChild.

@Test
public void handlesNullChild() {
    NugetInspection result = new NugetInspection();
    NugetContainer container = new NugetContainer();
    container.type = NugetContainerType.SOLUTION;
    container.children = new ArrayList<>();
    container.children.add(null);
    result.containers.add(container);
    String resultText = gson.toJson(result);
    NugetInspectorParser parser = new NugetInspectorParser(gson, new ExternalIdFactory());
    NugetParseResult parsed = parser.createCodeLocation(resultText);
    Assertions.assertEquals(0, parsed.getCodeLocations().size());
}
Also used : NugetInspection(com.synopsys.integration.detectable.detectables.nuget.model.NugetInspection) NugetContainer(com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) NugetParseResult(com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult) NugetInspectorParser(com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser) Test(org.junit.jupiter.api.Test)

Aggregations

NugetContainer (com.synopsys.integration.detectable.detectables.nuget.model.NugetContainer)3 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)2 NugetInspection (com.synopsys.integration.detectable.detectables.nuget.model.NugetInspection)2 ArrayList (java.util.ArrayList)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 NugetInspectorParser (com.synopsys.integration.detectable.detectables.nuget.parse.NugetInspectorParser)1 NugetParseResult (com.synopsys.integration.detectable.detectables.nuget.parse.NugetParseResult)1 Test (org.junit.jupiter.api.Test)1