Search in sources :

Example 1 with Component

use of com.blackducksoftware.bdio2.model.Component in project blackduck-common by blackducksoftware.

the class Bdio2Factory method createLegacyBdio2Document.

/**
 * @deprecated (Use createBdio2Document instead when the ProjectDependencyGraph has an accurate ProjectDependency)
 */
@Deprecated
public Bdio2Document createLegacyBdio2Document(BdioMetadata bdioMetadata, DependencyGraph dependencyGraph, ProjectInfo projectInfo, ExternalId projectExternalId) {
    Project project = createProject(projectInfo.getNameVersion(), projectExternalId, true);
    Pair<List<Project>, List<Component>> subprojectsAndComponents = createAndLinkComponents(dependencyGraph, project);
    return new Bdio2Document(bdioMetadata, project, subprojectsAndComponents.getLeft(), subprojectsAndComponents.getRight());
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProductList(com.blackducksoftware.common.value.ProductList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Component

use of com.blackducksoftware.bdio2.model.Component in project blackduck-common by blackducksoftware.

the class Bdio2Factory method createBdio2Document.

public Bdio2Document createBdio2Document(BdioMetadata bdioMetadata, ProjectDependencyGraph dependencyGraph) {
    Project project = createProject(dependencyGraph.getProjectDependency().getExternalId(), true);
    Pair<List<Project>, List<Component>> subprojectsAndComponents = createAndLinkComponents(dependencyGraph, project);
    return new Bdio2Document(bdioMetadata, project, subprojectsAndComponents.getLeft(), subprojectsAndComponents.getRight());
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) Bdio2Document(com.synopsys.integration.blackduck.bdio2.model.Bdio2Document) ProductList(com.blackducksoftware.common.value.ProductList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Component

use of com.blackducksoftware.bdio2.model.Component 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 4 with Component

use of com.blackducksoftware.bdio2.model.Component in project blackduck-common by blackducksoftware.

the class Bdio2FactoryTest method testCreateAndLinkComponents.

@Test
void testCreateAndLinkComponents() {
    ExternalIdFactory externalIdFactory = new ExternalIdFactory();
    String rootProjectGroup = "testRootProjectGroup";
    String rootProjectName = "testRootProjectName";
    String rootProjectVersion = "testRootProjectVersion";
    String subProjectGroup = "testSubProjectGroup";
    String subProjectName = "testSubProjectName";
    String subProjectVersion = "testSubProjectVersion";
    String compGroup = "testCompGroup";
    String compName = "testCompName";
    String compVersion = "testCompVersion";
    ExternalId rootProjectExternalId = externalIdFactory.createMavenExternalId(rootProjectGroup, rootProjectName, rootProjectVersion);
    ExternalId subProjectExternalId = externalIdFactory.createMavenExternalId(subProjectGroup, subProjectName, subProjectVersion);
    ExternalId componentExternalId = externalIdFactory.createMavenExternalId(compGroup, compName, compVersion);
    Bdio2Factory bdio2Factory = new Bdio2Factory();
    Project rootProject = bdio2Factory.createProject(rootProjectExternalId, true);
    DependencyGraph dependencyGraph = Mockito.mock(DependencyGraph.class);
    Set<Dependency> dependencies = new HashSet<>();
    ProjectDependency subProjectDependency = new ProjectDependency(subProjectName, subProjectVersion, subProjectExternalId);
    Dependency componentDependency = new Dependency(componentExternalId);
    dependencies.add(subProjectDependency);
    dependencies.add(componentDependency);
    Mockito.when(dependencyGraph.getDirectDependencies()).thenReturn(dependencies);
    Pair<List<Project>, List<Component>> results = bdio2Factory.createAndLinkComponents(dependencyGraph, rootProject);
    assertEquals(1, results.getLeft().size());
    assertEquals("http:maven/" + subProjectGroup + "/" + subProjectName + "/" + subProjectVersion, results.getLeft().get(0).id());
    assertEquals(1, results.getRight().size());
    assertEquals("http:maven/" + compGroup + "/" + compName + "/" + compVersion, results.getRight().get(0).id());
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) List(java.util.List) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 5 with Component

use of com.blackducksoftware.bdio2.model.Component in project blackduck-common by blackducksoftware.

the class Bdio2Writer method writeBdioDocument.

public void writeBdioDocument(BdioWriter bdioWriter, Project project, List<Project> subProjects, List<Component> components) throws IOException {
    bdioWriter.start();
    for (Project subProject : subProjects) {
        bdioWriter.next(subProject);
    }
    for (Component component : components) {
        bdioWriter.next(component);
    }
    // We put the project node at the end of the document to be more inline with the way Black Duck produces BDIO 2.
    bdioWriter.next(project);
    bdioWriter.close();
}
Also used : Project(com.blackducksoftware.bdio2.model.Project) Component(com.blackducksoftware.bdio2.model.Component)

Aggregations

Project (com.blackducksoftware.bdio2.model.Project)5 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)4 Bdio2Document (com.synopsys.integration.blackduck.bdio2.model.Bdio2Document)4 List (java.util.List)4 ProductList (com.blackducksoftware.common.value.ProductList)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 BdioMetadata (com.blackducksoftware.bdio2.BdioMetadata)2 Component (com.blackducksoftware.bdio2.model.Component)2 ProjectDependencyGraph (com.synopsys.integration.bdio.graph.ProjectDependencyGraph)2 ProjectDependency (com.synopsys.integration.bdio.model.dependency.ProjectDependency)2 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)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 UploadBatch (com.synopsys.integration.blackduck.codelocation.upload.UploadBatch)2 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)2 ProjectVersionWrapper (com.synopsys.integration.blackduck.service.model.ProjectVersionWrapper)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2