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.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Sep 3, 2024
1 parent 6b9e6dd commit bffba4d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 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 new 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 now.

## 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 @@ -104,7 +104,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/src/main/kotlin/Pub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Pub(

private val flutterAbsolutePath = flutterHome.resolve("bin")

private val gradleFactory = PackageManagerFactory.ALL["Gradle"]
private val gradleFactory = PackageManagerFactory.ALL["GradleInspector"]

private data class ParsePackagesResult(
val packages: Map<Identifier, Package>,
Expand Down

0 comments on commit bffba4d

Please sign in to comment.