Skip to content

Change added repositories order #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .run/Install for Java 8.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<GradleScriptDebugEnabled>true</GradleScriptDebugEnabled>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# kotlinVersion=1.4.255-SNAPSHOT
kotlinVersion=1.4.20-dev-3647
kotlinVersion=1.4.30-dev-1975
kotlinLanguageLevel=1.4
jvmTarget=1.8

Expand Down
3 changes: 0 additions & 3 deletions libraries/fuel.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"v": "-SNAPSHOT"
},
"link": "https://github.com/kittinunf/fuel",
"repositories": [
"https://www.jitpack.io"
],
"dependencies": [
"com.github.kittinunf.fuel:fuel:$v",
"com.github.kittinunf.fuel:fuel-gson:$v",
Expand Down
3 changes: 0 additions & 3 deletions libraries/kaliningraph.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"link": "https://github.com/breandan/kaliningraph",
"description": "Graph library with a DSL for constructing graphs and visualizing the behavior of graph algorithms",
"repositories": [
"https://jitpack.io"
],
"dependencies": [
"com.github.breandan:kaliningraph:0.1.1"
],
Expand Down
2 changes: 1 addition & 1 deletion libraries/lets-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"link": "https://github.com/JetBrains/lets-plot-kotlin",
"repositories": [
"https://jetbrains.bintray.com/lets-plot-maven"
"https://jetbrains.bintray.com/lets-plot-maven/"
],
"dependencies": [
"org.jetbrains.lets-plot-kotlin:lets-plot-kotlin-api-kernel:$api",
Expand Down
7 changes: 5 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ pluginManagement {
mavenLocal()
mavenCentral()
// only when using Kotlin EAP releases ...
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-dev") }
maven("https://dl.bintray.com/kotlin/kotlin-eap")

val teamcityUrl = "https://teamcity.jetbrains.com"
val teamcityProjectId = "Kotlin_KotlinPublic_Aggregate"
maven("$teamcityUrl/guestAuth/app/rest/builds/buildType:(id:$teamcityProjectId),number:$kotlinVersion,branch:default:any/artifacts/content/maven")

// Used for TeamCity build
val m2LocalPath = File(".m2/repository")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/jetbrains/kotlin/jupyter/config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ val defaultRuntimeProperties by lazy {
val defaultRepositories = arrayOf(
"https://jcenter.bintray.com/",
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
"https://jitpack.io/",
).map { RepositoryCoordinates(it) }

val defaultGlobalImports = listOf(
Expand Down
29 changes: 26 additions & 3 deletions src/main/kotlin/org/jetbrains/kotlin/jupyter/resolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@ open class JupyterScriptDependenciesResolver(resolverConfig: ResolverConfig?) {
DependenciesResolverOptionsName.SCOPE.key to "compile,runtime"
))

private val repositories = arrayListOf<RepositoryCoordinates>()
private val addedClasspath = arrayListOf<File>()

init {
resolver = CompoundDependenciesResolver(
FileSystemDependenciesResolver(),
RemoteResolverWrapper(IvyResolver())
)
resolverConfig?.repositories?.forEach { resolver.addRepository(it) }
resolverConfig?.repositories?.forEach { addRepository(it) }
}

private val addedClasspath: MutableList<File> = mutableListOf()
private fun addRepository(repository: RepositoryCoordinates): Boolean {
val repoIndex = repositories.indexOfFirst { it.string == repository.string }
if (repoIndex != -1) repositories.removeAt(repoIndex)
repositories.add(repository)

return resolver.addRepository(repository).valueOrNull() == true
}

fun popAddedClasspath(): List<File> {
val result = addedClasspath.toList()
Expand All @@ -43,13 +52,20 @@ open class JupyterScriptDependenciesResolver(resolverConfig: ResolverConfig?) {
fun resolveFromAnnotations(script: ScriptContents): ResultWithDiagnostics<List<File>> {
val scriptDiagnostics = mutableListOf<ScriptDiagnostic>()
val classpath = mutableListOf<File>()
var existingRepositories: List<RepositoryCoordinates>? = null

script.annotations.forEach { annotation ->
when (annotation) {
is Repository -> {
log.info("Adding repository: ${annotation.value}")
if (resolver.addRepository(RepositoryCoordinates(annotation.value)).valueOrNull() != true)
if (existingRepositories == null) {
existingRepositories = ArrayList(repositories)
}

if (!addRepository(RepositoryCoordinates(annotation.value)))
throw IllegalArgumentException("Illegal argument for Repository annotation: $annotation")

existingRepositories?.forEach{ addRepository(it) }
}
is DependsOn -> {
log.info("Resolving ${annotation.value}")
Expand All @@ -71,13 +87,20 @@ open class JupyterScriptDependenciesResolver(resolverConfig: ResolverConfig?) {
log.error(diagnostic.message, e)
scriptDiagnostics.add(diagnostic)
}
// Hack: after first resolution add "standard" Central repo to the end of the list, giving it the lowest priority
addRepository(CENTRAL_REPO_COORDINATES)
}
else -> throw Exception("Unknown annotation ${annotation.javaClass}")
}
}

return if (scriptDiagnostics.isEmpty()) classpath.asSuccess()
else makeFailureResult(scriptDiagnostics)
}

companion object {
val CENTRAL_REPO_COORDINATES = RepositoryCoordinates("https://repo1.maven.org/maven2/")
}
}

class RemoteResolverWrapper(private val remoteResolver: ExternalDependenciesResolver):
Expand Down
17 changes: 17 additions & 0 deletions src/test/kotlin/org/jetbrains/kotlin/jupyter/test/replTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,23 @@ class ReplWithResolverTest : AbstractReplTest() {
assertNotNull(res2.resultValue)
}

@Test
fun testResolverRepoOrder() {
val res = repl.eval("""
@file:Repository("https://repo.osgeo.org/repository/release/")
@file:DependsOn("org.geotools:gt-shapefile:[23,)")
@file:DependsOn("org.geotools:gt-cql:[23,)")

%use lets-plot(api=1.0.1-dev-1)

@file:DependsOn("org.jetbrains.lets-plot-kotlin:lets-plot-kotlin-geotools:1.0.1-dev-1")

import jetbrains.letsPlot.toolkit.geotools.toSpatialDataset
""".trimIndent())

assertTrue(res.newClasspath.size >= 2)
}

@Test
fun testTwoLibrariesInUse() {
val code = "%use lets-plot, krangl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.jetbrains.kotlin.jupyter.ReplCompilerException
import org.jetbrains.kotlin.jupyter.ReplForJupyterImpl
import org.jetbrains.kotlin.jupyter.ResolverConfig
import org.jetbrains.kotlin.jupyter.defaultRepositories
import org.jetbrains.kotlin.jupyter.libraries.EmptyResolutionInfoProvider
import org.jetbrains.kotlin.jupyter.libraries.LibraryFactory
import org.jetbrains.kotlin.jupyter.libraries.parseLibraryDescriptors
import org.junit.jupiter.api.Assertions.assertEquals
Expand Down