Skip to content

Commit 1ad5357

Browse files
committed
ScanResultsStorage: Remove the unused configuration functions
All users of the functions have been migrated to the new scanner API so they can safely be removed. Signed-off-by: Martin Nonnenmacher <[email protected]>
1 parent 9dcb6cd commit 1ad5357

File tree

2 files changed

+0
-110
lines changed

2 files changed

+0
-110
lines changed

scanner/src/funTest/kotlin/scanners/ScannerIntegrationFunTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import org.ossreviewtoolkit.model.readValue
3535
import org.ossreviewtoolkit.model.yamlMapper
3636
import org.ossreviewtoolkit.scanner.PathScannerWrapper
3737
import org.ossreviewtoolkit.scanner.ScanContext
38-
import org.ossreviewtoolkit.scanner.ScanResultsStorage
3938
import org.ossreviewtoolkit.scanner.Scanner
4039
import org.ossreviewtoolkit.scanner.ScannerCriteria
4140
import org.ossreviewtoolkit.scanner.provenance.DefaultNestedProvenanceResolver
@@ -85,8 +84,6 @@ class ScannerIntegrationFunTest : StringSpec() {
8584
val result = yamlMapper.writeValueAsString(ortResult)
8685

8786
patchActualResult(result, patchStartAndEndTime = true) shouldBe expectedResult
88-
89-
ScanResultsStorage.storage.stats.reset()
9087
}
9188
}
9289

scanner/src/main/kotlin/ScanResultsStorage.kt

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,8 @@ import org.ossreviewtoolkit.model.Identifier
3333
import org.ossreviewtoolkit.model.Package
3434
import org.ossreviewtoolkit.model.ScanResult
3535
import org.ossreviewtoolkit.model.UnknownProvenance
36-
import org.ossreviewtoolkit.model.config.ClearlyDefinedStorageConfiguration
37-
import org.ossreviewtoolkit.model.config.FileBasedStorageConfiguration
38-
import org.ossreviewtoolkit.model.config.PostgresStorageConfiguration
39-
import org.ossreviewtoolkit.model.config.ScanStorageConfiguration
40-
import org.ossreviewtoolkit.model.config.ScannerConfiguration
41-
import org.ossreviewtoolkit.model.config.Sw360StorageConfiguration
42-
import org.ossreviewtoolkit.model.utils.DatabaseUtils
4336
import org.ossreviewtoolkit.scanner.provenance.NestedProvenance
4437
import org.ossreviewtoolkit.scanner.provenance.NestedProvenanceScanResult
45-
import org.ossreviewtoolkit.scanner.storages.*
46-
import org.ossreviewtoolkit.utils.ort.ortDataDirectory
47-
import org.ossreviewtoolkit.utils.ort.storage.HttpFileStorage
48-
import org.ossreviewtoolkit.utils.ort.storage.LocalFileStorage
49-
import org.ossreviewtoolkit.utils.ort.storage.XZCompressedLocalFileStorage
5038

5139
/**
5240
* The abstract class that storage backends for scan results need to implement.
@@ -60,101 +48,6 @@ abstract class ScanResultsStorage : PackageBasedScanStorage {
6048
* A successful [Result] with an empty list of [ScanResult]s.
6149
*/
6250
val EMPTY_RESULT = Result.success<List<ScanResult>>(emptyList())
63-
64-
/**
65-
* The scan result storage in use. Needs to be set via the corresponding [configure] function.
66-
*/
67-
var storage: ScanResultsStorage = NoStorage()
68-
69-
/**
70-
* Configure the [ScanResultsStorage]. If [config] does not contain a storage configuration by default a
71-
* [FileBasedStorage] using a [XZCompressedLocalFileStorage] as backend is configured.
72-
*/
73-
fun configure(config: ScannerConfiguration): ScanResultsStorage {
74-
// Unfortunately, the smart cast does not work when moving this to a capturing "when" subject.
75-
val configuredStorages = config.storages
76-
77-
storage = when {
78-
configuredStorages.isNullOrEmpty() -> createDefaultStorage()
79-
configuredStorages.size == 1 -> createStorage(configuredStorages.values.first())
80-
else -> NoStorage()
81-
}
82-
83-
logger.info { "ScanResultStorage has been configured to ${storage.name}." }
84-
85-
return storage
86-
}
87-
88-
/**
89-
* Create a [FileBasedStorage] to be used as default if no other storage has been configured.
90-
*/
91-
private fun createDefaultStorage(): ScanResultsStorage {
92-
val localFileStorage = XZCompressedLocalFileStorage(ortDataDirectory.resolve("$TOOL_NAME/results"))
93-
return FileBasedStorage(localFileStorage)
94-
}
95-
96-
/**
97-
* Create the concrete [ScanResultsStorage] implementation based on the [config] passed in.
98-
*/
99-
private fun createStorage(config: ScanStorageConfiguration): ScanResultsStorage =
100-
when (config) {
101-
is FileBasedStorageConfiguration -> createFileBasedStorage(config)
102-
is PostgresStorageConfiguration -> createPostgresStorage(config)
103-
is ClearlyDefinedStorageConfiguration -> createClearlyDefinedStorage(config)
104-
is Sw360StorageConfiguration -> createSw360Storage(config)
105-
}
106-
107-
/**
108-
* Create a [FileBasedStorage] based on the [config] passed in.
109-
*/
110-
private fun createFileBasedStorage(config: FileBasedStorageConfiguration): ScanResultsStorage {
111-
val backend = config.backend.createFileStorage()
112-
113-
when (backend) {
114-
is HttpFileStorage -> logger.info { "Using file based storage with HTTP backend '${backend.url}'." }
115-
is LocalFileStorage -> logger.info {
116-
"Using file based storage with local directory '${backend.directory.invariantSeparatorsPath}'."
117-
}
118-
}
119-
120-
return FileBasedStorage(backend)
121-
}
122-
123-
/**
124-
* Create a [PostgresStorage] based on the [config] passed in.
125-
*/
126-
private fun createPostgresStorage(config: PostgresStorageConfiguration): ScanResultsStorage {
127-
val dataSource = DatabaseUtils.createHikariDataSource(
128-
config = config.connection,
129-
applicationNameSuffix = TOOL_NAME,
130-
// Use a value slightly higher than the number of transactions accessing the storage.
131-
maxPoolSize = config.connection.parallelTransactions + 3
132-
)
133-
134-
logger.info {
135-
"Using Postgres storage with URL '${config.connection.url}' and schema '${config.connection.schema}'."
136-
}
137-
138-
return PostgresStorage(dataSource, config.connection.parallelTransactions)
139-
}
140-
141-
/**
142-
* Create a [ClearlyDefinedStorage] based on the [config] passed in.
143-
*/
144-
private fun createClearlyDefinedStorage(config: ClearlyDefinedStorageConfiguration): ScanResultsStorage =
145-
ClearlyDefinedStorage(config).also {
146-
logger.info { "Using ClearlyDefined storage with URL '${config.serverUrl}'." }
147-
}
148-
149-
/**
150-
* Configure a [Sw360Storage] as the current storage backend.
151-
*/
152-
private fun createSw360Storage(config: Sw360StorageConfiguration): ScanResultsStorage =
153-
Sw360Storage(config).also {
154-
logger.info {
155-
"Using SW360 storage with auth URL '${config.authUrl}' and REST URL '${config.restUrl}'."
156-
}
157-
}
15851
}
15952

16053
/**

0 commit comments

Comments
 (0)