Search in sources :

Example 1 with BdioFileContent

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;
}
Also used : BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) ZipFile(java.util.zip.ZipFile) IntegrationException(com.synopsys.integration.exception.IntegrationException) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with BdioFileContent

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());
}
Also used : BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 3 with BdioFileContent

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;
}
Also used : FileNameUtils(org.apache.commons.compress.utils.FileNameUtils) IntegrationException(com.synopsys.integration.exception.IntegrationException) DataService(com.synopsys.integration.blackduck.service.DataService) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) HashMap(java.util.HashMap) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) NameVersion(com.synopsys.integration.util.NameVersion) RapidScanOptions(com.synopsys.integration.detect.workflow.blackduck.developer.RapidScanOptions) Charset(java.nio.charset.Charset) Map(java.util.Map) BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) Path(java.nio.file.Path) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) RapidCompareMode(com.synopsys.integration.detect.configuration.enumeration.RapidCompareMode) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) Bdio2ContentExtractor(com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor) List(java.util.List) BlackDuckRequestBuilderEditor(com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor) Bdio2StreamUploader(com.synopsys.integration.blackduck.bdio2.Bdio2StreamUploader) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) DetectZipUtil(com.synopsys.integration.detect.util.DetectZipUtil) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) BlackDuckRequestBuilderEditor(com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor) BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 4 with BdioFileContent

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);
}
Also used : BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent) NameVersion(com.synopsys.integration.util.NameVersion)

Example 5 with BdioFileContent

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);
}
Also used : BdioFileContent(com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)

Aggregations

BdioFileContent (com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 NameVersion (com.synopsys.integration.util.NameVersion)3 IOException (java.io.IOException)3 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 DataService (com.synopsys.integration.blackduck.service.DataService)2 BlackDuckRequestBuilderEditor (com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor)2 IntLogger (com.synopsys.integration.log.IntLogger)2 File (java.io.File)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Nullable (org.jetbrains.annotations.Nullable)2 Bdio2StreamUploader (com.synopsys.integration.blackduck.bdio2.Bdio2StreamUploader)1 RapidCompareMode (com.synopsys.integration.detect.configuration.enumeration.RapidCompareMode)1 DetectZipUtil (com.synopsys.integration.detect.util.DetectZipUtil)1