use of com.synopsys.integration.bdio.model.dependencyid.DependencyId in project hub-detect by blackducksoftware.
the class PodlockParser method extractDependencyGraph.
public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
final LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder();
final YAMLMapper mapper = new YAMLMapper();
final PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
final Map<DependencyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock);
for (final Pod pod : podfileLock.pods) {
logger.trace(String.format("Processing pod %s", pod.name));
processPod(pod, forgeOverrides, lazyBuilder);
}
for (final Pod dependency : podfileLock.dependencies) {
logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.name));
final String podText = dependency.name;
final Optional<DependencyId> dependencyId = parseDependencyId(podText);
if (dependencyId.isPresent()) {
lazyBuilder.addChildToRoot(dependencyId.get());
}
}
logger.trace("Attempting to build the dependency graph.");
final DependencyGraph dependencyGraph = lazyBuilder.build();
logger.trace("Completed the dependency graph.");
return dependencyGraph;
}
use of com.synopsys.integration.bdio.model.dependencyid.DependencyId in project hub-detect by blackducksoftware.
the class PodlockParser method processPod.
private void processPod(final Pod pod, final Map<DependencyId, Forge> forgeOverrides, final LazyExternalIdDependencyGraphBuilder lazyBuilder) {
final String podText = pod.name;
final Optional<DependencyId> dependencyIdMaybe = parseDependencyId(podText);
final String name = parseCorrectPodName(podText).orElse(null);
final String version = parseVersion(podText).orElse(null);
if (dependencyIdMaybe.isPresent()) {
final DependencyId dependencyId = dependencyIdMaybe.get();
final Forge forge = getForge(dependencyId, forgeOverrides);
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(forge, name, version);
lazyBuilder.setDependencyInfo(dependencyId, name, version, externalId);
for (final String child : pod.dependencies) {
logger.trace(String.format("Processing pod dependency %s", child));
final Optional<DependencyId> childId = parseDependencyId(child);
if (childId.isPresent()) {
if (!dependencyId.equals(childId.get())) {
lazyBuilder.addParentWithChild(dependencyId, childId.get());
}
}
}
}
}
use of com.synopsys.integration.bdio.model.dependencyid.DependencyId in project hub-detect by blackducksoftware.
the class PackRatNodeParser method parseProjectDependencies.
DependencyGraph parseProjectDependencies(final List<String> packratLockContents) {
final LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
DependencyId currentParent = null;
String name = null;
String version = null;
for (final String line : packratLockContents) {
if (line.startsWith("PackratFormat:") || line.startsWith("PackratVersion:") || line.startsWith("RVersion:")) {
continue;
}
if (line.contains("Package: ")) {
name = line.replace("Package: ", "").trim();
currentParent = new NameDependencyId(name);
graphBuilder.setDependencyName(currentParent, name);
graphBuilder.addChildToRoot(currentParent);
version = null;
continue;
}
if (line.contains("Version: ")) {
version = line.replace("Version: ", "").trim();
graphBuilder.setDependencyVersion(currentParent, version);
final DependencyId realId = new NameVersionDependencyId(name, version);
final ExternalId externalId = this.externalIdFactory.createNameVersionExternalId(Forge.CRAN, name, version);
graphBuilder.setDependencyAsAlias(realId, currentParent);
graphBuilder.setDependencyInfo(realId, name, version, externalId);
currentParent = realId;
}
if (line.contains("Requires: ")) {
final String[] parts = line.replace("Requires: ", "").split(",");
for (int i = 0; i < parts.length; i++) {
final String childName = parts[i].trim();
graphBuilder.addParentWithChild(currentParent, new NameDependencyId(childName));
}
}
}
return graphBuilder.build();
}
use of com.synopsys.integration.bdio.model.dependencyid.DependencyId in project hub-detect by blackducksoftware.
the class GraphParserTransformer method transform.
public DependencyGraph transform(final GraphParser graphParser, final String targetArchitecture) {
final Map<String, GraphNode> nodes = graphParser.getNodes();
final Map<String, GraphEdge> edges = graphParser.getEdges();
final LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
for (final GraphNode graphNode : nodes.values()) {
final String name = getNameFromNode(graphNode);
final DependencyId dependencyId = new NameDependencyId(name);
final Optional<String> version = getVersionFromNode(graphNode);
if (version.isPresent()) {
final ExternalId externalId = new ExternalId(Forge.YOCTO);
externalId.name = name;
externalId.version = version.get();
externalId.architecture = targetArchitecture;
graphBuilder.setDependencyInfo(dependencyId, name, version.get(), externalId);
}
graphBuilder.addChildToRoot(dependencyId);
}
for (final GraphEdge graphEdge : edges.values()) {
final DependencyId node1 = new NameDependencyId(getNameFromNode(graphEdge.getNode1()));
final DependencyId node2 = new NameDependencyId(getNameFromNode(graphEdge.getNode2()));
graphBuilder.addParentWithChild(node1, node2);
}
return graphBuilder.build();
}
use of com.synopsys.integration.bdio.model.dependencyid.DependencyId in project hub-detect by blackducksoftware.
the class GemlockParser method parseDependencySectionLine.
private void parseDependencySectionLine(final String trimmedLine) {
final NameVersion dependencyNameVersionNode = parseNameVersion(trimmedLine);
if (dependencyNameVersionNode.getName() == null) {
logger.error(String.format("Line in dependencies section can't be parsed: %s", trimmedLine));
} else {
DependencyId dependencyId = processNameVersion(dependencyNameVersionNode);
lazyBuilder.addChildToRoot(dependencyId);
}
}
Aggregations