Skip to content

Commit

Permalink
refactor(gradle): Turn extension functions into properties
Browse files Browse the repository at this point in the history
This simplifies the code a bit.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Sep 4, 2024
1 parent cb15705 commit fbc786d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ package org.ossreviewtoolkit.plugins.packagemanagers.gradlemodel
import OrtDependency

/**
* Determine the type of this Gradle dependency. In case of a project, it is "Gradle". Otherwise it is "Maven" unless
* there is no POM, then it is "Unknown".
* The type of this Gradle dependency. In case of a project, it is "Gradle". Otherwise it is "Maven" unless there is no
* POM, then it is "Unknown".
*/
fun OrtDependency.dependencyType(): String =
if (isProjectDependency()) {
val OrtDependency.dependencyType: String
get() = if (isProjectDependency) {
"Gradle"
} else {
pomFile?.let { "Maven" } ?: "Unknown"
}

/**
* Return true if this Gradle dependency refers to another project, or false if it refers to a package.
* A flag to indicate whether this Gradle dependency refers to a project, or to a package.
*/
fun OrtDependency.isProjectDependency() = localPath != null
val OrtDependency.isProjectDependency: Boolean
get() = localPath != null
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal class GradleDependencyHandler(

override fun identifierFor(dependency: OrtDependency): Identifier =
Identifier(
type = dependency.dependencyType(),
type = dependency.dependencyType,
namespace = dependency.groupId,
name = dependency.artifactId,
version = dependency.version
Expand Down Expand Up @@ -88,11 +88,11 @@ internal class GradleDependencyHandler(
)

override fun linkageFor(dependency: OrtDependency): PackageLinkage =
if (dependency.isProjectDependency()) PackageLinkage.PROJECT_DYNAMIC else PackageLinkage.DYNAMIC
if (dependency.isProjectDependency) PackageLinkage.PROJECT_DYNAMIC else PackageLinkage.DYNAMIC

override fun createPackage(dependency: OrtDependency, issues: MutableCollection<Issue>): Package? {
// Only look for a package if there was no error resolving the dependency and it is no project dependency.
if (dependency.error != null || dependency.isProjectDependency()) return null
if (dependency.error != null || dependency.isProjectDependency) return null

val artifact = DefaultArtifact(
dependency.groupId, dependency.artifactId, dependency.classifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private fun createMavenSupport(): MavenSupport {
/**
* Returns an [Identifier] for this [OrtDependency].
*/
private fun OrtDependency.toId() = Identifier(dependencyType(), groupId, artifactId, version)
private fun OrtDependency.toId() = Identifier(dependencyType, groupId, artifactId, version)

/**
* Return the package references from the given [scopes] associated with the scope with the given [scopeName].
Expand Down

0 comments on commit fbc786d

Please sign in to comment.