@@ -13,48 +13,40 @@ import kotlin.script.experimental.api.makeFailureResult
13
13
import kotlin.script.experimental.api.valueOrNull
14
14
import kotlin.script.experimental.dependencies.CompoundDependenciesResolver
15
15
import kotlin.script.experimental.dependencies.ExternalDependenciesResolver
16
- import kotlin.script.experimental.dependencies.ExternalDependenciesResolver.Options
17
16
import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver
18
17
import kotlin.script.experimental.dependencies.RepositoryCoordinates
19
18
import kotlin.script.experimental.dependencies.impl.DependenciesResolverOptionsName
20
19
import kotlin.script.experimental.dependencies.impl.makeExternalDependenciesResolverOptions
21
- import kotlin.script.experimental.dependencies.impl.set
22
20
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
23
21
24
22
open class JupyterScriptDependenciesResolverImpl (resolverConfig : ResolverConfig ? ) : JupyterScriptDependenciesResolver {
25
23
26
24
private val log = getLogger(" resolver" )
27
25
28
26
private val resolver: ExternalDependenciesResolver
29
- private val resolverOptions = buildOptions(
30
- DependenciesResolverOptionsName .SCOPE to " compile,runtime"
27
+ private val resolverOptions = makeExternalDependenciesResolverOptions(
28
+ mapOf (
29
+ DependenciesResolverOptionsName .SCOPE .key to " compile,runtime"
30
+ )
31
31
)
32
32
33
- private val repositories = arrayListOf<Repo >()
33
+ private val repositories = arrayListOf<RepositoryCoordinates >()
34
34
private val addedClasspath = arrayListOf<File >()
35
35
36
36
init {
37
37
resolver = CompoundDependenciesResolver (
38
38
FileSystemDependenciesResolver (),
39
39
RemoteResolverWrapper (MavenDependenciesResolver ())
40
40
)
41
- resolverConfig?.repositories?.forEach { addRepository(Repo (it)) }
42
- }
43
-
44
- private fun buildOptions (vararg options : Pair <DependenciesResolverOptionsName , String >): Options {
45
- return makeExternalDependenciesResolverOptions(
46
- mutableMapOf<String , String >().apply {
47
- for (option in options) this [option.first] = option.second
48
- }
49
- )
41
+ resolverConfig?.repositories?.forEach { addRepository(it) }
50
42
}
51
43
52
- private fun addRepository (repo : Repo ): Boolean {
53
- val repoIndex = repositories.indexOfFirst { it.coordinates. string == repo.coordinates .string }
44
+ private fun addRepository (repository : RepositoryCoordinates ): Boolean {
45
+ val repoIndex = repositories.indexOfFirst { it.string == repository .string }
54
46
if (repoIndex != - 1 ) repositories.removeAt(repoIndex)
55
- repositories.add(repo )
47
+ repositories.add(repository )
56
48
57
- return resolver.addRepository(repo.coordinates, repo.options ).valueOrNull() == true
49
+ return resolver.addRepository(repository ).valueOrNull() == true
58
50
}
59
51
60
52
fun popAddedClasspath (): List <File > {
@@ -66,7 +58,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
66
58
override fun resolveFromAnnotations (script : ScriptContents ): ResultWithDiagnostics <List <File >> {
67
59
val scriptDiagnostics = mutableListOf<ScriptDiagnostic >()
68
60
val classpath = mutableListOf<File >()
69
- var existingRepositories: List <Repo >? = null
61
+ var existingRepositories: List <RepositoryCoordinates >? = null
70
62
71
63
script.annotations.forEach { annotation ->
72
64
when (annotation) {
@@ -76,17 +68,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
76
68
existingRepositories = ArrayList (repositories)
77
69
}
78
70
79
- val options = if (annotation.username.isNotEmpty() || annotation.password.isNotEmpty()) {
80
- buildOptions(
81
- DependenciesResolverOptionsName .USERNAME to annotation.username,
82
- DependenciesResolverOptionsName .PASSWORD to annotation.password,
83
- )
84
- } else {
85
- Options .Empty
86
- }
87
- val repo = Repo (RepositoryCoordinates (annotation.value), options)
88
-
89
- if (! addRepository(repo)) {
71
+ if (! addRepository(RepositoryCoordinates (annotation.value))) {
90
72
throw IllegalArgumentException (" Illegal argument for Repository annotation: $annotation " )
91
73
}
92
74
@@ -113,7 +95,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
113
95
scriptDiagnostics.add(diagnostic)
114
96
}
115
97
// Hack: after first resolution add "standard" Central repo to the end of the list, giving it the lowest priority
116
- addRepository(CENTRAL_REPO )
98
+ addRepository(CENTRAL_REPO_COORDINATES )
117
99
}
118
100
else -> throw Exception (" Unknown annotation ${annotation.javaClass} " )
119
101
}
@@ -123,13 +105,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
123
105
else makeFailureResult(scriptDiagnostics)
124
106
}
125
107
126
- private class Repo (
127
- val coordinates : RepositoryCoordinates ,
128
- val options : Options = Options .Empty
129
- )
130
-
131
108
companion object {
132
- private val CENTRAL_REPO_COORDINATES = RepositoryCoordinates (" https://repo1.maven.org/maven2/" )
133
- private val CENTRAL_REPO = Repo (CENTRAL_REPO_COORDINATES )
109
+ val CENTRAL_REPO_COORDINATES = RepositoryCoordinates (" https://repo1.maven.org/maven2/" )
134
110
}
135
111
}
0 commit comments