Skip to content
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

Prep testing, clean-up Engine and use JS233 directly #7

Merged
merged 13 commits into from
Nov 1, 2021
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
13 changes: 11 additions & 2 deletions .github/workflows/gradle-test.pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 8
- name: "Test"
run: ./gradlew clean test --stacktrace
run: ./gradlew clean test :sample:dokkaHtml --stacktrace
- name: Bundle the build report
if: failure()
run: find . -type d -name 'reports' | zip -@ -r build-reports.zip
- name: "Make test reports available to download"
if: failure()
uses: actions/upload-artifact@v1
with:
name: error-report
path: build-reports.zip
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.idea
build/
*/build/
*/jsr223
6 changes: 6 additions & 0 deletions JarListScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

> list
for x in *.jar; do
echo $x >> list
done
39 changes: 29 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
import java.io.ByteArrayOutputStream

plugins {
kotlin("jvm") version "1.5.0"
id("org.jetbrains.dokka") version "1.5.0"
`maven-publish`
signing
base
}

group = "com.nomisrev"
Expand All @@ -17,6 +19,7 @@ repositories {
}

val dokkaVersion: String = "1.5.0"
configurations { create("toCopy") }

dependencies {
compileOnly("org.jetbrains.dokka:dokka-core:$dokkaVersion")
Expand All @@ -26,27 +29,43 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation("io.arrow-kt:arrow-fx-coroutines:0.13.2")

runtimeOnly(kotlin("reflect"))
runtimeOnly(kotlin("script-runtime"))
runtimeOnly("org.jetbrains.kotlin:kotlin-script-runtime:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jsr223-unshaded:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-common:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jvm:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-jvm-host-unshaded:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-compiler:1.5.0") { isTransitive = false }
runtimeOnly("org.jetbrains.kotlin:kotlin-scripting-compiler-impl:1.5.0") { isTransitive = false }

testImplementation(kotlin("test-junit"))
testImplementation("org.jetbrains.dokka:dokka-test-api:$dokkaVersion")
testImplementation("org.jetbrains.dokka:dokka-base-test-utils:$dokkaVersion")

"toCopy"("org.jetbrains.kotlin:kotlin-scripting-jsr223-unshaded:1.5.21")
}

val dokkaOutputDir = "$buildDir/dokka"

tasks {
register("downloadJS233") {
doLast {
if (!File("src/main/resources/jsr223/list").exists()) {
File("src/main/resources/jsr223").also { it.mkdirs() }

copy {
from(configurations.getAt("toCopy")).into("src/main/resources/jsr223")
}
exec {
workingDir = File("src/main/resources/jsr223")
executable = "../../../../JarListScript.sh"
}
}
}
}

clean {
doFirst {
File("src/main/resources/jsr223").deleteRecursively()
}
}

withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
dependsOn("downloadJS233")
}

dokkaHtml {
outputDirectory.set(file(dokkaOutputDir))
}
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/com/github/nomisrev/ank/AnkDokkaPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ private class AnkCompiler(private val ctx: DokkaContext) : PreMergeDocumentableT
override fun invoke(modules: List<DModule>): List<DModule> = runBlocking(Dispatchers.Default) {
ctx.logger.warn(colored(ANSI_PURPLE, "Λnk Dokka Plugin is running"))

// Shall we process all packages in parallel??
modules.parTraverse { module ->
val classpath = module.sourceSets.firstOrNull()?.classpath.orEmpty()
.map { it.toURI().toURL().toString() }

Engine.createEngine(classpath).use { engine ->
Engine.engine(module.classPath()).use { engine ->
val packages =
module.packages.parTraverseCodeBlock(module) { module, `package`, documentable, node, wrapper, codeBlock ->
Snippet(module, `package`, documentable, node, wrapper, codeBlock)?.let {
Engine.compileCode(engine, it)
engine.eval(it)
}?.toCodeBlock()
}

module.copy(packages = packages)
}

}
}.also { Engine.testReport()?.let(::println) }
}
}
21 changes: 12 additions & 9 deletions src/main/kotlin/com/github/nomisrev/ank/dokka.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.nomisrev.ank

import arrow.fx.coroutines.parTraverse
import java.net.URL
import org.jetbrains.dokka.model.DAnnotation
import org.jetbrains.dokka.model.DClass
import org.jetbrains.dokka.model.DClasslike
Expand Down Expand Up @@ -33,6 +34,8 @@ import org.jetbrains.dokka.model.doc.TagWrapper
import org.jetbrains.dokka.model.doc.Throws
import org.jetbrains.dokka.model.doc.Version

fun DModule.classPath(): List<URL> =
sourceSets.firstOrNull()?.classpath.orEmpty().map { it.toURI().toURL() }

/**
* This methods gives you all info available for a detected `CodeBlock`.
Expand All @@ -41,7 +44,7 @@ import org.jetbrains.dokka.model.doc.Version
*/
suspend fun List<DPackage>.parTraverseCodeBlock(
dModule: DModule,
transform: (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, CodeBlock) -> CodeBlock?
transform: suspend (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, CodeBlock) -> CodeBlock?
): List<DPackage> = parTraverse { `package` ->
`package`.copy(
properties = `package`.properties.map { property ->
Expand All @@ -57,10 +60,10 @@ suspend fun List<DPackage>.parTraverseCodeBlock(
)
}

private fun DClasslike.process(
private suspend fun DClasslike.process(
module: DModule,
`package`: DPackage,
transform: (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, CodeBlock) -> CodeBlock?
transform: suspend (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, CodeBlock) -> CodeBlock?
): DClasslike =
when (this) {
is DClass -> copy(documentation = documentation.process(module, `package`, this, transform))
Expand All @@ -70,20 +73,20 @@ private fun DClasslike.process(
is DAnnotation -> copy(documentation = documentation.process(module, `package`, this, transform))
}

private fun SourceSetDependent<DocumentationNode>.process(
private suspend fun SourceSetDependent<DocumentationNode>.process(
module: DModule,
`package`: DPackage,
documentable: Documentable,
transform: (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, code: CodeBlock) -> CodeBlock?
transform: suspend (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, code: CodeBlock) -> CodeBlock?
): SourceSetDependent<DocumentationNode> =
mapValues { (_, node) -> node.process(module, `package`, documentable, node, transform) }

private fun DocumentationNode.process(
private suspend fun DocumentationNode.process(
module: DModule,
`package`: DPackage,
documentable: Documentable,
node: DocumentationNode,
transform: (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, code: CodeBlock) -> CodeBlock?
transform: suspend (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, code: CodeBlock) -> CodeBlock?
): DocumentationNode =
copy(children = children.map {
when (it) {
Expand All @@ -105,13 +108,13 @@ private fun DocumentationNode.process(
}
})

private fun DocTag.process(
private suspend fun DocTag.process(
module: DModule,
`package`: DPackage,
documentable: Documentable,
node: DocumentationNode,
wrapper: TagWrapper,
transform: (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, code: CodeBlock) -> CodeBlock?
transform: suspend (module: DModule, `package`: DPackage, documentable: Documentable, node: DocumentationNode, wrapper: TagWrapper, code: CodeBlock) -> CodeBlock?
): DocTag =
when (this) {
is CodeBlock -> transform(module, `package`, documentable, node, wrapper, this) ?: this
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/com/github/nomisrev/ank/domain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ data class SnippetPath(
val node: DocumentationNode,
val tagWrapper: TagWrapper,
val codeBlock: CodeBlock
)
) {
fun prettyPrint(): String = """
Snippet in KDoc of ${documentable.name ?: "<anonymous>"} in ${`package`.packageName} failed.
""".trimIndent()
}

public data class Snippet(
val path: SnippetPath,
Expand Down
Loading