Skip to content

Commit

Permalink
feat(gradle)!: Make GradleInspector the new default
Browse files Browse the repository at this point in the history
Despite its documented limitations, the benefits outweight the drawbacks
of making this the default analyzer for Gradle projects.

Adjust the Pub package manager as well to use GradleInspector for a
smooth migration. This requires to hard-code "Gradle" as the project
type because "GradleInspector" is the only package manager that does not
follow the convention of the manager name to match the project type.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Sep 11, 2024
1 parent 500e680 commit b9657ff
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 112 deletions.
10 changes: 5 additions & 5 deletions analyzer/src/funTest/kotlin/PackageManagerFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PackageManagerFunTest : WordSpec({
"conan-txt/conanfile.txt"
)
managedFilesByName["GoMod"] should containExactly("gomod/go.mod")
managedFilesByName["Gradle"] should containExactlyInAnyOrder(
managedFilesByName["GradleInspector"] should containExactlyInAnyOrder(
"gradle-groovy/build.gradle",
"gradle-kotlin/build.gradle.kts"
)
Expand Down Expand Up @@ -139,7 +139,7 @@ class PackageManagerFunTest : WordSpec({
val managedFiles = PackageManager.findManagedFiles(
projectDir,
setOf(
PackageManagerFactory.ALL.getValue("Gradle"),
PackageManagerFactory.ALL.getValue("GradleInspector"),
PackageManagerFactory.ALL.getValue("Pip"),
PackageManagerFactory.ALL.getValue("Sbt")
)
Expand All @@ -149,7 +149,7 @@ class PackageManagerFunTest : WordSpec({

val managedFilesByName = managedFiles.groupByName(projectDir)

managedFilesByName["Gradle"] should containExactlyInAnyOrder(
managedFilesByName["GradleInspector"] should containExactlyInAnyOrder(
"gradle-groovy/build.gradle",
"gradle-kotlin/build.gradle.kts"
)
Expand Down Expand Up @@ -178,7 +178,7 @@ class PackageManagerFunTest : WordSpec({

val managedFilesByName = PackageManager.findManagedFiles(rootDir, excludes = excludes).groupByName(rootDir)

managedFilesByName["Gradle"] should containExactlyInAnyOrder(
managedFilesByName["GradleInspector"] should containExactlyInAnyOrder(
"gradle-groovy/build.gradle",
"gradle-kotlin/build.gradle.kts"
)
Expand All @@ -193,7 +193,7 @@ class PackageManagerFunTest : WordSpec({
val managedFiles = PackageManager.findManagedFiles(projectDir, excludes = excludes)
val managedFilesByName = managedFiles.groupByName(projectDir)

managedFilesByName["Gradle"] should containExactly(
managedFilesByName["GradleInspector"] should containExactly(
"gradle-kotlin/build.gradle.kts"
)
}
Expand Down
15 changes: 4 additions & 11 deletions plugins/package-managers/gradle-inspector/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
# GradleInspector

The [GradleInspector] is an alternative analyzer for projects that use the Gradle package manager.
It is supposed to address [several] [shortcomings] of the "legacy" [Gradle] analyzer, but to not interfere with it, the [GradleInspector] is disabled by default.
The [GradleInspector] is the default analyzer for projects that use the Gradle package manager.
It is supposed to address [several] [shortcomings] of the "legacy" [Gradle] analyzer, which is disabled by default.

## Usage

As the [GradleInspector] is disabled by default, it needs to be enabled explicitly (along with any other package managers that should be enabled):

```shell
ort -P ort.analyzer.enabledPackageManagers=GradleInspector[,...] analyze
```

It is recommended to *not* also enable the "legacy" [Gradle] analyzer at the same time, as both analyzers would find the same definition files.
> [!NOTE]
> It is *not* recommended to also enable the "legacy" [Gradle] analyzer at the same time, as both analyzers would find the same definition files.
## Implementation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class GradleInspector(
analyzerConfig: AnalyzerConfiguration,
repoConfig: RepositoryConfiguration
) : PackageManager(name, analysisRoot, analyzerConfig, repoConfig) {
class Factory : AbstractPackageManagerFactory<GradleInspector>("GradleInspector", isEnabledByDefault = false) {
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
// "build" file.
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 @@ -93,7 +93,7 @@ class Gradle(
const val OPTION_GRADLE_VERSION = "gradleVersion"
}

class Factory : AbstractPackageManagerFactory<Gradle>("Gradle") {
class Factory : AbstractPackageManagerFactory<Gradle>("Gradle", isEnabledByDefault = false) {
// 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
// "build" file.
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/pub/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
implementation(libs.kotlinx.serialization.core)
implementation(libs.kotlinx.serialization.yaml)

funTestImplementation(projects.plugins.packageManagers.gradlePackageManager)
funTestImplementation(projects.plugins.packageManagers.gradleInspector)

funTestImplementation(testFixtures(projects.analyzer))
}
Loading

0 comments on commit b9657ff

Please sign in to comment.