use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project blackduck-common by blackducksoftware.
the class Bdio2ContentExtractor method extractContent.
public List<BdioFileContent> extractContent(File bdio2File) throws IntegrationException {
validateBdioFile(bdio2File);
List<BdioFileContent> bdioFileContentList = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(bdio2File)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String fileExtension = FilenameUtils.getExtension(entry.getName());
if ("jsonld".equals(fileExtension)) {
bdioFileContentList.add(readEntryContent(zipFile, entry));
}
}
} catch (IOException ex) {
throw new IntegrationException(String.format("Exception unzipping BDIO file. Path: %s", bdio2File.getAbsolutePath()), ex);
}
return bdioFileContentList;
}
use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project blackduck-common by blackducksoftware.
the class Bdio2ContentExtractorTest method testReadValidFile.
@Test
public void testReadValidFile() throws Exception {
File bdioFile = new File(getClass().getResource("/bdio/scans/developerScanTest.bdio").getFile());
Bdio2ContentExtractor reader = new Bdio2ContentExtractor();
List<BdioFileContent> contents = reader.extractContent(bdioFile);
assertFalse(contents.isEmpty());
}
use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project synopsys-detect by blackducksoftware.
the class RapidScanUploadService method uploadFiles.
private HttpUrl uploadFiles(UploadTarget uploadTarget, List<BdioFileContent> bdioFiles, RapidScanOptions rapidScanOptions, @Nullable NameVersion nameVersion, @Nullable File rapidScanConfig, @Nullable File rapidScanWorkingDirectory) throws IntegrationException, IOException {
if (bdioFiles.isEmpty()) {
throw new IllegalArgumentException("BDIO files cannot be empty.");
}
BdioFileContent header = bdioFiles.stream().filter(content -> content.getFileName().equals(FILE_NAME_BDIO_HEADER_JSONLD)).findFirst().orElseThrow(() -> new BlackDuckIntegrationException("Cannot find BDIO header file" + FILE_NAME_BDIO_HEADER_JSONLD + "."));
List<BdioFileContent> remainingFiles = bdioFiles.stream().filter(content -> !content.getFileName().equals(FILE_NAME_BDIO_HEADER_JSONLD)).collect(Collectors.toList());
int count = remainingFiles.size();
logger.debug("BDIO upload file count = " + count);
BlackDuckRequestBuilderEditor editor = builder -> {
builder.addHeader(RapidCompareMode.HEADER_NAME, rapidScanOptions.getCompareMode().getHeaderValue());
if (nameVersion != null) {
builder.addHeader(Bdio2StreamUploader.PROJECT_NAME_HEADER, nameVersion.getName()).addHeader(Bdio2StreamUploader.VERSION_NAME_HEADER, nameVersion.getVersion());
}
};
HttpUrl url;
if (rapidScanConfig != null) {
url = bdio2Uploader.startWithConfig(zip(uploadTarget, rapidScanConfig, header, rapidScanWorkingDirectory), editor);
} else {
url = bdio2Uploader.start(header, editor);
}
for (BdioFileContent content : remainingFiles) {
bdio2Uploader.append(url, count, content, editor);
}
bdio2Uploader.finish(url, count, editor);
return url;
}
use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project synopsys-detect by blackducksoftware.
the class RapidScanUploadService method uploadFile.
public HttpUrl uploadFile(File workingDirectory, UploadTarget uploadTarget, RapidScanOptions rapidScanOptions, @Nullable File rapidScanConfig) throws IntegrationException, IOException {
logger.debug(String.format("Uploading BDIO file %s", uploadTarget.getUploadFile()));
List<BdioFileContent> bdioFileContentList = bdio2Extractor.extractContent(uploadTarget.getUploadFile());
NameVersion projectNameVersion = uploadTarget.getProjectAndVersion().orElse(null);
return uploadFiles(uploadTarget, bdioFileContentList, rapidScanOptions, projectNameVersion, rapidScanConfig, workingDirectory);
}
use of com.synopsys.integration.blackduck.bdio2.model.BdioFileContent in project blackduck-common by blackducksoftware.
the class Bdio2UploadJobTest method getUploadJob.
private Bdio2UploadJob getUploadJob(Bdio2StreamUploader bdio2StreamUploader) {
BdioFileContent header = new BdioFileContent("bdio-header.jsonld", "");
BdioFileContent entry = new BdioFileContent("bdio-entry-00.jsonld", "");
return new Bdio2UploadJob(bdio2StreamUploader, header, Collections.singletonList(entry), null, 2);
}
Aggregations