Search in sources :

Example 1 with SimpleBdioDocument

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

the class DockerExtractor method findCodeLocations.

private Extraction.Builder findCodeLocations(final File directoryToSearch, final File directory, final String imageName) {
    final File bdioFile = detectFileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
    if (bdioFile != null) {
        SimpleBdioDocument simpleBdioDocument = null;
        try (final InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
            BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
            simpleBdioDocument = bdioReader.readSimpleBdioDocument();
        } catch (final Exception e) {
            return new Extraction.Builder().exception(e);
        }
        if (simpleBdioDocument != null) {
            final DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(simpleBdioDocument.project, simpleBdioDocument.components);
            final String projectName = simpleBdioDocument.project.name;
            final String projectVersionName = simpleBdioDocument.project.version;
            final Forge dockerForge = new Forge(ExternalId.BDIO_ID_SEPARATOR, ExternalId.BDIO_ID_SEPARATOR, simpleBdioDocument.project.bdioExternalIdentifier.forge);
            final String externalIdPath = simpleBdioDocument.project.bdioExternalIdentifier.externalId;
            final ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
            final DetectCodeLocation detectCodeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.DOCKER, directory.toString(), projectExternalId, dependencyGraph).dockerImage(imageName).build();
            return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
        }
    }
    return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BdioReader(com.synopsys.integration.bdio.BdioReader) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) DetectCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation) Extraction(com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction) File(java.io.File)

Example 2 with SimpleBdioDocument

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

the class AggregateBdioCreator method createAggregateBdioFile.

public Optional<UploadTarget> createAggregateBdioFile(File sourcePath, File bdioDirectory, final List<DetectCodeLocation> codeLocations, NameVersion projectNameVersion) throws DetectUserFriendlyException {
    final DependencyGraph aggregateDependencyGraph = createAggregateDependencyGraph(sourcePath, codeLocations);
    if (aggregateDependencyGraph.getRootDependencies().size() == 0) {
        logger.info("The aggregate contained no dependencies, will not create bdio file.");
        return Optional.empty();
    }
    final ExternalId projectExternalId = simpleBdioFactory.createNameVersionExternalId(new Forge("/", "/", "DETECT"), projectNameVersion.getName(), projectNameVersion.getVersion());
    final String codeLocationName = codeLocationNameManager.createAggregateCodeLocationName(projectNameVersion);
    final SimpleBdioDocument aggregateBdioDocument = simpleBdioFactory.createSimpleBdioDocument(codeLocationName, projectNameVersion.getName(), projectNameVersion.getVersion(), projectExternalId, aggregateDependencyGraph);
    final String filename = String.format("%s.jsonld", integrationEscapeUtil.escapeForUri(detectConfiguration.getProperty(DetectProperty.DETECT_BOM_AGGREGATE_NAME, PropertyAuthority.None)));
    final File aggregateBdioFile = new File(bdioDirectory, filename);
    detectBdioWriter.writeBdioFile(aggregateBdioFile, aggregateBdioDocument);
    return Optional.of(UploadTarget.createDefault(codeLocationName, aggregateBdioFile));
}
Also used : ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) Forge(com.synopsys.integration.bdio.model.Forge) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) MutableDependencyGraph(com.synopsys.integration.bdio.graph.MutableDependencyGraph) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument)

Example 3 with SimpleBdioDocument

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

the class CodeLocationBdioCreator method createBdioFiles.

public List<UploadTarget> createBdioFiles(File bdioOutput, final List<BdioCodeLocation> bdioCodeLocations, NameVersion projectNameVersion) throws DetectUserFriendlyException {
    final List<UploadTarget> uploadTargets = new ArrayList<>();
    for (final BdioCodeLocation bdioCodeLocation : bdioCodeLocations) {
        String codeLocationName = bdioCodeLocation.codeLocationName;
        ExternalId externalId = bdioCodeLocation.codeLocation.getExternalId();
        DependencyGraph dependencyGraph = bdioCodeLocation.codeLocation.getDependencyGraph();
        final SimpleBdioDocument simpleBdioDocument = simpleBdioFactory.createSimpleBdioDocument(codeLocationName, projectNameVersion.getName(), projectNameVersion.getVersion(), externalId, dependencyGraph);
        final File outputFile = new File(bdioOutput, bdioCodeLocation.bdioName);
        detectBdioWriter.writeBdioFile(outputFile, simpleBdioDocument);
        uploadTargets.add(UploadTarget.createDefault(codeLocationName, outputFile));
    }
    return uploadTargets;
}
Also used : BdioCodeLocation(com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.bdioupload.UploadTarget) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ArrayList(java.util.ArrayList) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument)

Aggregations

DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)3 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)3 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)3 File (java.io.File)3 Forge (com.synopsys.integration.bdio.model.Forge)2 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)1 BdioCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.BdioCodeLocation)1 DetectCodeLocation (com.blackducksoftware.integration.hub.detect.workflow.codelocation.DetectCodeLocation)1 Extraction (com.blackducksoftware.integration.hub.detect.workflow.extraction.Extraction)1 BdioReader (com.synopsys.integration.bdio.BdioReader)1 MutableDependencyGraph (com.synopsys.integration.bdio.graph.MutableDependencyGraph)1 UploadTarget (com.synopsys.integration.blackduck.codelocation.bdioupload.UploadTarget)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1