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

feat: Gradle toolchains support #19789

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
10 changes: 10 additions & 0 deletions flow-plugins/flow-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ task functionalTest(type: Test) {
exceptionFormat = 'full'
showStandardStreams = true
}

// Gradlew CLI option -Dorg.gradle.testkit.debug=true allows to debug test projects running by testkit.
// However, during debug, the Gradle testkit limits the ability to use process isolation in Worker API and does not initialize underlying native services.
// The next condition excludes the tests that require Worker API and native services during debugging
// This limitation seem to be fixed in Gradle 8.8, see https://github.com/gradle/gradle/blob/98f0db0546f9d9c31268e079389d7fda8d8143dc/platforms/extensibility/unit-test-fixtures/src/main/java/org/gradle/testfixtures/internal/ProjectBuilderImpl.java#L134-L141
if(Boolean.getBoolean('org.gradle.testkit.debug')) {
useJUnit {
excludeCategories ' com.vaadin.gradle.GradleWorkerApiTestCategory'
}
}
}
check.dependsOn functionalTest
/***********************************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.vaadin.gradle

interface GradleWorkerApiTestCategory {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.vaadin.gradle

import org.junit.experimental.categories.Category

@Category(GradleWorkerApiTestCategory::class)
class JvmToolchainsMiscMultiModuleTest : MiscMultiModuleTest() {
override fun extraGradleDSL(): String {
return """
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
""".trimIndent()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2000-2022 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vaadin.gradle

import org.junit.Before
import org.junit.experimental.categories.Category


/**
* This is smoke tests of vaadin with respect of JVM toolchain configuration.
*
* @author skondrusiev
*/

@Category(GradleWorkerApiTestCategory::class)
class JvmToolchainsSmokeTest : VaadinSmokeTest() {
@Before
override fun setup() {
super.setup()

testProject.buildFile.appendText(
"""
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
""".trimIndent()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import java.nio.file.Files
import kotlin.io.path.writeText
import kotlin.test.expect

class MiscMultiModuleTest : AbstractGradleTest() {
open class MiscMultiModuleTest : AbstractGradleTest() {
internal open fun extraGradleDSL(): String {
return ""
}

/**
* Tests https://github.com/vaadin/vaadin-gradle-plugin/issues/38
*/
Expand Down Expand Up @@ -60,6 +64,7 @@ class MiscMultiModuleTest : AbstractGradleTest() {
nodeAutoUpdate = true // test the vaadin{} block by changing some innocent property with limited side-effect
}
}
${extraGradleDSL()}
""".trimIndent())
testProject.newFolder("lib")
testProject.newFolder("web")
Expand Down Expand Up @@ -104,6 +109,7 @@ class MiscMultiModuleTest : AbstractGradleTest() {
nodeAutoUpdate = true // test the vaadin{} block by changing some innocent property with limited side-effect
}
}
${extraGradleDSL()}
""".trimIndent())
testProject.newFolder("lib")
testProject.newFolder("web")
Expand Down Expand Up @@ -142,6 +148,7 @@ class MiscMultiModuleTest : AbstractGradleTest() {
project(':lib') {
apply plugin: 'java'
}
${extraGradleDSL()}
""".trimIndent())
testProject.newFolder("lib")
val webFolder = testProject.newFolder("web")
Expand All @@ -158,6 +165,7 @@ class MiscMultiModuleTest : AbstractGradleTest() {
vaadin {
nodeAutoUpdate = true // test the vaadin{} block by changing some innocent property with limited side-effect
}
${extraGradleDSL()}
""".trimIndent())

val b: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend", checkTasksSuccessful = false)
Expand Down Expand Up @@ -191,6 +199,7 @@ class MiscMultiModuleTest : AbstractGradleTest() {
project(':lib') {
apply plugin: 'java'
}
${extraGradleDSL()}
""".trimIndent())
testProject.newFolder("lib")
val webFolder = testProject.newFolder("web")
Expand All @@ -208,6 +217,7 @@ class MiscMultiModuleTest : AbstractGradleTest() {
nodeAutoUpdate = true // test the vaadin{} block by changing some innocent property with limited side-effect
applicationIdentifier = 'MY_APP_ID'
}
${extraGradleDSL()}
""".trimIndent())

val b: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend", checkTasksSuccessful = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {
}
"""
)
val result = testProject.build("vaadinPrepareFrontend", debug = true)
val result = testProject.build("vaadinPrepareFrontend")
expect(false) { result.output.contains("org.reflections.ReflectionsException") }
}

Expand All @@ -446,11 +446,11 @@ class MiscSingleModuleTest : AbstractGradleTest() {
implementation("org.slf4j:slf4j-simple:$slf4jVersion")
}
""")
var result = testProject.build("vaadinPrepareFrontend", debug = true)
var result = testProject.build("vaadinPrepareFrontend")
expect(true) { result.output.contains(
"Task ':vaadinPrepareFrontend' is not up-to-date") }

result = testProject.build("vaadinPrepareFrontend", debug = true, checkTasksSuccessful = false)
result = testProject.build("vaadinPrepareFrontend", checkTasksSuccessful = false)
result.expectTaskOutcome("vaadinPrepareFrontend", TaskOutcome.UP_TO_DATE)
println("Caching: " + result.output)
expect(true) { result.output.contains(
Expand All @@ -475,7 +475,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {
frontendHotdeploy = true
}
""")
result = testProject.build("vaadinPrepareFrontend", debug = true)
result = testProject.build("vaadinPrepareFrontend")
println("Caching: " + result.output)
expect(true) { result.output.contains(
"Task ':vaadinPrepareFrontend' is not up-to-date") }
Expand Down Expand Up @@ -505,7 +505,7 @@ class MiscSingleModuleTest : AbstractGradleTest() {
"""
)
repeat(5) {
val result = testProject.build("vaadinPrepareFrontend", debug = true)
val result = testProject.build("vaadinPrepareFrontend")
expect(true) {
result.output.contains(
"Task ':vaadinPrepareFrontend' is not up-to-date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ import org.gradle.testkit.runner.BuildTask
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import java.io.File
import java.io.IOException
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.PathMatcher
import java.util.zip.ZipInputStream
import kotlin.test.expect
Expand Down Expand Up @@ -230,10 +228,9 @@ class TestProject(val gradleVersion: String = if(JavaVersion.current().majorVers
val settingsFile: File get() = File(dir, "settings.gradle")


private fun createGradleRunner(debug: Boolean): GradleRunner = GradleRunner.create()
private fun createGradleRunner(): GradleRunner = GradleRunner.create()
.withProjectDir(dir)
.withPluginClasspath()
.withDebug(debug)
.forwardOutput() // a must, otherwise ./gradlew check freezes on windows!
.withGradleVersion(gradleVersion)

Expand Down Expand Up @@ -267,11 +264,11 @@ class TestProject(val gradleVersion: String = if(JavaVersion.current().majorVers
* The function by default checks that all tasks have succeeded; if not, throws an informative exception.
* You can suppress this functionality by setting [checkTasksSuccessful] to false.
*/
fun build(vararg args: String, checkTasksSuccessful: Boolean = true, debug: Boolean = false): BuildResult {
fun build(vararg args: String, checkTasksSuccessful: Boolean = true): BuildResult {
expect(true, "$buildFile doesn't exist, can't run build") { buildFile.exists() }

println("$dir/./gradlew ${args.joinToString(" ")}")
val result: BuildResult = createGradleRunner(debug)
val result: BuildResult = createGradleRunner()
.withArguments(args.toList() + "--stacktrace" + "--info")
.build()

Expand All @@ -291,7 +288,7 @@ class TestProject(val gradleVersion: String = if(JavaVersion.current().majorVers
*/
fun buildAndFail(vararg args: String): BuildResult {
println("$dir/./gradlew ${args.joinToString(" ")}")
return createGradleRunner(false)
return createGradleRunner()
.withArguments(args.toList() + "--stacktrace" + "--info")
.buildAndFail()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import java.nio.file.StandardCopyOption
* other test classes will possibly fail as well.
* @author mavi
*/
class VaadinSmokeTest : AbstractGradleTest() {
open class VaadinSmokeTest : AbstractGradleTest() {
@Before
fun setup() {
open fun setup() {
testProject.buildFile.writeText("""
plugins {
id 'war'
Expand Down Expand Up @@ -106,7 +106,7 @@ class VaadinSmokeTest : AbstractGradleTest() {

@Test
fun testBuildFrontendInProductionMode_customApplicationIdentifier() {
val result: BuildResult = testProject.build("-Pvaadin.applicationIdentifier=MY_APP_ID", "-Pvaadin.productionMode", "vaadinBuildFrontend", debug = true)
val result: BuildResult = testProject.build("-Pvaadin.applicationIdentifier=MY_APP_ID", "-Pvaadin.productionMode", "vaadinBuildFrontend")
// vaadinBuildFrontend depends on vaadinPrepareFrontend
// let's explicitly check that vaadinPrepareFrontend has been run
result.expectTaskSucceded("vaadinPrepareFrontend")
Expand Down
Loading
Loading