Skip to content

Commit 5a94e5b

Browse files
committed
Revert "Add repository authorization"
This reverts commit 99bfb5e
1 parent 1d930cd commit 5a94e5b

File tree

2 files changed

+15
-45
lines changed

2 files changed

+15
-45
lines changed

jupyter-lib/lib/src/main/kotlin/jupyter/kotlin/annotations.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,11 @@ annotation class DependsOn(val value: String = "")
1919
* @property value Can be one of the following:
2020
* - Maven repository URL
2121
* - Local directory in which JARs are stored
22-
* @property username In case of private Maven repositories, username which is used for authentication
23-
* @property password In case of private Maven repositories, password which is used for authentication
2422
*/
2523
@Target(AnnotationTarget.FILE)
2624
@Repeatable
2725
@Retention(AnnotationRetention.SOURCE)
28-
annotation class Repository(
29-
val value: String = "",
30-
val username: String = "",
31-
val password: String = "",
32-
)
26+
annotation class Repository(val value: String = "")
3327

3428
/**
3529
* Describes compilation arguments used for the compilation of this and all following snippets

src/main/kotlin/org/jetbrains/kotlinx/jupyter/dependencies/JupyterScriptDependenciesResolverImpl.kt

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,40 @@ import kotlin.script.experimental.api.makeFailureResult
1313
import kotlin.script.experimental.api.valueOrNull
1414
import kotlin.script.experimental.dependencies.CompoundDependenciesResolver
1515
import kotlin.script.experimental.dependencies.ExternalDependenciesResolver
16-
import kotlin.script.experimental.dependencies.ExternalDependenciesResolver.Options
1716
import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver
1817
import kotlin.script.experimental.dependencies.RepositoryCoordinates
1918
import kotlin.script.experimental.dependencies.impl.DependenciesResolverOptionsName
2019
import kotlin.script.experimental.dependencies.impl.makeExternalDependenciesResolverOptions
21-
import kotlin.script.experimental.dependencies.impl.set
2220
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
2321

2422
open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?) : JupyterScriptDependenciesResolver {
2523

2624
private val log = getLogger("resolver")
2725

2826
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+
)
3131
)
3232

33-
private val repositories = arrayListOf<Repo>()
33+
private val repositories = arrayListOf<RepositoryCoordinates>()
3434
private val addedClasspath = arrayListOf<File>()
3535

3636
init {
3737
resolver = CompoundDependenciesResolver(
3838
FileSystemDependenciesResolver(),
3939
RemoteResolverWrapper(MavenDependenciesResolver())
4040
)
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) }
5042
}
5143

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 }
5446
if (repoIndex != -1) repositories.removeAt(repoIndex)
55-
repositories.add(repo)
47+
repositories.add(repository)
5648

57-
return resolver.addRepository(repo.coordinates, repo.options).valueOrNull() == true
49+
return resolver.addRepository(repository).valueOrNull() == true
5850
}
5951

6052
fun popAddedClasspath(): List<File> {
@@ -66,7 +58,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
6658
override fun resolveFromAnnotations(script: ScriptContents): ResultWithDiagnostics<List<File>> {
6759
val scriptDiagnostics = mutableListOf<ScriptDiagnostic>()
6860
val classpath = mutableListOf<File>()
69-
var existingRepositories: List<Repo>? = null
61+
var existingRepositories: List<RepositoryCoordinates>? = null
7062

7163
script.annotations.forEach { annotation ->
7264
when (annotation) {
@@ -76,17 +68,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
7668
existingRepositories = ArrayList(repositories)
7769
}
7870

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))) {
9072
throw IllegalArgumentException("Illegal argument for Repository annotation: $annotation")
9173
}
9274

@@ -113,7 +95,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
11395
scriptDiagnostics.add(diagnostic)
11496
}
11597
// 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)
11799
}
118100
else -> throw Exception("Unknown annotation ${annotation.javaClass}")
119101
}
@@ -123,13 +105,7 @@ open class JupyterScriptDependenciesResolverImpl(resolverConfig: ResolverConfig?
123105
else makeFailureResult(scriptDiagnostics)
124106
}
125107

126-
private class Repo(
127-
val coordinates: RepositoryCoordinates,
128-
val options: Options = Options.Empty
129-
)
130-
131108
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/")
134110
}
135111
}

0 commit comments

Comments
 (0)