use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class MavenParseExtractor method extract.
public Extraction extract(File pomXmlFile, MavenParseOptions mavenParseOptions) {
try (InputStream pomXmlInputStream = new FileInputStream(pomXmlFile)) {
// we have to create a new handler or the state of all handlers would be shared.
// we could create a handler factory or some other indirection so it could be injected but for now we make a new one.
PomDependenciesHandler pomDependenciesHandler = new PomDependenciesHandler(mavenParseOptions.isIncludePlugins());
saxParser.parse(pomXmlInputStream, pomDependenciesHandler);
List<Dependency> dependencies = pomDependenciesHandler.getDependencies();
DependencyGraph dependencyGraph = new BasicDependencyGraph();
dependencyGraph.addChildrenToRoot(dependencies);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
return Extraction.success(codeLocation);
} catch (Exception e) {
return new Extraction.Builder().exception(e).build();
}
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class NpmLockfileGraphTransformer method transform.
public DependencyGraph transform(PackageLock packageLock, NpmProject project, List<NameVersion> externalDependencies) {
DependencyGraph dependencyGraph = new BasicDependencyGraph();
logger.debug("Processing project.");
if (packageLock.dependencies != null) {
logger.debug(String.format("Found %d dependencies in the lockfile.", packageLock.dependencies.size()));
// First we will recreate the graph from the resolved npm dependencies
for (NpmDependency resolved : project.getResolvedDependencies()) {
transformTreeToGraph(resolved, project, dependencyGraph, externalDependencies);
}
// Then we will add relationships between the project (root) and the graph
boolean atLeastOneRequired = !project.getDeclaredDependencies().isEmpty() || !project.getDeclaredDevDependencies().isEmpty() || !project.getDeclaredPeerDependencies().isEmpty();
if (atLeastOneRequired) {
addRootDependencies(project.getResolvedDependencies(), project.getDeclaredDependencies(), dependencyGraph, externalDependencies);
if (npmDependencyTypeFilter.shouldInclude(NpmDependencyType.DEV)) {
addRootDependencies(project.getResolvedDependencies(), project.getDeclaredDevDependencies(), dependencyGraph, externalDependencies);
}
if (npmDependencyTypeFilter.shouldInclude(NpmDependencyType.PEER)) {
addRootDependencies(project.getResolvedDependencies(), project.getDeclaredPeerDependencies(), dependencyGraph, externalDependencies);
}
} else {
project.getResolvedDependencies().stream().filter(this::shouldIncludeDependency).forEach(dependencyGraph::addChildToRoot);
}
logger.debug(String.format("Found %d root dependencies.", dependencyGraph.getRootDependencies().size()));
} else {
logger.debug("Lock file did not have a 'dependencies' section.");
}
return dependencyGraph;
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class PackageJsonExtractor method extract.
public Extraction extract(PackageJson packageJson) {
List<Dependency> dependencies = transformDependencies(packageJson.dependencies);
npmDependencyTypeFilter.ifShouldInclude(NpmDependencyType.DEV, transformDependencies(packageJson.devDependencies), dependencies::addAll);
npmDependencyTypeFilter.ifShouldInclude(NpmDependencyType.PEER, transformDependencies(packageJson.peerDependencies), dependencies::addAll);
DependencyGraph dependencyGraph = new BasicDependencyGraph();
dependencyGraph.addChildrenToRoot(dependencies);
CodeLocation codeLocation = new CodeLocation(dependencyGraph);
String projectName = StringUtils.stripToNull(packageJson.name);
String projectVersion = StringUtils.stripToNull(packageJson.version);
return new Extraction.Builder().success(codeLocation).projectName(projectName).projectVersion(projectVersion).build();
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class GradleReportTransformer method transform.
public CodeLocation transform(GradleReport gradleReport) {
DependencyGraph graph = new BasicDependencyGraph();
for (GradleConfiguration configuration : gradleReport.getConfigurations()) {
if (configuration.isResolved() || configurationTypeFilter.shouldInclude(GradleConfigurationType.UNRESOLVED)) {
logger.trace("Adding configuration to the graph: {}", configuration.getName());
addConfigurationToGraph(graph, configuration);
} else {
logger.trace("Excluding unresolved configuration from the graph: {}", configuration.getName());
}
}
ExternalId projectId = ExternalId.FACTORY.createMavenExternalId(gradleReport.getProjectGroup(), gradleReport.getProjectName(), gradleReport.getProjectVersionName());
if (StringUtils.isNotBlank(gradleReport.getProjectSourcePath())) {
return new CodeLocation(graph, projectId, new File(gradleReport.getProjectSourcePath()));
} else {
return new CodeLocation(graph, projectId);
}
}
use of com.synopsys.integration.bdio.graph.BasicDependencyGraph in project synopsys-detect by blackducksoftware.
the class NpmCliParser method convertNpmJsonFileToCodeLocation.
public NpmPackagerResult convertNpmJsonFileToCodeLocation(String npmLsOutput, PackageJson packageJson) {
JsonObject npmJson = JsonParser.parseString(npmLsOutput).getAsJsonObject();
DependencyGraph graph = new BasicDependencyGraph();
JsonElement projectNameElement = npmJson.getAsJsonPrimitive(JSON_NAME);
JsonElement projectVersionElement = npmJson.getAsJsonPrimitive(JSON_VERSION);
String projectName = null;
String projectVersion = null;
if (projectNameElement != null) {
projectName = projectNameElement.getAsString();
}
if (projectVersionElement != null) {
projectVersion = projectVersionElement.getAsString();
}
populateChildren(graph, null, npmJson.getAsJsonObject(JSON_DEPENDENCIES), true, packageJson);
ExternalId externalId = externalIdFactory.createNameVersionExternalId(Forge.NPMJS, projectName, projectVersion);
CodeLocation codeLocation = new CodeLocation(graph, externalId);
return new NpmPackagerResult(projectName, projectVersion, codeLocation);
}
Aggregations