Skip to content

Commit

Permalink
Merge branch 'main' into refactor/generator-cli/file-read
Browse files Browse the repository at this point in the history
  • Loading branch information
taefi authored Feb 21, 2025
2 parents b796312 + 25cb4dd commit 50d34ad
Show file tree
Hide file tree
Showing 47 changed files with 10,686 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ jobs:
- name: Test gradle-plugin's functional tests
run: ./packages/java/gradle-plugin/gradlew --info -p packages/java/gradle-plugin functionalTest
- name: Gradle ITs
run: ./packages/java/tests/gradle/single-module-tests/gradlew --info -p packages/java/tests/gradle/single-module-tests test
run: ./packages/java/tests/gradle/kotlin-gradle-test/gradlew --info --stacktrace -p packages/java/tests/gradle/kotlin-gradle-test clean integrationTest
- uses: actions/upload-artifact@v4
if: ${{ failure() || success() }}
with:
Expand Down
6 changes: 3 additions & 3 deletions packages/java/gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id 'maven-publish'
id 'idea'
id 'com.gradle.plugin-publish' version '0.11.0'
id 'org.jetbrains.kotlin.jvm' version '1.9.20-Beta2'
id 'org.jetbrains.kotlin.jvm' version '1.9.25'
id 'org.jetbrains.dokka' version '1.9.0'
}

Expand Down Expand Up @@ -66,13 +66,13 @@ repositories {
}

dependencies {
implementation('org.jetbrains.kotlin:kotlin-stdlib:1.9.20')
implementation('org.jetbrains.kotlin:kotlin-stdlib:1.9.25')
implementation("com.vaadin:hilla-engine-core:$version")
implementation("com.vaadin:flow-gradle-plugin:$flowVersion")
implementation("org.springframework.boot:spring-boot-loader-tools:$springBootVersion")

testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.20")
testImplementation("org.jetbrains.kotlin:kotlin-test:1.9.25")
}

idea {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.vaadin.hilla.engine.EngineConfiguration
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.internal.provider.DefaultListProperty
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.SourceSet
Expand All @@ -33,6 +34,8 @@ import java.util.stream.Stream
* The main class of the Hilla Gradle Plugin
*/
public class HillaPlugin : Plugin<Project> {
private val JSR_305_STRICT = "-Xjsr305=strict"
private val EMIT_JVM_TYPE_ANNOTATIONS = "-Xemit-jvm-type-annotations"

override fun apply(project: Project) {
// we need Java Plugin conventions so that we can ensure the order of tasks
Expand All @@ -46,16 +49,37 @@ public class HillaPlugin : Plugin<Project> {
if (project.plugins.hasPlugin("org.springframework.boot")) {
project.tasks.replace("vaadinBuildFrontend", EngineBuildFrontendTask::class.java)

project.tasks.apply {
register("hillaConfigure", EngineConfigureTask::class.java)
register("hillaGenerate", EngineGenerateTask::class.java)
}
project.tasks.register("hillaConfigure", EngineConfigureTask::class.java)
project.tasks.register("hillaGenerate", EngineGenerateTask::class.java)

project.tasks.named("vaadinBuildFrontend") {
it.dependsOn("hillaConfigure")
}
}

// Configure Kotlin-specific tasks only if Kotlin JVM plugin is applied
project.plugins.withId("org.jetbrains.kotlin.jvm") {
project.tasks.named("compileKotlin").configure { task ->
val compilerOptions = task.javaClass.methods.find { it.name == "getCompilerOptions" }?.invoke(task)
if (compilerOptions != null) {
val freeCompilerArgs = compilerOptions.javaClass.methods.find { it.name == "getFreeCompilerArgs" }
?.invoke(compilerOptions) as? DefaultListProperty<String>
freeCompilerArgs?.addAll(listOf(JSR_305_STRICT, EMIT_JVM_TYPE_ANNOTATIONS))
?: project.logger.warn("""
Kotlin JVM plugin is applied and 'compilerOption' was not null, but could not acquire the
'freeCompilerArgs' instance from the 'compilerOption' to configure Kotlin compiler options by
adding '$JSR_305_STRICT' and '$EMIT_JVM_TYPE_ANNOTATIONS'. To make sure annotation based form
validations are enabled, add the above compiler args in the build file explicitly.""".trimIndent())
} else {
project.logger.warn("""
Kotlin JVM plugin is applied, but could not acquire the 'compilerOption' instance from the
'compileKotlin' task instance to configure Kotlin compiler options by adding '$JSR_305_STRICT'
and '$EMIT_JVM_TYPE_ANNOTATIONS' to the 'freeCompilerArgs'. To make sure annotation based form
validations are enabled, add the above compiler args in the build file explicitly.""".trimIndent())
}
}
}

project.tasks.withType(Jar::class.java) { task: Jar ->
task.mustRunAfter("vaadinBuildFrontend")
}
Expand Down
6 changes: 5 additions & 1 deletion packages/java/tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ vite.config.ts
vite.generated.ts
*/**/tsconfig.json
types.d.ts
**/frontend/generated/*
**/frontend/generated
**/error-screenshots/*
**/node_modules/*
**/build/
*/**/src/main/bundles

3 changes: 3 additions & 0 deletions packages/java/tests/gradle/kotlin-gradle-test/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/gradlew text eol=lf
*.bat text eol=crlf
*.jar binary
41 changes: 41 additions & 0 deletions packages/java/tests/gradle/kotlin-gradle-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
node_modules
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Kotlin ###
.kotlin
136 changes: 136 additions & 0 deletions packages/java/tests/gradle/kotlin-gradle-test/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.9.25'
id 'org.jetbrains.kotlin.plugin.spring' version '1.9.25'
id 'org.jetbrains.kotlin.plugin.jpa' version '1.9.25'
id 'org.springframework.boot' version '3.4.1'
id 'io.spring.dependency-management' version '1.1.7'
}

apply plugin: 'com.vaadin.hilla'

group = 'com.vaadin.hilla.gradle.test'

dependencyManagement {
imports {
mavenBom "com.vaadin:hilla-bom:$hillaVersion"
mavenBom "com.vaadin:flow-bom:$flowVersion"
}
}

repositories {
mavenLocal()
mavenCentral()
maven { setUrl("https://maven.vaadin.com/vaadin-prereleases") }
maven { setUrl("https://maven.vaadin.com/vaadin-addons") }
}

dependencies {
implementation 'com.vaadin:vaadin-spring'
implementation 'com.vaadin:hilla'
implementation "com.vaadin:vaadin-lumo-theme:$vaadinComponentsVersion"
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.parttio:line-awesome:1.1.0'
implementation 'com.vaadin:vaadin-dev-server'
runtimeOnly 'jakarta.servlet:jakarta.servlet-api:6.0.0'

implementation 'org.jetbrains.kotlin:kotlin-reflect'
implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'

testImplementation "com.vaadin:flow-test-util:$flowVersion"
testImplementation "com.vaadin:vaadin-button-testbench:$vaadinComponentsVersion"
testImplementation "com.vaadin:vaadin-text-field-testbench:$vaadinComponentsVersion"
testImplementation "com.vaadin:vaadin-grid-testbench:$vaadinComponentsVersion"
}

sourceSets {
main {
java {
srcDirs("src/main/kotlin") // Include the directory for package-info.java
}
kotlin {
srcDirs("src/main/kotlin")
}
}
test {
kotlin {
srcDirs("src/test/kotlin")
}
}
}

import java.util.concurrent.Executors
import org.gradle.internal.os.OperatingSystem

def isWindows = OperatingSystem.current().isWindows()

tasks.register('productionBuild', Exec) {
description = 'Builds the Spring Boot application for production.'
def command
if (isWindows) {
command = ['cmd', '/c', 'gradlew.bat', 'clean', '-Pvaadin.productionMode', 'build', '-x', 'test']
} else {
command = ['sh', '-c', './gradlew clean -Pvaadin.productionMode build -x test']
}
commandLine command
doLast {
logger.info("Production build started...")
}
}

tasks.register('bootStart') {
description = 'Starts the Spring Boot application for integration tests.'
dependsOn productionBuild
doLast {
logger.info("Running the application in production for integration tests...")
// Retrieve the jar task
def bootJarTask = tasks.named('bootJar').get()
// Get the path to the generated JAR file
def bootJarFile = bootJarTask.archiveFile.get().asFile
if (!bootJarFile.exists()) {
throw new GradleException("The bootJar output file not found at: ${bootJarFile.absolutePath}")
}
def processBuilder = new ProcessBuilder('java', '-jar', bootJarFile.absolutePath)
processBuilder.redirectErrorStream(true)
def process = processBuilder.start()
def executor = Executors.newSingleThreadExecutor()
executor.submit {
process.inputStream.eachLine { println it }
}
// Store the process for later termination:
project.ext.applicationProcess = process
// Wait enough for the application to start:
sleep(10000)
}
}

tasks.register('bootStop') {
description = 'Stops the Spring Boot application after integration tests.'
doLast {
if (project.ext.has('applicationProcess')) {
def process = project.ext.applicationProcess
if (process && process.isAlive()) {
logger.lifecycle("Stopping the application after running the integration test ...")
process.destroy()
process.waitFor()
logger.lifecycle("Application stopped successfully.")
} else {
logger.lifecycle("Application process is not running.")
}
} else {
logger.lifecycle("No application process found.")
}
}
}

tasks.register('integrationTest', Test) {
description = 'Runs integration tests.'
dependsOn bootStart
finalizedBy bootStop
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.daemon=false
hillaVersion=24.7-SNAPSHOT
flowVersion=24.7-SNAPSHOT
vaadinComponentsVersion=24.7-SNAPSHOT
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 50d34ad

Please sign in to comment.