Skip to content

Commit

Permalink
chore(cargo): Reorder top-level functions
Browse files Browse the repository at this point in the history
Make higher-level functions go first for a better overview.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Apr 9, 2024
1 parent 630c502 commit 40c38da
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions plugins/package-managers/cargo/src/main/kotlin/Cargo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,6 @@ class Cargo(

private fun CargoMetadata.Package.isProject() = source == null

private fun parseDeclaredLicenses(pkg: CargoMetadata.Package): Set<String> {
val declaredLicenses = pkg.license.orEmpty().split('/')
.map { it.trim() }
.filterTo(mutableSetOf()) { it.isNotEmpty() }

// Cargo allows declaring non-SPDX licenses only by referencing a license file. If a license file is specified, add
// an unknown declared license to indicate that there is a declared license, but we cannot know which it is at this
// point.
// See: https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields
if (pkg.licenseFile.orEmpty().isNotBlank()) {
declaredLicenses += SpdxConstants.NOASSERTION
}

return declaredLicenses
}

private fun parsePackage(pkg: CargoMetadata.Package, hashes: Map<String, String>): Package {
val declaredLicenses = parseDeclaredLicenses(pkg)

Expand Down Expand Up @@ -245,6 +229,22 @@ private fun parsePackage(pkg: CargoMetadata.Package, hashes: Map<String, String>
)
}

private fun parseDeclaredLicenses(pkg: CargoMetadata.Package): Set<String> {
val declaredLicenses = pkg.license.orEmpty().split('/')
.map { it.trim() }
.filterTo(mutableSetOf()) { it.isNotEmpty() }

// Cargo allows declaring non-SPDX licenses only by referencing a license file. If a license file is specified, add
// an unknown declared license to indicate that there is a declared license, but we cannot know which it is at this
// point.
// See: https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields
if (pkg.licenseFile.orEmpty().isNotBlank()) {
declaredLicenses += SpdxConstants.NOASSERTION
}

return declaredLicenses
}

// Match source dependencies that directly reference git repositories. The specified tag or branch
// name is ignored (i.e. not captured) in favor of the actual commit hash that they currently refer
// to.
Expand Down

0 comments on commit 40c38da

Please sign in to comment.