-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug that haven't allowed to execute any code (including dependenc…
…ies code) via USE(). Add Gradle-like API for adding dependencies. Fix #367
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
jupyter-lib/api/src/main/kotlin/org/jetbrains/kotlinx/jupyter/api/libraries/gradleLike.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.jetbrains.kotlinx.jupyter.api.libraries | ||
|
||
import java.io.File | ||
|
||
interface RepositoryHandlerScope { | ||
fun maven(url: String) | ||
fun dir(dir: File) | ||
} | ||
|
||
interface DependencyHandlerScope { | ||
fun implementation(coordinates: String) | ||
fun implementation(group: String, artifact: String, version: String) | ||
} | ||
|
||
fun RepositoryHandlerScope.mavenCentral() = maven("https://repo.maven.apache.org/maven2/") | ||
fun RepositoryHandlerScope.google() = maven("https://dl.google.com/dl/android/maven2/") | ||
fun RepositoryHandlerScope.mavenLocal() = maven("*mavenLocal") | ||
|
||
fun JupyterIntegration.Builder.repositories(action: RepositoryHandlerScope.() -> Unit) { | ||
RepositoryHandlerScopeImpl(this).action() | ||
} | ||
|
||
fun JupyterIntegration.Builder.dependencies(action: DependencyHandlerScope.() -> Unit) { | ||
DependencyHandlerScopeImpl(this).action() | ||
} | ||
|
||
private class RepositoryHandlerScopeImpl(private val builder: JupyterIntegration.Builder) : RepositoryHandlerScope { | ||
override fun dir(dir: File) { | ||
builder.repositories(dir.absolutePath) | ||
} | ||
|
||
override fun maven(url: String) { | ||
builder.repositories(url) | ||
} | ||
} | ||
|
||
private class DependencyHandlerScopeImpl(private val builder: JupyterIntegration.Builder) : DependencyHandlerScope { | ||
override fun implementation(coordinates: String) { | ||
builder.dependencies(coordinates) | ||
} | ||
|
||
override fun implementation(group: String, artifact: String, version: String) { | ||
implementation("$group:$artifact:$version") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters