Search in sources :

Example 1 with IntelligentPersistenceService

use of com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService in project blackduck-common by blackducksoftware.

the class BlackDuckServicesFactory method createIntelligentPersistenceService.

public IntelligentPersistenceService createIntelligentPersistenceService() {
    Bdio2StreamUploader bdio2Uploader = new Bdio2StreamUploader(blackDuckApiClient, apiDiscovery, logger, ApiDiscovery.INTELLIGENT_PERSISTENCE_SCANS_PATH, IntelligentPersistenceService.CONTENT_TYPE);
    Bdio2FileUploadService bdio2FileUploadService = new Bdio2FileUploadService(blackDuckApiClient, apiDiscovery, logger, new Bdio2ContentExtractor(), bdio2Uploader);
    IntelligentPersistenceBatchRunner batchRunner = new IntelligentPersistenceBatchRunner(logger, executorService, bdio2FileUploadService);
    return new IntelligentPersistenceService(blackDuckApiClient, apiDiscovery, logger, batchRunner, createCodeLocationCreationService());
}
Also used : Bdio2FileUploadService(com.synopsys.integration.blackduck.bdio2.Bdio2FileUploadService) Bdio2ContentExtractor(com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor) IntelligentPersistenceService(com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService) IntelligentPersistenceBatchRunner(com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceBatchRunner) Bdio2StreamUploader(com.synopsys.integration.blackduck.bdio2.Bdio2StreamUploader)

Example 2 with IntelligentPersistenceService

use of com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService in project blackduck-common by blackducksoftware.

the class IntelligentPersistenceRecipeTest method uploadBdio2.

@Test
void uploadBdio2() throws IOException, IntegrationException, InterruptedException {
    Bdio2Factory bdio2Factory = new Bdio2Factory();
    // create the bdio2 metadata
    ZonedDateTime now = Instant.now().atZone(ZoneId.of("EST5EDT"));
    ProjectInfo projectInfo = ProjectInfo.nameVersion(PROJECT);
    BdioMetadata bdio2Metadata = bdio2Factory.createBdioMetadata(CODE_LOCATION_NAME, projectInfo, now);
    // create the bdio2 project
    Dependency projectDependency = Dependency.FACTORY.createMavenDependency("com.synopsys.integration", PROJECT.getName(), PROJECT.getVersion());
    // create a graph of one dependency
    Dependency dependency = Dependency.FACTORY.createMavenDependency("org.apache.commons", "commons-lang3", "3.11");
    ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraph(projectDependency);
    dependencyGraph.addDirectDependency(dependency);
    // now, with metadata, a project, and a graph, we can create a bdio2 document and write out the file
    Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdio2Metadata, dependencyGraph);
    File bdio2File = File.createTempFile("test_bdio2", ".bdio");
    bdio2File.createNewFile();
    bdio2File.deleteOnExit();
    Bdio2Writer bdio2Writer = new Bdio2Writer();
    bdio2Writer.writeBdioDocument(new FileOutputStream(bdio2File), bdio2Document);
    // using the file and the previously set values, we create the UploadBatch for uploading to Black Duck
    UploadBatch uploadBatch = new UploadBatch();
    uploadBatch.addUploadTarget(UploadTarget.createDefault(PROJECT, CODE_LOCATION_NAME, bdio2File));
    // now all the setup is done, we can upload the bdio2 file
    IntelligentPersistenceService intelligentPersistenceService = blackDuckServicesFactory.createIntelligentPersistenceService();
    UploadBatchOutput uploadBatchOutput = intelligentPersistenceService.uploadBdioAndWait(uploadBatch, 120);
    assertFalse(uploadBatchOutput.hasAnyFailures());
    // verify that we now have a bom with 1 component
    Optional<ProjectVersionWrapper> projectVersionWrapper = projectService.getProjectVersion(PROJECT);
    assertTrue(projectVersionWrapper.isPresent());
    List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.get().getProjectVersionView());
    assertEquals(1, bomComponents.size());
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) BdioMetadata(com.blackducksoftware.bdio2.BdioMetadata) Bdio2Writer(com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Bdio2Factory(com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory) IntelligentPersistenceService(com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService) ZonedDateTime(java.time.ZonedDateTime) FileOutputStream(java.io.FileOutputStream) ProjectInfo(com.synopsys.integration.blackduck.bdio2.model.ProjectInfo) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) File(java.io.File) ProjectVersionWrapper(com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Aggregations

IntelligentPersistenceService (com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceService)2 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)1 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)1 Bdio2FileUploadService (com.synopsys.integration.blackduck.bdio2.Bdio2FileUploadService)1 Bdio2StreamUploader (com.synopsys.integration.blackduck.bdio2.Bdio2StreamUploader)1 Bdio2Document (com.synopsys.integration.blackduck.bdio2.model.Bdio2Document)1 ProjectInfo (com.synopsys.integration.blackduck.bdio2.model.ProjectInfo)1 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)1 Bdio2Factory (com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory)1 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)1 IntelligentPersistenceBatchRunner (com.synopsys.integration.blackduck.codelocation.intelligentpersistence.IntelligentPersistenceBatchRunner)1 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)1 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)1 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 ZonedDateTime (java.time.ZonedDateTime)1 Test (org.junit.jupiter.api.Test)1