Skip to content

Commit

Permalink
feat(migrate): Add path conventions for package configuration files
Browse files Browse the repository at this point in the history
Apply the path conventions from the ort-config repository also to
package configuration files.

Signed-off-by: Martin Nonnenmacher <[email protected]>
  • Loading branch information
mnonnenmacher committed Sep 21, 2023
1 parent 750cee3 commit ea07049
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import com.github.ajalt.clikt.parameters.types.file
import java.io.File

import org.ossreviewtoolkit.model.FileFormat
import org.ossreviewtoolkit.model.Identifier

Check warning

Code scanning / detekt

Unused Imports are dead code and should be removed. Warning

The import 'org.ossreviewtoolkit.model.Identifier' is unused.

Check warning on line 31 in plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import org.ossreviewtoolkit.model.PackageCuration
import org.ossreviewtoolkit.model.config.PackageConfiguration
import org.ossreviewtoolkit.model.readValue
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

Check warning

Code scanning / detekt

Unused Imports are dead code and should be removed. Warning

The import 'org.ossreviewtoolkit.utils.common.encodeOr' is unused.

Check warning on line 39 in plugins/commands/migrate/src/main/kotlin/MigrateCommand.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import org.ossreviewtoolkit.utils.common.expandTilde
import org.ossreviewtoolkit.utils.common.getCommonParentFile
import org.ossreviewtoolkit.utils.common.safeMkdirs
Expand Down Expand Up @@ -92,6 +94,7 @@ class MigrateCommand : OrtCommand(
}
}.toMap()

val configsDir = getCommonParentFile(pkgConfigFiles.keys)
candidateFiles -= pkgConfigFiles.keys
echo("Skipping ${candidateFiles.size} files of unknown format.")

Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit ea07049

Please sign in to comment.