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());
}
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));
}
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;
}
Aggregations