SNRK-86: Assembly parts

This commit is contained in:
Kirill Grachev 2023-05-06 18:57:55 +03:00
parent 363f63b8da
commit 667688d46d
10 changed files with 82 additions and 6 deletions

View File

@ -44,4 +44,5 @@ include(
":snark-ktor", ":snark-ktor",
":snark-storage-driver", ":snark-storage-driver",
":snark-document-builder", ":snark-document-builder",
":snark-main",
) )

View File

@ -6,10 +6,12 @@ plugins {
val coroutinesVersion = space.kscience.gradle.KScienceVersions.coroutinesVersion val coroutinesVersion = space.kscience.gradle.KScienceVersions.coroutinesVersion
val jacksonVersion = "2.14.2" val jacksonVersion = "2.14.2"
val ktorVersion = space.kscience.gradle.KScienceVersions.ktorVersion
dependencies { dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
api("io.ktor:ktor-server-html-builder:$ktorVersion")
implementation(project(":snark-storage-driver")) implementation(project(":snark-storage-driver"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion") implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion")

View File

@ -4,10 +4,12 @@ import com.fasterxml.jackson.core.io.BigDecimalParser
import space.kscience.snark.storage.* import space.kscience.snark.storage.*
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import kotlinx.html.*
import kotlinx.html.dom.createHTMLDocument
private val DEFAULT_DOCUMENT_ROOT = "main.md" private val DEFAULT_DOCUMENT_ROOT = "main.md"
public suspend fun buildDocument(documentDirectory: Directory) { public suspend fun buildDocument(documentDirectory: Directory): HTML {
val dependencyGraph = buildDependencyGraph(documentDirectory) val dependencyGraph = buildDependencyGraph(documentDirectory)
TODO() /*resolving of dependencies*/ TODO() /*resolving of dependencies*/

View File

@ -2,6 +2,7 @@ package documentBuilder
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import space.kscience.snark.storage.local.localStorage
class SomeTest { class SomeTest {
@Test @Test

View File

@ -13,7 +13,7 @@ dependencies {
api("io.ktor:ktor-server-html-builder:$ktorVersion") api("io.ktor:ktor-server-html-builder:$ktorVersion")
api("io.ktor:ktor-server-host-common:$ktorVersion") api("io.ktor:ktor-server-host-common:$ktorVersion")
implementation("io.ktor:ktor-server-netty:2.3.0") implementation("io.ktor:ktor-server-netty:2.3.0")
implementation(project(mapOf("path" to ":snark-storage-driver"))) implementation(project(":snark-storage-driver"))
testApi("io.ktor:ktor-server-tests:$ktorVersion") testApi("io.ktor:ktor-server-tests:$ktorVersion")
} }

View File

@ -11,7 +11,10 @@ import io.ktor.server.response.*
import io.ktor.server.http.content.* import io.ktor.server.http.content.*
import kotlinx.html.* import kotlinx.html.*
import io.ktor.server.routing.* import io.ktor.server.routing.*
import kotlinx.css.h1
import kotlinx.css.html import kotlinx.css.html
import kotlinx.html.dom.create
import kotlinx.html.dom.document
import java.nio.file.Path import java.nio.file.Path
import space.kscience.snark.storage.Directory import space.kscience.snark.storage.Directory
import space.kscience.snark.storage.local.localStorage import space.kscience.snark.storage.local.localStorage
@ -22,9 +25,8 @@ import kotlin.io.path.name
import space.kscience.snark.storage.unzip.unzip import space.kscience.snark.storage.unzip.unzip
public interface DataHolder { public interface DataHolder {
public fun init() : Directory
fun init() : Directory public suspend fun represent(): String
fun represent(): String
//will be HTML later //will be HTML later
} }
class LocalDataHolder: DataHolder { class LocalDataHolder: DataHolder {
@ -44,7 +46,7 @@ class LocalDataHolder: DataHolder {
} }
} }
} }
override fun represent() : String = override suspend fun represent(): String =
if (source == null) { if (source == null) {
"No data was loaded!" "No data was loaded!"
} else { } else {

View File

@ -0,0 +1,21 @@
plugins {
id("space.kscience.gradle.jvm")
`maven-publish`
}
val coroutinesVersion = space.kscience.gradle.KScienceVersions.coroutinesVersion
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation(project(":snark-ktor"))
implementation(project(":snark-storage-driver"))
implementation(project(":snark-document-builder"))
testImplementation(kotlin("test"))
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
}
tasks.test {
useJUnitPlatform()
}

View File

@ -0,0 +1,17 @@
package space.kscience.snark.main
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import space.kscience.snark.ktor.SNARKServer
import space.kscience.snark.storage.local.localStorage
import kotlin.io.path.Path
fun main() = runBlocking {
val port = 8080
val directory = localStorage(Path("./rundata"))
val server = SNARKServer(ServerDataHolder(directory), port)
launch {
server.run()
}
}

View File

@ -0,0 +1,15 @@
package space.kscience.snark.main
import space.kscience.snark.ktor.DataHolder
import space.kscience.snark.storage.Directory
import documentBuilder.*
import kotlinx.html.HTML
internal class ServerDataHolder(private val directory: Directory): DataHolder {
override fun init(): Directory =
directory
override suspend fun represent(): String {
return buildDocument(directory).toString()
}
}

View File

@ -0,0 +1,15 @@
package space.kscience.snark.main
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import space.kscience.snark.ktor.SNARKServer
import space.kscience.snark.storage.local.localStorage
import kotlin.io.path.Path
class Acceptance {
@Test
fun justWorks() = runBlocking {
main()
}
}