Skip to content

Commit b6e0adc

Browse files
committed
enh: added watch mojo, compiling sources with deploy and reload
1 parent 5aa3b4f commit b6e0adc

4 files changed

Lines changed: 67 additions & 11 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222
import org.apache.maven.plugin.MojoFailureException;
2323
import org.apache.maven.plugins.annotations.Mojo;
2424
import org.apache.maven.plugins.annotations.Parameter;
25+
import org.apache.maven.plugins.annotations.ResolutionScope;
2526

2627
/**
2728
* Goal which deploys application to the server.
2829
* Works for both Payara and GlassFish servers.
2930
*/
30-
@Mojo(name = "deploy", requiresProject = false, threadSafe = true)
31+
@Mojo(name = "deploy", requiresProject = false, threadSafe = true,
32+
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
33+
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
3134
public class DeployMojo extends CommonDevMojo {
3235
@Parameter(property = "name")
3336
String name;
3437

3538
@Override
3639
public void execute() throws MojoFailureException {
3740
getLog().info("Packaging application for deployment...");
41+
compileSources();
3842
explodedWar();
3943
getLog().info("Application URL at " + getAppURL());
4044
getLog().info("Deploying application...");

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public class DevModeMojo extends CommonDevMojo {
5555
".swp", "~", ".tmp"
5656
);
5757

58+
protected boolean openBrowser = true;
59+
protected boolean deploy = true;
60+
5861
@Parameter(property = "livereload-helper-version", defaultValue = "1.0")
5962
String livereloadHelperVersion;
6063

@@ -72,11 +75,15 @@ public void execute() {
7275
return;
7376
}
7477

75-
getLog().info("Starting in dev mode, starting browser, monitoring %s for changes..."
76-
.formatted(getSrcMainDir()));
77-
getLog().info("Exploded WAR directory: " + getExplodedWarDir());
78+
if (openBrowser) {
79+
getLog().info("Starting in dev mode, starting browser, monitoring %s for changes..."
80+
.formatted(getSrcMainDir()));
81+
getLog().info("Exploded WAR directory: " + getExplodedWarDir());
82+
}
7883

79-
enableOrDeploy();
84+
if (deploy) {
85+
enableOrDeploy();
86+
}
8087
watcher.watch(getSrcMainDir(), this::onChange, watcherDelay);
8188
}
8289

@@ -96,11 +103,14 @@ private void enableOrDeploy() throws IOException {
96103
}
97104

98105
getLog().info("Application URL at " + getAppURL());
99-
getLog().info("App Server at %s".formatted(deployer.serverLocations().properties().baseRoot()));
100-
getLog().info("Domain at %s".formatted(deployer.serverLocations().properties().instanceRoot()));
101-
getLog().info("Logging at %s/logs/server.log".formatted(deployer.serverLocations().properties().instanceRoot()));
102-
getLog().info("Deps (optional) at %s/lib/warlibs/".formatted(deployer.serverLocations().properties().instanceRoot()));
103-
ForkJoinPool.commonPool().execute(this::openBrowser);
106+
if (openBrowser) {
107+
getLog().info("App Server at %s".formatted(deployer.serverLocations().properties().baseRoot()));
108+
getLog().info("Domain at %s".formatted(deployer.serverLocations().properties().instanceRoot()));
109+
getLog().info("Logging at %s/logs/server.log".formatted(deployer.serverLocations().properties().instanceRoot()));
110+
getLog().info("Deps (optional) at %s/lib/warlibs/".formatted(deployer.serverLocations().properties().instanceRoot()));
111+
ForkJoinPool.commonPool().execute(this::openBrowser);
112+
}
113+
104114
ForkJoinPool.commonPool().execute(this::deployLiveReloadHelper);
105115
}
106116

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
import com.flowlogix.maven.plugins.Deployer.CommandResult;
2222
import org.apache.maven.plugin.MojoFailureException;
2323
import org.apache.maven.plugins.annotations.Mojo;
24+
import org.apache.maven.plugins.annotations.ResolutionScope;
2425

2526
/**
2627
* Goal which reloads the application on the server.
2728
* Works for both Payara and GlassFish servers.
2829
*/
29-
@Mojo(name = "reload", requiresProject = false, threadSafe = true)
30+
@Mojo(name = "reload", requiresProject = false, threadSafe = true,
31+
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
32+
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
3033
public class ReloadMojo extends CommonDevMojo {
3134
@Override
3235
public void execute() throws MojoFailureException {
@@ -35,6 +38,7 @@ public void execute() throws MojoFailureException {
3538
throw new MojoFailureException("Application disable failed, see log for details.");
3639
}
3740
getLog().info("Packaging application for deployment...");
41+
compileSources();
3842
explodedWar();
3943
if (deployer.sendEnableCommand(deployer::printResponse) != CommandResult.SUCCESS) {
4044
throw new MojoFailureException("Application enable failed, see log for details.");
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 org.apache.maven.plugins.annotations.Mojo;
22+
import org.apache.maven.plugins.annotations.ResolutionScope;
23+
24+
/**
25+
* Goal which reloads the application on the server.
26+
* Works for both Payara and GlassFish servers.
27+
*/
28+
@Mojo(name = "watch", requiresProject = false, threadSafe = true,
29+
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
30+
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
31+
public class WatchMojo extends DevModeMojo {
32+
@Override
33+
public void execute() {
34+
openBrowser = false;
35+
deploy = false;
36+
super.execute();
37+
}
38+
}

0 commit comments

Comments
 (0)