Skip to content

Commit 32a6215

Browse files
authored
feat: add hotdeploy option (#15769)
Add the possibility to enable frontend hotdeploy using plugin configuration. Closes #15765
1 parent 74f3e0c commit 32a6215

File tree

7 files changed

+38
-6
lines changed

7 files changed

+38
-6
lines changed

flow-plugins/flow-dev-bundle-plugin/src/main/java/com/vaadin/flow/plugin/maven/BuildDevBundleMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public class BuildDevBundleMojo extends AbstractMojo
140140
* Whether vaadin home node executable usage is forced. If it's set to
141141
* {@code true} then vaadin home 'node' is checked and installed if it's
142142
* absent. Then it will be used instead of globally 'node' or locally
143-
* installed installed 'node'.
143+
* installed 'node'.
144144
*/
145145
@Parameter(property = InitParameters.REQUIRE_HOME_NODE_EXECUTABLE, defaultValue = ""
146146
+ Constants.DEFAULT_REQUIRE_HOME_NODE_EXECUTABLE)
@@ -398,4 +398,8 @@ public List<String> postinstallPackages() {
398398
return postinstallPackages;
399399
}
400400

401+
@Override
402+
public boolean isFrontendHotdeploy() {
403+
return false;
404+
}
401405
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,6 @@ internal class GradlePluginAdapter(val project: Project, private val isBeforePro
181181
return extension.projectBuildDir
182182
}
183183
override fun postinstallPackages(): List<String> = extension.postinstallPackages
184+
185+
override fun isFrontendHotdeploy(): Boolean = extension.frontendHotdeploy
184186
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ public open class VaadinFlowPluginExtension(project: Project) {
210210
*/
211211
public var processResourcesTaskName : String? = null
212212

213+
/**
214+
* Parameter to control if frontend development server should be used in
215+
* development mode or not.
216+
*/
217+
public var frontendHotdeploy: Boolean = false
218+
213219
public fun filterClasspath(@DelegatesTo(value = ClasspathFilter::class, strategy = Closure.DELEGATE_FIRST) block: Closure<*>? = null): ClasspathFilter {
214220
if (block != null) {
215221
block.delegate = classpathFilter

flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
214214
@Parameter(property = "npm.postinstallPackages", defaultValue = "")
215215
private List<String> postinstallPackages;
216216

217+
/**
218+
* Parameter to control if frontend development server should be used in
219+
* development mode or not.
220+
* <p>
221+
* By default, the frontend server is not used.
222+
*/
223+
@Parameter(property = InitParameters.FRONTEND_HOTDEPLOY, defaultValue = "false")
224+
private boolean frontendHotdeploy;
225+
217226
/**
218227
* Generates a List of ClasspathElements (Run and CompileTime) from a
219228
* MavenProject.
@@ -428,4 +437,9 @@ public String buildFolder() {
428437
public List<String> postinstallPackages() {
429438
return postinstallPackages;
430439
}
440+
441+
@Override
442+
public boolean isFrontendHotdeploy() {
443+
return frontendHotdeploy;
444+
}
431445
}

flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/PrepareFrontendMojoTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,27 @@ public void setup() throws Exception {
146146
}
147147

148148
@Test
149-
public void tokenFileShouldExist_noDevModeTokenVisible()
149+
public void tokenFileShouldExist_noHotdeployTokenVisible()
150150
throws IOException, MojoExecutionException, MojoFailureException {
151151
mojo.execute();
152152
Assert.assertTrue("No token file could be found", tokenFile.exists());
153153

154154
String json = org.apache.commons.io.FileUtils
155155
.readFileToString(tokenFile, "UTF-8");
156156
JsonObject buildInfo = JsonUtil.parse(json);
157-
Assert.assertNull("No devMode token should be available",
157+
Assert.assertNull("Default HotDeploy token should not be available",
158158
buildInfo.get(FRONTEND_HOTDEPLOY));
159159
Assert.assertNotNull("productionMode token should be available",
160160
buildInfo.get(SERVLET_PARAMETER_PRODUCTION_MODE));
161161
}
162162

163163
@Test
164-
public void existingTokenFile_frontendHotdeployShouldBeRemoved()
164+
public void existingTokenFile_defaultFrontendHotdeployShouldBeRemoved()
165165
throws IOException, MojoExecutionException, MojoFailureException {
166166

167167
JsonObject initialBuildInfo = Json.createObject();
168168
initialBuildInfo.put(SERVLET_PARAMETER_PRODUCTION_MODE, false);
169-
initialBuildInfo.put(FRONTEND_HOTDEPLOY, false);
169+
initialBuildInfo.put(FRONTEND_HOTDEPLOY, true);
170170
org.apache.commons.io.FileUtils.forceMkdir(tokenFile.getParentFile());
171171
org.apache.commons.io.FileUtils.write(tokenFile,
172172
JsonUtil.stringify(initialBuildInfo, 2) + "\n", "UTF-8");
@@ -176,7 +176,7 @@ public void existingTokenFile_frontendHotdeployShouldBeRemoved()
176176
String json = org.apache.commons.io.FileUtils
177177
.readFileToString(tokenFile, "UTF-8");
178178
JsonObject buildInfo = JsonUtil.parse(json);
179-
Assert.assertNull("No devMode token should be available",
179+
Assert.assertNull("Default hotdeploy should not be added",
180180
buildInfo.get(FRONTEND_HOTDEPLOY));
181181
Assert.assertNotNull("productionMode token should be available",
182182
buildInfo.get(SERVLET_PARAMETER_PRODUCTION_MODE));

flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/BuildFrontendUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static com.vaadin.flow.server.Constants.NPM_TOKEN;
2525
import static com.vaadin.flow.server.Constants.PACKAGE_JSON;
2626
import static com.vaadin.flow.server.Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN;
27+
import static com.vaadin.flow.server.InitParameters.FRONTEND_HOTDEPLOY;
2728
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
2829
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
2930
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_INITIAL_UIDL;
@@ -226,6 +227,9 @@ public static File propagateBuildInfo(PluginAdapterBase adapter) {
226227
adapter.eagerServerLoad());
227228
buildInfo.put(NPM_TOKEN, adapter.npmFolder().getAbsolutePath());
228229
buildInfo.put(NODE_VERSION, adapter.nodeVersion());
230+
if (adapter.isFrontendHotdeploy()) {
231+
buildInfo.put(FRONTEND_HOTDEPLOY, adapter.isFrontendHotdeploy());
232+
}
229233
try {
230234
buildInfo.put(NODE_DOWNLOAD_ROOT,
231235
adapter.nodeDownloadRoot().toString());
@@ -643,6 +647,7 @@ public static void updateBuildFile(PluginAdapterBuild adapter) {
643647
buildInfo.remove(NODE_DOWNLOAD_ROOT);
644648
buildInfo.remove(GENERATED_TOKEN);
645649
buildInfo.remove(FRONTEND_TOKEN);
650+
buildInfo.remove(FRONTEND_HOTDEPLOY);
646651
buildInfo.remove(InitParameters.SERVLET_PARAMETER_ENABLE_PNPM);
647652
buildInfo.remove(InitParameters.REQUIRE_HOME_NODE_EXECUTABLE);
648653
buildInfo.remove(

flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/PluginAdapterBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,5 @@ default Lookup createLookup(ClassFinder classFinder) {
281281
*/
282282
List<String> postinstallPackages();
283283

284+
boolean isFrontendHotdeploy();
284285
}

0 commit comments

Comments
 (0)