Skip to content

Commit

Permalink
refactor(stack): Move two constants to the model
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 3, 2024
1 parent d332eba commit b11d47c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 6 additions & 1 deletion plugins/package-managers/stack/src/main/kotlin/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import org.ossreviewtoolkit.model.jsonMapper
internal data class Location(
val url: String,
val type: String
)
) {
companion object {
const val TYPE_HACKAGE = "hackage"
const val TYPE_PROJECT = "project package"
}
}

@JsonIgnoreProperties(ignoreUnknown = true)
internal data class Dependency(
Expand Down
9 changes: 3 additions & 6 deletions plugins/package-managers/stack/src/main/kotlin/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ private const val TEST_SCOPE_NAME = "test"
private const val BENCH_SCOPE_NAME = "bench"
private val SCOPE_NAMES = setOf(EXTERNAL_SCOPE_NAME, TEST_SCOPE_NAME, BENCH_SCOPE_NAME)

private const val HACKAGE_PACKAGE_TYPE = "hackage"
private const val PROJECT_PACKAGE_TYPE = "project package"

/**
* The [Stack](https://haskellstack.org/) package manager for Haskell.
*/
Expand Down Expand Up @@ -167,7 +164,7 @@ class Stack(
version = version
)

if (location == null || location.type == HACKAGE_PACKAGE_TYPE) {
if (location == null || location.type == Location.TYPE_HACKAGE) {
okHttpClient.downloadCabalFile(id)?.let { return parseCabalFile(it, "Hackage") }
}

Expand All @@ -179,7 +176,7 @@ class Stack(
}
}

private fun Dependency.isProject(): Boolean = location?.type == PROJECT_PACKAGE_TYPE
private fun Dependency.isProject(): Boolean = location?.type == Location.TYPE_PROJECT

private fun Collection<Dependency>.toScope(scopeName: String, packageForName: Map<String, Package>): Scope {
// TODO: Stack identifies dependencies only by name. Find out how dependencies with the same name but in
Expand All @@ -189,7 +186,7 @@ private fun Collection<Dependency>.toScope(scopeName: String, packageForName: Ma
return Scope(
name = scopeName,
dependencies = single {
it.location?.type == PROJECT_PACKAGE_TYPE
it.location?.type == Location.TYPE_PROJECT
}.dependencies.mapTo(mutableSetOf()) { name ->
dependencyForName.getValue(name).toPackageReference(dependencyForName, packageForName)
}
Expand Down

0 comments on commit b11d47c

Please sign in to comment.