Skip to content

Commit cb411c7

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 6810745 commit cb411c7

File tree

134 files changed

+589
-500
lines changed

Some content is hidden

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

134 files changed

+589
-500
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

@@ -142,7 +126,7 @@ fun main() = runBlocking<Unit> { // start main coroutine
142126

143127
</div>
144128

145-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-02b.kt).
129+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt).
146130
147131
<!--- TEST
148132
Hello,
@@ -197,7 +181,7 @@ fun main() = runBlocking {
197181

198182
</div>
199183

200-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03.kt).
184+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt).
201185
202186
<!--- TEST
203187
Hello,
@@ -242,7 +226,7 @@ fun main() = runBlocking { // this: CoroutineScope
242226

243227
</div>
244228

245-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-03s.kt).
229+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt).
246230
247231
<!--- TEST
248232
Hello,
@@ -288,7 +272,7 @@ fun main() = runBlocking { // this: CoroutineScope
288272

289273
</div>
290274

291-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-04.kt).
275+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt).
292276
293277
<!--- TEST
294278
Task from coroutine scope
@@ -327,7 +311,7 @@ suspend fun doWorld() {
327311

328312
</div>
329313

330-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-05.kt).
314+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt).
331315
332316
<!--- TEST
333317
Hello,
@@ -364,7 +348,7 @@ fun main() = runBlocking {
364348

365349
</div>
366350

367-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-06.kt).
351+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-08.kt).
368352
369353
<!--- TEST lines.size == 1 && lines[0] == ".".repeat(100_000) -->
370354

@@ -396,7 +380,7 @@ fun main() = runBlocking {
396380

397381
</div>
398382

399-
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-07.kt).
383+
> You can get full code [here](../kotlinx-coroutines-core/jvm/test/guide/example-basic-09.kt).
400384
401385
You can run and see that it prints three lines and terminates:
402386

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 -->
@@ -260,7 +245,6 @@ to leak to its exception handler.
260245

261246

262247
<!--- INCLUDE
263-
264248
import kotlinx.coroutines.exceptions.*
265249
-->
266250

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)