@@ -39,9 +39,7 @@ import org.ossreviewtoolkit.model.KnownProvenance
39
39
import org.ossreviewtoolkit.model.OrtResult
40
40
import org.ossreviewtoolkit.model.Package
41
41
import org.ossreviewtoolkit.model.PackageType
42
- import org.ossreviewtoolkit.model.Provenance
43
42
import org.ossreviewtoolkit.model.ProvenanceResolutionResult
44
- import org.ossreviewtoolkit.model.RepositoryProvenance
45
43
import org.ossreviewtoolkit.model.ScanResult
46
44
import org.ossreviewtoolkit.model.ScanSummary
47
45
import org.ossreviewtoolkit.model.ScannerRun
@@ -54,14 +52,16 @@ import org.ossreviewtoolkit.model.createAndLogIssue
54
52
import org.ossreviewtoolkit.model.mapLicense
55
53
import org.ossreviewtoolkit.model.utils.FileArchiver
56
54
import org.ossreviewtoolkit.model.utils.ProvenanceFileStorage
57
- import org.ossreviewtoolkit.model.utils.getKnownProvenancesWithoutVcsPath
58
55
import org.ossreviewtoolkit.model.utils.vcsPath
59
56
import org.ossreviewtoolkit.scanner.provenance.NestedProvenance
60
57
import org.ossreviewtoolkit.scanner.provenance.NestedProvenanceResolver
61
58
import org.ossreviewtoolkit.scanner.provenance.NestedProvenanceScanResult
62
59
import org.ossreviewtoolkit.scanner.provenance.PackageProvenanceResolver
63
60
import org.ossreviewtoolkit.scanner.provenance.ProvenanceDownloader
64
61
import org.ossreviewtoolkit.scanner.utils.FileListResolver
62
+ import org.ossreviewtoolkit.scanner.utils.alignRevisions
63
+ import org.ossreviewtoolkit.scanner.utils.filterScanResultsByVcsPaths
64
+ import org.ossreviewtoolkit.scanner.utils.getVcsPathsForProvenances
65
65
import org.ossreviewtoolkit.utils.common.CommandLineTool
66
66
import org.ossreviewtoolkit.utils.common.collectMessages
67
67
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
@@ -190,25 +190,9 @@ class Scanner(
190
190
).filterByVcsPath()
191
191
}
192
192
193
- val vcsPathsForProvenances = buildMap<KnownProvenance , MutableSet <String >> {
194
- provenances.forEach { provenance ->
195
- val packageVcsPath = provenance.packageProvenance?.vcsPath.orEmpty()
193
+ val vcsPathsForProvenances = getVcsPathsForProvenances(provenances)
196
194
197
- provenance.getKnownProvenancesWithoutVcsPath().forEach { (repositoryPath, provenance) ->
198
- getVcsPathForRepositoryOrNull(packageVcsPath, repositoryPath)?.let { vcsPath ->
199
- getOrPut(provenance) { mutableSetOf () } + = vcsPath
200
- }
201
- }
202
- }
203
- }
204
-
205
- val scanResults = controller.getAllScanResults().map { scanResult ->
206
- scanResult.copy(provenance = scanResult.provenance.alignRevisions())
207
- }.mapNotNullTo(mutableSetOf ()) { scanResult ->
208
- vcsPathsForProvenances[scanResult.provenance]?.let {
209
- scanResult.copy(summary = scanResult.summary.filterByPaths(it))
210
- }
211
- }
195
+ val filteredScanResults = filterScanResultsByVcsPaths(controller.getAllScanResults(), vcsPathsForProvenances)
212
196
213
197
val files = controller.getAllFileLists().mapTo(mutableSetOf ()) { (provenance, fileList) ->
214
198
FileList (
@@ -229,7 +213,7 @@ class Scanner(
229
213
return ScannerRun .EMPTY .copy(
230
214
config = scannerConfig,
231
215
provenances = provenances,
232
- scanResults = scanResults ,
216
+ scanResults = filteredScanResults ,
233
217
files = files,
234
218
scanners = scanners
235
219
)
@@ -782,13 +766,6 @@ fun ScanResult.toNestedProvenanceScanResult(nestedProvenance: NestedProvenance):
782
766
return NestedProvenanceScanResult (nestedProvenance, scanResultsByProvenance)
783
767
}
784
768
785
- fun <T : Provenance > T.alignRevisions (): Provenance =
786
- if (this is RepositoryProvenance ) {
787
- copy(vcsInfo = vcsInfo.copy(revision = resolvedRevision))
788
- } else {
789
- this
790
- }
791
-
792
769
private fun ScanController.getSubRepositories (id : Identifier ): Map <String , VcsInfo > {
793
770
val nestedProvenance = getNestedProvenance(id) ? : return emptyMap()
794
771
@@ -802,21 +779,6 @@ private fun ProvenanceResolutionResult.filterByVcsPath(): ProvenanceResolutionRe
802
779
}
803
780
)
804
781
805
- /* *
806
- * Return the VCS path applicable to a (sub-) repository which appears under [repositoryPath] in the source tree of
807
- * a package residing in [vcsPath], or null if the subtrees for [repositoryPath] and [vcsPath] are disjoint.
808
- */
809
- private fun getVcsPathForRepositoryOrNull (vcsPath : String , repositoryPath : String ): String? {
810
- val repoPathFile = File (repositoryPath)
811
- val vcsPathFile = File (vcsPath)
812
-
813
- return if (repoPathFile.startsWith(vcsPathFile)) {
814
- " "
815
- } else {
816
- runCatching { vcsPathFile.toRelativeString(repoPathFile) }.getOrNull()
817
- }
818
- }
819
-
820
782
private fun FileList.filterByVcsPaths (paths : Collection <String >): FileList =
821
783
if (paths.any { it.isBlank() }) {
822
784
this
0 commit comments