From 02894f7756545218a97477309b80edac6ba158e2 Mon Sep 17 00:00:00 2001 From: "iacopo.pace" Date: Thu, 11 Mar 2021 20:36:44 -0800 Subject: [PATCH] Complete support for scala 2.8.x, adding tests and plugin support for java-forms. Forked from branch "gabizou:play-2.8" following PR "gradle/playframework#154" Signed-off-by: iacopo.pace --- .../plugins/PlayApplicationPlugin.java | 1 + .../internal/twirl/PlayTwirlAdapterV28X.java | 50 +++++++++++++++++++ .../internal/twirl/TwirlCompilerFactory.java | 4 +- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/gradle/playframework/tools/internal/twirl/PlayTwirlAdapterV28X.java diff --git a/src/main/java/org/gradle/playframework/plugins/PlayApplicationPlugin.java b/src/main/java/org/gradle/playframework/plugins/PlayApplicationPlugin.java index 06850f67..5c24dc80 100644 --- a/src/main/java/org/gradle/playframework/plugins/PlayApplicationPlugin.java +++ b/src/main/java/org/gradle/playframework/plugins/PlayApplicationPlugin.java @@ -103,6 +103,7 @@ private void addAutomaticDependencies(DependencyHandler dependencies, PlayPlatfo // if the project is Java or Scala based. case PLAY_2_6_X: case PLAY_2_7_X: + case PLAY_2_8_X: dependencies.add(PLATFORM_CONFIGURATION, playPlatform.getDependencyNotation("play-java-forms").get()); } } diff --git a/src/main/java/org/gradle/playframework/tools/internal/twirl/PlayTwirlAdapterV28X.java b/src/main/java/org/gradle/playframework/tools/internal/twirl/PlayTwirlAdapterV28X.java new file mode 100644 index 00000000..3b85bb5d --- /dev/null +++ b/src/main/java/org/gradle/playframework/tools/internal/twirl/PlayTwirlAdapterV28X.java @@ -0,0 +1,50 @@ +package org.gradle.playframework.tools.internal.twirl; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.gradle.playframework.sourcesets.TwirlImports; + +class PlayTwirlAdapterV28X implements VersionedPlayTwirlAdapter { + + // Based on https://github.com/playframework/playframework/blob/2.8.x/dev-mode/build-link/src/main/java/play/TemplateImports.java + private static List defaultTemplateImports = Collections.unmodifiableList( + Arrays.asList( + "models._", + "controllers._", + "play.api.i18n._", + "play.api.templates.PlayMagic._" + )); + + private static final List DEFAULT_JAVA_IMPORTS; + private static final List DEFAULT_SCALA_IMPORTS; + static { + List minimalJavaImports = new ArrayList(); + minimalJavaImports.addAll(defaultTemplateImports); + minimalJavaImports.add("java.lang._"); + minimalJavaImports.add("java.util._"); + minimalJavaImports.add("play.core.j.PlayMagicForJava._"); + minimalJavaImports.add("play.mvc._"); + minimalJavaImports.add("play.api.data.Field"); + + List defaultJavaImports = new ArrayList(); + defaultJavaImports.addAll(minimalJavaImports); + defaultJavaImports.add("play.data._"); + defaultJavaImports.add("play.core.j.PlayFormsMagicForJava._"); + DEFAULT_JAVA_IMPORTS = Collections.unmodifiableList(defaultJavaImports); + + List scalaImports = new ArrayList(); + scalaImports.addAll(defaultTemplateImports); + scalaImports.add("play.api.mvc._"); + scalaImports.add("play.api.data._"); + DEFAULT_SCALA_IMPORTS = Collections.unmodifiableList(scalaImports); + } + + @Override + public List getDefaultImports(TwirlImports language) { + return language == TwirlImports.JAVA ? DEFAULT_JAVA_IMPORTS : DEFAULT_SCALA_IMPORTS; + } +} + diff --git a/src/main/java/org/gradle/playframework/tools/internal/twirl/TwirlCompilerFactory.java b/src/main/java/org/gradle/playframework/tools/internal/twirl/TwirlCompilerFactory.java index 26e99b2f..a8ef5152 100644 --- a/src/main/java/org/gradle/playframework/tools/internal/twirl/TwirlCompilerFactory.java +++ b/src/main/java/org/gradle/playframework/tools/internal/twirl/TwirlCompilerFactory.java @@ -34,8 +34,10 @@ public static VersionedPlayTwirlAdapter createPlayTwirlAdapter(PlayPlatform play return new PlayTwirlAdapterV23X(); case PLAY_2_6_X: case PLAY_2_7_X: - default: return new PlayTwirlAdapterV26X(); + case PLAY_2_8_X: + default: + return new PlayTwirlAdapterV28X(); } }