Skip to content

Commit

Permalink
Verify Doc Code Snippets Compile
Browse files Browse the repository at this point in the history
* Verify Doc Code Snippets Compile
* Move snippets to a new (non-published) sub-project
* Suppress jar creation and publication
* Suppress Regexp checkstyle on Doc Snippets
* Add Java/Kotlin Toggle
* Compile Kotlin Snippets; Fix Checkstyle
* Fix Kotlin Syntax
* Remove runner() from Consumer app.
* Fix missing end tags.
* Topic configuration and other polishing.
* Fix Unused Import.
* Copy Code Snippets into the build dir.
* Fix spurious error messages; copy attributes to build.gradle; move asciidocs to spring-kafka-docs project.
* Fix ToC Synchronization; upgrade spring-doc-resources; add Maven/Gradle Toggle.
* Add `encoding` to `compileTestJava` to make encoding-specific tests OS-independent
* Remove redundant variables from the `index.adoc` since they are set in the plugin config in Gradle
* Fix typo for Kotlin code snippet
* Rework all the Kotlin samples to more Kotlin-idiomatic style
* Fix whitespace.

Co-authored-by: Artem Bilan <abilan@vmware.com>
  • Loading branch information
garyrussell and artembilan committed Feb 5, 2021
1 parent e718ac0 commit c75d244
Show file tree
Hide file tree
Showing 31 changed files with 1,027 additions and 321 deletions.
68 changes: 48 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ext {
linkScmUrl = 'https://github.com/spring-projects/spring-kafka'
linkScmConnection = 'https://github.com/spring-projects/spring-kafka.git'
linkScmDevConnection = 'git@github.com:spring-projects/spring-kafka.git'
docResourcesVersion = '0.2.4'
docResourcesVersion = '0.2.5'


if (gitPresent) {
Expand All @@ -65,6 +65,7 @@ ext {
mockitoVersion = '3.7.0'
reactorVersion = '2020.0.3'
scalaVersion = '2.13'
springBootVersion = '2.4.2' // docs module
springDataVersion = '2021.0.0-M2'
springRetryVersion = '1.3.0'
springVersion = '5.3.3'
Expand Down Expand Up @@ -140,6 +141,7 @@ subprojects { subproject ->

compileTestJava {
sourceCompatibility = 11
options.encoding = 'UTF-8'
}

compileTestKotlin {
Expand Down Expand Up @@ -342,6 +344,22 @@ project ('spring-kafka-test') {
}
}

project ('spring-kafka-docs') {
description = 'Spring Kafka Code Snippets For Docs'

dependencies {
api "org.springframework.boot:spring-boot-starter:$springBootVersion"
api project (':spring-kafka')
}

compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
}
}

}

sonarqube {
properties {
property 'sonar.links.homepage', linkHomepage
Expand All @@ -365,13 +383,14 @@ task prepareAsciidocBuild(type: Sync) {
from {
configurations.docs.collect { zipTree(it) }
}
from 'src/reference/asciidoc/'
from 'spring-kafka-docs/src/main/asciidoc/','spring-kafka-docs/src/main/java','spring-kafka-docs/src/main/kotlin'
into "$buildDir/asciidoc"
}

asciidoctorPdf {
dependsOn prepareAsciidocBuild
baseDirFollowsSourceFile()
configurations 'asciidoctorExt'

asciidoctorj {
sourceDir "$buildDir/asciidoc"
Expand All @@ -390,9 +409,34 @@ asciidoctorPdf {
}
}

asciidoctorj {
version = '2.4.1'
// fatalWarnings ".*"
options doctype: 'book', eruby: 'erubis'
attributes([
icons: 'font',
idprefix: '',
idseparator: '-',
docinfo: 'shared',
revnumber: project.version,
sectanchors: '',
sectnums: '',
'source-highlighter': 'highlight.js',
highlightjsdir: 'js/highlight',
'highlightjs-theme': 'googlecode',
stylesdir: 'css/',
stylesheet: 'stylesheet.css',
'spring-version': project.version,
'project-version': project.version,
'java-examples': 'org/springframework/kafka/jdocs',
'kotlin-examples': 'org/springframework/kafka/kdocs'
])
}

asciidoctor {
dependsOn asciidoctorPdf
baseDirFollowsSourceFile()
configurations 'asciidoctorExt'
sourceDir = file("$buildDir/asciidoc")
sources {
include '*.adoc'
Expand All @@ -402,25 +446,7 @@ asciidoctor {
include 'images/*', 'css/**', 'js/**'
}
}
options doctype: 'book', eruby: 'erubis'

attributes 'docinfo': 'shared',
stylesdir: "css/",
stylesheet: 'spring.css',
'linkcss': true,
'icons': 'font',
'sectanchors': '',
'source-highlighter': 'highlight.js',
'highlightjsdir': 'js/highlight',
'highlightjs-theme': 'github',
'idprefix': '',
'idseparator': '-',
'spring-version': project.version,
'allow-uri-read': '',
'toc': 'left',
'toclevbels': '4',
revnumber: project.version,
'project-version': project.version
}

task reference(dependsOn: asciidoctor) {
Expand Down Expand Up @@ -522,3 +548,5 @@ publishing {
}
}
}

apply from: "${rootDir}/gradle/docs.gradle"
16 changes: 16 additions & 0 deletions gradle/docs.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
configurations {
asciidoctorExt
}

dependencies {
asciidoctorExt("io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.5.0")
}

repositories {
maven {
url "https://repo.spring.io/release"
mavenContent {
includeGroup "io.spring.asciidoctor"
}
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ rootProject.name = 'spring-kafka-dist'

include 'spring-kafka'
include 'spring-kafka-test'
include 'spring-kafka-docs'
21 changes: 21 additions & 0 deletions spring-kafka-docs/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
jar {
enabled = false
}

sourcesJar {
enabled = false
}

javadocJar {
enabled = false
}

publishMavenJavaPublicationToMavenLocal {
enabled = false
}

project.afterEvaluate {

project.tasks.artifactoryPublish.enabled(false)

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ This is especially true when using the embedded Kafka broker in `spring-kafka-te

IMPORTANT: Backwards compatibility is not supported for all Boot versions; Spring for Apache Kafka 2.6 has been tested with Spring Boot 2.4 and 2.3.

**maven**

====
[source, xml, subs="+attributes"]
[source, xml, subs="+attributes", role="primary"]
.Maven
----
<dependency>
<groupId>org.springframework.kafka</groupId>
Expand Down Expand Up @@ -61,12 +60,9 @@ IMPORTANT: Backwards compatibility is not supported for all Boot versions; Sprin
<scope>test</scope>
</dependency>
----
====
**gradle**

====
[source, groovy, subs="+attributes"]
[source, groovy, subs="+attributes", role="secondary"]
.Gradle
----
dependencies {
Expand Down
31 changes: 31 additions & 0 deletions spring-kafka-docs/src/main/asciidoc/css/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@import 'css/spring.css';

.listingblock .switch {
border-style: none;
display: inline-block;
position: relative;
bottom: -3px;
}

.listingblock .switch--item {
padding: 10px;
background-color: #e6e1dc;
color: #282c34;
display: inline-block;
cursor: pointer;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}

.listingblock .switch--item:not(:first-child) {
border-style: none;
}

.listingblock .switch--item.selected {
background-color: #282c34;
color: #e6e1dc;
}

.listingblock pre.highlightjs {
padding: 0;
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ifdef::backend-html5[]
*{project-version}*
endif::[]

(C) 2016 - 2020 by Pivotal Software, Inc.
(C) 2016 - 2021 VMware, Inc.

Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,70 +77,31 @@ Version 2.3 introduced a new class `TopicBuilder` to make creation of such beans
The following example shows how to do so:

====
[source, java]
[source, java, indent=0, role="primary"]
.Java
----
@Bean
public KafkaAdmin admin() {
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, ...);
return new KafkaAdmin(configs);
}
@Bean
public NewTopic topic1() {
return TopicBuilder.name("thing1")
.partitions(10)
.replicas(3)
.compact()
.build();
}
@Bean
public NewTopic topic2() {
return TopicBuilder.name("thing2")
.partitions(10)
.replicas(3)
.config(TopicConfig.COMPRESSION_TYPE_CONFIG, "zstd")
.build();
}
@Bean
public NewTopic topic3() {
return TopicBuilder.name("thing3")
.assignReplicas(0, Arrays.asList(0, 1))
.assignReplicas(1, Arrays.asList(1, 2))
.assignReplicas(2, Arrays.asList(2, 0))
.config(TopicConfig.COMPRESSION_TYPE_CONFIG, "zstd")
.build();
}
include::{java-examples}/topics/Config.java[tag=topicBeans]
----
[source, kotlin, indent=0, role="secondary"]
.Kotlin
----
include::{kotlin-examples}/topics/Config.kt[tag=topicBeans]
----
====

Starting with version 2.6, you can omit `.partitions()` and/or `replicas()` and the broker defaults will be applied to those properties.
The broker version must be at least 2.4.0 to support this feature - see https://cwiki.apache.org/confluence/display/KAFKA/KIP-464%3A+Defaults+for+AdminClient%23createTopic[KIP-464].

====
[source, java]
[source, java, indent=0, role="primary"]
.Java
----
@Bean
public NewTopic topic4() {
return TopicBuilder.name("defaultBoth")
.build();
}
@Bean
public NewTopic topic5() {
return TopicBuilder.name("defaultPart")
.replicas(1)
.build();
}
@Bean
public NewTopic topic6() {
return TopicBuilder.name("defaultRepl")
.partitions(3)
.build();
}
include::{java-examples}/topics/Config.java[tag=brokerProps]
----
[source, kotlin, indent=0, role="secondary"]
.Kotlin
----
include::{kotlin-examples}/topics/Config.kt[tag=brokerProps]
----
====

Expand Down
File renamed without changes.

0 comments on commit c75d244

Please sign in to comment.