1919
2020package org.ossreviewtoolkit.plugins.scanners.scanoss
2121
22- import com.scanoss.Winnowing
23- import com.scanoss.rest.ScanApi
22+ import com.scanoss.Scanner
2423import com.scanoss.utils.JsonUtils
2524import com.scanoss.utils.PackageDetails
2625
2726import java.io.File
2827import java.time.Instant
2928
30- import org.apache.logging.log4j.kotlin.logger
31-
3229import org.ossreviewtoolkit.model.ScanSummary
3330import org.ossreviewtoolkit.plugins.api.OrtPlugin
3431import org.ossreviewtoolkit.plugins.api.PluginDescriptor
@@ -37,7 +34,6 @@ import org.ossreviewtoolkit.scanner.ScanContext
3734import org.ossreviewtoolkit.scanner.ScannerMatcher
3835import org.ossreviewtoolkit.scanner.ScannerMatcherConfig
3936import org.ossreviewtoolkit.scanner.ScannerWrapperFactory
40- import org.ossreviewtoolkit.utils.common.VCS_DIRECTORIES
4137
4238@OrtPlugin(
4339 id = " SCANOSS" ,
@@ -49,11 +45,10 @@ class ScanOss(
4945 override val descriptor : PluginDescriptor = ScanOssFactory .descriptor,
5046 config : ScanOssConfig
5147) : PathScannerWrapper {
52- private val service = ScanApi .builder()
48+ private val scanossBuilder = Scanner .builder()
5349 // As there is only a single endpoint, the SCANOSS API client expects the path to be part of the API URL.
5450 .url(config.apiUrl.removeSuffix(" /" ) + " /scan/direct" )
5551 .apiKey(config.apiKey.value)
56- .build()
5752
5853 override val version: String by lazy {
5954 // TODO: Find out the best / cheapest way to query the SCANOSS server for its version.
@@ -81,30 +76,16 @@ class ScanOss(
8176 override fun scanPath (path : File , context : ScanContext ): ScanSummary {
8277 val startTime = Instant .now()
8378
84- val wfpString = buildString {
85- path.walk()
86- .onEnter { it.name !in VCS_DIRECTORIES }
87- .filterNot { it.isDirectory }
88- .forEach {
89- logger.info { " Computing fingerprint for file ${it.absolutePath} ..." }
90- append(createWfpForFile(it))
91- }
92- }
93-
94- val result = service.scan(
95- wfpString,
96- context.labels[" scanOssContext" ],
97- context.labels[" scanOssId" ]?.toIntOrNull() ? : Thread .currentThread().threadId().toInt()
98- )
79+ // Build the scanner at function level in case any path-specific settings or filters are needed later.
80+ val scanoss = scanossBuilder.build()
9981
100- // Replace the anonymized UUIDs by their file paths.
101- val results = JsonUtils .toScanFileResultsFromObject(JsonUtils .toJsonObject(result))
82+ val rawResults = when {
83+ path.isFile -> listOf (scanoss.scanFile(path.toString()))
84+ else -> scanoss.scanFolder(path.toString())
85+ }
10286
87+ val results = JsonUtils .toScanFileResults(rawResults)
10388 val endTime = Instant .now()
10489 return generateSummary(startTime, endTime, results)
10590 }
106-
107- internal fun createWfpForFile (file : File ): String {
108- return Winnowing .builder().build().wfpForFile(file.path, file.path)
109- }
11091}
0 commit comments