Skip to content

Commit 973517c

Browse files
committed
Merge branch 'MartinAhrer-fix/afterEvaluate'
2 parents 1792fd7 + a2281b0 commit 973517c

File tree

4 files changed

+87
-79
lines changed

4 files changed

+87
-79
lines changed

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ plugins {
22
`java-gradle-plugin`
33
id("com.gradle.plugin-publish") version "0.14.0"
44
id("org.sonarqube") version "3.1.1"
5-
kotlin("jvm") version "1.4.31"
5+
kotlin("jvm") version "1.8.21"
66
`maven-publish`
77
id("com.github.ben-manes.versions") version "0.38.0"
88
id("io.gitlab.arturbosch.detekt") version "1.16.0"
99
}
1010

1111
group = "org.springdoc"
12-
version = "1.6.0"
12+
version = "1.7.0"
1313

1414
sonarqube {
1515
properties {
@@ -46,7 +46,7 @@ publishing {
4646

4747
dependencies {
4848
implementation(kotlin("reflect"))
49-
implementation("com.google.code.gson:gson:2.8.6")
49+
implementation("com.google.code.gson:gson:2.8.9")
5050
implementation("org.awaitility:awaitility-kotlin:4.0.3")
5151
implementation("com.github.psxpaul:gradle-execfork-plugin:0.2.0")
5252
implementation("org.springframework.boot:spring-boot-gradle-plugin:2.5.6")
@@ -55,7 +55,7 @@ dependencies {
5555
testImplementation(platform("org.junit:junit-bom:5.7.1"))
5656
testImplementation("org.junit.jupiter:junit-jupiter")
5757
testImplementation("com.beust:klaxon:5.5")
58-
testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.2")
58+
testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")
5959
testImplementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2")
6060

6161
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.16.0")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGeneratorTask.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import java.net.HttpURLConnection
1919
import java.net.URL
2020
import java.time.Duration
2121
import java.time.temporal.ChronoUnit.SECONDS
22+
import java.util.*
2223

2324
private const val MAX_HTTP_STATUS_CODE = 299
2425

@@ -65,7 +66,7 @@ open class OpenApiGeneratorTask : DefaultTask() {
6566

6667
private fun generateApiDocs(url: String, fileName: String) {
6768
try {
68-
val isYaml = url.toLowerCase().matches(Regex(".+[./]yaml(/.+)*"))
69+
val isYaml = url.lowercase(Locale.getDefault()).matches(Regex(".+[./]yaml(/.+)*"))
6970
await ignoreException ConnectException::class withPollInterval Durations.ONE_SECOND atMost Duration.of(
7071
waitTimeInSeconds.get().toLong(),
7172
SECONDS

src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePlugin.kt

Lines changed: 80 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,94 +4,101 @@ import com.github.psxpaul.task.JavaExecFork
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
66
import org.gradle.api.Task
7-
import org.gradle.api.logging.Logging
7+
import org.gradle.api.UnknownDomainObjectException
88
import org.gradle.api.tasks.TaskProvider
99
import org.gradle.internal.jvm.Jvm
1010
import org.springframework.boot.gradle.tasks.run.BootRun
1111

1212
open class OpenApiGradlePlugin : Plugin<Project> {
13-
private val logger = Logging.getLogger(OpenApiGradlePlugin::class.java)
1413

15-
override fun apply(project: Project) {
16-
with(project) {
17-
// Run time dependency on the following plugins
18-
plugins.apply(SPRING_BOOT_PLUGIN)
19-
plugins.apply(EXEC_FORK_PLUGIN)
14+
override fun apply(project: Project) {
15+
with(project) {
16+
// Run time dependency on the following plugins
17+
plugins.apply(SPRING_BOOT_PLUGIN)
18+
plugins.apply(EXEC_FORK_PLUGIN)
2019

21-
extensions.create(EXTENSION_NAME, OpenApiExtension::class.java)
22-
tasks.register(FORKED_SPRING_BOOT_RUN_TASK_NAME, JavaExecFork::class.java)
23-
tasks.register(OPEN_API_TASK_NAME, OpenApiGeneratorTask::class.java)
20+
extensions.create(EXTENSION_NAME, OpenApiExtension::class.java)
21+
tasks.register(FORKED_SPRING_BOOT_RUN_TASK_NAME, JavaExecFork::class.java)
22+
tasks.register(OPEN_API_TASK_NAME, OpenApiGeneratorTask::class.java)
2423

25-
afterEvaluate { generate(this) }
26-
}
27-
}
24+
generate(this)
25+
}
26+
}
2827

29-
private fun generate(project: Project) = project.run {
30-
springBoot3CompatibilityCheck()
28+
private fun generate(project: Project) = project.run {
29+
springBoot3CompatibilityCheck()
3130

32-
// The task, used to run the Spring Boot application (`bootRun`)
33-
val bootRunTask = tasks.named(SPRING_BOOT_RUN_TASK_NAME)
34-
// The task, used to resolve the application's main class (`bootRunMainClassName`)
35-
val bootRunMainClassNameTask = tasks.find { it.name == SPRING_BOOT_RUN_MAIN_CLASS_NAME_TASK_NAME }
36-
?: tasks.named(SPRING_BOOT_3_RUN_MAIN_CLASS_NAME_TASK_NAME)
31+
// The task, used to run the Spring Boot application (`bootRun`)
32+
val bootRunTask = tasks.named(SPRING_BOOT_RUN_TASK_NAME)
33+
// The task, used to resolve the application's main class (`bootRunMainClassName`)
34+
val bootRunMainClassNameTask =
35+
try {
36+
val task=tasks.named(SPRING_BOOT_RUN_MAIN_CLASS_NAME_TASK_NAME)
37+
logger.debug("Detected Spring Boot task {}", SPRING_BOOT_RUN_MAIN_CLASS_NAME_TASK_NAME)
38+
task
39+
} catch (e: UnknownDomainObjectException) {
40+
val task=tasks.named(SPRING_BOOT_3_RUN_MAIN_CLASS_NAME_TASK_NAME)
41+
logger.debug("Detected Spring Boot task {}", SPRING_BOOT_3_RUN_MAIN_CLASS_NAME_TASK_NAME)
42+
task
43+
}
3744

38-
val extension = extensions.findByName(EXTENSION_NAME) as OpenApiExtension
39-
val customBootRun = extension.customBootRun
40-
// Create a forked version spring boot run task
41-
val forkedSpringBoot = tasks.named(FORKED_SPRING_BOOT_RUN_TASK_NAME, JavaExecFork::class.java) { fork ->
42-
fork.dependsOn(bootRunMainClassNameTask)
43-
fork.onlyIf { needToFork(bootRunTask, customBootRun, fork) }
44-
}
45+
val extension = extensions.findByName(EXTENSION_NAME) as OpenApiExtension
46+
val customBootRun = extension.customBootRun
47+
// Create a forked version spring boot run task
48+
val forkedSpringBoot = tasks.named(FORKED_SPRING_BOOT_RUN_TASK_NAME, JavaExecFork::class.java) { fork ->
49+
fork.dependsOn(tasks.named(bootRunMainClassNameTask.name))
50+
fork.onlyIf { needToFork(bootRunTask, customBootRun, fork) }
51+
}
4552

46-
// This is my task. Before I can run it, I have to run the dependent tasks
47-
val openApiTask = tasks.named(OPEN_API_TASK_NAME, OpenApiGeneratorTask::class.java) {
48-
it.dependsOn(forkedSpringBoot)
49-
}
53+
// This is my task. Before I can run it, I have to run the dependent tasks
54+
val openApiTask = tasks.named(OPEN_API_TASK_NAME, OpenApiGeneratorTask::class.java) {
55+
it.dependsOn(forkedSpringBoot)
56+
}
5057

51-
// The forked task need to be terminated as soon as my task is finished
52-
forkedSpringBoot.get().stopAfter = openApiTask as TaskProvider<Task>
53-
}
58+
// The forked task need to be terminated as soon as my task is finished
59+
forkedSpringBoot.get().stopAfter = openApiTask as TaskProvider<Task>
60+
}
5461

55-
private fun Project.springBoot3CompatibilityCheck() {
56-
val tasksNames = tasks.names
57-
val boot2TaskName = "bootRunMainClassName"
58-
val boot3TaskName = "resolveMainClassName"
59-
if (!tasksNames.contains(boot2TaskName) && tasksNames.contains(boot3TaskName))
60-
tasks.register(boot2TaskName) { it.dependsOn(tasks.named(boot3TaskName)) }
61-
}
62+
private fun Project.springBoot3CompatibilityCheck() {
63+
val tasksNames = tasks.names
64+
val boot2TaskName = "bootRunMainClassName"
65+
val boot3TaskName = "resolveMainClassName"
66+
if (!tasksNames.contains(boot2TaskName) && tasksNames.contains(boot3TaskName))
67+
tasks.register(boot2TaskName) { it.dependsOn(tasks.named(boot3TaskName)) }
68+
}
6269

63-
private fun needToFork(
64-
bootRunTask: TaskProvider<Task>,
65-
customBootRun: CustomBootRunAction,
66-
fork: JavaExecFork
67-
): Boolean {
68-
val bootRun = bootRunTask.get() as BootRun
70+
private fun needToFork(
71+
bootRunTask: TaskProvider<Task>,
72+
customBootRun: CustomBootRunAction,
73+
fork: JavaExecFork
74+
): Boolean {
75+
val bootRun = bootRunTask.get() as BootRun
6976

70-
val baseSystemProperties = customBootRun.systemProperties.orNull?.takeIf { it.isNotEmpty() }
71-
?: bootRun.systemProperties
72-
with(fork) {
73-
// copy all system properties, excluding those starting with `java.class.path`
74-
systemProperties = baseSystemProperties.filter {
75-
!it.key.startsWith(CLASS_PATH_PROPERTY_NAME)
76-
}
77+
val baseSystemProperties = customBootRun.systemProperties.orNull?.takeIf { it.isNotEmpty() }
78+
?: bootRun.systemProperties
79+
with(fork) {
80+
// copy all system properties, excluding those starting with `java.class.path`
81+
systemProperties = baseSystemProperties.filter {
82+
!it.key.startsWith(CLASS_PATH_PROPERTY_NAME)
83+
}
7784

78-
// use original bootRun parameter if the list-type customBootRun properties are empty
79-
workingDir = customBootRun.workingDir.asFile.orNull
80-
?: fork.temporaryDir
81-
args = customBootRun.args.orNull?.takeIf { it.isNotEmpty() }?.toMutableList()
82-
?: bootRun.args?.toMutableList() ?: mutableListOf()
83-
classpath = customBootRun.classpath.takeIf { !it.isEmpty }
84-
?: bootRun.classpath
85-
main = customBootRun.mainClass.orNull
86-
?: bootRun.mainClass.get()
87-
jvmArgs = customBootRun.jvmArgs.orNull?.takeIf { it.isNotEmpty() }
88-
?: bootRun.jvmArgs
89-
environment = customBootRun.environment.orNull?.takeIf { it.isNotEmpty() }
90-
?: bootRun.environment
91-
if (Jvm.current().toString().startsWith("1.8")) {
92-
killDescendants = false
93-
}
94-
}
95-
return true
96-
}
85+
// use original bootRun parameter if the list-type customBootRun properties are empty
86+
workingDir = customBootRun.workingDir.asFile.orNull
87+
?: fork.temporaryDir
88+
args = customBootRun.args.orNull?.takeIf { it.isNotEmpty() }?.toMutableList()
89+
?: bootRun.args?.toMutableList() ?: mutableListOf()
90+
classpath = customBootRun.classpath.takeIf { !it.isEmpty }
91+
?: bootRun.classpath
92+
main = customBootRun.mainClass.orNull
93+
?: bootRun.mainClass.get()
94+
jvmArgs = customBootRun.jvmArgs.orNull?.takeIf { it.isNotEmpty() }
95+
?: bootRun.jvmArgs
96+
environment = customBootRun.environment.orNull?.takeIf { it.isNotEmpty() }
97+
?: bootRun.environment
98+
if (Jvm.current().toString().startsWith("1.8")) {
99+
killDescendants = false
100+
}
101+
}
102+
return true
103+
}
97104
}

0 commit comments

Comments
 (0)