use of org.jfrog.build.extractor.scan.DependencyTree in project build-info by JFrogDev.
the class NpmDependencyTree method createDependencyTree.
/**
* Create a npm dependency tree from the results of 'npm ls' command.
*
* @param npmList - Results of 'npm ls' command
* @param scope - Dependency scope
* @param workingDir - The package.json directory
* @return Tree of npm PackageInfos.
* @see NpmPackageInfo
*/
public static DependencyTree createDependencyTree(JsonNode npmList, NpmScope scope, Path workingDir) {
DependencyTree rootNode = new DependencyTree();
populateDependenciesTree(rootNode, npmList.get("dependencies"), new String[] { getProjectName(npmList, workingDir) }, scope);
for (DependencyTree child : rootNode.getChildren()) {
NpmPackageInfo packageInfo = (NpmPackageInfo) child.getUserObject();
child.setScopes(getScopes(packageInfo.getName(), packageInfo.getScope()));
}
return rootNode;
}
use of org.jfrog.build.extractor.scan.DependencyTree in project build-info by JFrogDev.
the class GoRun method populateModuleAndDeps.
/**
* Populate the module name and the dependencies.
*/
private void populateModuleAndDeps() throws Exception {
backupModAndSumFiles();
try {
DependencyTree dependencyTree = createDependencyTree(goDriver, logger, true);
moduleName = dependencyTree.toString();
String cachePath = getCachePath();
Enumeration<?> nodes = dependencyTree.breadthFirstEnumeration();
// Skip root
nodes.nextElement();
while (nodes.hasMoreElements()) {
DependencyTree node = (DependencyTree) nodes.nextElement();
addDependency(node.toString(), cachePath);
}
} finally {
restoreModAnsSumFiles();
}
}
use of org.jfrog.build.extractor.scan.DependencyTree in project build-info by JFrogDev.
the class GoDependencyTree method populateDependencyTree.
/**
* Recursively populate the dependency tree.
*
* @param currNode - The current node
* @param currNameVersionString - Current dependency in form of <name>@v<version>
* @param allDependencies - Dependency to children map
* @param logger - The logger
*/
private static void populateDependencyTree(DependencyTree currNode, String currNameVersionString, Map<String, List<String>> allDependencies, Log logger) {
if (hasLoop(currNode, logger)) {
return;
}
List<String> currDependencies = allDependencies.get(currNameVersionString);
if (currDependencies == null) {
return;
}
for (String dependency : currDependencies) {
String[] dependencyNameVersion = dependency.split("@v");
DependencyTree DependencyTree = new DependencyTree(dependencyNameVersion[0] + ":" + dependencyNameVersion[1]);
currNode.add(DependencyTree);
populateDependencyTree(DependencyTree, dependency, allDependencies, logger);
}
}
use of org.jfrog.build.extractor.scan.DependencyTree in project build-info by JFrogDev.
the class GoDependencyTree method createDependencyTree.
/**
* Create Go dependency tree of actually used dependencies.
*
* @param goDriver - Go driver
* @param logger - The logger
* @param verbose - verbose logging
* @return Go dependency tree
* @throws IOException in case of any I/O error.
*/
public static DependencyTree createDependencyTree(GoDriver goDriver, Log logger, boolean verbose) throws IOException {
// Run go mod graph.
CommandResults goGraphResult = goDriver.modGraph(verbose);
String[] dependenciesGraph = goGraphResult.getRes().split("\\r?\\n");
// Run go list -f "{{with .Module}}{{.Path}} {{.Version}}{{end}}" all
CommandResults usedModulesResults;
try {
usedModulesResults = goDriver.getUsedModules(false, false);
} catch (IOException e) {
// Errors occurred during running "go list". Run again and this time ignore errors.
usedModulesResults = goDriver.getUsedModules(false, true);
logger.warn("Errors occurred during building the Go dependency tree. The dependency tree may be incomplete:" + System.lineSeparator() + ExceptionUtils.getRootCauseMessage(e));
}
Set<String> usedDependencies = Arrays.stream(usedModulesResults.getRes().split("\\r?\\n")).map(String::trim).map(usedModule -> usedModule.replace(" ", "@")).collect(Collectors.toSet());
// Create root node.
String rootPackageName = goDriver.getModuleName();
DependencyTree rootNode = new DependencyTree(rootPackageName);
rootNode.setMetadata(true);
// Build dependency tree.
Map<String, List<String>> dependenciesMap = new HashMap<>();
populateDependenciesMap(dependenciesGraph, usedDependencies, dependenciesMap);
populateDependencyTree(rootNode, rootPackageName, dependenciesMap, logger);
return rootNode;
}
use of org.jfrog.build.extractor.scan.DependencyTree in project build-info by JFrogDev.
the class NpmDependencyTree method addSubtree.
private static void addSubtree(Map.Entry<String, JsonNode> stringJsonNodeEntry, DependencyTree node, String name, String version, String[] pathToRoot, NpmScope scope) {
JsonNode jsonNode = stringJsonNodeEntry.getValue();
String devScope = scope.toString();
NpmPackageInfo npmPackageInfo = new NpmPackageInfo(name, version, devScope, pathToRoot);
JsonNode childDependencies = jsonNode.get("dependencies");
DependencyTree childTreeNode = new DependencyTree(npmPackageInfo);
// Mutual recursive call
populateDependenciesTree(childTreeNode, childDependencies, ArrayUtils.insert(0, pathToRoot, npmPackageInfo.toString()), scope);
node.add(childTreeNode);
}
Aggregations