use of org.jfrog.build.extractor.npm.types.NpmPackageInfo in project build-info by JFrogDev.
the class NpmBuildInfoExtractor method populateDependenciesMap.
/**
* Populate the dependencies map for the specified scope by:
* 1. Create npm dependency tree from root node of 'npm ls' command tree. Populate each node with name, version and scope.
* 2. For each dependency, retrieve sha1 and md5 from Artifactory. Use the producer-consumer mechanism to parallelize it.
*/
private void populateDependenciesMap(Map<String, Dependency> dependencies, Map<String, Dependency> previousBuildDependencies, JsonNode npmDependencyTree, NpmScope scope, Path workingDir) throws Exception {
// Set of packages that could not be found in Artifactory.
Set<NpmPackageInfo> badPackages = Collections.synchronizedSet(new HashSet<>());
DefaultMutableTreeNode rootNode = NpmDependencyTree.createDependencyTree(npmDependencyTree, scope, workingDir);
try (ArtifactoryManager artifactoryManager = artifactoryManagerBuilder.build()) {
// Create producer Runnable.
ProducerRunnableBase[] producerRunnable = new ProducerRunnableBase[] { new NpmExtractorProducer(rootNode) };
// Create consumer Runnables.
ConsumerRunnableBase[] consumerRunnables = new ConsumerRunnableBase[] { new NpmExtractorConsumer(artifactoryManager, dependencies, previousBuildDependencies, badPackages), new NpmExtractorConsumer(artifactoryManager, dependencies, previousBuildDependencies, badPackages), new NpmExtractorConsumer(artifactoryManager, dependencies, previousBuildDependencies, badPackages) };
// Create the deployment executor.
ProducerConsumerExecutor deploymentExecutor = new ProducerConsumerExecutor(logger, producerRunnable, consumerRunnables, CONNECTION_POOL_SIZE);
deploymentExecutor.start();
if (!badPackages.isEmpty()) {
logger.info((Arrays.toString(badPackages.toArray())));
logger.info("The npm dependencies above could not be found in Artifactory and therefore are not included in the build-info. " + "Make sure the dependencies are available in Artifactory for this build. " + "Deleting the local cache will force populating Artifactory with these dependencies.");
}
}
}
use of org.jfrog.build.extractor.npm.types.NpmPackageInfo 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.npm.types.NpmPackageInfo in project build-info by JFrogDev.
the class NpmExtractorProducer method producerRun.
@Override
public void producerRun() throws InterruptedException {
try {
Enumeration e = dependenciesRootNode.breadthFirstEnumeration();
while (e.hasMoreElements()) {
if (Thread.interrupted()) {
break;
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
NpmPackageInfo npmPackageInfo = (NpmPackageInfo) node.getUserObject();
if (npmPackageInfo == null) {
continue;
}
if (StringUtils.isBlank(npmPackageInfo.getVersion())) {
log.warn("npm dependencies list contains the package " + npmPackageInfo.getName() + " without version information. The dependency will not be added to build-info");
continue;
}
executor.put(npmPackageInfo);
}
} catch (InterruptedException e) {
throw e;
} catch (Exception e) {
// Throw unchecked exception for the UncaughtExceptionHandler
throw new RuntimeException(e);
}
}
use of org.jfrog.build.extractor.npm.types.NpmPackageInfo in project build-info by JFrogDev.
the class NpmExtractorConsumer method consumerRun.
@Override
public void consumerRun() {
while (!Thread.interrupted()) {
try {
ProducerConsumerItem item = executor.take();
if (item == executor.TERMINATE) {
// If reached the TERMINATE NpmPackageInfo, return it to the queue and exit.
executor.put(item);
break;
}
NpmPackageInfo npmPackageInfo = (NpmPackageInfo) item;
// Try to extract sha1 and md5 for 'npmPackageInfo'. If it doesn't exist in Artifactory's cache, add it to the 'badPackages' list.
if (!appendDependency(npmPackageInfo)) {
badPackages.add(npmPackageInfo);
}
} catch (InterruptedException e) {
return;
}
}
}
use of org.jfrog.build.extractor.npm.types.NpmPackageInfo 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