-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gradle] Support incremental compilation
- Loading branch information
Showing
7 changed files
with
215 additions
and
93 deletions.
There are no files selected for viewing
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
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
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
128 changes: 128 additions & 0 deletions
128
gradle-twirl/src/test/java/play/twirl/gradle/SimpleProjectTest.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,128 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
package play.twirl.gradle; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.groovy.util.Maps; | ||
import org.gradle.testkit.runner.BuildResult; | ||
import org.gradle.testkit.runner.BuildTask; | ||
import org.gradle.testkit.runner.TaskOutcome; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
/** A simple functional test to check a Twirl Gradle Plugin. */ | ||
@DisplayName("Simple Gradle project with Twirl HTML template") | ||
public class SimpleProjectTest extends AbstractFunctionalTest { | ||
|
||
@Override | ||
protected File getProjectSourceDir() { | ||
return new File("src/test/resources/simple"); | ||
} | ||
|
||
@Override | ||
protected String getBuildFileContent() { | ||
Map<String, Object> params = | ||
Maps.of( | ||
"scalaVersion", getScalaVersion(), | ||
"twirlVersion", getTwirlVersion()); | ||
return templateProcess("build.gradle.kts.ftlh", params); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("gradleVersions") | ||
@DisplayName("Test common build") | ||
void testCommonBuild(String gradleVersion) throws IOException { | ||
File simpleSources = projectPath("src").toFile(); | ||
FileUtils.copyDirectory(projectSourcePath("src").toFile(), simpleSources); | ||
|
||
BuildResult result = build(gradleVersion, "build"); | ||
|
||
BuildTask compileTwirlResult = result.task(":compileTwirl"); | ||
assertThat(compileTwirlResult).isNotNull(); | ||
assertThat(compileTwirlResult.getOutcome()).isEqualTo(TaskOutcome.SUCCESS); | ||
assertThat(projectBuildPath("generated/sources/twirl/main/a/b/html/c.template.scala")) | ||
.isNotEmptyFile() | ||
.binaryContent() | ||
.asString() | ||
.contains("import java.lang._", "class c @java.lang.Deprecated()"); | ||
|
||
BuildTask compileScalaResult = result.task(":compileScala"); | ||
assertThat(compileScalaResult).isNotNull(); | ||
assertThat(compileScalaResult.getOutcome()).isEqualTo(TaskOutcome.SUCCESS); | ||
assertThat(projectBuildPath("classes/scala/main/a/b/html/c.class")).isNotEmptyFile(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("gradleVersions") | ||
@DisplayName("Test UP-TO-DATE behavior for build without changes in templates") | ||
void testUpToDateBuild(String gradleVersion) throws IOException { | ||
File simpleSources = projectPath("src").toFile(); | ||
FileUtils.copyDirectory(projectSourcePath("src").toFile(), simpleSources); | ||
|
||
build(gradleVersion, "build"); | ||
|
||
BuildResult result = build(gradleVersion, "build"); | ||
|
||
BuildTask compileTwirlResult = result.task(":compileTwirl"); | ||
assertThat(compileTwirlResult).isNotNull(); | ||
assertThat(compileTwirlResult.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE); | ||
|
||
BuildTask compileScalaResult = result.task(":compileScala"); | ||
assertThat(compileScalaResult).isNotNull(); | ||
assertThat(compileScalaResult.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("gradleVersions") | ||
@DisplayName("Test incremental compilation after add and delete template") | ||
void testIncrementalBuild(String gradleVersion) throws IOException { | ||
File simpleSources = projectPath("src").toFile(); | ||
FileUtils.copyDirectory(projectSourcePath("src").toFile(), simpleSources); | ||
|
||
build(gradleVersion, "build"); | ||
|
||
// Add new Twirl template | ||
Path newTemplate = projectPath("src/main/twirl/a/b/d.scala.html"); | ||
Files.copy(projectSourcePath("src/main/twirl/a/b/c.scala.html"), newTemplate); | ||
|
||
BuildResult result = build(gradleVersion, "build"); | ||
|
||
BuildTask compileTwirlResult = result.task(":compileTwirl"); | ||
assertThat(compileTwirlResult).isNotNull(); | ||
assertThat(compileTwirlResult.getOutcome()).isEqualTo(TaskOutcome.SUCCESS); | ||
|
||
assertThat(projectBuildPath("generated/sources/twirl/main/a/b/html/d.template.scala")) | ||
.isNotEmptyFile(); | ||
|
||
BuildTask compileScalaResult = result.task(":compileScala"); | ||
assertThat(compileScalaResult).isNotNull(); | ||
assertThat(compileScalaResult.getOutcome()).isEqualTo(TaskOutcome.SUCCESS); | ||
assertThat(projectBuildPath("classes/scala/main/a/b/html/d.class")).isNotEmptyFile(); | ||
|
||
// Delete twirl template | ||
Files.delete(newTemplate); | ||
|
||
result = build(gradleVersion, "build"); | ||
|
||
compileTwirlResult = result.task(":compileTwirl"); | ||
assertThat(compileTwirlResult).isNotNull(); | ||
assertThat(compileTwirlResult.getOutcome()).isEqualTo(TaskOutcome.SUCCESS); | ||
|
||
assertThat(projectBuildPath("generated/sources/twirl/main/a/b/html/d.template.scala")) | ||
.doesNotExist(); | ||
|
||
compileScalaResult = result.task(":compileScala"); | ||
assertThat(compileScalaResult).isNotNull(); | ||
assertThat(compileScalaResult.getOutcome()).isEqualTo(TaskOutcome.SUCCESS); | ||
assertThat(projectBuildPath("classes/scala/main/a/b/html/d.class")).doesNotExist(); | ||
} | ||
} |
Oops, something went wrong.