use of com.synopsys.integration.bdio.model.dependency.ProjectDependency 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.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.
the class DockerExtractor method findCodeLocations.
private Extraction.Builder findCodeLocations(File directoryToSearch, File directory, @Nullable String dockerInspectorMessage) {
File bdioFile = fileFinder.findFile(directoryToSearch, DEPENDENCIES_PATTERN);
if (bdioFile != null) {
SimpleBdioDocument simpleBdioDocument = null;
try (InputStream dockerOutputInputStream = new FileInputStream(bdioFile);
BdioReader bdioReader = new BdioReader(gson, dockerOutputInputStream)) {
simpleBdioDocument = bdioReader.readSimpleBdioDocument();
} catch (Exception e) {
return new Extraction.Builder().exception(e);
}
if (simpleBdioDocument != null) {
String projectName = simpleBdioDocument.getProject().name;
String projectVersionName = simpleBdioDocument.getProject().version;
// TODO ejk - update this when project external id is not req'd anymore
Forge dockerForge = new Forge(BdioId.BDIO_ID_SEPARATOR, simpleBdioDocument.getProject().bdioExternalIdentifier.forge);
String externalIdPath = simpleBdioDocument.getProject().bdioExternalIdentifier.externalId;
ExternalId projectExternalId = externalIdFactory.createPathExternalId(dockerForge, externalIdPath);
ProjectDependency projectDependency = new ProjectDependency(projectName, projectVersionName, projectExternalId);
DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(projectDependency, simpleBdioDocument.getProject(), simpleBdioDocument.getComponents());
CodeLocation detectCodeLocation = new CodeLocation(dependencyGraph, projectExternalId);
return new Extraction.Builder().success(detectCodeLocation).projectName(projectName).projectVersion(projectVersionName);
}
}
logger.error("Docker Inspector returned no BDIO files");
String dockerInspectorMsgSuffix = Optional.ofNullable(dockerInspectorMessage).filter(StringUtils::isNotBlank).map(s -> "; Docker Inspector message: " + s).orElse("");
return new Extraction.Builder().failure("No files found matching pattern [" + DEPENDENCIES_PATTERN + "]. Expected docker-inspector to produce file in " + directory.toString() + dockerInspectorMsgSuffix);
}
use of com.synopsys.integration.bdio.model.dependency.ProjectDependency 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;
}
use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.
the class FullAggregateGraphCreator method createAggregateNode.
private Dependency createAggregateNode(File sourcePath, DetectCodeLocation codeLocation) {
ExternalId original = codeLocation.getExternalId();
List<String> externalIdPieces = new ArrayList<>(Arrays.asList(original.getExternalIdPieces()));
NameVersion projectNameVersion = createProjectNameVersion(codeLocation);
createRelativePath(sourcePath, projectNameVersion, codeLocation).ifPresent(externalIdPieces::add);
String bomToolType = createBomToolType(codeLocation);
externalIdPieces.add(bomToolType);
String[] pieces = externalIdPieces.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
return new ProjectDependency(projectNameVersion.getName(), projectNameVersion.getVersion(), new ExternalIdFactory().createModuleNamesExternalId(original.getForge(), pieces));
}
use of com.synopsys.integration.bdio.model.dependency.ProjectDependency in project synopsys-detect by blackducksoftware.
the class BdioAggregationTest method readInputCodeLocations.
@NotNull
private static List<DetectCodeLocation> readInputCodeLocations(List<String> inputBdioFilenames, File sourceDir) throws IOException {
File inputBdioDir = new File("src/test/resources/workflow/bdio/aggregation/input");
List<DetectCodeLocation> inputCodelocations = new LinkedList<>();
for (String inputBdioFilename : inputBdioFilenames) {
File bdioFile = new File(inputBdioDir, inputBdioFilename);
SimpleBdioDocument simpleBdioDocument;
try (InputStream bdioInputStream = new FileInputStream(bdioFile);
BdioReader bdioReader = new BdioReader(gson, bdioInputStream)) {
simpleBdioDocument = bdioReader.readSimpleBdioDocument();
}
ExternalId externalId = simpleBdioDocument.getProject().bdioExternalIdentifier.externalIdMetaData;
ProjectDependency projectDependency = new ProjectDependency(externalId);
DependencyGraph dependencyGraph = bdioTransformer.transformToDependencyGraph(projectDependency, simpleBdioDocument.getProject(), simpleBdioDocument.getComponents());
DetectCodeLocation detectCodeLocation = DetectCodeLocation.forCreator(dependencyGraph, sourceDir, externalId, "testcreator");
inputCodelocations.add(detectCodeLocation);
}
return inputCodelocations;
}
Aggregations