Generate console output examples at build time
Closes gh-28208
This commit is contained in:
@@ -14,6 +14,8 @@ configurations {
|
||||
configurationProperties
|
||||
gradlePluginDocumentation
|
||||
mavenPluginDocumentation
|
||||
remoteSpringApplicationExample
|
||||
springApplicationExample
|
||||
testSlices
|
||||
}
|
||||
|
||||
@@ -161,6 +163,14 @@ dependencies {
|
||||
|
||||
mavenPluginDocumentation(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin", configuration: "documentation"))
|
||||
|
||||
remoteSpringApplicationExample(platform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||
remoteSpringApplicationExample(project(":spring-boot-project:spring-boot-devtools"))
|
||||
remoteSpringApplicationExample(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-logging"))
|
||||
remoteSpringApplicationExample("org.springframework:spring-web")
|
||||
|
||||
springApplicationExample(platform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||
springApplicationExample(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
|
||||
|
||||
testImplementation(project(":spring-boot-project:spring-boot-actuator-autoconfigure"))
|
||||
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
|
||||
testImplementation("org.assertj:assertj-core")
|
||||
@@ -249,8 +259,35 @@ task documentConfigurationProperties(type: org.springframework.boot.build.contex
|
||||
|
||||
task documentDevtoolsPropertyDefaults(type: org.springframework.boot.build.devtools.DocumentDevtoolsPropertyDefaults) {}
|
||||
|
||||
task runRemoteSpringApplicationExample(type: org.springframework.boot.build.docs.ApplicationRunner) {
|
||||
classpath = configurations.remoteSpringApplicationExample
|
||||
mainClass = "org.springframework.boot.devtools.RemoteSpringApplication"
|
||||
args = ["https://myapp.example.com", "--spring.devtools.remote.secret=secret", "--spring.devtools.livereload.port=0"]
|
||||
output = file("$buildDir/example-output/remote-spring-application.txt")
|
||||
expectedLogging = "Started RemoteSpringApplication in "
|
||||
}
|
||||
|
||||
task runSpringApplicationExample(type: org.springframework.boot.build.docs.ApplicationRunner) {
|
||||
classpath = configurations.springApplicationExample + sourceSets.main.output
|
||||
mainClass = "org.springframework.boot.docs.features.springapplication.MyApplication"
|
||||
args = ["--server.port=0"]
|
||||
output = file("$buildDir/example-output/spring-application.txt")
|
||||
expectedLogging = "Started MyApplication in "
|
||||
}
|
||||
|
||||
task runLoggingFormatExample(type: org.springframework.boot.build.docs.ApplicationRunner) {
|
||||
classpath = configurations.springApplicationExample + sourceSets.main.output
|
||||
mainClass = "org.springframework.boot.docs.features.springapplication.MyApplication"
|
||||
args = ["--spring.main.banner-mode=off", "--server.port=0"]
|
||||
output = file("$buildDir/example-output/logging-format.txt")
|
||||
expectedLogging = "Started MyApplication in "
|
||||
}
|
||||
|
||||
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
|
||||
dependsOn dependencyVersions
|
||||
inputs.files(runRemoteSpringApplicationExample).withPathSensitivity(PathSensitivity.RELATIVE)
|
||||
inputs.files(runSpringApplicationExample).withPathSensitivity(PathSensitivity.RELATIVE)
|
||||
inputs.files(runLoggingFormatExample).withPathSensitivity(PathSensitivity.RELATIVE)
|
||||
asciidoctorj {
|
||||
fatalWarnings = ['^((?!successfully validated).)*$']
|
||||
}
|
||||
@@ -280,7 +317,10 @@ tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
|
||||
"spring-kafka-version": versionConstraints["org.springframework.kafka:spring-kafka"],
|
||||
"spring-integration-version": versionConstraints["org.springframework.integration:spring-integration-core"],
|
||||
"spring-security-version": securityVersion,
|
||||
"spring-webservices-version": versionConstraints["org.springframework.ws:spring-ws-core"]
|
||||
"spring-webservices-version": versionConstraints["org.springframework.ws:spring-ws-core"],
|
||||
"remote-spring-application-output": runRemoteSpringApplicationExample.outputs.files.singleFile,
|
||||
"spring-application-output": runSpringApplicationExample.outputs.files.singleFile,
|
||||
"logging-format-output": runLoggingFormatExample.outputs.files.singleFile
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,7 @@ The default log output from Spring Boot resembles the following example:
|
||||
|
||||
[indent=0]
|
||||
----
|
||||
2019-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
|
||||
2019-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
|
||||
2019-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms
|
||||
2019-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
|
||||
2019-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
|
||||
include::{logging-format-output}[]
|
||||
----
|
||||
|
||||
The following items are output:
|
||||
|
||||
@@ -12,24 +12,7 @@ When your application starts, you should see something similar to the following
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
. ____ _ __ _ _
|
||||
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
|
||||
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
|
||||
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
|
||||
' |____| .__|_| |_|_| |_\__, | / / / /
|
||||
=========|_|==============|___/=/_/_/_/
|
||||
:: Spring Boot :: v{spring-boot-version}
|
||||
|
||||
2021-02-03 10:33:25.224 INFO 17321 --- [ main] o.s.b.d.s.s.SpringApplicationExample : Starting SpringApplicationExample using Java 1.8.0_232 on mycomputer with PID 17321 (/apps/myjar.jar started by pwebb)
|
||||
2021-02-03 10:33:25.226 INFO 17900 --- [ main] o.s.b.d.s.s.SpringApplicationExample : No active profile set, falling back to default profiles: default
|
||||
2021-02-03 10:33:26.046 INFO 17321 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
|
||||
2021-02-03 10:33:26.054 INFO 17900 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
|
||||
2021-02-03 10:33:26.055 INFO 17900 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
|
||||
2021-02-03 10:33:26.097 INFO 17900 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
|
||||
2021-02-03 10:33:26.097 INFO 17900 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 821 ms
|
||||
2021-02-03 10:33:26.144 INFO 17900 --- [ main] s.tomcat.SampleTomcatApplication : ServletContext initialized
|
||||
2021-02-03 10:33:26.376 INFO 17900 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
|
||||
2021-02-03 10:33:26.384 INFO 17900 --- [ main] o.s.b.d.s.s.SpringApplicationExample : Started SampleTomcatApplication in 1.514 seconds (JVM running for 1.823)
|
||||
include::{spring-application-output}[]
|
||||
----
|
||||
|
||||
|
||||
|
||||
@@ -393,19 +393,7 @@ A running remote client might resemble the following listing:
|
||||
|
||||
[indent=0,subs="verbatim,attributes"]
|
||||
----
|
||||
. ____ _ __ _ _
|
||||
/\\ / ___'_ __ _ _(_)_ __ __ _ ___ _ \ \ \ \
|
||||
( ( )\___ | '_ | '_| | '_ \/ _` | | _ \___ _ __ ___| |_ ___ \ \ \ \
|
||||
\\/ ___)| |_)| | | | | || (_| []::::::[] / -_) ' \/ _ \ _/ -_) ) ) ) )
|
||||
' |____| .__|_| |_|_| |_\__, | |_|_\___|_|_|_\___/\__\___|/ / / /
|
||||
=========|_|==============|___/===================================/_/_/_/
|
||||
:: Spring Boot Remote :: {spring-boot-version}
|
||||
|
||||
2015-06-10 18:25:06.632 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Starting RemoteSpringApplication on pwmbp with PID 14938 (/Users/pwebb/projects/spring-boot/code/spring-boot-project/spring-boot-devtools/target/classes started by pwebb in /Users/pwebb/projects/spring-boot/code)
|
||||
2015-06-10 18:25:06.671 INFO 14938 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2a17b7b6: startup date [Wed Jun 10 18:25:06 PDT 2015]; root of context hierarchy
|
||||
2015-06-10 18:25:07.043 WARN 14938 --- [ main] o.s.b.d.r.c.RemoteClientConfiguration : The connection to http://localhost:8080 is insecure. You should use a URL starting with 'https://'.
|
||||
2015-06-10 18:25:07.074 INFO 14938 --- [ main] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
|
||||
2015-06-10 18:25:07.130 INFO 14938 --- [ main] o.s.b.devtools.RemoteSpringApplication : Started RemoteSpringApplication in 0.74 seconds (JVM running for 1.105)
|
||||
include::{remote-spring-application-output}[]
|
||||
----
|
||||
|
||||
NOTE: Because the remote client is using the same classpath as the real application it can directly read application properties.
|
||||
|
||||
Reference in New Issue
Block a user