use of com.blackducksoftware.bdio2.model.Project 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());
}
use of com.blackducksoftware.bdio2.model.Project 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());
}
use of com.blackducksoftware.bdio2.model.Project 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());
}
use of com.blackducksoftware.bdio2.model.Project in project terra-workspace-manager by DataBiosphere.
the class CreateGcpContextFlightTest method successCreatesProjectAndContext.
@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void successCreatesProjectAndContext() throws Exception {
UUID workspaceId = createWorkspace(spendUtils.defaultSpendId());
AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
// Retry steps once to validate idempotency.
Map<String, StepStatus> retrySteps = getStepNameToStepStatusMap();
FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().doStepFailures(retrySteps).build();
FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlight.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, debugInfo);
assertEquals(FlightStatus.SUCCESS, flightState.getFlightStatus());
String projectId = flightState.getResultMap().get().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isPresent());
String contextProjectId = workspaceService.getAuthorizedRequiredGcpProject(workspaceId, userRequest);
assertEquals(projectId, contextProjectId);
Project project = crl.getCloudResourceManagerCow().projects().get(projectId).execute();
assertEquals(projectId, project.getProjectId());
assertEquals("billingAccounts/" + spendUtils.defaultBillingAccountId(), crl.getCloudBillingClientCow().getProjectBillingInfo("projects/" + projectId).getBillingAccountName());
assertRolesExist(project);
assertPolicyGroupsSynced(workspaceId, project);
}
use of com.blackducksoftware.bdio2.model.Project in project synopsys-detect by blackducksoftware.
the class CreateBdio2FilesOperation method createBdioFiles.
public List<UploadTarget> createBdioFiles(BdioCodeLocationResult bdioCodeLocationResult, File outputDirectory, NameVersion projectNameVersion) throws DetectUserFriendlyException {
List<UploadTarget> uploadTargets = new ArrayList<>();
for (BdioCodeLocation bdioCodeLocation : bdioCodeLocationResult.getBdioCodeLocations()) {
String codeLocationName = bdioCodeLocation.getCodeLocationName();
ExternalId externalId = bdioCodeLocation.getDetectCodeLocation().getExternalId();
DependencyGraph dependencyGraph = bdioCodeLocation.getDetectCodeLocation().getDependencyGraph();
// Bdio 2
String detectVersion = detectInfo.getDetectVersion();
SpdxCreator detectCreator = SpdxCreator.createToolSpdxCreator("Detect", detectVersion);
BdioMetadata bdioMetadata = bdio2Factory.createBdioMetadata(codeLocationName, ZonedDateTime.now(), new Product.Builder().name(detectCreator.getIdentifier()).build());
bdioMetadata.scanType(Bdio.ScanType.PACKAGE_MANAGER);
Project bdio2Project = bdio2Factory.createProject(externalId, projectNameVersion.getName(), projectNameVersion.getVersion(), true);
Bdio2Document bdio2Document = bdio2Factory.createBdio2Document(bdioMetadata, bdio2Project, dependencyGraph);
Bdio2Writer bdio2Writer = new Bdio2Writer();
File bdio2OutputFile = new File(outputDirectory, bdioCodeLocation.getBdioName() + ".bdio");
try {
OutputStream outputStream = new FileOutputStream(bdio2OutputFile);
bdio2Writer.writeBdioDocument(outputStream, bdio2Document);
logger.debug(String.format("BDIO Generated: %s", bdio2OutputFile.getAbsolutePath()));
uploadTargets.add(UploadTarget.createDefault(projectNameVersion, codeLocationName, bdio2OutputFile));
} catch (IOException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
return uploadTargets;
}
Aggregations