Skip to content

Commit

Permalink
refactor(package-managers)!: Make explicit which project type gets ma…
Browse files Browse the repository at this point in the history
…naged

The old convention of the type of a project ID being set to the
manager's name is not applicable anymore since the introduction of
"inspector"-like package manager implementations, also see related
changes like 7c52615.

To prepare for not hard-coding the type for project IDs when a `Project`
is created, require all package manager implementations to explicitly
specify the type of project they manage.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 13, 2024
1 parent b80ec20 commit 5d5ea5c
Show file tree
Hide file tree
Showing 27 changed files with 29 additions and 28 deletions.
5 changes: 3 additions & 2 deletions analyzer/src/main/kotlin/PackageManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ typealias ManagedProjectFiles = Map<PackageManagerFactory, List<File>>
typealias ProjectResults = Map<File, List<ProjectAnalyzerResult>>

/**
* A class representing a package manager that handles software dependencies. The package manager is referred to by its
* [managerName]. The analysis of any projects and their dependencies starts in the [analysisRoot] directory using the
* A class to represent a package manager of the given [managerName] that handles dependencies for the given
* [projectType]. The analysis of any projects and their dependencies starts in the [analysisRoot] directory using the
* given general [analyzerConfig]. Per-repository configuration is passed in [repoConfig].
*/
abstract class PackageManager(
val managerName: String,
val projectType: String,
val analysisRoot: File,
val analyzerConfig: AnalyzerConfiguration,
val repoConfig: RepositoryConfiguration
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Bazel(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Bazel", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Bazel>("Bazel") {
override val globsForDefinitionFiles = listOf("MODULE", "MODULE.bazel")

Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/bower/src/main/kotlin/Bower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Bower(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Bower", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Bower>("Bower") {
override val globsForDefinitionFiles = listOf("bower.json")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Bundler(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "Bundler", analysisRoot, analyzerConfig, repoConfig) {
companion object {
/**
* The name of the option to specify the Bundler version.
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/cargo/src/main/kotlin/Cargo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Cargo(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Cargo", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Cargo>("Cargo") {
override val globsForDefinitionFiles = listOf("Cargo.toml")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Carthage(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "Carthage", analysisRoot, analyzerConfig, repoConfig) {
class Factory : AbstractPackageManagerFactory<Carthage>("Carthage") {
// TODO: Add support for the Cartfile.
// This would require to resolve the actual dependency versions as a Cartfile supports dynamic versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class CocoaPods(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "CocoaPods", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<CocoaPods>("CocoaPods") {
override val globsForDefinitionFiles = listOf("Podfile")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Composer(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Composer", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Composer>("Composer") {
override val globsForDefinitionFiles = listOf("composer.json")

Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/conan/src/main/kotlin/Conan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Conan(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Conan", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
companion object {
/**
* The name of the option to specify the name of the lockfile.
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/go/src/main/kotlin/GoMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class GoMod(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Go", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<GoMod>("GoMod") {
override val globsForDefinitionFiles = listOf("go.mod")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class GradleInspector(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "Gradle", analysisRoot, analyzerConfig, repoConfig) {
class Factory : AbstractPackageManagerFactory<GradleInspector>("GradleInspector") {
// Gradle prefers Groovy ".gradle" files over Kotlin ".gradle.kts" files, but "build" files have to come before
// "settings" files as we should consider "settings" files only if the same directory does not also contain a
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/gradle/src/main/kotlin/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class Gradle(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "Gradle", analysisRoot, analyzerConfig, repoConfig) {
companion object {
/**
* The name of the option to specify the Gradle version.
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/maven/src/main/kotlin/Maven.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Maven(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "Maven", analysisRoot, analyzerConfig, repoConfig) {
class Factory : AbstractPackageManagerFactory<Maven>("Maven") {
override val globsForDefinitionFiles = listOf("pom.xml")

Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/node/src/main/kotlin/npm/Npm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Npm(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "NPM", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
companion object {
/** Name of the configuration option to toggle legacy peer dependency support. */
const val OPTION_LEGACY_PEER_DEPS = "legacyPeerDeps"
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/node/src/main/kotlin/pnpm/Pnpm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Pnpm(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "PNPM", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Pnpm>("PNPM") {
override val globsForDefinitionFiles = listOf("package.json", "pnpm-lock.yaml")

Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/node/src/main/kotlin/yarn/Yarn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ open class Yarn(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Yarn", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Yarn>("Yarn") {
override val globsForDefinitionFiles = listOf("package.json")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Yarn2(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Yarn2", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
companion object {
/**
* The name of the option to disable HTTPS server certificate verification.
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/nuget/src/main/kotlin/NuGet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NuGet(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "NuGet", analysisRoot, analyzerConfig, repoConfig) {
companion object {
const val OPTION_NUGET_CONFIG = "nugetConfigFile"
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/pub/src/main/kotlin/Pub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Pub(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Pub", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
companion object {
const val OPTION_FLUTTER_VERSION = "flutterVersion"
const val OPTION_GRADLE_VERSION = "gradleVersion"
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/python/src/main/kotlin/Pip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Pip(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "PIP", analysisRoot, analyzerConfig, repoConfig) {
companion object {
const val OPTION_OPERATING_SYSTEM = "operatingSystem"
const val OPTION_PYTHON_VERSION = "pythonVersion"
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/python/src/main/kotlin/Pipenv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Pipenv(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Pipenv", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Pipenv>("Pipenv") {
override val globsForDefinitionFiles = listOf("Pipfile.lock")

Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/python/src/main/kotlin/Poetry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Poetry(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Poetry", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
companion object {
/**
* The name of the build system requirements and information file used by modern Python packages.
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/sbt/src/main/kotlin/Sbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Sbt(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "SBT", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Sbt>("SBT") {
override val globsForDefinitionFiles = listOf("build.sbt", "build.scala")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class SpdxDocumentFile(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(managerName, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(managerName, "SpdxDocument", analysisRoot, analyzerConfig, repoConfig) {
class Factory : AbstractPackageManagerFactory<SpdxDocumentFile>("SpdxDocumentFile") {
override val globsForDefinitionFiles = listOf("*.spdx.yml", "*.spdx.yaml", "*.spdx.json")

Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Stack(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "Stack", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<Stack>("Stack") {
override val globsForDefinitionFiles = listOf("stack.yaml")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SwiftPm(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
) : PackageManager(name, "SwiftPM", analysisRoot, analyzerConfig, repoConfig), CommandLineTool {
class Factory : AbstractPackageManagerFactory<SwiftPm>("SwiftPM") {
override val globsForDefinitionFiles = listOf(PACKAGE_SWIFT_NAME, PACKAGE_RESOLVED_NAME)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Unmanaged(
analysisRoot: File,
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
) : PackageManager(name, "Unmanaged", analysisRoot, analyzerConfig, repoConfig) {
class Factory : AbstractPackageManagerFactory<Unmanaged>("Unmanaged") {
// The empty list returned here deliberately causes this special package manager to never be considered in
// PackageManager.findManagedFiles(). Instead, it will only be explicitly instantiated as part of
Expand Down

0 comments on commit 5d5ea5c

Please sign in to comment.