Skip to content

Commit

Permalink
fix: Gradle frontend folder handling
Browse files Browse the repository at this point in the history
Closes #18859
  • Loading branch information
caalador committed Mar 1, 2024
1 parent 8fc9cd9 commit 12118da
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.gradle

import com.vaadin.flow.plugin.base.BuildFrontendUtil
import com.vaadin.flow.server.Constants
import com.vaadin.flow.server.frontend.FrontendUtils
import org.gradle.api.Project
Expand Down Expand Up @@ -70,8 +71,8 @@ internal class PrepareFrontendOutputProperties(
}

@OutputDirectory
public fun getGeneratedTsFolder(): Property<File> =
config.generatedTsFolder
public fun getGeneratedTsFolder(): File =
BuildFrontendUtil.getGeneratedFrontendDirectory(GradlePluginAdapter(project, config, true))

@OutputDirectory
public fun getResourceOutputDirectory(): Property<File> = config.resourceOutputDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public open class VaadinBuildFrontendTask : DefaultTask() {
check(tokenFile.exists()) { "token file $tokenFile doesn't exist!" }

val cleanTask = TaskCleanFrontendFiles(config.npmFolder.get(),
config.frontendDirectory.get(), adapter.classFinder
BuildFrontendUtil.getGeneratedFrontendDirectory(adapter), adapter.classFinder
)
BuildFrontendUtil.runNodeUpdater(adapter)

Expand Down Expand Up @@ -105,7 +105,7 @@ public open class VaadinBuildFrontendTask : DefaultTask() {
*/
protected open fun cleanFrontendFiles(): Boolean {
val adapter = GradlePluginAdapter(project, config, false)
if (FrontendUtils.isHillaUsed(adapter.frontendDirectory(),
if (FrontendUtils.isHillaUsed(BuildFrontendUtil.getGeneratedFrontendDirectory(adapter),
adapter.classFinder)) {
/*
* Override this to not clean generated frontend files after the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.gradle

import com.vaadin.flow.plugin.base.BuildFrontendUtil
import com.vaadin.flow.server.Constants
import com.vaadin.flow.server.InitParameters
import com.vaadin.flow.server.frontend.FrontendTools
Expand Down Expand Up @@ -421,7 +422,7 @@ public class PluginEffectiveConfiguration(
.convention(false)

public val reactEnable: Provider<Boolean> = extension.reactEnable
.convention(FrontendUtils.isReactRouterRequired(frontendDirectory.get()))
.convention(FrontendUtils.isReactRouterRequired(BuildFrontendUtil.getGeneratedFrontendDirectory(GradlePluginAdapter(project, this, true))))
.overrideWithSystemProperty(InitParameters.REACT_ENABLE)

public val cleanFrontendFiles: Property<Boolean> = extension.cleanFrontendFiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.gradle.api.Task
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.TaskAction
import kotlin.math.log

/**
* This task checks that node and npm tools are installed, copies frontend
Expand Down Expand Up @@ -58,9 +59,9 @@ public open class VaadinPrepareFrontendTask : DefaultTask() {
@TaskAction
public fun vaadinPrepareFrontend() {
// Remove Frontend/generated folder to get clean files copied/generated
project.delete(config.generatedTsFolder)
logger.info("Running the vaadinPrepareFrontend task with effective configuration $config")
val adapter = GradlePluginAdapter(project, config, true)
project.delete(BuildFrontendUtil.getGeneratedFrontendDirectory(adapter))
logger.debug("Running the vaadinPrepareFrontend task with effective configuration $config")
val tokenFile = BuildFrontendUtil.propagateBuildInfo(adapter)

logger.info("Generated token file $tokenFile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public static void runDevBuildNodeUpdater(PluginAdapterBuild adapter)
* PluginAdapterBase
* @return correct folder or legacy folder if not user defined
*/
private static File getFrontendDirectory(PluginAdapterBase adapter) {
public static File getFrontendDirectory(PluginAdapterBase adapter) {
File frontendDir = adapter.frontendDirectory();
if (!frontendDir.exists() && frontendDir.toPath()
.endsWith(DEFAULT_FRONTEND_DIR.substring(2))) {
Expand All @@ -440,7 +440,7 @@ private static File getFrontendDirectory(PluginAdapterBase adapter) {
* PluginAdapterBase
* @return correct generated folder as child to frontend
*/
private static File getGeneratedFrontendDirectory(
public static File getGeneratedFrontendDirectory(
PluginAdapterBase adapter) {
if (adapter.generatedTsFolder().toPath()
.startsWith(adapter.frontendDirectory().toPath())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,9 @@ public static DevModeHandler initDevModeHandler(Set<Class<?>> classes,
InitParameters.ADDITIONAL_POSTINSTALL_PACKAGES, "")
.split(",");

String frontendGeneratedFolderName = config
.getStringProperty(PROJECT_FRONTEND_GENERATED_DIR_TOKEN,
Paths.get(baseDir.getAbsolutePath(),
DEFAULT_PROJECT_FRONTEND_GENERATED_DIR)
.toString());
String frontendGeneratedFolderName = config.getStringProperty(
PROJECT_FRONTEND_GENERATED_DIR_TOKEN,
Paths.get(frontendFolder, GENERATED).toString());
File frontendGeneratedFolder = new File(frontendGeneratedFolderName);
File jarFrontendResourcesFolder = new File(frontendGeneratedFolder,
FrontendUtils.JAR_RESOURCES_FOLDER);
Expand Down

0 comments on commit 12118da

Please sign in to comment.