Skip to content

Commit

Permalink
refactor(conan): Split the function to configure remote authentication
Browse files Browse the repository at this point in the history
Modularize code to prepare for adding more functionality.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Nov 7, 2024
1 parent 151858e commit e13d2d6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions plugins/package-managers/conan/src/main/kotlin/Conan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,29 @@ class Conan(
return
}

// Iterate over configured remotes.
remoteList.stdout.lines().forEach { line ->
val remotes = parseConanRemoteList(remoteList.stdout)
configureUserAuthentication(remotes)
}

private fun parseConanRemoteList(remoteList: String): List<Pair<String, String>> =
remoteList.lines().mapNotNull { line ->
// Extract the remote URL.
val trimmedLine = line.trim()
if (trimmedLine.isEmpty() || trimmedLine.startsWith('#')) return@forEach
if (trimmedLine.isEmpty() || trimmedLine.startsWith('#')) return@mapNotNull null

val wordIterator = trimmedLine.splitToSequence(' ').iterator()

if (!wordIterator.hasNext()) return@forEach
if (!wordIterator.hasNext()) return@mapNotNull null
val remoteName = wordIterator.next()

if (!wordIterator.hasNext()) return@forEach
if (!wordIterator.hasNext()) return@mapNotNull null
val remoteUrl = wordIterator.next()

remoteName to remoteUrl
}

private fun configureUserAuthentication(remotes: List<Pair<String, String>>) =
remotes.forEach { (remoteName, remoteUrl) ->
remoteUrl.toUri().onSuccess { uri ->
logger.info { "Found remote '$remoteName' pointing to URL $remoteUrl." }

Expand All @@ -269,7 +278,6 @@ class Conan(
logger.warn { "The remote '$remoteName' points to invalid URL $remoteUrl." }
}
}
}

/**
* Return the dependency tree for the given [direct scope dependencies][requires].
Expand Down

0 comments on commit e13d2d6

Please sign in to comment.