use of com.synopsys.integration.bdio.model.SpdxCreator in project synopsys-detect by blackducksoftware.
the class CreateBdio2FilesOperation method createBdioFiles.
public List<UploadTarget> createBdioFiles(BdioCodeLocationResult bdioCodeLocationResult, File outputDirectory, NameVersion projectNameVersion) throws DetectUserFriendlyException {
List<UploadTarget> uploadTargets = new ArrayList<>();
for (BdioCodeLocation bdioCodeLocation : bdioCodeLocationResult.getBdioCodeLocations()) {
String codeLocationName = bdioCodeLocation.getCodeLocationName();
ExternalId externalId = bdioCodeLocation.getDetectCodeLocation().getExternalId();
DependencyGraph dependencyGraph = bdioCodeLocation.getDetectCodeLocation().getDependencyGraph();
// Bdio 2
String detectVersion = detectInfo.getDetectVersion();
SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
BdioMetadata bdioMetadata = bdio2Factory.createBdioMetadata(codeLocationName, ZonedDateTime.now(), new Product.Builder().name(detectCreator.getIdentifier()).build());
bdioMetadata.scanType(Bdio.ScanType.PACKAGE_MANAGER);
Project bdio2Project = bdio2Factory.createProject(externalId, projectNameVersion.getName(), projectNameVersion.getVersion(), true);
Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdioMetadata, bdio2Project, dependencyGraph);
Bdio2Writer bdio2Writer = new Bdio2Writer();
File bdio2OutputFile = new File(outputDirectory, bdioCodeLocation.getBdioName() + ".bdio");
try {
OutputStream outputStream = new FileOutputStream(bdio2OutputFile);
bdio2Writer.writeBdioDocument(outputStream, bdio2Document);
logger.debug(String.format("BDIO Generated: %s", bdio2OutputFile.getAbsolutePath()));
uploadTargets.add(UploadTarget.createDefault(projectNameVersion, codeLocationName, bdio2OutputFile));
} catch (IOException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
return uploadTargets;
}
use of com.synopsys.integration.bdio.model.SpdxCreator in project hub-detect by blackducksoftware.
the class DetectBdioWriter method writeBdioFile.
public void writeBdioFile(final File outputFile, final SimpleBdioDocument simpleBdioDocument) throws DetectUserFriendlyException {
if (outputFile.exists()) {
final boolean deleteSuccess = outputFile.delete();
logger.debug(String.format("%s deleted: %b", outputFile.getAbsolutePath(), deleteSuccess));
}
try {
final String hubDetectVersion = detectInfo.getDetectVersion();
final SpdxCreator hubDetectCreator = SpdxCreator.createToolSpdxCreator("Detect", hubDetectVersion);
simpleBdioDocument.billOfMaterials.creationInfo.setPrimarySpdxCreator(hubDetectCreator);
simpleBdioFactory.writeSimpleBdioDocumentToFile(outputFile, simpleBdioDocument);
logger.info(String.format("BDIO Generated: %s", outputFile.getAbsolutePath()));
} catch (final IOException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
use of com.synopsys.integration.bdio.model.SpdxCreator in project synopsys-detect by blackducksoftware.
the class CreateAggregateBdio2FileOperation method writeAggregateBdio2File.
public void writeAggregateBdio2File(AggregateCodeLocation aggregateCodeLocation) throws DetectUserFriendlyException {
String detectVersion = detectInfo.getDetectVersion();
SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
ExternalId projectExternalId = aggregateCodeLocation.getAggregateDependencyGraph().getProjectDependency().getExternalId();
String group = StringUtils.defaultIfBlank(projectExternalId.getGroup(), null);
ProjectInfo projectInfo = ProjectInfo.nameVersionGroup(aggregateCodeLocation.getProjectNameVersion(), group);
BdioMetadata bdioMetadata = bdio2Factory.createBdioMetadata(aggregateCodeLocation.getCodeLocationName(), projectInfo, ZonedDateTime.now(), new Product.Builder().name(detectCreator.getIdentifier()).build());
bdioMetadata.scanType(Bdio.ScanType.PACKAGE_MANAGER);
Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdioMetadata, aggregateCodeLocation.getAggregateDependencyGraph());
writeDocument(aggregateCodeLocation.getAggregateFile(), bdio2Document);
}
use of com.synopsys.integration.bdio.model.SpdxCreator in project synopsys-detect by blackducksoftware.
the class DetectBdioWriter method writeBdioFile.
public void writeBdioFile(File outputFile, SimpleBdioDocument simpleBdioDocument) throws DetectUserFriendlyException {
if (outputFile.exists()) {
boolean deleteSuccess = outputFile.delete();
logger.debug(String.format("%s deleted: %b", outputFile.getAbsolutePath(), deleteSuccess));
}
try {
String detectVersion = detectInfo.getDetectVersion();
SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
simpleBdioDocument.getBillOfMaterials().creationInfo.setPrimarySpdxCreator(detectCreator);
simpleBdioFactory.writeSimpleBdioDocumentToFile(outputFile, simpleBdioDocument);
logger.debug(String.format("BDIO Generated: %s", outputFile.getAbsolutePath()));
} catch (IOException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
Aggregations