Skip to content

Commit

Permalink
refactor(migrate): Extract a function to migrate identifiers
Browse files Browse the repository at this point in the history
Extract the code to migrate the identifiers of package curations and
package configurations into a separate function to prepare for adding an
option to migrate Pub identifiers.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
  • Loading branch information
mnonnenmacher committed Jan 18, 2024
1 parent 34046a6 commit 119de17
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.github.ajalt.clikt.parameters.types.file
import java.io.File

import org.ossreviewtoolkit.model.FileFormat
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.PackageCuration
import org.ossreviewtoolkit.model.config.PackageConfiguration
import org.ossreviewtoolkit.model.readValue
Expand Down Expand Up @@ -65,7 +66,16 @@ class MigrateCommand : OrtCommand(
}
}

private fun migrateNuGetIds(configDir: File) {
private fun migrateNuGetIds(configDir: File) =
migrateIds(configDir) { id ->
if (id.type == "NuGet") {
getIdentifierWithNamespace(id.type, id.name, id.version)
} else {
id
}
}

private fun migrateIds(configDir: File, transformId: (Identifier) -> Identifier) {
val configYamlMapper = yamlMapper.copy()
.enable(YAMLGenerator.Feature.LITERAL_BLOCK_STYLE)
.disable(YAMLGenerator.Feature.SPLIT_LINES)
Expand Down Expand Up @@ -99,11 +109,7 @@ class MigrateCommand : OrtCommand(
echo("Processing ${pkgCurationFiles.size} package curation files...")
pkgCurationFiles.forEach { (file, curations) ->
val curationsWithFixedIds = curations.map {
if (it.id.type == "NuGet") {
it.copy(id = getIdentifierWithNamespace(it.id.type, it.id.name, it.id.version))
} else {
it
}
it.copy(id = transformId(it.id))
}

if (curationsWithFixedIds != curations) {
Expand All @@ -123,11 +129,7 @@ class MigrateCommand : OrtCommand(

echo("Processing ${pkgConfigFiles.size} package configuration files...")
pkgConfigFiles.forEach { (file, config) ->
val configWithFixedId = if (config.id.type == "NuGet") {
config.copy(id = getIdentifierWithNamespace(config.id.type, config.id.name, config.id.version))
} else {
config
}
val configWithFixedId = config.copy(id = transformId(config.id))

if (configWithFixedId != config) {
val oldPath = file.relativeTo(configsDir).path
Expand Down

0 comments on commit 119de17

Please sign in to comment.