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

fix: Gradle frontend folder handling #18862

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading