Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get CI build working again #147

Merged
merged 51 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f9ef5b5
use single threaded build for better debugging
cstroe Sep 10, 2020
76ae0b9
fix ktlint error
cstroe Sep 10, 2020
924597f
add detailed logging when running on TravisCI
cstroe Sep 10, 2020
5a75315
fix tests by skipping version 2.3.x of Play for certain tests
cstroe Sep 10, 2020
1c341e6
fix assertions for version 2.3
cstroe Sep 11, 2020
0ecc385
Play 2.7 no longer works with static methods
cstroe Sep 11, 2020
540664d
tests generate correct files for all supported Play versions
cstroe Sep 12, 2020
16f977c
convert Application.scala into template
cstroe Sep 12, 2020
86c16b6
convert routes to template
cstroe Sep 12, 2020
e8bcfd2
convert build.gradle into template
cstroe Sep 12, 2020
e258c4f
convert Application.scala into template
cstroe Sep 12, 2020
7109080
convert Application.scala to template
cstroe Sep 12, 2020
78fbb3f
convert Application.scala to template
cstroe Sep 12, 2020
3c7aa59
convert Application.scala to template
cstroe Sep 12, 2020
6513851
convert routes to template
cstroe Sep 12, 2020
c56e624
convert routes to template
cstroe Sep 12, 2020
b685591
convert routes to template
cstroe Sep 12, 2020
97b1c5d
convert build.gradle to template
cstroe Sep 12, 2020
e7031bf
convert build.gradle to template
cstroe Sep 12, 2020
ce18994
convert build.gradle to template
cstroe Sep 12, 2020
56f0159
convert build.gradle to template
cstroe Sep 12, 2020
59bf500
convert build.gradle to template
cstroe Sep 12, 2020
34d8d70
convert application.conf to template
cstroe Sep 12, 2020
bc78ebd
convert application.conf to template
cstroe Sep 12, 2020
6236a32
fix typo
cstroe Sep 12, 2020
5a5dc1e
fix template loading issues
cstroe Sep 12, 2020
7a0413e
Fix WithFailingTestsApp to correctly write build.gradle file
cstroe Sep 12, 2020
2ea4c2b
run tests in parallel again
cstroe Sep 12, 2020
8b895e6
Break up CI build into several smaller builds
cstroe Sep 12, 2020
e7ec34a
fix some 2.3 integration tests
cstroe Sep 12, 2020
d03a667
fix another 2.3 test
cstroe Sep 12, 2020
f396931
Fix another 2.3 test
cstroe Sep 12, 2020
ec0ceaa
Fix all 2.3 tests
cstroe Sep 12, 2020
949dde9
Add EOL @ EOF to src/integTestFixtures/resources/org/gradle/playframe…
cstroe Sep 14, 2020
226add5
Add EOL @ EOF for src/integTestFixtures/resources/org/gradle/playfram…
cstroe Sep 14, 2020
f0dae8a
Add EOL @ EOF for src/integTestFixtures/resources/org/gradle/playfram…
cstroe Sep 14, 2020
7589bef
Add EOL @ EOF for src/integTestFixtures/resources/org/gradle/playfram…
cstroe Sep 14, 2020
e1650eb
Add EOL @ EOF for src/integTestFixtures/resources/org/gradle/playfram…
cstroe Sep 14, 2020
ab1d2a9
Add EOL @ EOF for src/integTestFixtures/resources/org/gradle/playfram…
cstroe Sep 14, 2020
83bd68c
Add EOL @ EOF for src/integTestFixtures/resources/org/gradle/playfram…
cstroe Sep 14, 2020
9fdefb9
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
3f744fb
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
1c3dd6e
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
345ffc1
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
992bcc3
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
cb03a6f
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
f3e5059
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
6ea1826
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
d09b068
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
1d6423e
Update src/integTestFixtures/resources/org/gradle/playframework/fixtu…
cstroe Sep 16, 2020
a7f1175
add EOL @ EOF
cstroe Sep 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
cstroe marked this conversation as resolved.
Show resolved Hide resolved
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