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

Refactor project (standard layout, split up Knit from Gradle plugin, buildSrc convention plugins) #51

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.gradle
.idea
build
out
out
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Kotlin source code documentation management tool.

This is a tool that produces Kotlin source example files and tests from markdown documents
This is a tool that produces Kotlin source example files and tests from Markdown documents
with embedded snippets of Kotlin code. It also helps to add links to the API documentation website into the
documents and has a few other helpful markdown-management features.

Expand All @@ -20,7 +20,7 @@ which are committed to the VCS. The overall workflow is:
3. Commit to VCS.
4. Generated files are automatically verified on subsequent project builds.

Knit does not really parse markdown format or HTML, but understands certain Knit markup patterns and _directives_.
Knit does not really parse Markdown format or HTML, but understands certain Knit markup patterns and _directives_.
Directives in markdown files must always start at the beginning of the line and have the following general format for
single-line directives:

Expand Down Expand Up @@ -158,7 +158,7 @@ file name, for example:

The name of the example file must match a specific pattern. By default, this pattern's regex is
`example-[a-zA-Z0-9-]+-##\\.kt`. It can be overridden via `knit.pattern` [property](#knit-properties).
The sequence of hashes (`#`) in the pattern matches any alpha-numeric sequence and causes the examples to
The sequence of hashes (`#`) in the pattern matches any alphanumeric sequence and causes the examples to
be automatically consecutively numbered inside the markdown file. For example, you can add a
new section of code at the beginning of the document and write in the markdown file:

Expand All @@ -183,7 +183,7 @@ fun foo() {}
A `KNIT` directive can be used to trigger generation of an example file instead of providing a readable reference to a file.
In this case, only an example file name shall be specified (without a path).
An example file will be written to the `knit.dir` [property](#knit-properties) directory.
The name of the file shall still match the `knit.pattern` [property](#knit-properties) pattern and
The name of the file shall still match the `knit.pattern` [property](#knit-properties) pattern, and
it will be automatically numbered as explained in the previous section.
For example:

Expand All @@ -195,7 +195,7 @@ For example:

#### Merging code pieces

All tripple-backquoted Kotlin sections are merged together and are output to the Kotlin source file when the next
All triple-backquoted Kotlin sections are merged together and are output to the Kotlin source file when the next
Knit pattern in encountered. This way, documentation can be written fluently, explaining
functions as they are introduced. For example, the following markdown:

Expand Down Expand Up @@ -289,7 +289,7 @@ A single piece of code can be included into multiple examples (as opposed to the
by specifying regex pattern of the example file name right after the `INCLUDE` directive as its parameter.

With the pattern the `INCLUDE` directive can also be specified on a single line, without the
code inside of it. In this case, the code to be included is taken from the previously tripple-backquoted
code inside it. In this case, the code to be included is taken from the previously triple-backquoted
Kotlin source code before it. This way, the code snippet can be introduced and shown to the reader of
the documentation and then included into the several subsequent examples.

Expand Down Expand Up @@ -362,7 +362,7 @@ test.package=com.example.test
Here `test.dir` specified the directory where the Kotlin test code is generated too and `test.package` specifies
the package. In the beginning of the markdown file you specify the name of the test using `TEST_NAME` directive.
There is one test file per the source markdown file with a test-case for each example. After the example
you can place the expected output of the test in tripple-quoted `text` block and add `TEST` directive after
you can place the expected output of the test in triple-quoted `text` block and add `TEST` directive after
it to get the test-case added. For example:

<!--- TEST_NAME BasicTest -->
Expand Down Expand Up @@ -446,7 +446,7 @@ The names of the modes are mapped to comparison functions via `test.mode.<mode-n
#### Test template

Generation of the test source code is completely template-based. The default template
is located in [`knit.test.template`](resources/knit.test.template) file and can be overridden
is located in [`knit.test.template`](kotlinx-knit-core/src/main/resources/knit.test.template) file and can be overridden
via `test.template` [property](#knit-properties).
You can use arbitrary `test.xxx` [properties](#knit-properties) in the test template.

Expand All @@ -455,7 +455,7 @@ console. By tweaking the template you can test other kinds of examples in your m

### Kotlin Source Comments

Knit directives and other Knit-recognized markdown markup can be embedded into documentation of
Knit directives and other Knit-recognized Markdown markup can be embedded into documentation of
Kotlin source (`.kt`/`.kts`) files. There are several ways to embed Knit markup into Kotlin sources.

Knit markup can be nested inside regular /* ... */ comment block, directives starting at the beginning of the line.
Expand Down Expand Up @@ -529,7 +529,7 @@ knitPrepare.dependsOn rootProject.getTasksByName("dokka", true)

The modules providing APIs can be stored in separate directories named after the module name. For example,
this project has [`kotlinx-knit-test`](kotlinx-knit-test) module in a separate directory. You can reference
functions and classes declared there using a regular markdown link syntax and give instructions to Knit
functions and classes declared there using a regular Markdown link syntax and give instructions to Knit
tool to expand those links like this:

Here is a link to [captureOutput] function.
Expand Down
113 changes: 3 additions & 110 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,116 +2,9 @@
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

import com.gradle.publish.*
import kotlinx.knit.build.*
import org.jetbrains.kotlin.gradle.tasks.*

plugins {
kotlin("jvm")
id("org.jetbrains.dokka") apply false
id("com.gradle.plugin-publish") apply false
`java-gradle-plugin`
signing
`maven-publish`
}

repositories {
mavenCentral()
jcenter()
gradlePluginPortal()
}

allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.gradle.maven-publish")

repositories {
jcenter()
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.11.1")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.1")
testImplementation(kotlin("test-junit"))
}

tasks.withType<KotlinCompile> {
kotlinOptions.apply {
languageVersion = "1.4"
jvmTarget = "1.8"
allWarningsAsErrors = true
freeCompilerArgs = freeCompilerArgs + listOf("-Xsuppress-version-warnings") // suppress deprecated 1.4
}
}

sourceSets {
main.kotlin.dir = "src"
test.kotlin.dir = "test"
main.resources.dir = "resources"
}

// Set version when deploying
properties["DeployVersion"]?.let { version = it }
}

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
mavenCentralArtifacts(project, project.sourceSets.main.allSource)
}
}
mavenCentralMetadata()
mavenRepositoryPublishing(project)
publications.withType(MavenPublication::class).all {
signPublicationIfKeyPresent(this)
}
}

// ---------- This root project -- Gradle plugin ----------

apply(plugin = "org.gradle.java-gradle-plugin")
apply(plugin = "com.gradle.plugin-publish")

extensions.getByType(PluginBundleExtension::class).apply {
website = "https://github.com/Kotlin/kotlinx-knit"
vcsUrl = "https://github.com/Kotlin/kotlinx-knit"
tags = listOf("kotlin", "documentation", "markdown")
}

gradlePlugin {
plugins {
create("kotlinx-knit") {
// This is a fully-qualified plugin id, short id of 'kotlinx-knit' is added manually in resources
id = "org.jetbrains.kotlinx.knit"
implementationClass = "kotlinx.knit.KnitPlugin"
displayName = "Knit documentation plugin"
description = "Produces Kotlin source example files and tests from markdown documents with embedded snippets of Kotlin code"
}
}
}

val publishPlugins by tasks.getting(PublishTask::class)

val deploy: Task by tasks.creating {
dependsOn(getTasksByName("publish", true))
dependsOn(publishPlugins)
}

val freemarkerVersion: String by project
val dokkaVersion: String by project

dependencies {
implementation(gradleApi())
implementation(project(":pathsaver"))
implementation("org.freemarker:freemarker:$freemarkerVersion")
implementation(project(":kotlinx-knit-test"))
implementation("org.jetbrains.dokka:dokka-core:$dokkaVersion")
buildsrc.conventions.base
}

val test: Task by tasks.getting {
dependsOn(tasks.findByPath(":kotlinx-knit-test:dokka"))
dependsOn(tasks.findByPath(":kotlinx-knit-test:dokkaHtml"))
}
group = "kotlinx.knit"
version = "0.4.0-SNAPSHOT"
30 changes: 18 additions & 12 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
/*
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

import org.jetbrains.kotlin.gradle.plugin.*
import java.util.*

plugins {
`kotlin-dsl`
kotlin("jvm") version embeddedKotlinVersion
}

repositories {
mavenCentral()
}

val props = Properties().apply {
project.file("../gradle.properties").inputStream().use { load(it) }
dependencies {
implementation(platform(libs.kotlin.bom))
implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.dokka)
implementation(libs.gradlePlugin.gradlePluginPublish)
}

val kotlinVersion: String = props.getProperty("kotlinVersion")
val projectJvmTarget: String = "11"

dependencies {
implementation(kotlin("gradle-plugin-api", kotlinVersion))
kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(projectJvmTarget))
}
}

sourceSets["main"].withConvention(KotlinSourceSet::class) { kotlin.srcDirs("src") }
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = projectJvmTarget
}
}

kotlinDslPluginOptions {
experimentalWarning.set(false)
jvmTarget.set(projectJvmTarget)
}
23 changes: 23 additions & 0 deletions buildSrc/repositories.settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Shared repository config, for use in both build-logic and the root project


@Suppress("UnstableApiUsage") // Central declaration of repositories is an incubating feature
dependencyResolutionManagement {

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

repositories {
mavenCentral()
gradlePluginPortal()
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/") {
mavenContent { includeGroup("org.jetbrains.dokka") }
}
}

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
}
12 changes: 12 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rootProject.name = "buildSrc"

apply(from = "repositories.settings.gradle.kts")

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
57 changes: 0 additions & 57 deletions buildSrc/src/MavenCentralMetadata.kt

This file was deleted.

Loading