use of com.synopsys.integration.bdio.model.dependencyid.NameDependencyId in project hub-detect by blackducksoftware.
the class GemlockParser method discoveredDependencyInfo.
private void discoveredDependencyInfo(final NameVersionDependencyId id) {
NameDependencyId nameOnlyId = new NameDependencyId(id.name);
// regardless we found the external id for this specific dependency.
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.RUBYGEMS, id.name, id.version);
lazyBuilder.setDependencyInfo(id, id.name, id.version, externalId);
if (!resolvedDependencies.contains(id.name)) {
// if this is our first time encountering a dependency of this name, we become the 'version-less'
resolvedDependencies.add(id.name);
lazyBuilder.setDependencyInfo(nameOnlyId, id.name, id.version, externalId);
} else {
// otherwise, add us as a child to the version-less
lazyBuilder.addChildWithParent(id, nameOnlyId);
}
}
use of com.synopsys.integration.bdio.model.dependencyid.NameDependencyId 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.NameDependencyId 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.NameDependencyId in project hub-detect by blackducksoftware.
the class PackagistParser method getDependencyGraphFromProject.
public PackagistParseResult getDependencyGraphFromProject(final String sourcePath, final String composerJsonText, final String composerLockText) {
final LazyExternalIdDependencyGraphBuilder builder = new LazyExternalIdDependencyGraphBuilder();
final JsonObject composerJsonObject = new JsonParser().parse(composerJsonText).getAsJsonObject();
final NameVersion projectNameVersion = parseNameVersionFromJson(composerJsonObject);
final JsonObject composerLockObject = new JsonParser().parse(composerLockText).getAsJsonObject();
final List<PackagistPackage> models = convertJsonToModel(composerLockObject, detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None));
final List<NameVersion> rootPackages = parseDependencies(composerJsonObject, detectConfiguration.getBooleanProperty(DetectProperty.DETECT_PACKAGIST_INCLUDE_DEV_DEPENDENCIES, PropertyAuthority.None));
models.forEach(it -> {
final ExternalId id = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, it.getNameVersion().getName(), it.getNameVersion().getVersion());
final NameDependencyId dependencyId = new NameDependencyId(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)) {
final NameDependencyId childId = new NameDependencyId(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());
}
});
});
ExternalId projectExternalId;
if (projectNameVersion.getName() == null || projectNameVersion.getVersion() == null) {
projectExternalId = externalIdFactory.createPathExternalId(Forge.PACKAGIST, sourcePath);
} else {
projectExternalId = externalIdFactory.createNameVersionExternalId(Forge.PACKAGIST, projectNameVersion.getName(), projectNameVersion.getVersion());
}
final DependencyGraph graph = builder.build();
final DetectCodeLocation codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.PACKAGIST, sourcePath, projectExternalId, graph).build();
return new PackagistParseResult(projectNameVersion.getName(), projectNameVersion.getVersion(), codeLocation);
}
use of com.synopsys.integration.bdio.model.dependencyid.NameDependencyId in project hub-detect by blackducksoftware.
the class GemlockParser method parseSpecPackageLine.
private void parseSpecPackageLine(final String trimmedLine) {
final NameVersion parentNameVersion = parseNameVersion(trimmedLine);
if (StringUtils.isNotBlank(parentNameVersion.getVersion())) {
currentParent = new NameDependencyId(parentNameVersion.getName());
discoveredDependencyInfo(new NameVersionDependencyId(parentNameVersion.getName(), parentNameVersion.getVersion()));
} else {
logger.error(String.format("An installed spec did not have a non-fuzzy version: %s", trimmedLine));
}
}
Aggregations