Skip to content

Commit

Permalink
refactor(swiftpm): Move the dependency handler into SwiftPm
Browse files Browse the repository at this point in the history
This is also part of mapping the upstream model to ORT's model. So,
move it next to the related code.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Feb 2, 2024
1 parent 22a7baa commit 8c6d7ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 43 deletions.
18 changes: 16 additions & 2 deletions plugins/package-managers/swiftpm/src/main/kotlin/SwiftPm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.ossreviewtoolkit.model.DependencyGraph
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Issue
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.PackageLinkage
import org.ossreviewtoolkit.model.Project
import org.ossreviewtoolkit.model.ProjectAnalyzerResult
import org.ossreviewtoolkit.model.RemoteArtifact
Expand All @@ -38,6 +39,7 @@ import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.orEmpty
import org.ossreviewtoolkit.model.utils.DependencyGraphBuilder
import org.ossreviewtoolkit.model.utils.DependencyHandler
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.toUri
Expand Down Expand Up @@ -170,15 +172,15 @@ class SwiftPm(
}
}

internal val SwiftPackage.Dependency.id: Identifier
private val SwiftPackage.Dependency.id: Identifier
get() = Identifier(
type = PACKAGE_TYPE,
namespace = "",
name = getCanonicalName(repositoryUrl),
version = version
)

internal fun SwiftPackage.Dependency.toPackage(): Package {
private fun SwiftPackage.Dependency.toPackage(): Package {
val vcsInfoFromUrl = VcsHost.parseUrl(repositoryUrl)
val vcsInfo = vcsInfoFromUrl.takeUnless { it.revision.isBlank() } ?: vcsInfoFromUrl.copy(revision = version)

Expand Down Expand Up @@ -238,3 +240,15 @@ internal fun getCanonicalName(repositoryUrl: String): String {
it.host + it.path.removeSuffix(".git")
}.getOrDefault(normalizedUrl).lowercase()
}

private class SwiftPmDependencyHandler : DependencyHandler<SwiftPackage.Dependency> {
override fun identifierFor(dependency: SwiftPackage.Dependency): Identifier = dependency.id

override fun dependenciesFor(dependency: SwiftPackage.Dependency): Collection<SwiftPackage.Dependency> =
dependency.dependencies

override fun linkageFor(dependency: SwiftPackage.Dependency): PackageLinkage = PackageLinkage.DYNAMIC

override fun createPackage(dependency: SwiftPackage.Dependency, issues: MutableList<Issue>): Package =
dependency.toPackage()
}

This file was deleted.

0 comments on commit 8c6d7ae

Please sign in to comment.