Skip to content

Commit 3e991dd

Browse files
committed
enh: added reload goal
1 parent edc9a00 commit 3e991dd

4 files changed

Lines changed: 80 additions & 32 deletions

File tree

plugin/src/main/java/com/flowlogix/maven/plugins/CommonDevMojo.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package com.flowlogix.maven.plugins;
2020

21+
import lombok.Getter;
2122
import org.apache.maven.execution.MavenSession;
2223
import org.apache.maven.model.PluginExecution;
2324
import org.apache.maven.plugin.AbstractMojo;
@@ -28,6 +29,8 @@
2829
import org.codehaus.plexus.util.xml.Xpp3Dom;
2930
import org.jspecify.annotations.Nullable;
3031
import javax.inject.Inject;
32+
import java.nio.file.Path;
33+
import java.nio.file.Paths;
3134
import java.util.function.Consumer;
3235
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
3336
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
@@ -98,6 +101,15 @@ abstract class CommonDevMojo extends AbstractMojo {
98101
final Deployer deployer = new Deployer(this);
99102
final Watcher watcher = new Watcher(this);
100103

104+
@Getter(lazy = true)
105+
private final Path explodedWarDir = Paths.get(project.getBuild().getDirectory(), project.getBuild().getFinalName());
106+
@Getter(lazy = true)
107+
private final Path srcMainDir = Paths.get(project.getBasedir().getAbsolutePath(), "src", "main");
108+
@Getter(lazy = true)
109+
private final String baseURL = computeBaseURL();
110+
@Getter(lazy = true)
111+
private final String appURL = computeApplicationURL();
112+
101113
boolean callGenericMojo(String groupId, String artifactId, String goal,
102114
@Nullable String execution, MavenProject project, MavenSession session,
103115
BuildPluginManager pluginManager, Consumer<Xpp3Dom> configurator) {
@@ -188,4 +200,24 @@ boolean startAppServer() {
188200
getLog().info("Server already running");
189201
return false;
190202
}
203+
204+
boolean compileSources() {
205+
return callGenericMojo(ORG_APACHE_MAVEN_PLUGINS,
206+
"maven-compiler-plugin", "compile", null,
207+
project, session, pluginManager, config -> { });
208+
}
209+
210+
boolean explodedWar() {
211+
return callGenericMojo(ORG_APACHE_MAVEN_PLUGINS,
212+
"maven-war-plugin", "exploded", null,
213+
project, session, pluginManager, config -> { });
214+
}
215+
216+
private String computeBaseURL() {
217+
return serverAminURL.replaceFirst(":\\d+$", ":" + serverHttpPort);
218+
}
219+
220+
private String computeApplicationURL() {
221+
return "%s/%s".formatted(getBaseURL(), project.getBuild().getFinalName());
222+
}
191223
}

plugin/src/main/java/com/flowlogix/maven/plugins/DeployMojo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class DeployMojo extends CommonDevMojo {
3434

3535
@Override
3636
public void execute() throws MojoFailureException {
37+
getLog().info("Packaging application for deployment...");
38+
explodedWar();
39+
getLog().info("Application URL at " + getAppURL());
3740
getLog().info("Deploying application...");
3841
if (deployer.sendDeployCommand(deployer::printResponse, name, null) != CommandResult.SUCCESS) {
3942
throw new MojoFailureException("Deployment failed, see log for details.");

plugin/src/main/java/com/flowlogix/maven/plugins/DevModeMojo.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.flowlogix.maven.plugins;
2020

2121
import com.flowlogix.maven.plugins.Deployer.CommandResult;
22-
import lombok.Getter;
2322
import lombok.SneakyThrows;
2423
import org.apache.maven.plugins.annotations.Mojo;
2524
import org.apache.maven.plugins.annotations.Parameter;
@@ -28,7 +27,6 @@
2827
import java.io.IOException;
2928
import java.net.URI;
3029
import java.nio.file.Path;
31-
import java.nio.file.Paths;
3230
import java.util.List;
3331
import java.util.Map;
3432
import java.util.Set;
@@ -66,15 +64,6 @@ public class DevModeMojo extends CommonDevMojo {
6664
@Parameter(property = "additionalRepositories", defaultValue = "")
6765
List<String> additionalRepositories;
6866

69-
@Getter(lazy = true)
70-
private final Path explodedWarDir = Paths.get(project.getBuild().getDirectory(), project.getBuild().getFinalName());
71-
@Getter(lazy = true)
72-
private final Path srcMainDir = Paths.get(project.getBasedir().getAbsolutePath(), "src", "main");
73-
@Getter(lazy = true)
74-
private final String baseURL = computeBaseURL();
75-
@Getter(lazy = true)
76-
private final String appURL = computeApplicationURL();
77-
7867
@Override
7968
@SneakyThrows(IOException.class)
8069
public void execute() {
@@ -130,7 +119,7 @@ private void openBrowser() {
130119
}
131120

132121
private void deployLiveReloadHelper() {
133-
if (!deployer.pingWebsite("%s/%s/ping".formatted(baseURL, FLOWLOGIX_LIVERELOAD))) {
122+
if (!deployer.pingWebsite("%s/%s/ping".formatted(getBaseURL(), FLOWLOGIX_LIVERELOAD))) {
134123
getLog().info("Deploying LiveReload helper application");
135124
if (deployer.sendCommand("deploy-remote-archive", Map.of(
136125
"name", FLOWLOGIX_LIVERELOAD_HELPER_APP_NAME,
@@ -181,18 +170,6 @@ private void onChange(Set<Path> modifiedFiles) {
181170
}
182171
}
183172

184-
private boolean compileSources() {
185-
return callGenericMojo(ORG_APACHE_MAVEN_PLUGINS,
186-
"maven-compiler-plugin", "compile", null,
187-
project, session, pluginManager, config -> { });
188-
}
189-
190-
private boolean explodedWar() {
191-
return callGenericMojo(ORG_APACHE_MAVEN_PLUGINS,
192-
"maven-war-plugin", "exploded", null,
193-
project, session, pluginManager, config -> { });
194-
}
195-
196173
private boolean isSourceCode(Path path) {
197174
Path relativePath = project.getBasedir().toPath()
198175
.resolve("src/main").relativize(path);
@@ -202,12 +179,4 @@ private boolean isSourceCode(Path path) {
202179
private boolean isIgnoredFile(Path path) {
203180
return IGNORED_FILE_SUFFIXES.stream().anyMatch(path.toString()::endsWith);
204181
}
205-
206-
private String computeBaseURL() {
207-
return serverAminURL.replaceFirst(":\\d+$", ":" + serverHttpPort);
208-
}
209-
210-
private String computeApplicationURL() {
211-
return "%s/%s".formatted(getBaseURL(), project.getBuild().getFinalName());
212-
}
213182
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.flowlogix.maven.plugins;
20+
21+
import com.flowlogix.maven.plugins.Deployer.CommandResult;
22+
import org.apache.maven.plugin.MojoFailureException;
23+
import org.apache.maven.plugins.annotations.Mojo;
24+
25+
/**
26+
* Goal which reloads the application on the server.
27+
* Works for both Payara and GlassFish servers.
28+
*/
29+
@Mojo(name = "reload", requiresProject = false, threadSafe = true)
30+
public class ReloadMojo extends CommonDevMojo {
31+
@Override
32+
public void execute() throws MojoFailureException {
33+
getLog().info("Application URL at " + getAppURL());
34+
if (deployer.sendDisableCommand(deployer::printResponse) != CommandResult.SUCCESS) {
35+
throw new MojoFailureException("Application disable failed, see log for details.");
36+
}
37+
getLog().info("Packaging application for deployment...");
38+
explodedWar();
39+
if (deployer.sendEnableCommand(deployer::printResponse) != CommandResult.SUCCESS) {
40+
throw new MojoFailureException("Application enable failed, see log for details.");
41+
}
42+
getLog().info("Application reloaded.");
43+
}
44+
}

0 commit comments

Comments
 (0)