use of com.synopsys.integration.bdio.graph.builder.LazyId in project synopsys-detect by blackducksoftware.
the class PackratLockFileParser method parseProjectDependencies.
public DependencyGraph parseProjectDependencies(List<String> packratLockContents) throws MissingExternalIdException {
LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
LazyId currentParent = null;
String name = null;
boolean requiresSection = false;
for (String line : packratLockContents) {
if (StringUtils.isBlank(line)) {
currentParent = null;
name = null;
requiresSection = false;
continue;
}
if (!(line.startsWith(PACKAGE_TOKEN) || line.startsWith(VERSION_TOKEN) || line.startsWith(REQUIRES_TOKEN) || line.startsWith(INDENTATION_TOKEN))) {
continue;
}
if (line.startsWith(PACKAGE_TOKEN)) {
name = getValueFromLine(line);
currentParent = LazyId.fromName(name);
graphBuilder.setDependencyName(currentParent, name);
graphBuilder.addChildToRoot(currentParent);
requiresSection = false;
} else if (line.startsWith(VERSION_TOKEN)) {
String version = getValueFromLine(line);
graphBuilder.setDependencyVersion(currentParent, version);
LazyId realId = LazyId.fromNameAndVersion(name, version);
ExternalId externalId = this.externalIdFactory.createNameVersionExternalId(Forge.CRAN, name, version);
graphBuilder.setDependencyAsAlias(realId, currentParent);
graphBuilder.setDependencyInfo(realId, name, version, externalId);
currentParent = realId;
} else if (line.startsWith(REQUIRES_TOKEN)) {
requiresSection = true;
String cleanLine = getValueFromLine(line);
List<LazyId> children = getChildrenNames(cleanLine).stream().map(LazyId::fromName).collect(Collectors.toList());
graphBuilder.addParentWithChildren(currentParent, children);
} else if (requiresSection && line.startsWith(INDENTATION_TOKEN)) {
List<LazyId> children = getChildrenNames(line).stream().map(LazyId::fromName).collect(Collectors.toList());
graphBuilder.addParentWithChildren(currentParent, children);
}
}
return graphBuilder.build();
}
use of com.synopsys.integration.bdio.graph.builder.LazyId in project synopsys-detect by blackducksoftware.
the class PackagistParser method getDependencyGraphFromProject.
// TODO: Why are we dealing with JsonObjects rather than Gson straight to classes? Is this to avoid TypeAdapters? If so... smh JM-01/2022
public PackagistParseResult getDependencyGraphFromProject(String composerJsonText, String composerLockText) throws MissingExternalIdException {
LazyExternalIdDependencyGraphBuilder builder = new LazyExternalIdDependencyGraphBuilder();
JsonObject composerJsonObject = new JsonParser().parse(composerJsonText).getAsJsonObject();
NameVersion projectNameVersion = parseNameVersionFromJson(composerJsonObject);
JsonObject composerLockObject = new JsonParser().parse(composerLockText).getAsJsonObject();
List<PackagistPackage> models = convertJsonToModel(composerLockObject);
List<NameVersion> rootPackages = parseDependencies(composerJsonObject);
models.forEach(it -> {
ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, it.getNameVersion().getName(), it.getNameVersion().getVersion());
LazyId dependencyId = LazyId.fromName(it.getNameVersion().getName());
builder.setDependencyInfo(dependencyId, it.getNameVersion().getName(), it.getNameVersion().getVersion(), id);
if (isRootPackage(it.getNameVersion(), rootPackages)) {
builder.addChildToRoot(dependencyId);
}
it.getDependencies().forEach(child -> {
if (existsInPackages(child, models)) {
LazyId childId = LazyId.fromName(child.getName());
builder.addChildWithParent(childId, dependencyId);
} else {
logger.warn("Dependency was not found in packages list but found a require that used it: " + child.getName());
}
});
});
DependencyGraph graph = builder.build();
CodeLocation codeLocation;
if (projectNameVersion.getName() == null || projectNameVersion.getVersion() == null) {
codeLocation = new CodeLocation(graph);
} else {
codeLocation = new CodeLocation(graph, externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, projectNameVersion.getName(), projectNameVersion.getVersion()));
}
return new PackagistParseResult(projectNameVersion.getName(), projectNameVersion.getVersion(), codeLocation);
}
use of com.synopsys.integration.bdio.graph.builder.LazyId in project synopsys-detect by blackducksoftware.
the class YarnTransformer method buildGraphForProjectOrWorkspace.
private DependencyGraph buildGraphForProjectOrWorkspace(YarnLockResult yarnLockResult, NullSafePackageJson projectOrWorkspacePackageJson, List<NameVersion> externalDependencies) throws MissingExternalIdException {
LazyExternalIdDependencyGraphBuilder graphBuilder = new LazyExternalIdDependencyGraphBuilder();
addRootNodesToGraph(graphBuilder, projectOrWorkspacePackageJson, yarnLockResult.getWorkspaceData());
for (YarnLockEntry entry : yarnLockResult.getYarnLock().getEntries()) {
for (YarnLockEntryId entryId : entry.getIds()) {
LazyId id = generateComponentDependencyId(entryId.getName(), entryId.getVersion());
graphBuilder.setDependencyInfo(id, entryId.getName(), entry.getVersion(), generateComponentExternalId(entryId.getName(), entry.getVersion()));
addYarnLockDependenciesToGraph(yarnLockResult, graphBuilder, entry, id);
}
}
return graphBuilder.build(getLazyBuilderHandler(externalDependencies));
}
use of com.synopsys.integration.bdio.graph.builder.LazyId in project synopsys-detect by blackducksoftware.
the class CargoLockPackageTransformer method transformToGraph.
public DependencyGraph transformToGraph(List<CargoLockPackage> lockPackages) throws MissingExternalIdException, DetectableException {
verifyNoDuplicatePackages(lockPackages);
LazyExternalIdDependencyGraphBuilder graph = new LazyExternalIdDependencyGraphBuilder();
lockPackages.forEach(lockPackage -> {
String parentName = lockPackage.getPackageNameVersion().getName();
String parentVersion = lockPackage.getPackageNameVersion().getVersion();
LazyId parentId = LazyId.fromNameAndVersion(parentName, parentVersion);
Dependency parentDependency = dependencyFactory.createNameVersionDependency(Forge.CRATES, parentName, parentVersion);
graph.addChildToRoot(parentId);
graph.setDependencyInfo(parentId, parentDependency.getName(), parentDependency.getVersion(), parentDependency.getExternalId());
graph.setDependencyAsAlias(parentId, LazyId.fromName(parentName));
lockPackage.getDependencies().forEach(childPackage -> {
if (childPackage.getVersion().isPresent()) {
LazyId childId = LazyId.fromNameAndVersion(childPackage.getName(), childPackage.getVersion().get());
graph.addChildWithParent(childId, parentId);
} else {
LazyId childId = LazyId.fromName(childPackage.getName());
graph.addChildWithParent(childId, parentId);
}
});
});
return graph.build();
}
use of com.synopsys.integration.bdio.graph.builder.LazyId in project synopsys-detect by blackducksoftware.
the class PodlockParser method extractDependencyGraph.
public DependencyGraph extractDependencyGraph(String podLockText) throws IOException, MissingExternalIdException {
LazyExternalIdDependencyGraphBuilder lazyBuilder = new LazyExternalIdDependencyGraphBuilder();
YAMLMapper mapper = new YAMLMapper();
PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
Map<LazyId, Forge> forgeOverrides = createForgeOverrideMap(podfileLock);
List<String> knownPods = determineAllPodNames(podfileLock);
for (Pod pod : podfileLock.getPods()) {
logger.trace(String.format("Processing pod %s", pod.getName()));
processPod(pod, forgeOverrides, lazyBuilder, knownPods);
}
for (Pod dependency : podfileLock.getDependencies()) {
logger.trace(String.format("Processing pod dependency from pod lock file %s", dependency.getName()));
String podText = dependency.getName();
Optional<LazyId> dependencyId = parseDependencyId(podText);
dependencyId.ifPresent(lazyBuilder::addChildToRoot);
}
logger.trace("Attempting to build the dependency graph.");
DependencyGraph dependencyGraph = lazyBuilder.build();
logger.trace("Completed the dependency graph.");
return dependencyGraph;
}
Aggregations