Search in sources :

Example 1 with SimpleBdioDocument

use of com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument in project hub-docker-inspector by blackducksoftware.

the class RestClientInspector method getSimpleBdioDocument.

private SimpleBdioDocument getSimpleBdioDocument(final String bdioString) throws IOException {
    final InputStream bdioInputStream = new ByteArrayInputStream(bdioString.getBytes());
    SimpleBdioDocument simpleBdioDocument = null;
    try (BdioReader bdioReader = new BdioReader(new Gson(), bdioInputStream)) {
        simpleBdioDocument = bdioReader.readSimpleBdioDocument();
    }
    return simpleBdioDocument;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BdioReader(com.blackducksoftware.integration.hub.bdio.BdioReader) Gson(com.google.gson.Gson) SimpleBdioDocument(com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument)

Example 2 with SimpleBdioDocument

use of com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument 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 3 with SimpleBdioDocument

use of com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument in project hub-detect by blackducksoftware.

the class DetectProjectManager method createSimpleBdioDocument.

private SimpleBdioDocument createSimpleBdioDocument(final String codeLocationName, final String projectName, final String projectVersionName, final ExternalId projectExternalId, final DependencyGraph dependencyGraph) {
    final SimpleBdioDocument simpleBdioDocument = simpleBdioFactory.createSimpleBdioDocument(codeLocationName, projectName, projectVersionName, projectExternalId, dependencyGraph);
    final String hubDetectVersion = detectInfo.getDetectVersion();
    final ToolSpdxCreator hubDetectCreator = new ToolSpdxCreator("HubDetect", hubDetectVersion);
    simpleBdioDocument.billOfMaterials.creationInfo.addSpdxCreator(hubDetectCreator);
    return simpleBdioDocument;
}
Also used : ToolSpdxCreator(com.blackducksoftware.integration.hub.bdio.model.ToolSpdxCreator) SimpleBdioDocument(com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument)

Example 4 with SimpleBdioDocument

use of com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument in project hub-docker-inspector by blackducksoftware.

the class RestClientInspector method deriveOutputBdioFilename.

private String deriveOutputBdioFilename(final String bdioString) throws IOException, IntegrationException {
    final SimpleBdioDocument bdioDocument = getSimpleBdioDocument(bdioString);
    final BdioFilename outputFilename = new BdioFilename(bdioDocument.billOfMaterials.spdxName, bdioDocument.project.name, bdioDocument.project.version, bdioDocument.project.bdioExternalIdentifier.externalIdMetaData.forge.getName());
    return outputFilename.getBdioFilename();
}
Also used : SimpleBdioDocument(com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument)

Aggregations

SimpleBdioDocument (com.blackducksoftware.integration.hub.bdio.model.SimpleBdioDocument)4 BdioReader (com.blackducksoftware.integration.hub.bdio.BdioReader)1 MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)1 ToolSpdxCreator (com.blackducksoftware.integration.hub.bdio.model.ToolSpdxCreator)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation)1 Gson (com.google.gson.Gson)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1