Search in sources :

Example 1 with ProjectDependencyGraph

use of com.synopsys.integration.bdio.graph.ProjectDependencyGraph 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)

Example 2 with ProjectDependencyGraph

use of com.synopsys.integration.bdio.graph.ProjectDependencyGraph in project synopsys-detect by blackducksoftware.

the class UniversalStepRunner method generateBdio.

public BdioResult generateBdio(UniversalToolsResult universalToolsResult, NameVersion projectNameVersion) throws OperationException {
    ProjectDependencyGraph aggregateDependencyGraph = operationFactory.aggregateSubProject(projectNameVersion, universalToolsResult.getDetectCodeLocations());
    AggregateCodeLocation aggregateCodeLocation = operationFactory.createAggregateCodeLocation(aggregateDependencyGraph, projectNameVersion);
    operationFactory.createAggregateBdio2File(aggregateCodeLocation);
    List<UploadTarget> uploadTargets = new ArrayList<>();
    Map<DetectCodeLocation, String> codeLocationNamesResult = new HashMap<>();
    universalToolsResult.getDetectCodeLocations().forEach(cl -> codeLocationNamesResult.put(cl, aggregateCodeLocation.getCodeLocationName()));
    // TODO: This doesn't seem right, it should just be the aggregate CL name right?
    uploadTargets.add(UploadTarget.createDefault(projectNameVersion, aggregateCodeLocation.getCodeLocationName(), aggregateCodeLocation.getAggregateFile()));
    return new BdioResult(uploadTargets, new DetectCodeLocationNamesResult(codeLocationNamesResult));
}
Also used : AggregateCodeLocation(com.synopsys.integration.detect.workflow.bdio.AggregateCodeLocation) UploadTarget(com.synopsys.integration.blackduck.codelocation.upload.UploadTarget) HashMap(java.util.HashMap) DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) ArrayList(java.util.ArrayList) BdioResult(com.synopsys.integration.detect.workflow.bdio.BdioResult) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) DetectCodeLocationNamesResult(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocationNamesResult)

Example 3 with ProjectDependencyGraph

use of com.synopsys.integration.bdio.graph.ProjectDependencyGraph in project synopsys-detect by blackducksoftware.

the class FullAggregateGraphCreator method aggregateCodeLocations.

public ProjectDependencyGraph aggregateCodeLocations(File sourcePath, NameVersion projectNameVersion, List<DetectCodeLocation> codeLocations) {
    ExternalId projectExternalId = ExternalId.FACTORY.createNameVersionExternalId(DETECT_FORGE, projectNameVersion.getName(), projectNameVersion.getVersion());
    ProjectDependency projectDependency = new ProjectDependency(projectExternalId);
    ProjectDependencyGraph aggregateDependencyGraph = new ProjectDependencyGraph(projectDependency);
    for (DetectCodeLocation detectCodeLocation : codeLocations) {
        Dependency codeLocationDependency = createAggregateNode(sourcePath, detectCodeLocation);
        aggregateDependencyGraph.addDirectDependency(codeLocationDependency);
        DependencyGraphUtil.copyDirectDependenciesToParent(aggregateDependencyGraph, codeLocationDependency, detectCodeLocation.getDependencyGraph());
    }
    return aggregateDependencyGraph;
}
Also used : DetectCodeLocation(com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency)

Example 4 with ProjectDependencyGraph

use of com.synopsys.integration.bdio.graph.ProjectDependencyGraph in project blackduck-common by blackducksoftware.

the class Bdio2UploadRecipeTest 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 = new ProjectInfo(PROJECT, GROUP_NAME, // TODO: What is this supposed to look like? Only used for chunking? JM-04/2022
    null, new GitInfo(new URL("https://github.com/blackducksoftware/blackduck-common"), "4a1f431d7aa4ac15f755edd5de004f07d36ae89a", "master"));
    BdioMetadata bdio2Metadata = bdio2Factory.createBdioMetadata(CODE_LOCATION_NAME, projectInfo, now);
    // create a graph of one dependency
    Dependency projectDependency = Dependency.FACTORY.createMavenDependency(GROUP_NAME, PROJECT.getName(), PROJECT.getVersion());
    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
    UploadBatchOutput uploadBatchOutput = bdio2UploadService.uploadBdioAndWait(uploadBatch, 120);
    assertFalse(uploadBatchOutput.hasAnyFailures());
    Optional<ProjectVersionWrapper> projectVersionWrapper = projectService.getProjectVersion(PROJECT);
    assertTrue(projectVersionWrapper.isPresent());
    // Verify project headers are being set correctly
    String projectName = projectVersionWrapper.get().getProjectView().getName();
    String projectVersionName = projectVersionWrapper.get().getProjectVersionView().getVersionName();
    assertEquals(PROJECT, new NameVersion(projectName, projectVersionName));
    assertEquals(PROJECT.getName(), bdio2Document.getBdioMetadata().get(Bdio.DataProperty.project.toString()));
    assertEquals(PROJECT.getVersion(), bdio2Document.getBdioMetadata().get(Bdio.DataProperty.projectVersion.toString()));
    assertEquals(GROUP_NAME, bdio2Document.getBdioMetadata().get(Bdio.DataProperty.projectGroup.toString()));
    // verify that we now have a bom with 1 component
    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) NameVersion(com.synopsys.integration.util.NameVersion) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) Bdio2Factory(com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory) GitInfo(com.synopsys.integration.blackduck.bdio2.model.GitInfo) URL(java.net.URL) 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)

Example 5 with ProjectDependencyGraph

use of com.synopsys.integration.bdio.graph.ProjectDependencyGraph in project blackduck-common by blackducksoftware.

the class CodeLocationServiceTestIT method createAndUploadSimpleBdioObject.

private void createAndUploadSimpleBdioObject(List<String> codeLocationNames) throws IOException, IntegrationException {
    UploadBatch uploadBatch = new UploadBatch();
    for (String codeLocationName : codeLocationNames) {
        File bdioFile = File.createTempFile("bdio", "jsonld");
        bdioFile.deleteOnExit();
        ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraph(Dependency.FACTORY.createMavenDependency(GROUP, PROJECT_NAME, VERSION));
        Dependency bdioTestDependency = Dependency.FACTORY.createMavenDependency(GROUP, COMPONENT_NAME, VERSION);
        dependencyGraph.addChildrenToRoot(bdioTestDependency);
        SimpleBdioDocument simpleBdioDocument = simpleBdioFactory.createPopulatedBdioDocument(codeLocationName, dependencyGraph);
        simpleBdioFactory.writeSimpleBdioDocumentToFile(bdioFile, simpleBdioDocument);
        uploadBatch.addUploadTarget(UploadTarget.createDefault(new NameVersion(PROJECT_NAME, VERSION), codeLocationName, bdioFile));
    }
    BdioUploadService bdioUploadService = blackDuckServices.blackDuckServicesFactory.createBdioUploadService();
    BdioUploadCodeLocationCreationRequest uploadRequest = bdioUploadService.createUploadRequest(uploadBatch);
    UploadBatchOutput uploadBatchOutput = bdioUploadService.uploadBdio(uploadRequest).getOutput();
    for (UploadOutput uploadOutput : uploadBatchOutput) {
        assertEquals(Result.SUCCESS, uploadOutput.getResult(), String.format("Upload result for %s was not successful", uploadOutput.getCodeLocationName()));
    }
}
Also used : UploadBatchOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput) NameVersion(com.synopsys.integration.util.NameVersion) BdioUploadService(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadService) BdioUploadCodeLocationCreationRequest(com.synopsys.integration.blackduck.codelocation.bdiolegacy.BdioUploadCodeLocationCreationRequest) UploadBatch(com.synopsys.integration.blackduck.codelocation.upload.UploadBatch) ProjectDependencyGraph(com.synopsys.integration.bdio.graph.ProjectDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) UploadOutput(com.synopsys.integration.blackduck.codelocation.upload.UploadOutput) File(java.io.File) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument)

Aggregations

ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)5 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)4 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)3 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)3 File (java.io.File)3 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)2 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)2 Bdio2Document (com.synopsys.integration.blackduck.bdio2.model.Bdio2Document)2 ProjectInfo (com.synopsys.integration.blackduck.bdio2.model.ProjectInfo)2 Bdio2Factory (com.synopsys.integration.blackduck.bdio2.util.Bdio2Factory)2 Bdio2Writer (com.synopsys.integration.blackduck.bdio2.util.Bdio2Writer)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2 DetectCodeLocation (com.synopsys.integration.detect.workflow.codelocation.DetectCodeLocation)2 NameVersion (com.synopsys.integration.util.NameVersion)2 FileOutputStream (java.io.FileOutputStream)2 ZonedDateTime (java.time.ZonedDateTime)2 Test (org.junit.jupiter.api.Test)2 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 ProjectDependency (com.synopsys.integration.bdio.model.dependency.ProjectDependency)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1