Skip to content

Commit 56e56c4

Browse files
committed
Gradle plugin: improve test coverage
1 parent 520a7d7 commit 56e56c4

10 files changed

Lines changed: 221 additions & 1 deletion

File tree

‎dev-mode/gradle-plugin/src/test/java/play/gradle/PlayRunPluginTest.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,35 @@ private SettingsState mockSettings() {
5050
return settings;
5151
}
5252

53+
@Test
54+
@DisplayName("Check assets directories with submodules")
55+
void checkAssetsDirectoriesWithSubmodules() {
56+
Project playLib = ProjectBuilder.builder().withParent(project).withName("play-lib").build();
57+
playLib.getPluginManager().apply("org.playframework.play");
58+
59+
Project javaLib = ProjectBuilder.builder().withParent(project).withName("java-lib").build();
60+
javaLib.getPluginManager().apply("java");
61+
62+
project.getRepositories().add(project.getRepositories().mavenCentral());
63+
project.getDependencies().add("implementation", playLib);
64+
project.getDependencies().add("implementation", javaLib);
65+
66+
((DefaultProject) playLib).evaluate();
67+
((DefaultProject) javaLib).evaluate();
68+
((DefaultProject) project).evaluate();
69+
70+
assertThat(((PlayRun) project.getTasks().findByName("playRun")).getAssetsDirs())
71+
.contains(
72+
project.getLayout().getBuildDirectory().file("web/public/main").get().getAsFile(),
73+
project.getLayout().getBuildDirectory().file("web/assets/main").get().getAsFile(),
74+
playLib.getLayout().getBuildDirectory().file("web/public/main").get().getAsFile(),
75+
playLib.getLayout().getBuildDirectory().file("web/assets/main").get().getAsFile())
76+
.doesNotContain(
77+
javaLib.getLayout().getBuildDirectory().file("web/public/main").get().getAsFile(),
78+
javaLib.file("src/main/java"),
79+
javaLib.file("src/main/resources"));
80+
}
81+
5382
@Test
5483
@DisplayName("Check classpath with submodules")
5584
void checkClasspathWithSubmodules() {

‎dev-mode/gradle-plugin/src/test/java/play/gradle/functional/AbstractFunctionalTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static Stream<String> gradleVersions() {
108108
return Stream.of(latest);
109109
}
110110
if (JavaVersion.current().compareTo(JavaVersion.VERSION_17) >= 0) { // Gradle 7.3+
111-
return Stream.of("7.6.2", "8.0.2", latest);
111+
return Stream.of("7.3.3", "7.6.2", "8.0.2", latest);
112112
}
113113
// https://docs.gradle.org/current/userguide/scala_plugin.html#sec:configure_zinc_compiler
114114
if (getScalaVersion().equals("3")) { // Gradle 7.5+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
3+
*/
4+
package play.gradle.functional;
5+
6+
import static java.nio.charset.StandardCharsets.UTF_8;
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
13+
import java.util.List;
14+
import java.util.Map;
15+
import org.apache.commons.io.file.PathUtils;
16+
import org.gradle.testkit.runner.BuildResult;
17+
import org.gradle.testkit.runner.TaskOutcome;
18+
import org.junit.jupiter.api.DisplayName;
19+
import org.junit.jupiter.params.ParameterizedTest;
20+
import org.junit.jupiter.params.provider.MethodSource;
21+
22+
@DisplayName("Check project `routes-compiler-aggregate-reverse-routes`")
23+
public class RoutesCompilerAggregateReverseRoutesTest extends AbstractFunctionalTest {
24+
25+
private static final List<String> PLAY_PROJECTS = List.of("common", "a", "b", "c");
26+
27+
@Override
28+
protected Path getProjectSourcePath() {
29+
return Paths.get(
30+
"../sbt-plugin/src/sbt-test/play-sbt-plugin/routes-compiler-aggregate-reverse-routes");
31+
}
32+
33+
@Override
34+
protected String getBuildFileContent() {
35+
return templateProcess("build.gradle.kts.ftlh", Map.of());
36+
}
37+
38+
@Override
39+
protected String getSettingsFileContent() {
40+
return templateProcess("settings.gradle.kts.ftlh", Map.of());
41+
}
42+
43+
@Override
44+
protected void prepareProject() throws IOException {
45+
super.prepareProject();
46+
PathUtils.copyDirectory(projectSourcePath("conf"), projectPath("conf"));
47+
for (String project : List.of("common", "a", "b", "c", "nonplay")) {
48+
Files.createDirectories(projectPath(project));
49+
PathUtils.writeString(
50+
projectPath(project + "/build.gradle.kts"),
51+
templateProcess(project + "/build.gradle.kts.ftlh", Map.of()),
52+
UTF_8);
53+
}
54+
for (String project : List.of("a", "b", "c")) {
55+
PathUtils.copyDirectory(projectSourcePath(project + "/conf"), projectPath(project + "/conf"));
56+
}
57+
}
58+
59+
private Path generated(String project, String path) {
60+
String prefix = project.isEmpty() ? "" : project + "/";
61+
return projectPath(prefix + "build/" + ROUTES_GEN_PATH + path);
62+
}
63+
64+
@ParameterizedTest
65+
@MethodSource("gradleVersions")
66+
@DisplayName("Reverse routes are aggregated into a single project")
67+
void testAggregateReverseRoutes(String gradleVersion) {
68+
BuildResult result = build(gradleVersion, "compilePlayRoutes");
69+
70+
for (String project : PLAY_PROJECTS) {
71+
var compileRoutes = result.task(":" + project + ":compilePlayRoutes");
72+
assertThat(compileRoutes).isNotNull();
73+
assertThat(compileRoutes.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
74+
}
75+
76+
// The aggregating project generates the reverse routers of the projects it aggregates
77+
for (String project : List.of("a", "b", "c")) {
78+
assertThat(generated("common", "controllers/" + project + "/ReverseRoutes.scala"))
79+
.isNotEmptyFile();
80+
assertThat(generated("common", "controllers/" + project + "/routes.java")).isNotEmptyFile();
81+
assertThat(
82+
generated(
83+
"common", "controllers/" + project + "/javascript/JavaScriptReverseRoutes.scala"))
84+
.isNotEmptyFile();
85+
}
86+
87+
// The aggregated projects generate their forwards router only
88+
for (String project : List.of("a", "b", "c")) {
89+
assertThat(generated(project, project + "/Routes.scala")).isNotEmptyFile();
90+
assertThat(generated(project, "controllers/" + project + "/ReverseRoutes.scala"))
91+
.doesNotExist();
92+
assertThat(generated(project, "controllers/" + project + "/routes.java")).doesNotExist();
93+
}
94+
95+
assertThat(generated("", "router/Routes.scala")).isNotEmptyFile();
96+
}
97+
98+
@ParameterizedTest
99+
@MethodSource("gradleVersions")
100+
@DisplayName("Aggregation after add and delete routes of an aggregated project")
101+
void testIncrementalAggregation(String gradleVersion) throws IOException {
102+
Path routes = projectPath("a/conf/a.routes");
103+
Path aggregated = generated("common", "controllers/a/ReverseRoutes.scala");
104+
105+
build(gradleVersion, "compilePlayRoutes");
106+
assertThat(aggregated).isNotEmptyFile();
107+
108+
Files.delete(routes);
109+
110+
build(gradleVersion, "compilePlayRoutes");
111+
assertThat(aggregated).doesNotExist();
112+
assertThat(generated("common", "controllers/b/ReverseRoutes.scala")).isNotEmptyFile();
113+
114+
Files.copy(projectSourcePath("a/conf/a.routes"), routes);
115+
116+
build(gradleVersion, "compilePlayRoutes");
117+
assertThat(aggregated).isNotEmptyFile();
118+
}
119+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id("org.playframework.play")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
mavenLocal()
8+
}
9+
10+
dependencies {
11+
implementation(project(":nonplay"))
12+
implementation(project(":common"))
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
id("org.playframework.play")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
mavenLocal()
8+
}
9+
10+
dependencies {
11+
implementation(project(":common"))
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id("org.playframework.play")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
mavenLocal()
8+
}
9+
10+
dependencies {
11+
implementation(project(":a"))
12+
implementation(project(":c"))
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
id("org.playframework.play")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
mavenLocal()
8+
}
9+
10+
dependencies {
11+
implementation(project(":b"))
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id("org.playframework.play")
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
mavenLocal()
8+
}
9+
10+
play {
11+
routes {
12+
aggregateReverseRoutes.set(listOf(project(":a"), project(":b"), project(":c")))
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
java
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include("common", "a", "b", "c", "nonplay")

0 commit comments

Comments
 (0)