Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sellmair committed Jun 9, 2020
1 parent 23e0d26 commit b426059
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 56 deletions.
36 changes: 1 addition & 35 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions core/src/main/kotlin/DokkaException.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.jetbrains.dokka

class DokkaException(message: String) : RuntimeException(message)
29 changes: 23 additions & 6 deletions core/src/main/kotlin/DokkaGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.jetbrains.dokka.analysis.DokkaResolutionFacade
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.model.SourceSetCache
import org.jetbrains.dokka.model.SourceSetData
import org.jetbrains.dokka.model.sourceSet
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
Expand Down Expand Up @@ -55,9 +54,7 @@ class DokkaGenerator(
report("Rendering")
render(transformedPages, context)

context.unusedPoints.takeIf { it.isNotEmpty() }
?.also { logger.warn("Unused extension points found: ${it.joinToString(", ")}") }
logger.report()
reportAfterRendering(context)
}.dump("\n\n === TIME MEASUREMENT ===\n")

fun generateAllModulesPage() = timed {
Expand Down Expand Up @@ -139,14 +136,28 @@ class DokkaGenerator(
renderer.render(transformedPages)
}

fun reportAfterRendering(context: DokkaContext) {
context.unusedPoints.takeIf { it.isNotEmpty() }?.also {
logger.warn("Unused extension points found: ${it.joinToString(", ")}")
}

logger.report()

if (context.configuration.failOnWarning && (logger.warningsCount > 0 || logger.errorsCount > 0)) {
throw DokkaException(
"Failed with warningCount=${logger.warningsCount} and errorCount=${logger.errorsCount}"
)
}
}

private fun createEnvironmentAndFacade(pass: DokkaConfiguration.PassConfiguration): EnvironmentAndFacade =
AnalysisEnvironment(DokkaMessageCollector(logger), pass.analysisPlatform).run {
if (analysisPlatform == Platform.jvm) {
addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre())
}
pass.classpath.forEach { addClasspath(File(it)) }

addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path })
addSources((pass.sourceRoots + pass.dependentSourceRoots).map { it.path })

loadLanguageVersionSettings(pass.languageVersion, pass.apiVersion)

Expand Down Expand Up @@ -205,4 +216,10 @@ private class Timer(startTime: Long, private val logger: DokkaLogger?) {
}

private fun timed(logger: DokkaLogger? = null, block: Timer.() -> Unit): Timer =
Timer(System.currentTimeMillis(), logger).apply(block).apply { report("") }
Timer(System.currentTimeMillis(), logger).apply {
try {
block()
} finally {
report("")
}
}
1 change: 1 addition & 0 deletions core/src/main/kotlin/configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface DokkaConfiguration {
val impliedPlatforms: List<String>
val pluginsClasspath: List<File>
val pluginsConfiguration: Map<String, String>
val failOnWarning: Boolean

interface PassConfiguration {
val moduleName: String
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/kotlin/defaultConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ data class DokkaConfigurationImpl(
override val passesConfigurations: List<PassConfigurationImpl>,
override val pluginsClasspath: List<File>,
override val pluginsConfiguration: Map<String, String>,
override val modules: List<DokkaModuleDescriptionImpl>
override val modules: List<DokkaModuleDescriptionImpl>,
override val failOnWarning: Boolean
) : DokkaConfiguration

data class PassConfigurationImpl (
Expand Down
321 changes: 314 additions & 7 deletions plugins/base/src/main/resources/dokka/scripts/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/base/src/main/resources/dokka/scripts/main.js.map

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions plugins/base/src/test/kotlin/basic/FailOnWarningTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package basic

import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.jetbrains.dokka.utilities.DokkaConsoleLogger
import org.jetbrains.dokka.utilities.DokkaLogger
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

class FailOnWarningTest : AbstractCoreTest() {

@Test
fun `throws exception if one or more warnings were emitted`() {
val configuration = dokkaConfiguration {
failOnWarning = true
passes {
pass {
sourceRoots = listOf("src/main/kotlin")
}
}
}

assertThrows<DokkaException> {
testInline(
"""
|/src/main/kotlin
|package sample
""".trimIndent(), configuration
) {
analysisSetupStage = {
logger.warn("Warning!")
}
}
}
}

@Test
fun `throws exception if one or more error were emitted`() {
val configuration = dokkaConfiguration {
failOnWarning = true
passes {
pass {
sourceRoots = listOf("src/main/kotlin")
}
}
}

assertThrows<DokkaException> {
testInline(
"""
|/src/main/kotlin
|package sample
""".trimIndent(), configuration
) {
analysisSetupStage = {
logger.error("Error!")
}
}
}
}

@Test
fun `does not throw if now warning or error was emitted`() {
logger = ZeroErrorOrWarningCountDokkaLogger()

val configuration = dokkaConfiguration {
failOnWarning = true
passes {
pass {
sourceRoots = listOf("src/main/kotlin")
}
}
}


testInline(
"""
|/src/main/kotlin
|package sample
""".trimIndent(), configuration
) {
/* We expect no Exception */
}
}

@Test
fun `does not throw if disabled`() {
val configuration = dokkaConfiguration {
failOnWarning = false
passes {
pass {
sourceRoots = listOf("src/main/kotlin")
}
}
}


testInline(
"""
|/src/main/kotlin
|package sample
""".trimIndent(), configuration
) {
analysisSetupStage = {
logger.warn("Error!")
logger.error("Error!")
}
}
}
}

private class ZeroErrorOrWarningCountDokkaLogger(
logger: DokkaLogger = DokkaConsoleLogger
) : DokkaLogger by logger {
override var warningsCount: Int = 0
override var errorsCount: Int = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class RenderingOnlyTestBase {
DokkaBase().externalLocationProviderFactory to { _ -> ::JavadocExternalLocationProviderFactory },
DokkaBase().externalLocationProviderFactory to { _ -> ::DokkaExternalLocationProviderFactory },
sourceSetCache = SourceSetCache(),
testConfiguration = DokkaConfigurationImpl("", "", false, null, emptyList(), emptyList(), emptyList(), emptyMap(), emptyList())
testConfiguration = DokkaConfigurationImpl("", "", false, null, emptyList(), emptyList(), emptyList(), emptyMap(), emptyList(), false)
)

protected val renderedContent: Element by lazy {
Expand Down
4 changes: 4 additions & 0 deletions runners/cli/src/main/kotlin/cli/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ open class GlobalArguments(parser: DokkaArgumentsParser) : DokkaConfiguration {

override val impliedPlatforms: List<String> = emptyList()

override val failOnWarning: Boolean by parser.singleFlag(
listOf("-failOnWarning"), "Fail dokka task if at least one warning was reported"
)

override val passesConfigurations: List<Arguments> by parser.repeatableFlag(
listOf("-pass"),
"Single dokka pass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ open class DokkaTask : DefaultTask(), Configurable {
@Input
var disableAutoconfiguration: Boolean = false

@Input
var failOnWarning: Boolean = false

private var outputDiagnosticInfo: Boolean =
false // Workaround for Gradle, which fires some methods (like collectConfigurations()) multiple times in its lifecycle

Expand Down Expand Up @@ -199,6 +202,7 @@ open class DokkaTask : DefaultTask(), Configurable {
passesConfigurations = defaultModulesConfiguration
pluginsClasspath = pluginsConfig.resolve().toList()
pluginsConfiguration = this@DokkaTask.pluginsConfiguration
failOnWarning = this@DokkaTask.failOnWarning
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class GradleDokkaConfigurationImpl: DokkaConfiguration {
override var pluginsClasspath: List<File> = emptyList()
override var pluginsConfiguration: Map<String, String> = mutableMapOf()
override var modules: List<GradleDokkaModuleDescription> = emptyList()
override var failOnWarning: Boolean = false
}

class GradlePackageOptionsImpl: PackageOptions, Serializable {
Expand Down
6 changes: 5 additions & 1 deletion runners/maven-plugin/src/main/kotlin/DokkaMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ abstract class AbstractDokkaMojo : AbstractMojo() {
@Parameter
var generateIndexPages: Boolean = false

@Parameter
var failOnWarning: Boolean = false

@Parameter
var dokkaPlugins: List<Dependency> = emptyList()

Expand Down Expand Up @@ -263,7 +266,8 @@ abstract class AbstractDokkaMojo : AbstractMojo() {
pluginsClasspath = getArtifactByAether("org.jetbrains.dokka", "dokka-base", dokkaVersion) +
dokkaPlugins.map { getArtifactByAether(it.groupId, it.artifactId, it.version) }.flatten(),
pluginsConfiguration = mutableMapOf(), //TODO implement as it is in Gradle
modules = emptyList()
modules = emptyList(),
failOnWarning = failOnWarning
)

val gen = DokkaGenerator(configuration, logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ internal class DokkaTestGenerator(
)
analysisSetupStage(platforms)

val context = dokkaGenerator.initializePlugins(configuration, logger, platforms, sourceSetsCache, pluginOverrides)
val context =
dokkaGenerator.initializePlugins(configuration, logger, platforms, sourceSetsCache, pluginOverrides)
pluginsSetupStage(context)

val modulesFromPlatforms = dokkaGenerator.createDocumentationModels(platforms, context)
Expand All @@ -48,5 +49,7 @@ internal class DokkaTestGenerator(

dokkaGenerator.render(transformedPages, context)
renderingStage(transformedPages, context)

dokkaGenerator.reportAfterRendering(context)
}
}
Loading

0 comments on commit b426059

Please sign in to comment.