Skip to content

Commit

Permalink
Merge pull request #147 from cstroe/fix-ci-build
Browse files Browse the repository at this point in the history
  • Loading branch information
JLLeitschuh committed Sep 16, 2020
2 parents 540da9d + a7f1175 commit b0b48a5
Show file tree
Hide file tree
Showing 64 changed files with 495 additions and 383 deletions.
18 changes: 14 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@ install: true
jdk:
- openjdk8

matrix:
jobs:
include:
- env: GRADLE_TASK=integrationTest
- env: GRADLE_TASK=docTest
- name: "Play 2.3.10 Integration Tests"
env: GRADLE_TASK=integrationTest PLAY_VERSION=2.3.10
- name: "Play 2.4.11 Integration Tests"
env: GRADLE_TASK=integrationTest PLAY_VERSION=2.4.11
- name: "Play 2.5.19 Integration Tests"
env: GRADLE_TASK=integrationTest PLAY_VERSION=2.5.19
- name: "Play 2.6.25 Integration Tests"
env: GRADLE_TASK=integrationTest PLAY_VERSION=2.6.25
- name: "Play 2.7.3 Integration Tests"
env: GRADLE_TASK=integrationTest PLAY_VERSION=2.7.3
- name: "Documentation Tests"
env: GRADLE_TASK=docTest PLAY_VERSION=not_used

script:
- ./gradlew $GRADLE_TASK -s --continue
- ./gradlew -Pplayframework.int-test.target.version=$PLAY_VERSION $GRADLE_TASK -s --continue

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
integTestFixturesImplementation("com.google.guava:guava:23.0")
integTestFixturesImplementation("org.hamcrest:hamcrest-library:1.3")
integTestFixturesImplementation("org.apache.ant:ant:1.9.3")
integTestFixturesImplementation("org.freemarker:freemarker:2.3.30")
docTestImplementation("org.gradle:sample-check:0.7.0")
docTestRuntimeOnly("org.slf4j:slf4j-simple:1.7.16")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.gradle.playframework
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.kotlin.dsl.withType


Expand All @@ -11,8 +12,13 @@ class TestSetupPlugin : Plugin<Project> {
tasks.withType<Test>().configureEach {
// Log test execution so that Travis CI doesn't time out
if (System.getenv("CI") != null) {
// Enable detailed logging when running in Travis CI,
// so that we can understand why a build failed
// From: https://stackoverflow.com/a/47458666
testLogging {
events("started")
events("started", "passed", "skipped", "failed")
showStackTraces = true
exceptionFormat = TestExceptionFormat.FULL
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ abstract class PlayApplicationPluginIntegrationTest extends PlayMultiVersionAppl
}

void verifyJars() {
jar("build/libs/${playApp.name}.jar").containsDescendants(
'router/Routes.class',
'views/html/index.class',
'views/html/main.class',
'controllers/Application.class',
'application.conf',
'logback.xml')
if (playVersion.major == 2 && playVersion.minor == 3) {
jar("build/libs/${playApp.name}.jar").containsDescendants(
'Routes.class',
'views/html/index.class',
'views/html/main.class',
'controllers/Application.class',
'application.conf',
'logback.xml')
} else {
jar("build/libs/${playApp.name}.jar").containsDescendants(
'router/Routes.class',
'views/html/index.class',
'views/html/main.class',
'controllers/Application.class',
'application.conf',
'logback.xml')
}
jar("build/libs/${playApp.name}-assets.jar").containsDescendants(
'public/images/favicon.svg',
'public/stylesheets/main.css',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gradle.playframework.PlayMultiVersionIntegrationTest
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.util.VersionNumber
import org.junit.Assume

import static org.gradle.playframework.fixtures.Repositories.playRepositories
import static org.gradle.playframework.fixtures.file.FileFixtures.assertContentsHaveChangedSince
Expand Down Expand Up @@ -242,6 +243,8 @@ GET / ${controllers()}${packageId}.Application.inde
}

def "can add additional imports"() {
// Play version 2.3 not supported
Assume.assumeTrue(playVersion > VersionNumber.parse("2.3.99"))
given:
withRoutesTemplate()
and:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,54 @@ class Play24RoutesCompileIntegrationTest extends AbstractRoutesCompileIntegratio

@Override
def getJavaRoutesFileName(String packageName, String namespace) {
return "${namespace ? namespace + '/' :''}controllers/${packageName ? packageName + '/' :''}routes.java"
if (playVersion < VersionNumber.parse("2.4")) {
return "${namespace ? namespace + '/' : ''}controllers/${packageName ? packageName + "/" : ''}/routes.java"
} else {
return "${namespace ? namespace + '/' : ''}controllers/${packageName ? packageName + '/' : ''}routes.java"
}
}

@Override
def getReverseRoutesFileName(String packageName, String namespace) {
return "${namespace ? namespace + '/' :''}controllers/${packageName ? packageName + '/' :''}ReverseRoutes.scala"
if (playVersion < VersionNumber.parse("2.4")) {
if (namespace) {
return "${namespace ? namespace + '/' : ''}routes_reverseRouting.scala"
} else {
return "${packageName ? packageName + '/' : ''}routes_reverseRouting.scala"
}
} else {
return "${namespace ? namespace + '/' : ''}controllers/${packageName ? packageName + '/' : ''}ReverseRoutes.scala"
}
}

@Override
def getScalaRoutesFileName(String packageName, String namespace) {
return "${packageName?:'router'}/Routes.scala"
if (playVersion < VersionNumber.parse("2.4")) {
if (namespace) {
return "${namespace ? namespace + '/' : ''}routes_routing.scala"
} else {
return "${packageName ? packageName + '/' : ''}routes_routing.scala"
}
} else {
return "${packageName ?: 'router'}/Routes.scala"
}
}

@Override
def getOtherRoutesFileNames() {
return [
{packageName, namespace -> "${namespace ? namespace + '/' :''}controllers/${packageName ? packageName + '/' :''}javascript/JavaScriptReverseRoutes.scala" },
{packageName, namespace -> "${packageName?:'router'}/RoutesPrefix.scala" }
]
if (playVersion < VersionNumber.parse("2.4")) {
return []
} else {
return [
{ packageName, namespace -> "${namespace ? namespace + '/' : ''}controllers/${packageName ? packageName + '/' : ''}javascript/JavaScriptReverseRoutes.scala" },
{ packageName, namespace -> "${packageName ?: 'router'}/RoutesPrefix.scala" }
]
}
}

def "can specify route compiler type as injected"() {
// Play version 2.3 not supported
Assume.assumeTrue(playVersion > VersionNumber.parse("2.3.99"))
given:
withRoutesTemplate()
withInjectedRoutesController()
Expand All @@ -48,6 +74,8 @@ play {
}

def "recompiles when route compiler type is changed"() {
// Play version 2.3 not supported
Assume.assumeTrue(playVersion > VersionNumber.parse("2.3.99"))
// Play 2.7+ only has a single route compiler type.
Assume.assumeTrue(playVersion < VersionNumber.parse("2.7"))
when:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,59 @@

package org.gradle.playframework.fixtures.app

import freemarker.cache.ClassTemplateLoader
import freemarker.template.Configuration
import freemarker.template.Template
import freemarker.template.TemplateExceptionHandler
import org.gradle.playframework.extensions.PlayPlatform
import org.gradle.util.RelativePathUtil
import org.gradle.util.VersionNumber

import static org.gradle.playframework.fixtures.Repositories.playRepositories

abstract class PlayApp {
boolean oldVersion
final VersionNumber playVersion
final Configuration cfg
final Map<String, String> model

PlayApp() {
this(VersionNumber.parse(PlayPlatform.DEFAULT_PLAY_VERSION))
}

PlayApp(VersionNumber version) {
this.oldVersion = version < VersionNumber.parse('2.6.0')
playVersion = version
cfg = new Configuration(Configuration.VERSION_2_3_29)
cfg.setTemplateLoader(new ClassTemplateLoader())
cfg.setDefaultEncoding("UTF-8")
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER)
cfg.setLogTemplateExceptions(false)
cfg.setWrapUncheckedExceptions(true)
cfg.setFallbackOnNullLoopVariable(false)
model = new HashMap<>()
model.put("playVersion", playVersion.major + "." + playVersion.minor)
}

String getName() {
getClass().getSimpleName().toLowerCase()
}

String getResourcePath(String relativePath) {
String basePath = this.getClass().getCanonicalName().split("\\.").dropRight(1).join("/")
return basePath + "/" + relativePath
}

List<SourceFile> getAllFiles() {
return appSources + testSources + viewSources + assetSources + confSources + otherSources
}

SourceFile getGradleBuild() {
def buildFileName = oldVersion ? "build.gradle.old" : "build.gradle"
def gradleBuild = sourceFile("", buildFileName)
def gradleBuildWithRepositories = gradleBuild.content.concat """
String gradleBuildContent = renderTemplate(getResourcePath(getName() + "/build.gradle.ftl"))
def gradleBuildWithRepositories = gradleBuildContent.concat """
allprojects {
${playRepositories()}
}
"""
return new SourceFile(gradleBuild.path, "build.gradle", gradleBuildWithRepositories)
return new SourceFile("", "build.gradle", gradleBuildWithRepositories)
}

List<SourceFile> getAssetSources() {
Expand Down Expand Up @@ -78,9 +99,20 @@ abstract class PlayApp {


protected SourceFile sourceFile(String path, String name, String baseDir = getName()) {
URL resource = getClass().getResource("$baseDir/$path/$name")
File file = new File(resource.toURI())
return new SourceFile(path, name, file.text)
String resourcePath = getResourcePath("$baseDir/$path/$name")
URL resource = getClass().getClassLoader().getResource(resourcePath)

if(resource == null) {
throw new IllegalStateException("Could not find resource on the classpath: $resourcePath")
}

File source = new File(resource.toURI())
if(isTemplate(source)) {
String content = renderTemplate(resourcePath)
return new SourceFile(path, source.name[0..<-4], content)
} else {
return new SourceFile(path, source.name, source.text)
}
}

void writeSources(File sourceDir) {
Expand All @@ -90,10 +122,15 @@ abstract class PlayApp {
}
}

/**
* Generate a list of source files for this app, based on existing files
* in the project.
*/
List<SourceFile> sourceFiles(String baseDir, String rootDir = getName()) {
List sourceFiles = new ArrayList()

URL resource = getClass().getResource("$rootDir/$baseDir")
String resourcePath = "$rootDir/$baseDir"
URL resource = getClass().getResource(resourcePath)
if(resource != null){
File baseDirFile = new File(resource.toURI())
baseDirFile.eachFileRecurse { File source ->
Expand All @@ -103,28 +140,32 @@ abstract class PlayApp {

def subpath = RelativePathUtil.relativePath(baseDirFile, source.parentFile)

if(oldVersion) {
if(isOldVersionFile(source)) {
sourceFiles.add(new SourceFile("$baseDir/$subpath", source.name[0..<-4], source.text))
} else if (!oldVersionFileExists(source)) {
sourceFiles.add(new SourceFile("$baseDir/$subpath", source.name, source.text))
}
if(isTemplate(source)) {
String content = renderTemplate(getResourcePath(resourcePath + "/" + subpath + "/" + source.name))
SourceFile file = new SourceFile("$baseDir/$subpath", source.name[0..<-4], content)
sourceFiles.add(file)
} else {
if(!isOldVersionFile(source)) {
sourceFiles.add(new SourceFile("$baseDir/$subpath", source.name, source.text))
}
SourceFile file = new SourceFile("$baseDir/$subpath", source.name, source.text)
sourceFiles.add(file)
}
}
}

return sourceFiles
}

static boolean isOldVersionFile(File file) {
return file.name.endsWith('.old')
static boolean isTemplate(File file) {
return file.name.endsWith('.ftl')
}

static boolean oldVersionFileExists(File file) {
return new File(file.parentFile, "${file.name}.old").exists()
String renderTemplate(String templatePath) {
try {
Template tmpl = cfg.getTemplate(templatePath)
StringWriter sw = new StringWriter()
tmpl.process(model, sw)
return sw.toString()
} catch(Exception e) {
throw e
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ class SourceFile {
}
file.write(content)
}

@Override
String toString() {
return path + File.separator + name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class WithFailingTestsApp extends PlayApp {

@Override
SourceFile getGradleBuild() {
def gradleBuild = sourceFile("", "build.gradle", "basicplayapp")
def gradleBuild = sourceFile("", "build.gradle.ftl", "basicplayapp")
def gradleBuildWithRepositories = gradleBuild.content.concat """
allprojects {
${playRepositories()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@

package controllers

<#if playVersion == "2.7" || playVersion == "2.6">
import javax.inject._
import play.api._
import play.api.mvc._
import models._

@Singleton
class Application @Inject() extends InjectedController {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
def root = Action {
Ok(views.html.awesome.index(java.util.Arrays.asList(new DataType("bar", 2))))
}
def shutdown = Action {
Runtime.getRuntime().halt(0)
Ok("shutdown")
}
}
<#else>
import play.api._
import play.api.mvc._
import models._
Expand All @@ -32,4 +51,5 @@ object Application extends Controller {
System.exit(0)
Ok("shutdown")
}
}
}
</#if>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

public class PureJava extends Controller {

<#if playVersion == "2.7">
public Result index() {
<#else>
public static Result index() {
</#if>
return ok(index.render("Your new application is ready."));
}

Expand Down
Loading

0 comments on commit b0b48a5

Please sign in to comment.