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

Make GradleInspector the new default analyzer for Gradle projects #9070

Merged
merged 5 commits into from
Sep 11, 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
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
27 changes: 11 additions & 16 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 All @@ -31,18 +24,20 @@ Execution of the Gradle plugin will be blocked until the remote debugger is atta

## Limitations

The retrieval of the checksum values for remote artifacts is currently done via plain OkHttp calls, which means it will not work out of the box for private repositories.
To work around this, credentials need to be configured in `.netrc` additionally to in Gradle.
This is similar to how the "legacy" [Gradle] analyzer required to additionally configure credentials in Maven.
Currently, the [GradleInspector] has the following known limitations:

Also, the `isModified` check which compares with artifacts of the same name in Maven Central is not implemented yet.
* The retrieval of the checksum values for remote artifacts is currently done via plain OkHttp calls, which means it will not work out of the box for private repositories.
To work around this, credentials need to be configured in a `.netrc` file in addition to the Gradle build.
* The `isModified` check which compares build artifacts with artifacts of the same name in Maven Central is not implemented yet.
* The implementation [cannot deal with classifiers and / or non-JAR artifacts].

[GradleInspector]: ./src/main/kotlin/GradleInspector.kt
[several]: https://github.com/oss-review-toolkit/ort/issues/4694
[shortcomings]: https://github.com/oss-review-toolkit/ort/issues/5782
[Gradle]: ../gradle/src/main/kotlin/Gradle.kt
[initialization script]: https://docs.gradle.org/current/userguide/init_scripts.html
[init.gradle]: ./src/main/resources/init.gradle.template
[init.gradle]: ./src/main/resources/template.init.gradle
[Gradle plugin]: ../gradle-plugin/src/main/kotlin/OrtModelPlugin.kt
[OrtModelBuilder]: ../gradle-plugin/src/main/kotlin/OrtModelBuilder.kt
[data model for Gradle projects]: ../gradle-model/src/main/kotlin/GradleModel.kt
[cannot deal with classifiers and / or non-JAR artifacts]: https://github.com/oss-review-toolkit/ort/issues/7995
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
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
Loading