Skip to content

Commit

Permalink
Start fixing Gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cromoteca committed Aug 2, 2024
1 parent 6110dfb commit a917323
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,43 +32,6 @@ import kotlin.test.expect

class SingleModuleTest : AbstractGradleTest() {

@Test
fun `hillaConfigure executed HillaEngineConfigurationJson should exist`() {
createProject()

testProject.build("hillaConfigure", checkTasksSuccessful = true)

expect(true, "hilla-engine-configuration.json should be created after executing hillaConfigure task!") {
testProject.folder("build").find("hilla-engine-configuration.json").first().exists()
}
}

@Test
fun `exposedPackagesToParser configured in build file hillaConfigure executed HillaEngineConfigurationJson should contain exposed packages`() {
val package1 = "com.example.app"
val package2 = "com.vaadin.hilla.foo"

createProject(package1, package2)

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

buildResult.expectTaskSucceded("hillaConfigure")

val hillaEngineConfigFile = testProject.folder("build").find("hilla-engine-configuration.json").first()
expect(true, "hilla-engine-configuration.json should be created after executing hillaConfigure task!") {
hillaEngineConfigFile.exists()
}

val configuration = EngineConfiguration.load(hillaEngineConfigFile)
val packages = configuration.parser.packages.orElseThrow()
expect(true, "Configuration json should contained exposed package '$package1'") {
packages.contains(package1)
}
expect(true, "Configuration json should contained exposed package '$package2'") {
packages.contains(package2)
}
}

@Test
fun `endpoints ts and openapi json are generated after hillaGenerate task executed in dev mode`() {
createProject(withNpmInstall = true)
Expand All @@ -77,7 +40,6 @@ class SingleModuleTest : AbstractGradleTest() {

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

buildResult.expectTaskSucceded("hillaConfigure")
buildResult.expectTaskSucceded("hillaGenerate")

verifyOpenApiJsonFileGeneratedProperly(false)
Expand All @@ -92,7 +54,6 @@ class SingleModuleTest : AbstractGradleTest() {

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

buildResult.expectTaskSucceded("hillaConfigure")
buildResult.expectTaskSucceded("hillaGenerate")

verifyOpenApiJsonFileGeneratedProperly(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,40 @@
*/
package com.vaadin.hilla.gradle.plugin

import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import java.io.File

/**
* Extend the VaadinBuildFrontendTask so that frontend files are not cleaned after build.
*/
public open class EngineBuildFrontendTask : com.vaadin.gradle.VaadinBuildFrontendTask() {
@Input
val classpathElements: List<String> = project.configurations.getByName("compileClasspath").files.map { it.absolutePath }

@Input
val groupId: String = project.group.toString()

@Input
val artifactId: String = project.name

@InputFile
val buildDir: File = project.buildDir

@Input
@Optional
var mainClass: String? = project.findProperty("spring-boot.aot.main-class") as String?

@TaskAction
override fun exec() {
EngineConfiguration.classpath = classpathElements.joinToString(File.pathSeparator)
EngineConfiguration.groupId = groupId
EngineConfiguration.artifactId = artifactId
EngineConfiguration.mainClass = mainClass
EngineConfiguration.buildDir = buildDir.toPath()

super.exec()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vaadin.hilla.gradle.plugin

import com.vaadin.gradle.VaadinFlowPluginExtension
import com.vaadin.hilla.engine.AotEndpointFinder
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.tasks.TaskAction
Expand All @@ -36,9 +37,6 @@ public open class EngineGenerateTask : DefaultTask() {
group = "Vaadin"
description = "Hilla Generate Task"

// we need the build/hilla-engine-configuration.json and the compiled classes:
dependsOn("classes", "hillaConfigure")

// Make sure to run this task before the `war`/`jar` tasks, so that
// generated endpoints and models will end up packaged in the war/jar archive.
// The inclusion rule itself is configured in the HillaPlugin class.
Expand Down Expand Up @@ -75,11 +73,14 @@ public open class EngineGenerateTask : DefaultTask() {
val parserProcessor = ParserProcessor(conf, classLoader, isProductionMode)
val generatorProcessor = GeneratorProcessor(conf, extension.nodeCommand, isProductionMode)

parserProcessor.process()
val endpoints = AotEndpointFinder(conf).findEndpointClasses()
parserProcessor.process(endpoints)
generatorProcessor.process()

} catch (e: IOException) {
throw GradleException("Loading saved configuration failed", e)
throw GradleException("Endpoint collection failed", e)
} catch (e: InterruptedException) {
throw GradleException("Endpoint collection failed", e)
} catch (e: GeneratorException) {
throw GradleException("Execution failed", e)
} catch (e: ParserException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class HillaPlugin : Plugin<Project> {
project.extensions.create(extensionName, EngineProjectExtension::class.java, project)

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

Expand Down

0 comments on commit a917323

Please sign in to comment.