Skip to content

Commit b2aa08e

Browse files
authored
fix: instead of throwing, warn if legace frontend folder is used (#22370)
* fix: instead of throwing, warn if legace frontend folder is used * simplify; emphasize moving/removing contents * fix typo * fix test name * fix review comments
1 parent 4581460 commit b2aa08e

File tree

2 files changed

+48
-32
lines changed

2 files changed

+48
-32
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/FrontendUtils.java

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class FrontendUtils {
8585
/**
8686
* Default folder for the node related content. It's the base directory for
8787
* {@link Constants#PACKAGE_JSON} and {@link FrontendUtils#NODE_MODULES}.
88-
*
88+
* <p>
8989
* By default it's the project root folder.
9090
*/
9191
public static final String DEFAULT_NODE_DIR = "./";
@@ -111,7 +111,7 @@ public class FrontendUtils {
111111
/**
112112
* Path of the folder containing application frontend source files, it needs
113113
* to be relative to the {@link FrontendUtils#DEFAULT_NODE_DIR}
114-
*
114+
* <p>
115115
* By default it is <code>/src/main/frontend</code> in the project folder.
116116
*/
117117
public static final String DEFAULT_FRONTEND_DIR = DEFAULT_NODE_DIR
@@ -120,7 +120,7 @@ public class FrontendUtils {
120120
/**
121121
* Path of the old folder containing application frontend source files, it
122122
* needs to be relative to the {@link FrontendUtils#DEFAULT_NODE_DIR}
123-
*
123+
* <p>
124124
* By default the old folder is <code>/frontend</code> in the project
125125
* folder.
126126
*/
@@ -260,7 +260,7 @@ public class FrontendUtils {
260260
/**
261261
* A parameter for overriding the {@link FrontendUtils#DEFAULT_FRONTEND_DIR}
262262
* folder.
263-
*
263+
* <p>
264264
* NOTE: For internal use only.
265265
*/
266266
public static final String PARAM_FRONTEND_DIR = "vaadin.frontend.folder";
@@ -484,7 +484,6 @@ public static ProcessBuilder createProcessBuilder(List<String> command,
484484
* found.
485485
* @throws IOException
486486
* on error when reading file
487-
*
488487
*/
489488
public static String getIndexHtmlContent(VaadinService service)
490489
throws IOException {
@@ -507,7 +506,6 @@ public static String getIndexHtmlContent(VaadinService service)
507506
* not found.
508507
* @throws IOException
509508
* on error when reading file
510-
*
511509
*/
512510
public static String getWebComponentHtmlContent(VaadinService service)
513511
throws IOException {
@@ -646,28 +644,17 @@ public static File getFrontendFolder(File projectRoot, File frontendDir) {
646644
File legacyDir = new File(projectRoot, LEGACY_FRONTEND_DIR);
647645

648646
if (legacyDir.exists()) {
649-
boolean configParamPointsToLegacyDir = legacyDir.toPath().toString()
650-
.replace("./", "").equals(frontendDir.toPath().toString());
651-
if (configParamPointsToLegacyDir) {
652-
if (new File(projectRoot, DEFAULT_FRONTEND_DIR).exists()) {
653-
getLogger().warn(
654-
"This project has both default ({}) frontend directory"
655-
+ " and legacy ({})- frontend directory present, and "
656-
+ "'frontendDirectory' parameter points to the legacy directory."
657-
+ "\n\nDefault frontend directory will be ignored.",
658-
DEFAULT_FRONTEND_DIR, LEGACY_FRONTEND_DIR);
659-
}
660-
return frontendDir;
661-
} else {
662-
throw new RuntimeException(
663-
"This project has a legacy fronted directory ("
664-
+ LEGACY_FRONTEND_DIR
665-
+ ") frontend directory present, but no 'frontendDirectory' "
666-
+ "configuration parameter set. "
667-
+ "Please set the parameter or move the legacy directory contents "
668-
+ "to the default frontend folder ("
669-
+ DEFAULT_FRONTEND_DIR + ").");
670-
}
647+
getLogger().warn(
648+
"This project has a legacy frontend directory ({}) "
649+
+ "present and it will be used as a fallback."
650+
+ "\n\nSupport for the legacy directory will be removed "
651+
+ "in a future release. Please move its contents to "
652+
+ "the default frontend directory ({}), or delete it "
653+
+ "if its contents are not needed in the project. "
654+
+ "Also remove 'frontendDirectory' parameter that "
655+
+ "points to the legacy directory, if present.",
656+
LEGACY_FRONTEND_DIR, DEFAULT_FRONTEND_DIR);
657+
return legacyDir;
671658
}
672659

673660
// Legacy dir does not exist. Use default or custom-set dir.
@@ -754,7 +741,6 @@ private static String buildTooOldString(String tool, String version,
754741
*
755742
* @param configuration
756743
* the current deployment configuration
757-
*
758744
* @return {@link #DEFAULT_FRONTEND_DIR} or value of
759745
* {@link #PARAM_FRONTEND_DIR} if it is set.
760746
*/
@@ -955,14 +941,14 @@ public static String executeCommand(List<String> command,
955941

956942
/**
957943
* Reads input and error stream from the give process asynchronously.
958-
*
944+
* <p>
959945
* The method returns a {@link CompletableFuture} that is completed when
960946
* both the streams are consumed.
961-
*
947+
* <p>
962948
* Streams are converted into strings and wrapped into a {@link Pair},
963949
* mapping input stream into {@link Pair#getFirst()} and error stream into
964950
* {@link Pair#getSecond()}.
965-
*
951+
* <p>
966952
* This method should be mainly used to avoid that {@link Process#waitFor()}
967953
* hangs indefinitely on some operating systems because process streams are
968954
* not consumed. See https://github.com/vaadin/flow/issues/15339 for an

flow-server/src/test/java/com/vaadin/flow/server/DefaultDeploymentConfigurationTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,36 @@ public void productionModeTrue_frontendHotdeployTrue_frontendHotdeployReturnsFal
296296
config.isProductionMode());
297297
}
298298

299+
@Test
300+
public void hillaViewInLegacyFrontendFolderExists_shouldUseLegacyFolderAndHotdeploy()
301+
throws IOException {
302+
File projectRoot = tempFolder.getRoot();
303+
File legacyFrontend = tempFolder
304+
.newFolder(FrontendUtils.LEGACY_FRONTEND_DIR);
305+
306+
File legacyFrontendViews = new File(legacyFrontend,
307+
FrontendUtils.HILLA_VIEWS_PATH);
308+
if (!legacyFrontendViews.mkdir()) {
309+
Assert.fail("Failed to generate legacy frontend views folder");
310+
}
311+
312+
File viewFile = new File(legacyFrontendViews, "MyView.tsx");
313+
org.apache.commons.io.FileUtils.writeStringToFile(viewFile,
314+
"export default function MyView(){}", "UTF-8");
315+
316+
try (MockedStatic<EndpointRequestUtil> util = Mockito
317+
.mockStatic(EndpointRequestUtil.class)) {
318+
util.when(EndpointRequestUtil::isHillaAvailable).thenReturn(true);
319+
Properties init = new Properties();
320+
init.put(FrontendUtils.PROJECT_BASEDIR,
321+
projectRoot.getAbsolutePath());
322+
DefaultDeploymentConfiguration config = createDeploymentConfig(
323+
init);
324+
Assert.assertEquals("Should use the legacy frontend folder",
325+
Mode.DEVELOPMENT_FRONTEND_LIVERELOAD, config.getMode());
326+
}
327+
}
328+
299329
private DefaultDeploymentConfiguration createDeploymentConfig(
300330
Properties initParameters) {
301331
ApplicationConfiguration appConfig = setupAppConfig();

0 commit comments

Comments
 (0)