Skip to content

Commit 66f2bf6

Browse files
authored
fix: expose effective plugin configuration at vaadin.effective (#18695)
1 parent 2af862c commit 66f2bf6

File tree

3 files changed

+79
-42
lines changed

3 files changed

+79
-42
lines changed

flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/MiscSingleModuleTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,4 +654,38 @@ class MiscSingleModuleTest : AbstractGradleTest() {
654654

655655
testProject.build("build")
656656
}
657+
658+
/**
659+
* Tests https://github.com/vaadin/flow/issues/18572
660+
*/
661+
@Test
662+
fun testPluginEffectiveConfiguration() {
663+
testProject.buildFile.writeText(
664+
"""
665+
plugins {
666+
id 'java'
667+
id 'com.vaadin'
668+
}
669+
repositories {
670+
mavenLocal()
671+
mavenCentral()
672+
maven { url = 'https://maven.vaadin.com/vaadin-prereleases' }
673+
}
674+
dependencies {
675+
implementation("com.vaadin:flow:$flowVersion") {
676+
println("!!!effective1.productionMode=" + vaadin.effective.productionMode.get() + "!!!")
677+
afterEvaluate {
678+
println("!!!cfg2.productionMode=" + vaadin.productionMode.get() + "!!!")
679+
println("!!!effective2.productionMode=" + vaadin.effective.productionMode.get() + "!!!")
680+
}
681+
}
682+
}
683+
""".trimIndent()
684+
)
685+
686+
val buildResult = testProject.build("assemble", "-Pvaadin.productionMode")
687+
expect(true, buildResult.output) { buildResult.output.contains("!!!cfg2.productionMode=false!!!") }
688+
expect(true, buildResult.output) { buildResult.output.contains("!!!effective1.productionMode=true!!!") }
689+
expect(true, buildResult.output) { buildResult.output.contains("!!!effective2.productionMode=true!!!") }
690+
}
657691
}

flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/PrepareFrontendInputProperties.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ internal class PrepareFrontendInputProperties(private val config: PluginEffectiv
137137
public fun getForceProductionBuild(): Provider<Boolean> = config.forceProductionBuild
138138

139139
@Input
140-
public fun getReactEnabled(): Provider<Boolean> = config.reactEnable
140+
public fun getReactEnable(): Provider<Boolean> = config.reactEnable
141141

142142
@Input
143143
@Optional

flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/VaadinFlowPluginExtension.kt

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ import org.gradle.api.provider.ListProperty
2929
import org.gradle.api.provider.Property
3030
import org.gradle.api.provider.Provider
3131
import java.io.File
32+
import javax.inject.Inject
3233

33-
public abstract class VaadinFlowPluginExtension {
34+
public abstract class VaadinFlowPluginExtension @Inject constructor(private val project: Project) {
3435
/**
3536
* Whether we are running in productionMode or not. Defaults to false.
3637
* Responds to the `-Pvaadin.productionMode` property.
@@ -286,102 +287,104 @@ public abstract class VaadinFlowPluginExtension {
286287
block.execute(classpathFilter)
287288
}
288289

290+
public val effective: PluginEffectiveConfiguration get() = PluginEffectiveConfiguration.get(project)
291+
289292
public companion object {
290293
public fun get(project: Project): VaadinFlowPluginExtension =
291294
project.extensions.getByType(VaadinFlowPluginExtension::class.java)
292295
}
293296
}
294297

295-
internal class PluginEffectiveConfiguration(
298+
public class PluginEffectiveConfiguration(
296299
private val project: Project,
297300
extension: VaadinFlowPluginExtension
298301
) {
299-
val productionMode: Provider<Boolean> = extension.productionMode
302+
public val productionMode: Provider<Boolean> = extension.productionMode
300303
.convention(false)
301304
.overrideWithSystemProperty("vaadin.productionMode")
302305

303-
val sourceSetName: Property<String> = extension.sourceSetName
306+
public val sourceSetName: Property<String> = extension.sourceSetName
304307
.convention("main")
305308

306-
val webpackOutputDirectory: Provider<File> = extension.webpackOutputDirectory
309+
public val webpackOutputDirectory: Provider<File> = extension.webpackOutputDirectory
307310
.convention(sourceSetName.map { File(project.getBuildResourcesDir(it), Constants.VAADIN_WEBAPP_RESOURCES) })
308311

309-
val npmFolder: Provider<File> = extension.npmFolder
312+
public val npmFolder: Provider<File> = extension.npmFolder
310313
.convention(project.projectDir)
311314

312-
val frontendDirectory: Provider<File> = extension.frontendDirectory
315+
public val frontendDirectory: Provider<File> = extension.frontendDirectory
313316
.convention(File(project.projectDir, "frontend"))
314317

315-
val generateBundle: Provider<Boolean> = extension.generateBundle
318+
public val generateBundle: Provider<Boolean> = extension.generateBundle
316319
.convention(true)
317320

318-
val runNpmInstall: Provider<Boolean> = extension.runNpmInstall
321+
public val runNpmInstall: Provider<Boolean> = extension.runNpmInstall
319322
.convention(true)
320323

321-
val generateEmbeddableWebComponents: Provider<Boolean> = extension.generateEmbeddableWebComponents
324+
public val generateEmbeddableWebComponents: Provider<Boolean> = extension.generateEmbeddableWebComponents
322325
.convention(true)
323326

324-
val frontendResourcesDirectory: Property<File> = extension.frontendResourcesDirectory
327+
public val frontendResourcesDirectory: Property<File> = extension.frontendResourcesDirectory
325328
.convention(File(project.projectDir, Constants.LOCAL_FRONTEND_RESOURCES_PATH))
326329

327-
val optimizeBundle: Property<Boolean> = extension.optimizeBundle
330+
public val optimizeBundle: Property<Boolean> = extension.optimizeBundle
328331
.convention(true)
329332

330-
val pnpmEnable: Provider<Boolean> = extension.pnpmEnable
333+
public val pnpmEnable: Provider<Boolean> = extension.pnpmEnable
331334
.convention(Constants.ENABLE_PNPM_DEFAULT)
332335
.overrideWithSystemProperty(InitParameters.SERVLET_PARAMETER_ENABLE_PNPM)
333336

334-
val bunEnable: Provider<Boolean> = extension.bunEnable
337+
public val bunEnable: Provider<Boolean> = extension.bunEnable
335338
.convention(Constants.ENABLE_BUN_DEFAULT)
336339
.overrideWithSystemProperty(InitParameters.SERVLET_PARAMETER_ENABLE_BUN)
337340

338-
val useGlobalPnpm: Provider<Boolean> = extension.useGlobalPnpm
341+
public val useGlobalPnpm: Provider<Boolean> = extension.useGlobalPnpm
339342
.convention(Constants.GLOBAL_PNPM_DEFAULT)
340343
.overrideWithSystemProperty(InitParameters.SERVLET_PARAMETER_GLOBAL_PNPM)
341344

342-
val requireHomeNodeExec: Property<Boolean> = extension.requireHomeNodeExec
345+
public val requireHomeNodeExec: Property<Boolean> = extension.requireHomeNodeExec
343346
.convention(false)
344347

345-
val eagerServerLoad: Provider<Boolean> = extension.eagerServerLoad
348+
public val eagerServerLoad: Provider<Boolean> = extension.eagerServerLoad
346349
.convention(false)
347350
.overrideWithSystemProperty("vaadin.eagerServerLoad")
348351

349-
val applicationProperties: Property<File> = extension.applicationProperties
352+
public val applicationProperties: Property<File> = extension.applicationProperties
350353
.convention(File(project.projectDir, "src/main/resources/application.properties"))
351354

352-
val openApiJsonFile: Property<File> = extension.openApiJsonFile
355+
public val openApiJsonFile: Property<File> = extension.openApiJsonFile
353356
.convention(project.layout.buildDirectory.file("generated-resources/openapi.json").asFile())
354357

355-
val javaSourceFolder: Property<File> = extension.javaSourceFolder
358+
public val javaSourceFolder: Property<File> = extension.javaSourceFolder
356359
.convention(File(project.projectDir, "src/main/java"))
357360

358-
val javaResourceFolder: Property<File> = extension.javaResourceFolder
361+
public val javaResourceFolder: Property<File> = extension.javaResourceFolder
359362
.convention(File(project.projectDir, "src/main/resources"))
360363

361-
val generatedTsFolder: Property<File> = extension.generatedTsFolder
364+
public val generatedTsFolder: Property<File> = extension.generatedTsFolder
362365
.convention(File(project.projectDir, "frontend/generated"))
363366

364-
val nodeVersion: Property<String> = extension.nodeVersion
367+
public val nodeVersion: Property<String> = extension.nodeVersion
365368
.convention(FrontendTools.DEFAULT_NODE_VERSION)
366369

367-
val nodeDownloadRoot: Property<String> = extension.nodeDownloadRoot
370+
public val nodeDownloadRoot: Property<String> = extension.nodeDownloadRoot
368371
.convention(Platform.guess().nodeDownloadRoot)
369372

370-
val nodeAutoUpdate: Property<Boolean> = extension.nodeAutoUpdate
373+
public val nodeAutoUpdate: Property<Boolean> = extension.nodeAutoUpdate
371374
.convention(false)
372375

373-
val resourceOutputDirectory: Property<File> = extension.resourceOutputDirectory
376+
public val resourceOutputDirectory: Property<File> = extension.resourceOutputDirectory
374377
.convention(project.layout.buildDirectory.dir("vaadin-generated").asFile())
375378

376-
val projectBuildDir: Property<String> = extension.projectBuildDir
379+
public val projectBuildDir: Property<String> = extension.projectBuildDir
377380
.convention(project.layout.buildDirectory.map { it.asFile.toString() })
378381

379-
val postinstallPackages: ListProperty<String> = extension.postinstallPackages
382+
public val postinstallPackages: ListProperty<String> = extension.postinstallPackages
380383
.convention(listOf())
381384

382-
val classpathFilter = extension.classpathFilter
385+
public val classpathFilter: ClasspathFilter = extension.classpathFilter
383386

384-
val dependencyScope: Property<String> = extension.dependencyScope
387+
public val dependencyScope: Property<String> = extension.dependencyScope
385388
.convention(sourceSetName.map {
386389
if (it == "main") {
387390
"runtimeClasspath"
@@ -390,7 +393,7 @@ internal class PluginEffectiveConfiguration(
390393
}
391394
})
392395

393-
val processResourcesTaskName: Property<String> = extension.processResourcesTaskName
396+
public val processResourcesTaskName: Property<String> = extension.processResourcesTaskName
394397
.convention(sourceSetName.map {
395398
if (it == "main") {
396399
"processResources"
@@ -399,29 +402,29 @@ internal class PluginEffectiveConfiguration(
399402
}
400403
})
401404

402-
val frontendHotdeploy: Provider<Boolean> = extension.frontendHotdeploy
405+
public val frontendHotdeploy: Provider<Boolean> = extension.frontendHotdeploy
403406
.convention(FrontendUtils.isHillaUsed(frontendDirectory.get()))
404407
.overrideWithSystemProperty(InitParameters.FRONTEND_HOTDEPLOY)
405408

406-
val ciBuild: Provider<Boolean> = extension.ciBuild
409+
public val ciBuild: Provider<Boolean> = extension.ciBuild
407410
.convention(false)
408411
.overrideWithSystemProperty(InitParameters.CI_BUILD)
409412

410-
val skipDevBundleBuild: Property<Boolean> = extension.skipDevBundleBuild
413+
public val skipDevBundleBuild: Property<Boolean> = extension.skipDevBundleBuild
411414
.convention(false)
412415

413-
val forceProductionBuild: Provider<Boolean> = extension.forceProductionBuild
416+
public val forceProductionBuild: Provider<Boolean> = extension.forceProductionBuild
414417
.convention(false)
415418
.overrideWithSystemProperty(InitParameters.FORCE_PRODUCTION_BUILD)
416419

417-
val alwaysExecutePrepareFrontend: Property<Boolean> = extension.alwaysExecutePrepareFrontend
420+
public val alwaysExecutePrepareFrontend: Property<Boolean> = extension.alwaysExecutePrepareFrontend
418421
.convention(false)
419422

420-
val reactEnable: Provider<Boolean> = extension.reactEnable
423+
public val reactEnable: Provider<Boolean> = extension.reactEnable
421424
.convention(FrontendUtils.isReactRouterRequired(frontendDirectory.get()))
422425
.overrideWithSystemProperty(InitParameters.REACT_ENABLE)
423426

424-
var cleanFrontendFiles: Property<Boolean> = extension.cleanFrontendFiles
427+
public val cleanFrontendFiles: Property<Boolean> = extension.cleanFrontendFiles
425428
.convention(true)
426429
/**
427430
* Finds the value of a boolean property. It searches in gradle and system properties.
@@ -436,7 +439,7 @@ internal class PluginEffectiveConfiguration(
436439
project.getBooleanProperty(propertyName) ?: originalValue
437440
}
438441

439-
override fun toString(): String = "VaadinFlowPluginExtension(" +
442+
override fun toString(): String = "PluginEffectiveConfiguration(" +
440443
"productionMode=${productionMode.get()}, " +
441444
"webpackOutputDirectory=${webpackOutputDirectory.get()}, " +
442445
"npmFolder=${npmFolder.get()}, " +
@@ -473,8 +476,8 @@ internal class PluginEffectiveConfiguration(
473476
"reactEnable=${reactEnable.get()}," +
474477
"cleanFrontendFiles=${cleanFrontendFiles.get()}" +
475478
")"
476-
companion object {
477-
internal fun get(project: Project): PluginEffectiveConfiguration =
479+
public companion object {
480+
public fun get(project: Project): PluginEffectiveConfiguration =
478481
PluginEffectiveConfiguration(project, VaadinFlowPluginExtension.get(project))
479482
}
480483
}

0 commit comments

Comments
 (0)