diff --git a/plugins/package-managers/node/src/main/kotlin/Npm.kt b/plugins/package-managers/node/src/main/kotlin/Npm.kt index ac0b3c27f23a7..e4e479df79a2c 100644 --- a/plugins/package-managers/node/src/main/kotlin/Npm.kt +++ b/plugins/package-managers/node/src/main/kotlin/Npm.kt @@ -24,11 +24,6 @@ package org.ossreviewtoolkit.plugins.packagemanagers.node import java.io.File import java.util.concurrent.ConcurrentHashMap -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.withContext - import org.apache.logging.log4j.kotlin.logger import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory @@ -120,7 +115,7 @@ open class Npm( private val graphBuilder by lazy { DependencyGraphBuilder(NpmDependencyHandler(this)) } - private val npmViewCache = ConcurrentHashMap>() + private val npmViewCache = mutableMapOf() protected open fun hasLockfile(projectDir: File) = NodePackageManager.NPM.hasLockfile(projectDir) @@ -249,11 +244,7 @@ open class Npm( * Construct a [Package] by parsing its _package.json_ file and - if applicable - querying additional * content via the `npm view` command. The result is a [Pair] with the raw identifier and the new package. */ - internal suspend fun parsePackage(workingDir: File, packageJsonFile: File): Package { - val packageDir = packageJsonFile.parentFile - - logger.debug { "Found a 'package.json' file in '$packageDir'." } - + internal fun parsePackage(workingDir: File, packageJsonFile: File): Package { val packageJson = parsePackageJson(packageJsonFile) // The "name" and "version" fields are only required if the package is going to be published, otherwise they are @@ -289,7 +280,7 @@ open class Npm( if (hasIncompleteData) { runCatching { - getRemotePackageDetailsAsync(workingDir, "$rawName@$version").await() + getRemotePackageDetails(workingDir, "$rawName@$version") }.onSuccess { details -> if (description.isEmpty()) description = details.description.orEmpty() if (homepageUrl.isEmpty()) homepageUrl = details.homepage.orEmpty() @@ -342,20 +333,12 @@ open class Npm( return module } - private suspend fun getRemotePackageDetailsAsync(workingDir: File, packageName: String): Deferred = - withContext(Dispatchers.IO) { - npmViewCache.getOrPut(packageName) { - async { - getRemotePackageDetails(workingDir, packageName) - } - } + protected open fun getRemotePackageDetails(workingDir: File, packageName: String): PackageJson = + npmViewCache.getOrPut(packageName) { + val process = run(workingDir, "info", "--json", packageName) + parsePackageJson(process.stdout) } - protected open fun getRemotePackageDetails(workingDir: File, packageName: String): PackageJson { - val process = run(workingDir, "info", "--json", packageName) - return parsePackageJson(process.stdout) - } - /** Cache for submodules identified by its moduleDir absolutePath */ private val submodulesCache = ConcurrentHashMap>() diff --git a/plugins/package-managers/node/src/main/kotlin/utils/NpmDependencyHandler.kt b/plugins/package-managers/node/src/main/kotlin/utils/NpmDependencyHandler.kt index a18c62be7086f..af874762b97c4 100644 --- a/plugins/package-managers/node/src/main/kotlin/utils/NpmDependencyHandler.kt +++ b/plugins/package-managers/node/src/main/kotlin/utils/NpmDependencyHandler.kt @@ -28,7 +28,6 @@ import org.ossreviewtoolkit.model.PackageLinkage import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.utils.DependencyHandler import org.ossreviewtoolkit.plugins.packagemanagers.node.Npm -import org.ossreviewtoolkit.utils.ort.runBlocking /** * A data class storing information about a specific NPM module and its dependencies. @@ -76,7 +75,5 @@ internal class NpmDependencyHandler(private val npm: Npm) : DependencyHandler): Package? = - runBlocking { - npm.takeUnless { dependency.isProject }?.parsePackage(dependency.workingDir, dependency.packageFile) - } + npm.takeUnless { dependency.isProject }?.parsePackage(dependency.workingDir, dependency.packageFile) }