use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class BazelCodeLocationBuilderTest method test.
@Test
public void test() {
BazelCodeLocationBuilder bdioBuilder = new BazelCodeLocationBuilder(new ExternalIdFactory());
final List<DetectCodeLocation> codeLocations = bdioBuilder.setWorkspaceDir(new File("src/test/resources/bazel/multiLevel")).addDependency(BazelExternalId.fromBazelArtifactString("testGroup:testArtifact:testVersion", ":")).build();
assertEquals(1, codeLocations.size());
assertEquals("src/test/resources/bazel/multiLevel", codeLocations.get(0).getExternalId().path);
assertEquals(1, codeLocations.get(0).getDependencyGraph().getRootDependencies().size());
Dependency dep = codeLocations.get(0).getDependencyGraph().getRootDependencies().iterator().next();
assertEquals("testArtifact", dep.name);
assertEquals("testVersion", dep.version);
assertEquals("testGroup", dep.externalId.group);
}
use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class DependencyGraphAssertions method assertDoesNotHave.
private static void assertDoesNotHave(final DependencyGraph dependencyGraph, final String target, final ExternalId current) {
if (current == null) {
for (final Dependency dep : dependencyGraph.getRootDependencies()) {
assertDoesNotHave(dep, target);
assertDoesNotHave(dependencyGraph, target, dep.externalId);
}
} else {
for (final Dependency dep : dependencyGraph.getChildrenForParent(current)) {
assertDoesNotHave(dep, target);
assertDoesNotHave(dependencyGraph, target, dep.externalId);
}
}
}
use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class DependencyGraphAssertions method assertHasMavenGav.
public static void assertHasMavenGav(final DependencyGraph dependencyGraph, final String org, final String name, final String version) {
final ExternalIdFactory externalIdFactory = new ExternalIdFactory();
final ExternalId id = externalIdFactory.createMavenExternalId(org, name, version);
final Dependency dep = dependencyGraph.getDependency(id);
assertNotNull("Expected dependency '" + org + ":" + name + ":" + version + "' to exist in graph but it was null.", dep);
}
use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class NpmCliParser method populateChildren.
private void populateChildren(final MutableDependencyGraph graph, final Dependency parentDependency, final JsonObject parentNodeChildren, final Boolean root) {
if (parentNodeChildren == null) {
return;
}
final Set<Entry<String, JsonElement>> elements = parentNodeChildren.entrySet();
elements.forEach(it -> {
if (it.getValue() != null && it.getValue().isJsonObject()) {
}
final JsonObject element = it.getValue().getAsJsonObject();
final String name = it.getKey();
String version = null;
final JsonPrimitive versionPrimitive = element.getAsJsonPrimitive(JSON_VERSION);
if (versionPrimitive != null && versionPrimitive.isString()) {
version = versionPrimitive.getAsString();
}
final JsonObject children = element.getAsJsonObject(JSON_DEPENDENCIES);
if (name != null && version != null) {
final ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPM, name, version);
final Dependency child = new Dependency(name, version, externalId);
populateChildren(graph, child, children, false);
if (root) {
graph.addChildToRoot(child);
} else {
graph.addParentWithChild(parentDependency, child);
}
}
});
}
use of com.synopsys.integration.bdio.model.dependency.Dependency in project hub-detect by blackducksoftware.
the class GradleReportParser method parseDependencies.
public Optional<DetectCodeLocation> parseDependencies(final File codeLocationFile) {
DetectCodeLocation codeLocation = null;
String projectSourcePath = "";
String projectGroup = "";
String projectName = "";
String projectVersionName = "";
boolean processingMetaData = false;
final MutableDependencyGraph graph = new MutableMapDependencyGraph();
final DependencyHistory history = new DependencyHistory();
try (FileInputStream dependenciesInputStream = new FileInputStream(codeLocationFile);
BufferedReader reader = new BufferedReader(new InputStreamReader(dependenciesInputStream, StandardCharsets.UTF_8))) {
while (reader.ready()) {
final String line = reader.readLine();
/**
* The meta data section will be at the end of the file after all of the "gradle dependencies" output
*/
if (line.startsWith(DETECT_META_DATA_HEADER)) {
processingMetaData = true;
continue;
}
if (line.startsWith(DETECT_META_DATA_FOOTER)) {
processingMetaData = false;
continue;
}
if (processingMetaData) {
if (line.startsWith(PROJECT_PATH_PREFIX)) {
projectSourcePath = line.substring(PROJECT_PATH_PREFIX.length()).trim();
} else if (line.startsWith(PROJECT_GROUP_PREFIX)) {
projectGroup = line.substring(PROJECT_GROUP_PREFIX.length()).trim();
} else if (line.startsWith(PROJECT_NAME_PREFIX)) {
projectName = line.substring(PROJECT_NAME_PREFIX.length()).trim();
} else if (line.startsWith(PROJECT_VERSION_PREFIX)) {
projectVersionName = line.substring(PROJECT_VERSION_PREFIX.length()).trim();
}
continue;
}
if (StringUtils.isBlank(line)) {
history.clear();
gradleReportConfigurationParser = new GradleReportConfigurationParser();
continue;
}
final Dependency dependency = gradleReportConfigurationParser.parseDependency(externalIdFactory, line);
if (dependency == null) {
continue;
}
final int lineTreeLevel = gradleReportConfigurationParser.getTreeLevel();
try {
history.clearDependenciesDeeperThan(lineTreeLevel);
} catch (final IllegalStateException e) {
logger.warn(String.format("Problem parsing line '%s': %s", line, e.getMessage()));
}
if (history.isEmpty()) {
graph.addChildToRoot(dependency);
} else {
graph.addChildWithParents(dependency, history.getLastDependency());
}
history.add(dependency);
}
final ExternalId id = externalIdFactory.createMavenExternalId(projectGroup, projectName, projectVersionName);
codeLocation = new DetectCodeLocation.Builder(DetectCodeLocationType.GRADLE, projectSourcePath, id, graph).build();
} catch (final IOException e) {
codeLocation = null;
}
return Optional.ofNullable(codeLocation);
}
Aggregations