Skip to content

Commit

Permalink
Fix integration test of CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Nov 23, 2022
1 parent 608f854 commit badb710
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
16 changes: 16 additions & 0 deletions integration-tests/cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
val dokka_version: String by project
evaluationDependsOn(":runners:cli")
evaluationDependsOn(":plugins:base")
evaluationDependsOn(":plugins:html")

dependencies {
implementation(kotlin("stdlib"))
Expand All @@ -21,22 +22,37 @@ val basePluginShadow: Configuration by configurations.creating {
}
}

val htmlPluginShadow: Configuration by configurations.creating {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage::class.java, "java-runtime"))
}
}

dependencies {
basePluginShadow(project(":plugins:base"))
basePluginShadow(project(":kotlin-analysis")) // compileOnly in base plugin
htmlPluginShadow(project(":plugins:html"))
}

val basePluginShadowJar by tasks.register("basePluginShadowJar", ShadowJar::class) {
configurations = listOf(basePluginShadow)
archiveFileName.set("fat-base-plugin-$dokka_version.jar")
archiveClassifier.set("")
}
val htmlPluginShadowJar by tasks.register("htmlPluginShadowJar", ShadowJar::class) {
configurations = listOf(htmlPluginShadow)
archiveFileName.set("fat-html-plugin-$dokka_version.jar")
archiveClassifier.set("")
}

tasks.integrationTest {
inputs.dir(file("projects"))
val cliJar = tasks.getByPath(":runners:cli:shadowJar") as ShadowJar
environment("CLI_JAR_PATH", cliJar.archiveFile.get())
environment("HTML_PLUGIN_JAR_PATH", htmlPluginShadowJar.archiveFile.get())
environment("BASE_PLUGIN_JAR_PATH", basePluginShadowJar.archiveFile.get())
dependsOn(cliJar)
dependsOn(basePluginShadowJar)
dependsOn(htmlPluginShadowJar)
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import kotlin.test.*

class CliIntegrationTest : AbstractCliIntegrationTest() {

val pluginClasspath by lazy {
listOf(basePluginJarFile, htmlPluginJarFile).joinToString(separator = ";") { it.path }
}

@BeforeTest
fun copyProject() {
val templateProjectDir = File("projects", "it-cli")
Expand All @@ -32,7 +36,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-pluginsClasspath", pluginClasspath,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
Expand Down Expand Up @@ -107,7 +111,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-pluginsClasspath", pluginClasspath,
"-moduleName", "Basic Project",
"-failOnWarning",
"-sourceSet",
Expand Down Expand Up @@ -135,7 +139,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-pluginsClasspath", pluginClasspath,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
Expand Down Expand Up @@ -166,7 +170,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-loggingLevel", "DEBUG",
"-pluginsClasspath", basePluginJarFile.path,
"-pluginsClasspath", pluginClasspath,
"-sourceSet",
buildString {
append(" -src ${File(projectDir, "src").path}")
Expand Down Expand Up @@ -202,7 +206,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-loggingLevel", "WARN",
"-pluginsClasspath", basePluginJarFile.path,
"-pluginsClasspath", pluginClasspath,
"-sourceSet",
buildString {
append(" -src ${File(projectDir, "src").path}")
Expand All @@ -223,7 +227,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
val process = ProcessBuilder(
"java", "-jar", cliJarFile.path,
"-outputDir", dokkaOutputDir.path,
"-pluginsClasspath", basePluginJarFile.path,
"-pluginsClasspath", pluginClasspath,
"-moduleName", "Basic Project",
"-sourceSet",
buildString {
Expand Down Expand Up @@ -270,7 +274,13 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
val resourcePath = javaClass.getResource("/my-file.json")?.toURI() ?: throw IllegalStateException("No JSON found!")
val jsonPath = File(resourcePath).absolutePath
PrintWriter(jsonPath).run {
write(jsonBuilder(dokkaOutputDir.invariantSeparatorsPath, basePluginJarFile.invariantSeparatorsPath, File(projectDir, "src").invariantSeparatorsPath, reportUndocumented = true))
write(
jsonBuilder(
outputPath = dokkaOutputDir.invariantSeparatorsPath,
pluginsClasspath = "\"${basePluginJarFile.invariantSeparatorsPath}\", \"${htmlPluginJarFile.invariantSeparatorsPath}\"",
projectPath = File(projectDir, "src").invariantSeparatorsPath, reportUndocumented = true
)
)
close()
}

Expand Down Expand Up @@ -313,7 +323,7 @@ class CliIntegrationTest : AbstractCliIntegrationTest() {
write(
jsonBuilder(
outputPath = dokkaOutputDir.invariantSeparatorsPath,
pluginsClasspath = basePluginJarFile.invariantSeparatorsPath,
pluginsClasspath = "\"${basePluginJarFile.invariantSeparatorsPath}\", \"${htmlPluginJarFile.invariantSeparatorsPath}\"",
projectPath = File(projectDir, "src").invariantSeparatorsPath,
globalSourceLinks = """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ abstract class AbstractCliIntegrationTest : AbstractIntegrationTest() {
File(temporaryTestFolder.root, "base-plugin.jar")
}

protected val htmlPluginJarFile: File by lazy {
File(temporaryTestFolder.root, "html-plugin.jar")
}

@BeforeTest
fun copyJarFiles() {
val cliJarPathEnvironmentKey = "CLI_JAR_PATH"
Expand All @@ -32,5 +36,13 @@ abstract class AbstractCliIntegrationTest : AbstractIntegrationTest() {
"Missing path to base plugin jar System.getenv($basePluginPathEnvironmentKey)"
)
basePluginJarFile.copyTo(this.basePluginJarFile)

val htmlPluginPathEnvironmentKey = "HTML_PLUGIN_JAR_PATH"
val htmlPluginJarFile = File(System.getenv(htmlPluginPathEnvironmentKey))
assertTrue(
htmlPluginJarFile.exists() && htmlPluginJarFile.isFile,
"Missing path to html plugin jar System.getenv($htmlPluginPathEnvironmentKey)"
)
htmlPluginJarFile.copyTo(this.htmlPluginJarFile)
}
}

0 comments on commit badb710

Please sign in to comment.