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);
}
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);
}
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());
}
Aggregations