Search in sources :

Example 1 with MutableDependencyGraph

use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.

the class CondaListParser method parse.

public DependencyGraph parse(String listJsonText, String infoJsonText) {
    final Type listType = new TypeToken<ArrayList<CondaListElement>>() {
    }.getType();
    final List<CondaListElement> condaList = gson.fromJson(listJsonText, listType);
    final CondaInfo condaInfo = gson.fromJson(infoJsonText, CondaInfo.class);
    final String platform = condaInfo.getPlatform();
    MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (CondaListElement condaListElement : condaList) {
        graph.addChildToRoot(condaListElementToDependency(platform, condaListElement));
    }
    return graph;
}
Also used : MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) Type(java.lang.reflect.Type) ArrayList(java.util.ArrayList) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)

Example 2 with MutableDependencyGraph

use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.

the class CpanPackager method makeDependencyGraph.

public DependencyGraph makeDependencyGraph(List<String> cpanListText, List<String> directDependenciesText) {
    Map<String, NameVersionNode> allModules = cpanListParser.parse(cpanListText);
    List<String> directModuleNames = getDirectModuleNames(directDependenciesText);
    MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (String moduleName : directModuleNames) {
        NameVersionNode nameVersionNode = allModules.get(moduleName);
        if (null != nameVersionNode) {
            nameVersionNode.setName(nameVersionNode.getName().replace("::", "-"));
            Dependency module = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.CPAN, nameVersionNode);
            graph.addChildToRoot(module);
        } else {
            logger.warn(String.format("Could node find resolved version for module: %s", moduleName));
        }
    }
    return graph;
}
Also used : MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 3 with MutableDependencyGraph

use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.

the class NameVersionNodeTransformer method createDependencyGraph.

public DependencyGraph createDependencyGraph(final Forge defaultForge, final NameVersionNode nameVersionNode, final Boolean rootIsRealRoot) {
    final MutableDependencyGraph graph = new MutableMapDependencyGraph();
    final Dependency root = addNameVersionNodeToDependencyGraph(graph, defaultForge, nameVersionNode);
    if (rootIsRealRoot) {
        graph.addChildToRoot(root);
    } else {
        graph.addChildrenToRoot(graph.getChildrenForParent(root));
    }
    return graph;
}
Also used : MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 4 with MutableDependencyGraph

use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.

the class DetectProjectManager method createBdioFiles.

public List<File> createBdioFiles(final DetectProject detectProject) throws DetectUserFriendlyException {
    final List<File> bdioFiles = new ArrayList<>();
    final MutableDependencyGraph aggregateDependencyGraph = simpleBdioFactory.createMutableDependencyGraph();
    if (StringUtils.isBlank(detectConfiguration.getAggregateBomName())) {
        for (final String codeLocationNameString : detectProject.getCodeLocationNameStrings()) {
            final DetectCodeLocation detectCodeLocation = detectProject.getDetectCodeLocation(codeLocationNameString);
            final String bdioFileName = detectProject.getBdioFilename(codeLocationNameString);
            final SimpleBdioDocument simpleBdioDocument = createSimpleBdioDocument(codeLocationNameString, detectProject.getProjectName(), detectProject.getProjectVersionName(), detectCodeLocation);
            final File outputFile = new File(detectConfiguration.getBdioOutputDirectoryPath(), bdioFileName);
            if (outputFile.exists()) {
                final boolean deleteSuccess = outputFile.delete();
                logger.debug(String.format("%s deleted: %b", outputFile.getAbsolutePath(), deleteSuccess));
            }
            writeBdioFile(outputFile, simpleBdioDocument);
            bdioFiles.add(outputFile);
        }
    } else {
        for (final DetectCodeLocation detectCodeLocation : detectProject.getDetectCodeLocations()) {
            if (detectCodeLocation.getDependencyGraph() == null) {
                logger.warn(String.format("Dependency graph is null for code location %s", detectCodeLocation.getSourcePath()));
                continue;
            }
            if (detectCodeLocation.getDependencyGraph().getRootDependencies().size() <= 0) {
                logger.warn(String.format("Could not find any dependencies for code location %s", detectCodeLocation.getSourcePath()));
            }
            aggregateDependencyGraph.addGraphAsChildrenToRoot(detectCodeLocation.getDependencyGraph());
        }
        final SimpleBdioDocument aggregateBdioDocument = createAggregateSimpleBdioDocument(detectProject.getProjectName(), detectProject.getProjectVersionName(), aggregateDependencyGraph);
        final String filename = String.format("%s.jsonld", integrationEscapeUtil.escapeForUri(detectConfiguration.getAggregateBomName()));
        final File aggregateBdioFile = new File(detectConfiguration.getOutputDirectory(), filename);
        if (aggregateBdioFile.exists()) {
            final boolean deleteSuccess = aggregateBdioFile.delete();
            logger.debug(String.format("%s deleted: %b", aggregateBdioFile.getAbsolutePath(), deleteSuccess));
        }
        writeBdioFile(aggregateBdioFile, aggregateBdioDocument);
    }
    return bdioFiles;
}
Also used : MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation) ArrayList(java.util.ArrayList) File(java.io.File) SimpleBdioDocument(com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument)

Example 5 with MutableDependencyGraph

use of com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph in project hub-detect by blackducksoftware.

the class CocoapodsPackager method extractDependencyGraph.

public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
    YAMLMapper mapper = new YAMLMapper();
    PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
    NameVersionNode root = new NameVersionNode();
    root.setName(String.format("detectRootNode - %s", UUID.randomUUID()));
    final SubcomponentNodeBuilder builder = new SubcomponentNodeBuilder(root);
    for (Pod pod : podfileLock.getPods()) {
        buildNameVersionNode(builder, pod);
    }
    ;
    for (Pod dependency : podfileLock.getDependencies()) {
        NameVersionNode child = new NameVersionNode();
        child.setName(cleanPodName(dependency.getName()));
        builder.addChildNodeToParent(child, root);
    }
    ;
    if (null != podfileLock.getExternalSources() && !podfileLock.getExternalSources().getSources().isEmpty()) {
        for (PodSource podSource : podfileLock.getExternalSources().getSources()) {
            NodeMetadata nodeMetadata = createMetadata(builder, podSource.getName());
            if (null != podSource.getGit() && podSource.getGit().contains("github")) {
                // Change the forge to GitHub when there is better KB support
                nodeMetadata.setForge(Forge.COCOAPODS);
            } else if (null != podSource.getPath() && podSource.getPath().contains("node_modules")) {
                nodeMetadata.setForge(Forge.NPM);
            }
        }
    }
    MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (NameVersionNode nameVersionNode : builder.build().getChildren()) {
        Dependency childDependency = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.COCOAPODS, nameVersionNode);
        graph.addChildToRoot(childDependency);
    }
    return graph;
}
Also used : NodeMetadata(com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata) MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) SubcomponentNodeBuilder(com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder) NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Aggregations

MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)5 MutableMapDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)4 Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)3 NameVersionNode (com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)2 ArrayList (java.util.ArrayList)2 SimpleBdioDocument (com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation)1 NodeMetadata (com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata)1 SubcomponentNodeBuilder (com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 File (java.io.File)1 Type (java.lang.reflect.Type)1