Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node follow-ups #9389

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* License-Filename: LICENSE
*/

package org.ossreviewtoolkit.plugins.packagemanagers.node.utils
package org.ossreviewtoolkit.plugins.packagemanagers.node

import java.io.File
import java.nio.file.FileSystems
Expand All @@ -31,7 +31,7 @@ import org.ossreviewtoolkit.utils.common.collectMessages
/**
* A class to detect the package managers used for the give [definitionFiles].
*/
class NpmDetection(private val definitionFiles: Collection<File>) {
internal class NpmDetection(private val definitionFiles: Collection<File>) {
/**
* A map of project directories to the set of package managers that are most likely responsible for the project. If
* the set is empty, none of the package managers is responsible.
Expand Down Expand Up @@ -110,7 +110,7 @@ class NpmDetection(private val definitionFiles: Collection<File>) {
/**
* An enum of all supported Node package managers.
*/
enum class NodePackageManager(
internal enum class NodePackageManager(
val lockfileName: String,
val markerFileName: String? = null,
val workspaceFileName: String = NodePackageManager.DEFINITION_FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* License-Filename: LICENSE
*/

package org.ossreviewtoolkit.plugins.packagemanagers.node.utils
package org.ossreviewtoolkit.plugins.packagemanagers.node

import java.io.File
import java.lang.invoke.MethodHandles
Expand All @@ -37,14 +37,14 @@
import org.ossreviewtoolkit.model.RemoteArtifact
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.utils.common.realFile
import org.ossreviewtoolkit.utils.common.toUri
import org.ossreviewtoolkit.utils.spdx.SpdxConstants

internal const val NON_EXISTING_SEMVER = "0.0.0"

private val logger = loggerOf(MethodHandles.lookup().lookupClass())

/**
* Expand an NPM shortcut [url] to a regular URL as used for dependencies, see
* https://docs.npmjs.com/cli/v7/configuring-npm/package-json#urls-as-dependencies.
Expand Down Expand Up @@ -98,7 +98,7 @@
private val ARTIFACTORY_API_PATH_PATTERN = Regex("(.*artifactory.*)/api/npm/(.*)")

/**
* Parse information about the author from the [package.json][json] file of a module. According to

Check warning on line 101 in plugins/package-managers/node/src/main/kotlin/NpmSupport.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unresolved reference in KDoc

Cannot resolve symbol 'json'
* https://docs.npmjs.com/files/package.json#people-fields-author-contributors, there are two formats to
* specify the author of a package: An object with multiple properties or a single string.
*/
Expand Down Expand Up @@ -130,7 +130,7 @@
}

/**
* Parse information about the VCS from the [package.json][node] file of a module.

Check warning on line 133 in plugins/package-managers/node/src/main/kotlin/NpmSupport.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unresolved reference in KDoc

Cannot resolve symbol 'node'
*/
internal fun parseNpmVcsInfo(packageJson: PackageJson): VcsInfo {
// See https://github.com/npm/read-package-json/issues/7 for some background info.
Expand Down Expand Up @@ -247,8 +247,6 @@
return module
}

private val logger = loggerOf(MethodHandles.lookup().lookupClass())

internal fun parseProject(packageJsonFile: File, analysisRoot: File, managerName: String): Project {
logger.debug { "Parsing project info from '$packageJsonFile'." }

Expand Down
7 changes: 4 additions & 3 deletions plugins/package-managers/node/src/main/kotlin/npm/Npm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.PackageManagerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.yarn.Yarn
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.ProcessCapture
Expand Down Expand Up @@ -95,7 +96,7 @@ class Npm(
return runCatching {
val process = run(workingDir, "info", "--json", packageName)

org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson(process.stdout)
parsePackageJson(process.stdout)
}.onFailure { e ->
logger.warn { "Error getting details for $packageName in directory $workingDir: ${e.message.orEmpty()}" }
}.onSuccess {
Expand Down
6 changes: 3 additions & 3 deletions plugins/package-managers/node/src/main/kotlin/pnpm/Pnpm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import org.ossreviewtoolkit.model.ProjectAnalyzerResult
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.utils.DependencyGraphBuilder
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseProject
import org.ossreviewtoolkit.plugins.packagemanagers.node.parseProject
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.stashDirectories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.utils.DependencyHandler
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackage
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.pnpm.ModuleInfo.Dependency
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parsePackage
import org.ossreviewtoolkit.utils.common.realFile

internal class PnpmDependencyHandler(private val pnpm: Pnpm) : DependencyHandler<Dependency> {
Expand Down
8 changes: 4 additions & 4 deletions plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.createAndLogIssue
import org.ossreviewtoolkit.model.readTree
import org.ossreviewtoolkit.model.utils.DependencyGraphBuilder
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.npm.groupLines
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseProject
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.splitNpmNamespaceAndName
import org.ossreviewtoolkit.plugins.packagemanagers.node.parseProject
import org.ossreviewtoolkit.plugins.packagemanagers.node.splitNpmNamespaceAndName
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.DiskCache
import org.ossreviewtoolkit.utils.common.Os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.utils.DependencyHandler
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parsePackage
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackage

/**
* A data class storing information about a specific NPM module and its dependencies.
Expand Down
14 changes: 7 additions & 7 deletions plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.createAndLogIssue
import org.ossreviewtoolkit.model.utils.DependencyGraphBuilder
import org.ossreviewtoolkit.model.utils.DependencyHandler
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.fixNpmDownloadUrl
import org.ossreviewtoolkit.plugins.packagemanagers.node.mapNpmLicenses
import org.ossreviewtoolkit.plugins.packagemanagers.node.parseNpmAuthor
import org.ossreviewtoolkit.plugins.packagemanagers.node.parseNpmVcsInfo
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.parsePackageJsons
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NpmDetection
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.fixNpmDownloadUrl
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.mapNpmLicenses
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmAuthor
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.parseNpmVcsInfo
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.splitNpmNamespaceAndName
import org.ossreviewtoolkit.plugins.packagemanagers.node.splitNpmNamespaceAndName
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.ort.runBlocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* License-Filename: LICENSE
*/

package org.ossreviewtoolkit.plugins.packagemanagers.node.utils
package org.ossreviewtoolkit.plugins.packagemanagers.node

import io.kotest.core.spec.style.WordSpec
import io.kotest.engine.spec.tempdir
Expand All @@ -30,14 +30,14 @@
import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.analyzer.PackageManager
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager.NPM
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager.PNPM
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager.YARN
import org.ossreviewtoolkit.plugins.packagemanagers.node.utils.NodePackageManager.YARN2
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager.NPM
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager.PNPM
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager.YARN
import org.ossreviewtoolkit.plugins.packagemanagers.node.NodePackageManager.YARN2
import org.ossreviewtoolkit.utils.common.withoutPrefix
import org.ossreviewtoolkit.utils.test.getAssetFile

class NpmDetectionTest : WordSpec({

Check warning on line 40 in plugins/package-managers/node/src/test/kotlin/NpmDetectionTest.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unused symbol

Class "NpmDetectionTest" is never used
"All Node package manager detections" should {
"ignore empty lockfiles" {
NodePackageManager.entries.forAll {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
* License-Filename: LICENSE
*/

package org.ossreviewtoolkit.plugins.packagemanagers.node.utils
package org.ossreviewtoolkit.plugins.packagemanagers.node

import io.kotest.core.spec.style.WordSpec
import io.kotest.inspectors.forAll
import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson.Author
import org.ossreviewtoolkit.plugins.packagemanagers.node.PackageJson.Repository

class NpmSupportTest : WordSpec({

Check warning on line 31 in plugins/package-managers/node/src/test/kotlin/NpmSupportTest.kt

View workflow job for this annotation

GitHub Actions / qodana-scan

Unused symbol

Class "NpmSupportTest" is never used
"expandNpmShortcutUrl()" should {
"do nothing for empty URLs" {
expandNpmShortcutUrl("") shouldBe ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* License-Filename: LICENSE
*/

package org.ossreviewtoolkit.plugins.packagemanagers.node.utils
package org.ossreviewtoolkit.plugins.packagemanagers.node.yarn

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.collections.containExactly
Expand All @@ -32,11 +32,9 @@ import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.plugins.packagemanagers.node.npm.Npm
import org.ossreviewtoolkit.plugins.packagemanagers.node.yarn.NpmModuleInfo
import org.ossreviewtoolkit.plugins.packagemanagers.node.yarn.YarnDependencyHandler
import org.ossreviewtoolkit.utils.test.USER_DIR

class NpmDependencyHandlerTest : StringSpec({
class YarnDependencyHandlerTest : StringSpec({
"identifierFor extracts the correct identifier" {
val id = createIdentifier("foo")
val module = createModuleInfo(id)
Expand Down
Loading