diff options
8 files changed, 66 insertions, 39 deletions
diff --git a/core/src/main/kotlin/configuration.kt b/core/src/main/kotlin/configuration.kt index 0c877bd4..f0e77f09 100644 --- a/core/src/main/kotlin/configuration.kt +++ b/core/src/main/kotlin/configuration.kt @@ -109,9 +109,9 @@ interface DokkaConfiguration : Serializable { } interface SourceLinkDefinition : Serializable { - val path: String - val url: String - val lineSuffix: String? + val localDirectory: String + val remoteUrl: String + val remoteLineSuffix: String? } interface DokkaModuleDescription : Serializable { diff --git a/core/src/main/kotlin/defaultConfiguration.kt b/core/src/main/kotlin/defaultConfiguration.kt index ec461ffd..4f70cfbb 100644 --- a/core/src/main/kotlin/defaultConfiguration.kt +++ b/core/src/main/kotlin/defaultConfiguration.kt @@ -48,9 +48,9 @@ data class DokkaModuleDescriptionImpl( ) : DokkaConfiguration.DokkaModuleDescription data class SourceLinkDefinitionImpl( - override val path: String, - override val url: String, - override val lineSuffix: String? + override val localDirectory: String, + override val remoteUrl: String, + override val remoteLineSuffix: String? ) : DokkaConfiguration.SourceLinkDefinition { companion object { fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinitionImpl { diff --git a/integration-tests/gradle/projects/it-basic/build.gradle.kts b/integration-tests/gradle/projects/it-basic/build.gradle.kts index 43d3a0f3..081197ad 100644 --- a/integration-tests/gradle/projects/it-basic/build.gradle.kts +++ b/integration-tests/gradle/projects/it-basic/build.gradle.kts @@ -21,6 +21,13 @@ tasks.withType<DokkaTask> { prefix.set("it.suppressedByPackage") suppress.set(true) } + sourceLink { + localDirectory.set(file("src/main")) + remoteUrl.set( + "https://github.com/Kotlin/dokka/tree/master/" + + "integration-tests/gradle/projects/it-basic/src/main" + ) + } } register("myTest") { diff --git a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt index 46577e81..60f03d0f 100644 --- a/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt +++ b/integration-tests/gradle/src/integrationTest/kotlin/org/jetbrains/dokka/it/gradle/BasicGradleIntegrationTest.kt @@ -84,6 +84,24 @@ class BasicGradleIntegrationTest(override val versions: BuildVersions) : Abstrac allHtmlFiles().any { file -> "Basic Project" in file.readText() }, "Expected configured moduleDisplayName to be present in html" ) + + assertTrue( + allHtmlFiles().any { file -> + "https://github.com/Kotlin/dokka/tree/master/" + + "integration-tests/gradle/projects/it-basic/" + + "src/main/kotlin/it/basic/PublicClass.kt" in file.readText() + }, + "Expected `PublicClass` source link to GitHub" + ) + + assertTrue( + allHtmlFiles().any { file -> + "https://github.com/Kotlin/dokka/tree/master/" + + "integration-tests/gradle/projects/it-basic/" + + "src/main/java/it/basic/java/SampleJavaClass.java" in file.readText() + }, + "Expected `SampleJavaClass` source link to GitHub" + ) } private fun File.assertJavadocOutputDir() { diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt index f0e62f11..c8ef7cbc 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -123,8 +123,8 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent data class SourceLink(val path: String, val url: String, val lineSuffix: String?, val sourceSetData: DokkaSourceSet) { constructor(sourceLinkDefinition: DokkaConfiguration.SourceLinkDefinition, sourceSetData: DokkaSourceSet) : this( - sourceLinkDefinition.path, sourceLinkDefinition.url, sourceLinkDefinition.lineSuffix, sourceSetData + sourceLinkDefinition.localDirectory, sourceLinkDefinition.remoteUrl, sourceLinkDefinition.remoteLineSuffix, sourceSetData ) } -fun ContentGroup.hasTabbedContent(): Boolean = children.any { it.hasStyle(ContentStyle.TabbedContent) }
\ No newline at end of file +fun ContentGroup.hasTabbedContent(): Boolean = children.any { it.hasStyle(ContentStyle.TabbedContent) } diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index a8fc9f6d..40c87b75 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -69,9 +69,9 @@ class LinkableContentTest : AbstractCoreTest() { sourceRoots = listOf("$testDataDir/jsMain/kotlin") sourceLinks = listOf( SourceLinkDefinitionImpl( - path = "jsMain/kotlin", - url = "https://github.com/user/repo/tree/master/src/jsMain/kotlin", - lineSuffix = "#L" + localDirectory = "jsMain/kotlin", + remoteUrl = "https://github.com/user/repo/tree/master/src/jsMain/kotlin", + remoteLineSuffix = "#L" ) ) name = "js" @@ -82,9 +82,9 @@ class LinkableContentTest : AbstractCoreTest() { sourceRoots = listOf("$testDataDir/jvmMain/kotlin") sourceLinks = listOf( SourceLinkDefinitionImpl( - path = "jvmMain/kotlin", - url = "https://github.com/user/repo/tree/master/src/jvmMain/kotlin", - lineSuffix = "#L" + localDirectory = "jvmMain/kotlin", + remoteUrl = "https://github.com/user/repo/tree/master/src/jvmMain/kotlin", + remoteLineSuffix = "#L" ) ) name = "jvm" diff --git a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt index 54700fe9..89ecb5e7 100644 --- a/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt +++ b/runners/gradle-plugin/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt @@ -7,27 +7,29 @@ import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional import org.jetbrains.dokka.DokkaConfigurationBuilder import org.jetbrains.dokka.SourceLinkDefinitionImpl +import java.io.File class GradleSourceLinkBuilder( @Transient @get:Internal internal val project: Project ) : DokkaConfigurationBuilder<SourceLinkDefinitionImpl> { + @Input - val path: Property<String> = project.objects.safeProperty<String>() - .safeConvention("") + val localDirectory: Property<File?> = project.objects.safeProperty() @Input - val url: Property<String> = project.objects.safeProperty<String>() + val remoteUrl: Property<String> = project.objects.safeProperty<String>() .safeConvention("") @Optional @Input - val lineSuffix: Property<String?> = project.objects.safeProperty() + val remoteLineSuffix: Property<String> = project.objects.safeProperty<String>() + .safeConvention("#L") override fun build(): SourceLinkDefinitionImpl { return SourceLinkDefinitionImpl( - path = path.getSafe(), - url = url.getSafe(), - lineSuffix = lineSuffix.getSafe() + localDirectory = localDirectory.getSafe()?.absolutePath ?: project.projectDir.absolutePath, + remoteUrl = remoteUrl.getSafe(), + remoteLineSuffix = remoteLineSuffix.getSafe() ) } } diff --git a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt index 26d02fe0..4ab644e7 100644 --- a/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt +++ b/runners/gradle-plugin/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt @@ -219,39 +219,39 @@ class GradleDokkaSourceSetBuilderTest { sourceSet.sourceLinks.add( GradleSourceLinkBuilder(project).apply { - this.lineSuffix by "ls1" - this.path by "p1" - this.url by "u1" + this.remoteLineSuffix by "ls1" + this.localDirectory by project.file("p1") + this.remoteUrl by "u1" }) sourceSet.sourceLink { - it.lineSuffix by "ls2" - it.path by "p2" - it.url by "u2" + it.remoteLineSuffix by "ls2" + it.localDirectory by project.file("p2") + it.remoteUrl by "u2" } sourceSet.sourceLink(project.closureOf<GradleSourceLinkBuilder> { - this.lineSuffix by "ls3" - this.path by "p3" - this.url by "u3" + this.remoteLineSuffix by "ls3" + this.localDirectory by project.file("p3") + this.remoteUrl by "u3" }) assertEquals( setOf( SourceLinkDefinitionImpl( - lineSuffix = "ls1", - path = "p1", - url = "u1" + remoteLineSuffix = "ls1", + localDirectory = project.file("p1").absolutePath, + remoteUrl = "u1" ), SourceLinkDefinitionImpl( - lineSuffix = "ls2", - path = "p2", - url = "u2" + remoteLineSuffix = "ls2", + localDirectory = project.file("p2").absolutePath, + remoteUrl = "u2" ), SourceLinkDefinitionImpl( - lineSuffix = "ls3", - path = "p3", - url = "u3" + remoteLineSuffix = "ls3", + localDirectory = project.file("p3").absolutePath, + remoteUrl = "u3" ) ), sourceSet.build().sourceLinks, |