From ea07049002957fdac3cc92dee34fc670cef76bf3 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Tue, 19 Sep 2023 08:42:57 +0200 Subject: [PATCH] feat(migrate): Add path conventions for package configuration files Apply the path conventions from the ort-config repository also to package configuration files. Signed-off-by: Martin Nonnenmacher --- .../migrate/src/main/kotlin/MigrateCommand.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt b/plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt index 18f74de0cef23..bf3f0ac3c6319 100644 --- a/plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt +++ b/plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt @@ -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 @@ -35,6 +36,7 @@ import org.ossreviewtoolkit.model.yamlMapper import org.ossreviewtoolkit.plugins.commands.api.OrtCommand import org.ossreviewtoolkit.plugins.packagecurationproviders.ortconfig.toCurationPath import org.ossreviewtoolkit.plugins.packagemanagers.nuget.utils.getIdentifierWithNamespace +import org.ossreviewtoolkit.utils.common.encodeOr import org.ossreviewtoolkit.utils.common.expandTilde import org.ossreviewtoolkit.utils.common.getCommonParentFile import org.ossreviewtoolkit.utils.common.safeMkdirs @@ -92,6 +94,7 @@ class MigrateCommand : OrtCommand( } }.toMap() + val configsDir = getCommonParentFile(pkgConfigFiles.keys) candidateFiles -= pkgConfigFiles.keys echo("Skipping ${candidateFiles.size} files of unknown format.") @@ -129,7 +132,18 @@ class MigrateCommand : OrtCommand( } if (configWithFixedId != config) { - configYamlMapper.writeValue(file, configWithFixedId) + val oldPath = file.relativeTo(configsDir).path + val newName = if (configWithFixedId.sourceArtifactUrl != null) "source-artifact" else "vcs" + val newPath = "${configWithFixedId.id.toPath(emptyValue = "_")}/$newName.yml" + val newFile = configsDir.resolve(newPath) + + // TODO: Maybe make this optional to support layouts that do not follow ort-config conventions. + if (newPath != oldPath) { + configsDir.resolve(oldPath).delete() + newFile.parentFile.safeMkdirs() + } + + configYamlMapper.writeValue(newFile, configWithFixedId) } } }