Search in sources :

Example 1 with NugetInspection

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

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

the class NugetParserTest method handlesNullContainer.

@Test
public void handlesNullContainer() {
    NugetInspection result = new NugetInspection();
    result.containers.add(null);
    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) 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)

Example 3 with NugetInspection

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

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