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: gather Flow and Hilla Gradle tasks under vaadin group #1996

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import com.vaadin.hilla.engine.EngineConfiguration
import io.swagger.v3.core.util.Json
import io.swagger.v3.oas.models.OpenAPI
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Test
import java.io.File
import java.nio.file.Files
@@ -84,45 +83,6 @@ class SingleModuleTest : AbstractGradleTest() {
verifyEndpointsTsFileGeneratedProperly()
}

@Test
fun `when hilla productionMode=true in build file then building the project executes vaadinBuildFrontend`() {
createProject(withNpmInstall = true, productionMode = true, disableAllTasksToSimulateDryRun = true)

addHelloReactEndpoint()

val buildResult: BuildResult = testProject.build("build", checkTasksSuccessful = false)

expect(TaskOutcome.SKIPPED, "Building project while hilla.productionMode=true should plan to execute vaadinBuildFrontend task") {
buildResult.task(":vaadinBuildFrontend")?.outcome
}
}

@Test
fun `when hilla productionMode not set in build file then building the project with productionMode commandline arg executes vaadinBuildFrontend`() {
createProject(withNpmInstall = true, productionMode = false, disableAllTasksToSimulateDryRun = true)

addHelloReactEndpoint()

val buildResult: BuildResult = testProject.build("-Philla.productionMode=true", "build", checkTasksSuccessful = false)

expect(TaskOutcome.SKIPPED, "Building project while hilla.productionMode=true should plan to execute vaadinBuildFrontend task") {
buildResult.task(":vaadinBuildFrontend")?.outcome
}
}

@Test
fun `when hilla productionMode=true in build file then building the project with commandline arg productionMode=false does not execute vaadinBuildFrontend`() {
createProject(withNpmInstall = true, productionMode = true, disableAllTasksToSimulateDryRun = true)

addHelloReactEndpoint()

val buildResult: BuildResult = testProject.build("-Philla.productionMode=false", "build", checkTasksSuccessful = false)

expect(null, "Building project while hilla.productionMode=true should plan to execute vaadinBuildFrontend task") {
buildResult.task(":vaadinBuildFrontend")
}
}

@Test
fun `check hillaInitApp properly scaffolds project according to framework`() {
createProject()
@@ -222,7 +182,7 @@ class SingleModuleTest : AbstractGradleTest() {

val productionBuild = if (productionMode) {
"""
hilla {
vaadin {
productionMode = true
}
""".trimIndent()
@@ -280,7 +240,6 @@ class SingleModuleTest : AbstractGradleTest() {
dependencies {
implementation 'com.vaadin.hilla:hilla-react'
implementation 'com.vaadin:vaadin-spring'
implementation 'com.vaadin.hilla:hilla'
implementation 'org.springframework.boot:spring-boot-starter-web'
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,5 +18,5 @@ package com.vaadin.hilla.gradle.plugin
/**
* Extend the VaadinBuildFrontendTask so that frontend files are not cleaned after build.
*/
public open class HillaBuildFrontendTask : com.vaadin.gradle.VaadinBuildFrontendTask() {
public open class EngineBuildFrontendTask : com.vaadin.gradle.VaadinBuildFrontendTask() {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.vaadin.hilla.gradle.plugin

import com.vaadin.gradle.VaadinFlowPluginExtension
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.SourceSet
@@ -35,14 +36,16 @@ public open class EngineConfigureTask : DefaultTask() {
}

init {
group = "Hilla"
group = "Vaadin"
description = "Hilla Configure Task"
}

@TaskAction
public fun engineConfigure() {
val extension: EngineProjectExtension = EngineProjectExtension.get(project)
logger.info("Running the engineConfigure task with effective configuration $extension")
logger.info("Running the engineConfigure task with effective Hilla configuration $extension")
val vaadinExtension = VaadinFlowPluginExtension.get(project)
logger.info("Running the engineConfigure task with effective Vaadin configuration $extension")

val generator = GeneratorConfiguration()
val parser = ParserConfiguration()
@@ -52,15 +55,15 @@ public open class EngineConfigureTask : DefaultTask() {

val projectBuildDir = project.buildDir.toPath()
val projectClassesDir = projectBuildDir.resolve("classes")
val classPathElements = (sourceSets.getByName(extension.sourceSetName) as SourceSet)
val classPathElements = (sourceSets.getByName(vaadinExtension.sourceSetName.get()) as SourceSet)
.runtimeClasspath.elements.get().stream().map { it.toString() }.toList()

val conf = EngineConfiguration.Builder(project.projectDir.toPath())
.classPath(classPathElements)
.outputDir(extension.generatedTsFolder.toPath())
.outputDir(vaadinExtension.generatedTsFolder.get().toPath())
.generator(generator)
.parser(parser)
.buildDir(extension.projectBuildDir)
.buildDir(vaadinExtension.projectBuildDir.get())
.classesDir(projectClassesDir)
.create()

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.vaadin.hilla.gradle.plugin

import com.vaadin.gradle.VaadinFlowPluginExtension
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.TaskAction
@@ -32,7 +33,7 @@ import com.vaadin.hilla.engine.*
*/
public open class EngineGenerateTask : DefaultTask() {
init {
group = "Hilla"
group = "Vaadin"
description = "Hilla Generate Task"

// we need the build/hilla-engine-configuration.json and the compiled classes:
@@ -49,10 +50,12 @@ public open class EngineGenerateTask : DefaultTask() {
@TaskAction
public fun engineGenerate() {
val extension: EngineProjectExtension = EngineProjectExtension.get(project)
logger.info("Running the engineGenerate task with effective configuration $extension")
logger.info("Running the engineGenerate task with effective Hilla configuration $extension")
val vaadinExtension = VaadinFlowPluginExtension.get(project)
logger.info("Running the engineGenerate task with effective Vaadin configuration $extension")

val baseDir: Path = project.projectDir.toPath()
val buildDir: Path = baseDir.resolve(extension.projectBuildDir)
val buildDir: Path = baseDir.resolve(vaadinExtension.projectBuildDir.get())

try {
val conf: EngineConfiguration = Objects.requireNonNull(
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ import java.io.IOException
public open class EngineInitAppTask : DefaultTask() {

init {
group = "Hilla"
group = "Vaadin"
description = "Task for scaffolding and initializing a Hilla application"
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,7 @@
*/
package com.vaadin.hilla.gradle.plugin

import com.vaadin.gradle.getBooleanProperty
import org.gradle.api.Project
import java.io.File

public open class EngineProjectExtension(project: Project) {

@@ -33,30 +31,6 @@ public open class EngineProjectExtension(project: Project) {
*/
public var exposedPackagesToParser: List<String> = mutableListOf()

/**
* Indicates whether the application should run in production mode, defaults to false.
* Responds to the `-Philla.productionMode` property.
*/
public var productionMode: Boolean = false

/**
* The folder where flow will put TS API files for client projects.
*/
public var generatedTsFolder: File = File(project.projectDir, "frontend/generated")

/**
* Defines the output folder used by the project.
*
* Default value is the `project.buildDir` and should not need to be changed.
*/
public var projectBuildDir: String = project.buildDir.toString()

/**
* The name of the SourceSet to scan for Vaadin components - i.e. the classes that are annotated with
* Vaadin annotations.
*/
public var sourceSetName : String = "main"

/**
* The node command to execute
*/
@@ -68,18 +42,8 @@ public open class EngineProjectExtension(project: Project) {
project.extensions.getByType(EngineProjectExtension::class.java)
}

internal fun autoconfigure(project: Project) {
val productionModeProperty: Boolean? = project.getBooleanProperty("hilla.productionMode")
if (productionModeProperty != null) {
productionMode = productionModeProperty
}
}

override fun toString(): String = "HillaPluginExtension(" +
"exposedPackagesToParser=$exposedPackagesToParser, " +
"productionMode=$productionMode, " +
"generatedTsFolder=$generatedTsFolder, " +
"sourceSetName=$sourceSetName, " +
"nodeCommand=$nodeCommand, " +
"nodeCommand=$nodeCommand" +
")"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2000-2023 Vaadin Ltd
* Copyright 2000-2024 Vaadin Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,12 @@
*/
package com.vaadin.hilla.gradle.plugin

import com.vaadin.gradle.VaadinFlowPluginExtension
import com.vaadin.gradle.VaadinPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.bundling.Jar

/**
* The main class of the Hilla Gradle Plugin
@@ -37,7 +35,7 @@ public class HillaPlugin : Plugin<Project> {
// to leverage from vaadinPrepareFrontend and vaadinBuildFrontend:
project.pluginManager.apply(VaadinPlugin::class.java)

project.tasks.replace("vaadinBuildFrontend", HillaBuildFrontendTask::class.java)
project.tasks.replace("vaadinBuildFrontend", EngineBuildFrontendTask::class.java)

val extensionName = "hilla"
project.extensions.create(extensionName, EngineProjectExtension::class.java, project)
@@ -54,16 +52,5 @@ public class HillaPlugin : Plugin<Project> {
copyTask.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
}

project.afterEvaluate {
val extension: EngineProjectExtension = EngineProjectExtension.get(it)
extension.autoconfigure(it)
if (extension.productionMode) {
// this will also catch the War task since it extends from Jar
project.tasks.withType(Jar::class.java) { task: Jar ->
task.dependsOn("vaadinBuildFrontend")
}
}
}
}
}
27 changes: 18 additions & 9 deletions packages/java/tests/gradle/single-module-tests/package.json
Original file line number Diff line number Diff line change
@@ -24,10 +24,12 @@
"@vaadin/router": "1.7.5",
"classnames": "^2.3.2",
"construct-style-sheets-polyfill": "3.1.0",
"lit": "3.1.0",
"lit": "3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.2"
"react-router-dom": "6.21.2",
"@types/react-dom": "18.2.18",
"@types/react": "18.2.48"
},
"devDependencies": {
"@lit-labs/react": "^1.1.0",
@@ -40,15 +42,16 @@
"async": "3.2.5",
"glob": "10.3.10",
"rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.11.0",
"rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0",
"transform-ast": "2.4.4",
"typescript": "5.3.3",
"vite": "5.0.10",
"vite": "5.0.12",
"vite-plugin-checker": "0.6.2",
"workbox-build": "7.0.0",
"workbox-core": "7.0.0",
"workbox-precaching": "7.0.0"
"workbox-precaching": "7.0.0",
"@babel/preset-react": "^7"
},
"overrides": {
"@vaadin/router": "$@vaadin/router",
@@ -96,7 +99,12 @@
"@vaadin/hilla-react-form": "24.4.0",
"@vaadin/router": "1.7.5",
"construct-style-sheets-polyfill": "3.1.0",
"lit": "3.1.0"
"lit": "3.1.1",
"react-dom": "18.2.0",
"@types/react-dom": "18.2.18",
"react-router-dom": "6.21.2",
"@types/react": "18.2.48",
"react": "18.2.0"
},
"devDependencies": {
"@rollup/plugin-replace": "5.0.5",
@@ -106,15 +114,16 @@
"async": "3.2.5",
"glob": "10.3.10",
"rollup-plugin-brotli": "3.1.0",
"rollup-plugin-visualizer": "5.11.0",
"rollup-plugin-visualizer": "5.12.0",
"strip-css-comments": "5.0.0",
"transform-ast": "2.4.4",
"typescript": "5.3.3",
"vite": "5.0.10",
"vite": "5.0.12",
"vite-plugin-checker": "0.6.2",
"workbox-build": "7.0.0",
"workbox-core": "7.0.0",
"workbox-precaching": "7.0.0"
"workbox-precaching": "7.0.0",
"@babel/preset-react": "^7"
},
"hash": "8cfd18de14d73f98a9103e7cad17ecf3ccf80d4f3eb6f1599c55919db3883372"
}
Loading