use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.
the class BdioUploadService method uploadBdioAndWait.
public UploadBatchOutput uploadBdioAndWait(UploadTarget uploadTarget, long timeoutInSeconds) throws IntegrationException, InterruptedException {
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(uploadTarget);
BdioUploadCodeLocationCreationRequest uploadRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
return uploadBdioAndWait(uploadRequest, timeoutInSeconds);
}
use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.
the class CreateProjectWithBdioAndVerifyBOMTest method testCreatingProject.
@Test
public void testCreatingProject() throws IntegrationException, InterruptedException {
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(createUploadTarget(CODE_LOCATION_NAMES.get(0), BDIO_FILE_NAMES[0]));
uploadBatch.addUploadTarget(createUploadTarget(CODE_LOCATION_NAMES.get(1), BDIO_FILE_NAMES[1]));
Set<String> expectedCodeLocationNames = getCodeLocationNames(uploadBatch);
uploadAndVerifyBdio(uploadBatch, expectedCodeLocationNames);
uploadBatch.addUploadTarget(createUploadTarget(CODE_LOCATION_NAMES.get(2), BDIO_FILE_NAMES[2]));
expectedCodeLocationNames = getCodeLocationNames(uploadBatch);
uploadAndVerifyBdio(uploadBatch, expectedCodeLocationNames);
}
use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch 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.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.
the class BdioUploadRecipeTest method testBdioUploadAndMapToVersion.
@Test
public void testBdioUploadAndMapToVersion() throws InterruptedException, IntegrationException {
assertCodeLocationDoesNotExist();
File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_without_project_section.jsonld");
// in this case we upload the bdio but we have to map it to a project and version ourselves since the Project information is missing in the bdio file
IntLogger logger = new BufferedIntLogger();
UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
codeLocationCreationService.createCodeLocations(scanRequest);
// now that the file is uploaded, we want to lookup the code location that was created by the upload. in this case we know the name of the code location that was specified in the bdio file
Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
int maxAttempts = 6;
int attempt = 0;
while (!optionalCodeLocationView.isPresent() && attempt < maxAttempts) {
// creating the code location can take a few seconds
attempt++;
Thread.sleep(5000);
optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
}
CodeLocationView codeLocationView = optionalCodeLocationView.get();
// then we map the code location to a version
String versionName = "27.0.0-SNAPSHOT";
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectAndVersion);
projectService.createProject(projectSyncModel.createProjectRequest());
projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
assertTrue(versionCodeLocations.isEmpty());
NotificationTaskRange notificationTaskRange = codeLocationCreationService.calculateCodeLocationRange();
System.out.println(RestConstants.formatDate(notificationTaskRange.getStartDate()));
System.out.println(RestConstants.formatDate(notificationTaskRange.getEndDate()));
codeLocationService.mapCodeLocation(codeLocationView, projectVersionWrapper.get().getProjectVersionView());
CodeLocationWaitResult waitResult = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectAndVersion, new HashSet<>(Arrays.asList(codeLocationView.getName())), 1, 3 * 60);
System.out.println("wait status: " + waitResult.getStatus());
if (waitResult.getErrorMessage().isPresent()) {
System.out.println(waitResult.getErrorMessage().get());
}
waitResult.getCodeLocationNames().stream().forEach(System.out::println);
assertEquals(CodeLocationWaitResult.Status.COMPLETE, waitResult.getStatus());
assertEquals(1, waitResult.getCodeLocationNames().size());
assertTrue(waitResult.getCodeLocationNames().contains(codeLocationName));
versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
assertEquals(codeLocationName, versionCodeLocation.getName());
}
use of com.synopsys.integration.blackduck.codelocation.upload.UploadBatch in project blackduck-common by blackducksoftware.
the class BdioUploadRecipeTest method testBdioUpload.
@Test
public void testBdioUpload() throws IntegrationException, InterruptedException {
assertCodeLocationDoesNotExist();
File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_with_project_section.jsonld");
// in this case we can upload the bdio and it will be mapped to a project and version because it has the Project information within the bdio file
IntLogger logger = new BufferedIntLogger();
UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
codeLocationCreationService.createCodeLocationsAndWait(scanRequest, 15 * 60);
projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
assertTrue(projectVersionWrapper.isPresent());
List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
assertEquals(1, versionCodeLocations.size());
CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
assertEquals(codeLocationName, versionCodeLocation.getName());
}
Aggregations