From 4fb53b4be5a8ef33ae63339aa1a56237812d3049 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Sat, 16 Mar 2024 13:14:08 +0100 Subject: [PATCH] refactor(scanner)!: Rename the package based storages Rename the package based file and Postgres storage to match the names of their provenance based counterparts. Signed-off-by: Martin Nonnenmacher --- .../src/main/kotlin/commands/ImportScanResultsCommand.kt | 4 ++-- .../main/kotlin/commands/packageconfig/CreateCommand.kt | 4 ++-- ...torageFunTest.kt => PackageBasedFileStorageFunTest.kt} | 4 ++-- ...geFunTest.kt => PackageBasedPostgresStorageFunTest.kt} | 5 +++-- scanner/src/main/kotlin/ScanStorages.kt | 8 ++++---- .../{FileBasedStorage.kt => PackageBasedFileStorage.kt} | 2 +- ...{PostgresStorage.kt => PackageBasedPostgresStorage.kt} | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) rename scanner/src/funTest/kotlin/storages/{FileBasedStorageFunTest.kt => PackageBasedFileStorageFunTest.kt} (84%) rename scanner/src/funTest/kotlin/storages/{PostgresStorageFunTest.kt => PackageBasedPostgresStorageFunTest.kt} (79%) rename scanner/src/main/kotlin/storages/{FileBasedStorage.kt => PackageBasedFileStorage.kt} (99%) rename scanner/src/main/kotlin/storages/{PostgresStorage.kt => PackageBasedPostgresStorage.kt} (99%) diff --git a/helper-cli/src/main/kotlin/commands/ImportScanResultsCommand.kt b/helper-cli/src/main/kotlin/commands/ImportScanResultsCommand.kt index 454285b100ce8..081e56479729c 100644 --- a/helper-cli/src/main/kotlin/commands/ImportScanResultsCommand.kt +++ b/helper-cli/src/main/kotlin/commands/ImportScanResultsCommand.kt @@ -26,7 +26,7 @@ import com.github.ajalt.clikt.parameters.options.required import com.github.ajalt.clikt.parameters.types.file import org.ossreviewtoolkit.helper.utils.readOrtResult -import org.ossreviewtoolkit.scanner.storages.FileBasedStorage +import org.ossreviewtoolkit.scanner.storages.PackageBasedFileStorage import org.ossreviewtoolkit.utils.common.expandTilde import org.ossreviewtoolkit.utils.ort.storage.LocalFileStorage @@ -51,7 +51,7 @@ internal class ImportScanResultsCommand : CliktCommand( override fun run() { val ortResult = readOrtResult(ortFile) - val scanResultsStorage = FileBasedStorage(LocalFileStorage(scanResultsStorageDir)) + val scanResultsStorage = PackageBasedFileStorage(LocalFileStorage(scanResultsStorageDir)) val ids = ortResult.getProjects().map { it.id } + ortResult.getPackages().map { it.metadata.id } ids.forEach { id -> diff --git a/helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt b/helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt index b7db5664414e9..4b9697f86a6e8 100644 --- a/helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt +++ b/helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt @@ -43,7 +43,7 @@ import org.ossreviewtoolkit.model.config.PackageConfiguration import org.ossreviewtoolkit.model.config.VcsMatcher import org.ossreviewtoolkit.model.licenses.LicenseClassifications import org.ossreviewtoolkit.model.readValue -import org.ossreviewtoolkit.scanner.storages.FileBasedStorage +import org.ossreviewtoolkit.scanner.storages.PackageBasedFileStorage import org.ossreviewtoolkit.utils.common.expandTilde import org.ossreviewtoolkit.utils.common.safeMkdirs import org.ossreviewtoolkit.utils.ort.storage.LocalFileStorage @@ -119,7 +119,7 @@ internal class CreateCommand : CliktCommand( override fun run() { outputDir.safeMkdirs() - val scanResultsStorage = FileBasedStorage(LocalFileStorage(scanResultsStorageDir)) + val scanResultsStorage = PackageBasedFileStorage(LocalFileStorage(scanResultsStorageDir)) val scanResults = scanResultsStorage.read(Package.EMPTY.copy(id = packageId)).getOrThrow().run { listOfNotNull( find { it.provenance is RepositoryProvenance }, diff --git a/scanner/src/funTest/kotlin/storages/FileBasedStorageFunTest.kt b/scanner/src/funTest/kotlin/storages/PackageBasedFileStorageFunTest.kt similarity index 84% rename from scanner/src/funTest/kotlin/storages/FileBasedStorageFunTest.kt rename to scanner/src/funTest/kotlin/storages/PackageBasedFileStorageFunTest.kt index 2235d16af2eb7..35b097bc113b2 100644 --- a/scanner/src/funTest/kotlin/storages/FileBasedStorageFunTest.kt +++ b/scanner/src/funTest/kotlin/storages/PackageBasedFileStorageFunTest.kt @@ -23,6 +23,6 @@ import io.kotest.engine.spec.tempdir import org.ossreviewtoolkit.utils.ort.storage.LocalFileStorage -class FileBasedStorageFunTest : AbstractPackageBasedScanStorageFunTest() { - override fun createStorage() = FileBasedStorage(LocalFileStorage(tempdir())) +class PackageBasedFileStorageFunTest : AbstractPackageBasedScanStorageFunTest() { + override fun createStorage() = PackageBasedFileStorage(LocalFileStorage(tempdir())) } diff --git a/scanner/src/funTest/kotlin/storages/PostgresStorageFunTest.kt b/scanner/src/funTest/kotlin/storages/PackageBasedPostgresStorageFunTest.kt similarity index 79% rename from scanner/src/funTest/kotlin/storages/PostgresStorageFunTest.kt rename to scanner/src/funTest/kotlin/storages/PackageBasedPostgresStorageFunTest.kt index 6c8b379007b99..f1aa92d5820d1 100644 --- a/scanner/src/funTest/kotlin/storages/PostgresStorageFunTest.kt +++ b/scanner/src/funTest/kotlin/storages/PackageBasedPostgresStorageFunTest.kt @@ -23,6 +23,7 @@ import org.ossreviewtoolkit.utils.test.PostgresListener private val postgresListener = PostgresListener() -class PostgresStorageFunTest : AbstractPackageBasedScanStorageFunTest(postgresListener) { - override fun createStorage() = PostgresStorage(dataSource = postgresListener.dataSource, parallelTransactions = 5) +class PackageBasedPostgresStorageFunTest : AbstractPackageBasedScanStorageFunTest(postgresListener) { + override fun createStorage() = + PackageBasedPostgresStorage(dataSource = postgresListener.dataSource, parallelTransactions = 5) } diff --git a/scanner/src/main/kotlin/ScanStorages.kt b/scanner/src/main/kotlin/ScanStorages.kt index 08f9c9d39f40a..d73b24b2c2218 100644 --- a/scanner/src/main/kotlin/ScanStorages.kt +++ b/scanner/src/main/kotlin/ScanStorages.kt @@ -37,8 +37,8 @@ import org.ossreviewtoolkit.scanner.provenance.ResolvedArtifactProvenance import org.ossreviewtoolkit.scanner.provenance.ResolvedRepositoryProvenance import org.ossreviewtoolkit.scanner.provenance.UnresolvedPackageProvenance import org.ossreviewtoolkit.scanner.storages.ClearlyDefinedStorage -import org.ossreviewtoolkit.scanner.storages.FileBasedStorage -import org.ossreviewtoolkit.scanner.storages.PostgresStorage +import org.ossreviewtoolkit.scanner.storages.PackageBasedFileStorage +import org.ossreviewtoolkit.scanner.storages.PackageBasedPostgresStorage import org.ossreviewtoolkit.scanner.storages.ProvenanceBasedFileStorage import org.ossreviewtoolkit.scanner.storages.ProvenanceBasedPostgresStorage import org.ossreviewtoolkit.scanner.storages.Sw360Storage @@ -132,13 +132,13 @@ private fun createStorage(config: ScanStorageConfiguration): ScanStorage = private fun createFileBasedStorage(config: FileBasedStorageConfiguration) = when (config.type) { - StorageType.PACKAGE_BASED -> FileBasedStorage(config.backend.createFileStorage()) + StorageType.PACKAGE_BASED -> PackageBasedFileStorage(config.backend.createFileStorage()) StorageType.PROVENANCE_BASED -> ProvenanceBasedFileStorage(config.backend.createFileStorage()) } private fun createPostgresStorage(config: PostgresStorageConfiguration) = when (config.type) { - StorageType.PACKAGE_BASED -> PostgresStorage( + StorageType.PACKAGE_BASED -> PackageBasedPostgresStorage( DatabaseUtils.createHikariDataSource(config = config.connection, applicationNameSuffix = TOOL_NAME), config.connection.parallelTransactions ) diff --git a/scanner/src/main/kotlin/storages/FileBasedStorage.kt b/scanner/src/main/kotlin/storages/PackageBasedFileStorage.kt similarity index 99% rename from scanner/src/main/kotlin/storages/FileBasedStorage.kt rename to scanner/src/main/kotlin/storages/PackageBasedFileStorage.kt index 803af9bb91f83..fab4e7eabd931 100644 --- a/scanner/src/main/kotlin/storages/FileBasedStorage.kt +++ b/scanner/src/main/kotlin/storages/PackageBasedFileStorage.kt @@ -43,7 +43,7 @@ const val SCAN_RESULTS_FILE_NAME = "scan-results.yml" /** * A [PackageBasedScanStorage] using a [FileStorage] as backend. Scan results are serialized using [YAML][yamlMapper]. */ -class FileBasedStorage( +class PackageBasedFileStorage( /** * The [FileStorage] to use for storing scan results. */ diff --git a/scanner/src/main/kotlin/storages/PostgresStorage.kt b/scanner/src/main/kotlin/storages/PackageBasedPostgresStorage.kt similarity index 99% rename from scanner/src/main/kotlin/storages/PostgresStorage.kt rename to scanner/src/main/kotlin/storages/PackageBasedPostgresStorage.kt index bf1e6c86b5905..2f25b4dcdbc40 100644 --- a/scanner/src/main/kotlin/storages/PostgresStorage.kt +++ b/scanner/src/main/kotlin/storages/PackageBasedPostgresStorage.kt @@ -61,7 +61,7 @@ private val TABLE_NAME = ScanResults.tableName /** * The Postgres storage back-end. */ -class PostgresStorage( +class PackageBasedPostgresStorage( /** * The JDBC data source to obtain database connections. */