Skip to content

Commit 83291d4

Browse files
committed
Knit: Remove copypaste from markdown files, introduce props
* Hierarchical knit.properties files are introduced which are gathered while walking up the directory tree with the properties in knit resources being top-level ones. * Freemarker templates for "knit.include" (top-level of example files) and "test.include" (test template) are introduced with locations that are resolved from properties. * KNIT and TEST_OUT directives are not supported anymore. - Knitting is controlled by "knit.dir" and "knit.pattern" props. - "test.name" prop or TEST_NAME directive drives test gen. * All markdown files are now clean of top-level knit-related boilerplate (only TEST_NAME directive is remaining in some) * All example files are renumbered. It affects example-basic-xx, which had the legacy numbering with later insertions. * All auto-generated files now have the correct source-file name specified at their beginning, due to consistent use of template substitution.
1 parent fd0428e commit 83291d4

File tree

136 files changed

+593
-520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+593
-520
lines changed

docs/basics.md

+8-24
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/BasicsGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class BasicsGuideTest {
17-
-->
1+
<!--- TEST_NAME BasicsGuideTest -->
182

193
**Table of contents**
204

@@ -141,7 +125,7 @@ fun main() = runBlocking<Unit> { // start main coroutine
141125

142126
</div>
143127

144-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt).
128+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt).
145129
146130
<!--- TEST
147131
Hello,
@@ -196,7 +180,7 @@ fun main() = runBlocking {
196180

197181
</div>
198182

199-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt).
183+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt).
200184
201185
<!--- TEST
202186
Hello,
@@ -241,7 +225,7 @@ fun main() = runBlocking { // this: CoroutineScope
241225

242226
</div>
243227

244-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt).
228+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt).
245229
246230
<!--- TEST
247231
Hello,
@@ -281,7 +265,7 @@ fun main() = runBlocking { // this: CoroutineScope
281265

282266
</div>
283267

284-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt).
268+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt).
285269
286270
<!--- TEST
287271
Task from coroutine scope
@@ -317,7 +301,7 @@ suspend fun doWorld() {
317301

318302
</div>
319303

320-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt).
304+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt).
321305
322306
<!--- TEST
323307
Hello,
@@ -354,7 +338,7 @@ fun main() = runBlocking {
354338

355339
</div>
356340

357-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt).
341+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-08.kt).
358342
359343
<!--- TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->
360344

@@ -386,7 +370,7 @@ fun main() = runBlocking {
386370

387371
</div>
388372

389-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt).
373+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-09.kt).
390374
391375
You can run and see that it prints three lines and terminates:
392376

docs/cancellation-and-timeouts.md

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
1+
<!--- TEST_NAME CancellationGuideTest -->
52

6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/CancellationTimeOutsGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class CancellationTimeOutsGuideTest {
17-
-->
183
**Table of contents**
194

205
<!--- TOC -->

docs/channels.md

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
1+
<!--- TEST_NAME ChannelsGuideTest -->
52

6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/ChannelsGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class ChannelsGuideTest {
17-
-->
183
**Table of contents**
194

205
<!--- TOC -->

docs/compatibility.md

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
<!---
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
--->
6-
71
<!--- TOC -->
82

93
* [Compatibility](#compatibility)

docs/composing-suspending-functions.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/ComposingGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class ComposingGuideTest {
17-
-->
1+
<!--- TEST_NAME ComposingGuideTest -->
182

193
**Table of contents**
204

docs/coroutine-context-and-dispatchers.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/DispatcherGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class DispatchersGuideTest {
17-
-->
1+
<!--- TEST_NAME DispatcherGuideTest -->
182

193
**Table of contents**
204

docs/exception-handling.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
1+
<!--- TEST_NAME ExceptionsGuideTest -->
52

6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/ExceptionsGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class ExceptionsGuideTest {
17-
-->
183
**Table of contents**
194

205
<!--- TOC -->
@@ -261,7 +246,6 @@ to leak to its exception handler.
261246

262247

263248
<!--- INCLUDE
264-
265249
import kotlinx.coroutines.exceptions.*
266250
-->
267251

docs/flow.md

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*-##\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/FlowGuideTest.kt
11-
// This file was automatically generated from flow.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class FlowGuideTest {
17-
-->
1+
<!--- TEST_NAME FlowGuideTest -->
182

193
**Table of contents**
204

docs/knit.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
#
4+
5+
knit.package=kotlinx.coroutines.guide
6+
knit.dir=../kotlinx-coroutines-core/jvm/test/guide/
7+
8+
test.package=kotlinx.coroutines.guide.test
9+
test.dir=../kotlinx-coroutines-core/jvm/test/guide/test/

docs/select-expression.md

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,4 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/SelectGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class SelectGuideTest {
17-
-->
18-
1+
<!--- TEST_NAME SelectGuideTest -->
192

203
**Table of contents**
214

docs/shared-mutable-state-and-concurrency.md

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
<!--- INCLUDE .*/example-([a-z]+)-([0-9a-z]+)\.kt
2-
/*
3-
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
4-
*/
5-
6-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
7-
package kotlinx.coroutines.guide.$$1$$2
8-
-->
9-
<!--- KNIT ../kotlinx-coroutines-core/jvm/test/guide/.*\.kt -->
10-
<!--- TEST_OUT ../kotlinx-coroutines-core/jvm/test/guide/test/SharedStateGuideTest.kt
11-
// This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit.
12-
package kotlinx.coroutines.guide.test
13-
14-
import org.junit.Test
15-
16-
class SharedStateGuideTest {
17-
-->
1+
<!--- TEST_NAME SharedStateGuideTest -->
2+
183
**Table of contents**
194

205
<!--- TOC -->

knit/build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
apply plugin: "application"
@@ -10,6 +10,10 @@ sourceSets {
1010
main.resources.srcDirs = ['resources']
1111
}
1212

13+
dependencies {
14+
compile "org.freemarker:freemarker:2.3.29"
15+
}
16+
1317
FileTree mdFiles = fileTree(project.rootDir) {
1418
include '**/*.md'
1519
exclude '**/build/**'

knit/resources/knit.code.include

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
// This file was automatically generated from ${file.name} by Knit tool. Do not edit.
6+
package ${knit.package}.$$1$$2

knit/resources/knit.properties

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#
2-
# Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2+
# Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
#
44

55
site.root=https://kotlin.github.io/kotlinx.coroutines
66

77
module.roots=. integration reactive ui
88
module.marker=build.gradle
9-
module.docs=build/dokka
9+
module.docs=build/dokka
10+
11+
knit.pattern=example-([a-z]+)-(##)\\.kt
12+
knit.include=knit.code.include
13+
14+
test.include=knit.test.include

knit/resources/knit.test.include

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
// This file was automatically generated from ${file.name} by Knit tool. Do not edit.
6+
package ${test.package}
7+
8+
import org.junit.Test
9+
10+
class ${test.name} {

0 commit comments

Comments
 (0)