Search in sources :

Example 1 with NugetContainer

use of com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetContainer in project hub-detect by blackducksoftware.

the class NugetInspectorPackager method createDetectCodeLocationFromNugetContainer.

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

Example 2 with NugetContainer

use of com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetContainer in project hub-detect by blackducksoftware.

the class NugetInspectorPackager method createDetectCodeLocation.

public NugetParseResult createDetectCodeLocation(final File dependencyNodeFile) throws IOException {
    final String text = FileUtils.readFileToString(dependencyNodeFile, StandardCharsets.UTF_8);
    final NugetInspection nugetInspection = gson.fromJson(text, NugetInspection.class);
    final List<DetectCodeLocation> codeLocations = new ArrayList<>();
    String projectName = "";
    String projectVersion = "";
    for (final NugetContainer it : nugetInspection.containers) {
        final Optional<NugetParseResult> possibleParseResult = createDetectCodeLocationFromNugetContainer(it);
        if (possibleParseResult.isPresent()) {
            final NugetParseResult result = possibleParseResult.get();
            if (StringUtils.isNotBlank(result.projectName)) {
                projectName = result.projectName;
                projectVersion = result.projectVersion;
            }
            codeLocations.addAll(result.codeLocations);
        }
    }
    return new NugetParseResult(projectName, projectVersion, codeLocations);
}
Also used : NugetInspection(com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetInspection) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) NugetContainer(com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetContainer) ArrayList(java.util.ArrayList)

Aggregations

NugetContainer (com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetContainer)2 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)2 ArrayList (java.util.ArrayList)2 NugetInspection (com.blackducksoftware.integration.hub.detect.detector.nuget.model.NugetInspection)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1