-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RESTdocs build when using Gradle with the Kotlin DSL
Closes gh-581
- Loading branch information
1 parent
fd6e0d4
commit f9aa3d4
Showing
7 changed files
with
181 additions
and
21 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...site/extension/dependency/springrestdocs/AbstractSpringRestDocsGradleBuildCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springrestdocs; | ||
|
||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; | ||
import io.spring.initializr.generator.spring.build.BuildCustomizer; | ||
|
||
/** | ||
* Abstract {@link BuildCustomizer Customizer} for a {@link GradleBuild} when the | ||
* generated project * depends on Spring REST Docs. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
abstract class AbstractSpringRestDocsGradleBuildCustomizer implements BuildCustomizer<GradleBuild> { | ||
|
||
@Override | ||
public void customize(GradleBuild build) { | ||
build.plugins().add("org.asciidoctor.jvm.convert", (plugin) -> plugin.setVersion("3.3.2")); | ||
build.properties().property("snippetsDir", "file(\"build/generated-snippets\")"); | ||
customizeForDialect(build); | ||
} | ||
|
||
abstract void customizeForDialect(GradleBuild build); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...t/site/extension/dependency/springrestdocs/SpringRestDocsGradleKotlinBuildCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springrestdocs; | ||
|
||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; | ||
import io.spring.initializr.generator.spring.build.BuildCustomizer; | ||
|
||
/** | ||
* {@link BuildCustomizer Customizer} for a Kotlin {@link GradleBuild} when the generated | ||
* project depends on Spring REST Docs. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class SpringRestDocsGradleKotlinBuildCustomizer extends AbstractSpringRestDocsGradleBuildCustomizer { | ||
|
||
@Override | ||
void customizeForDialect(GradleBuild build) { | ||
build.tasks().customize("test", (task) -> task.invoke("outputs.dir", "project.extra[\"snippetsDir\"]!!")); | ||
build.tasks().customize("asciidoctor", (task) -> { | ||
task.invoke("inputs.dir", "project.extra[\"snippetsDir\"]!!"); | ||
task.invoke("dependsOn", "tasks.test"); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...e/extension/dependency/springrestdocs/SpringRestDocsGradleKotlinBuildCustomizerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2012-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springrestdocs; | ||
|
||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; | ||
import io.spring.initializr.generator.buildsystem.gradle.GradleTask; | ||
import io.spring.initializr.generator.buildsystem.gradle.GradleTask.Invocation; | ||
import io.spring.initializr.generator.buildsystem.gradle.StandardGradlePlugin; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.entry; | ||
|
||
/** | ||
* Tests for {@link SpringRestDocsGradleKotlinBuildCustomizer}. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class SpringRestDocsGradleKotlinBuildCustomizerTests { | ||
|
||
private final SpringRestDocsGradleKotlinBuildCustomizer customizer = new SpringRestDocsGradleKotlinBuildCustomizer(); | ||
|
||
@Test | ||
void customizesGradleBuild() { | ||
GradleBuild build = new GradleBuild(); | ||
this.customizer.customize(build); | ||
assertThat(build.plugins().values()).singleElement().satisfies((plugin) -> { | ||
assertThat(plugin.getId()).isEqualTo("org.asciidoctor.jvm.convert"); | ||
assertThat(((StandardGradlePlugin) plugin).getVersion()).isEqualTo("3.3.2"); | ||
}); | ||
assertThat(build.properties().values()).contains(entry("snippetsDir", "file(\"build/generated-snippets\")")); | ||
GradleTask testTask = build.tasks().get("test"); | ||
assertThat(testTask).isNotNull(); | ||
assertThat(testTask.getInvocations()).hasSize(1); | ||
Invocation invocation = testTask.getInvocations().get(0); | ||
assertThat(invocation.getTarget()).isEqualTo("outputs.dir"); | ||
assertThat(invocation.getArguments()).containsExactly("project.extra[\"snippetsDir\"]!!"); | ||
GradleTask asciidoctorTask = build.tasks().get("asciidoctor"); | ||
assertThat(asciidoctorTask).isNotNull(); | ||
assertThat(asciidoctorTask.getInvocations()).hasSize(2); | ||
Invocation inputsDir = asciidoctorTask.getInvocations().get(0); | ||
assertThat(inputsDir.getTarget()).isEqualTo("inputs.dir"); | ||
assertThat(inputsDir.getArguments()).containsExactly("project.extra[\"snippetsDir\"]!!"); | ||
Invocation dependsOn = asciidoctorTask.getInvocations().get(1); | ||
assertThat(dependsOn.getTarget()).isEqualTo("dependsOn"); | ||
assertThat(dependsOn.getArguments()).containsExactly("tasks.test"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters