Skip to content

Commit

Permalink
refactor(bower): Factor out toProject()
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Viernau <frank_viernau@epam.com>
  • Loading branch information
fviernau committed Jul 23, 2024
1 parent 1a00466 commit c8e47f2
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions plugins/package-managers/bower/src/main/kotlin/Bower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.util.LinkedList

import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory
import org.ossreviewtoolkit.analyzer.PackageManager
import org.ossreviewtoolkit.analyzer.PackageManager.Companion.processProjectVcs
import org.ossreviewtoolkit.analyzer.parseAuthorString
import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.model.Identifier
Expand Down Expand Up @@ -88,17 +89,7 @@ class Bower(
)
}

val projectPackage = projectPackageInfo.toPackage()
val project = Project(
id = projectPackage.id,
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
authors = projectPackage.authors,
declaredLicenses = projectPackage.declaredLicenses,
vcs = projectPackage.vcs,
vcsProcessed = processProjectVcs(workingDir, projectPackage.vcs, projectPackage.homepageUrl),
homepageUrl = projectPackage.homepageUrl,
scopeDependencies = scopes
)
val project = projectPackageInfo.toProject(definitionFile, scopes)

return listOf(ProjectAnalyzerResult(project, packages))
}
Expand Down Expand Up @@ -166,6 +157,20 @@ private fun PackageInfo.toPackage() =
vcs = toVcsInfo()
)

private fun PackageInfo.toProject(definitionFile: File, scopes: Set<Scope>) =
with(toPackage()) {
Project(
id = id,
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
authors = authors,
declaredLicenses = declaredLicenses,
vcs = vcs,
vcsProcessed = processProjectVcs(definitionFile.parentFile, vcs, homepageUrl),
homepageUrl = homepageUrl,
scopeDependencies = scopes
)
}

private fun hasCompleteDependencies(info: PackageInfo, scopeName: String): Boolean {
val dependencyKeys = info.dependencies.keys
val dependencyRefKeys = info.getScopeDependencies(scopeName)
Expand Down

0 comments on commit c8e47f2

Please sign in to comment.