Search in sources :

Example 1 with BdioReader

use of com.synopsys.integration.bdio.BdioReader 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)

Aggregations

ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)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 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 Forge (com.synopsys.integration.bdio.model.Forge)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1