Skip to content

Commit c6f89bc

Browse files
committed
Add watch goal to automatically refresh app
1 parent 67b69c0 commit c6f89bc

22 files changed

+1010
-173
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 2.7.0 (2017-11-31)
2+
3+
* [new] Add watch goal which automatically refreshes the application when a source file change.
4+
15
# Version 2.6.4 (2017-10-19)
26

37
* [fix] Uninstall ansi console before exiting.

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
<groupId>org.seedstack</groupId>
2121
<artifactId>seedstack-maven-plugin</artifactId>
22-
<version>2.6.4-SNAPSHOT</version>
22+
<version>2.7.0-SNAPSHOT</version>
2323
<packaging>maven-plugin</packaging>
2424

2525
<properties>
@@ -90,16 +90,6 @@
9090
</execution>
9191
</executions>
9292
</plugin>
93-
<plugin>
94-
<groupId>org.codehaus.mojo</groupId>
95-
<artifactId>animal-sniffer-maven-plugin</artifactId>
96-
<executions>
97-
<execution>
98-
<id>check-java-1.6-compatibility</id>
99-
<phase>none</phase>
100-
</execution>
101-
</executions>
102-
</plugin>
10393
</plugins>
10494
</pluginManagement>
10595
<plugins>
@@ -239,6 +229,16 @@
239229
<artifactId>jackson-databind</artifactId>
240230
<version>${jackson.version}</version>
241231
</dependency>
232+
<dependency>
233+
<groupId>com.fasterxml.jackson.dataformat</groupId>
234+
<artifactId>jackson-dataformat-yaml</artifactId>
235+
<version>${jackson.version}</version>
236+
</dependency>
237+
<dependency>
238+
<groupId>asm</groupId>
239+
<artifactId>asm</artifactId>
240+
<version>3.3.1</version>
241+
</dependency>
242242
<dependency>
243243
<groupId>junit</groupId>
244244
<artifactId>junit</artifactId>

src/license/THIRD-PARTY.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# Please fill the missing licenses for dependencies :
1414
#
1515
#
16-
#Thu Oct 19 17:24:25 CEST 2017
16+
#Mon Nov 20 23:13:24 CET 2017
1717
classworlds--classworlds--1.1-alpha-2=
1818
commons-collections--commons-collections--3.1=
1919
dom4j--dom4j--1.6.1=

src/main/java/org/seedstack/maven/AbstractExecutableMojo.java

Lines changed: 74 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,63 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.maven;
910

1011
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11-
import org.apache.maven.artifact.Artifact;
12-
import org.apache.maven.model.Resource;
13-
import org.apache.maven.plugin.AbstractMojo;
14-
import org.apache.maven.plugin.MojoExecutionException;
15-
import org.apache.maven.plugin.MojoFailureException;
16-
import org.apache.maven.plugins.annotations.Parameter;
17-
import org.apache.maven.project.MavenProject;
18-
import org.codehaus.plexus.util.cli.CommandLineUtils;
19-
2012
import java.io.File;
2113
import java.net.MalformedURLException;
2214
import java.net.URL;
2315
import java.net.URLClassLoader;
16+
import java.security.AccessController;
17+
import java.security.PrivilegedAction;
2418
import java.util.ArrayList;
2519
import java.util.Collection;
2620
import java.util.List;
21+
import org.apache.maven.artifact.Artifact;
22+
import org.apache.maven.execution.MavenSession;
23+
import org.apache.maven.model.Resource;
24+
import org.apache.maven.plugin.BuildPluginManager;
25+
import org.apache.maven.plugin.MojoExecutionException;
26+
import org.apache.maven.plugin.MojoFailureException;
27+
import org.apache.maven.plugins.annotations.Component;
28+
import org.apache.maven.plugins.annotations.Parameter;
29+
import org.apache.maven.project.MavenProject;
30+
import org.codehaus.plexus.util.cli.CommandLineUtils;
2731

2832
/**
2933
* Provides a common base for mojos that run SeedStack applications.
3034
*/
31-
public class AbstractExecutableMojo extends AbstractSeedStackMojo {
32-
35+
public abstract class AbstractExecutableMojo extends AbstractSeedStackMojo {
3336
@Parameter(defaultValue = "${project}", required = true, readonly = true)
3437
private MavenProject project;
35-
38+
@Parameter(defaultValue = "${session}", required = true, readonly = true)
39+
private MavenSession mavenSession;
40+
@Component
41+
private BuildPluginManager buildPluginManager;
3642
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
3743
private File classesDirectory;
38-
3944
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
4045
private File testClassesDirectory;
41-
4246
@Parameter(property = "args")
4347
private String args;
44-
4548
private final IsolatedThreadGroup isolatedThreadGroup = new IsolatedThreadGroup("seed-app");
46-
4749
private final Object monitor = new Object();
4850

49-
private boolean testMode = false;
50-
51-
protected Runnable runnable;
52-
53-
@Override
54-
@SuppressFBWarnings(value = {"UW_UNCOND_WAIT", "WA_NOT_IN_LOOP"}, justification = "Cannot know when the application is started")
55-
public void execute() throws MojoExecutionException, MojoFailureException {
56-
// Create an isolated thread
57-
Thread bootstrapThread = new Thread(isolatedThreadGroup, runnable, "main");
58-
File[] classPathFiles = getClassPathFiles();
51+
@SuppressFBWarnings(value = {"UW_UNCOND_WAIT", "WA_NOT_IN_LOOP"}, justification = "Cannot know when the "
52+
+ "application is started")
53+
protected void execute(Runnable runnable, boolean testMode) throws MojoExecutionException, MojoFailureException {
54+
File[] classPathFiles = getClassPathFiles(testMode);
5955

6056
// Set the system property for proper detection of classpath
6157
System.setProperty("java.class.path", buildCpProperty(classPathFiles));
6258

6359
// Start the launcher thread
64-
bootstrapThread.setContextClassLoader(buildClassLoader(classPathFiles));
60+
ClassLoader classLoader = buildClassLoader(classPathFiles);
61+
62+
// Create an isolated thread
63+
Thread bootstrapThread = new Thread(isolatedThreadGroup, runnable, "main");
64+
bootstrapThread.setContextClassLoader(classLoader);
6565
bootstrapThread.start();
6666

6767
// Wait for the application to launch
@@ -76,12 +76,50 @@ public void execute() throws MojoExecutionException, MojoFailureException {
7676
// Check for any uncaught exception
7777
synchronized (isolatedThreadGroup) {
7878
if (isolatedThreadGroup.uncaughtException != null) {
79-
throw new MojoExecutionException("An exception occurred while executing Seed", isolatedThreadGroup.uncaughtException);
79+
throw new MojoExecutionException("An exception occurred while executing Seed",
80+
isolatedThreadGroup.uncaughtException);
8081
}
8182
}
83+
}
84+
85+
MavenSession getMavenSession() {
86+
return mavenSession;
87+
}
8288

83-
// Join the application non-daemon threads
84-
joinNonDaemonThreads(isolatedThreadGroup);
89+
BuildPluginManager getBuildPluginManager() {
90+
return buildPluginManager;
91+
}
92+
93+
MavenProject getProject() {
94+
return project;
95+
}
96+
97+
File getClassesDirectory() {
98+
return classesDirectory;
99+
}
100+
101+
File getTestClassesDirectory() {
102+
return testClassesDirectory;
103+
}
104+
105+
Object getMonitor() {
106+
return monitor;
107+
}
108+
109+
String[] getArgs() throws MojoExecutionException {
110+
try {
111+
return CommandLineUtils.translateCommandline(args);
112+
} catch (Exception e) {
113+
throw new MojoExecutionException("Failed to parse arguments", e);
114+
}
115+
}
116+
117+
URLClassLoader getClassLoader(final URL[] classPathUrls) {
118+
return AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
119+
public URLClassLoader run() {
120+
return new URLClassLoader(classPathUrls);
121+
}
122+
});
85123
}
86124

87125
private ClassLoader buildClassLoader(File[] classPathFiles) throws MojoExecutionException {
@@ -93,7 +131,7 @@ private ClassLoader buildClassLoader(File[] classPathFiles) throws MojoExecution
93131
throw new MojoExecutionException("Unable to create URL from " + classPathFiles[i]);
94132
}
95133
}
96-
return new URLClassLoader(classPathUrls);
134+
return getClassLoader(classPathUrls);
97135
}
98136

99137
private String buildCpProperty(File[] classPathFiles) {
@@ -108,29 +146,13 @@ private String buildCpProperty(File[] classPathFiles) {
108146
return stringBuilder.toString();
109147
}
110148

111-
protected void enableTestMode() {
112-
this.testMode = true;
113-
}
114-
115-
protected Object getMonitor() {
116-
return monitor;
117-
}
118-
119-
public String[] getArgs() throws MojoExecutionException {
120-
try {
121-
return CommandLineUtils.translateCommandline(args);
122-
} catch (Exception e) {
123-
throw new MojoExecutionException("Failed to parse arguments", e);
124-
}
125-
}
126-
127-
private void joinNonDaemonThreads(ThreadGroup threadGroup) {
149+
void waitForShutdown() {
128150
boolean found = true;
129151

130152
while (found) {
131153
found = false;
132154

133-
for (Thread groupThread : getGroupThreads(threadGroup)) {
155+
for (Thread groupThread : getGroupThreads(isolatedThreadGroup)) {
134156
if (!groupThread.isDaemon()) {
135157
found = true;
136158

@@ -158,7 +180,7 @@ private Thread[] getGroupThreads(final ThreadGroup group) {
158180
return java.util.Arrays.copyOf(threads, n);
159181
}
160182

161-
private File[] getClassPathFiles() throws MojoExecutionException {
183+
private File[] getClassPathFiles(boolean testMode) throws MojoExecutionException {
162184
List<File> files = new ArrayList<>();
163185

164186
try {
@@ -194,7 +216,8 @@ private void addArtifacts(Collection<Artifact> artifacts, List<File> files) thro
194216
}
195217
}
196218

197-
private void addResources(File classesDirectory, List<Resource> resources, List<File> files) throws MalformedURLException {
219+
private void addResources(File classesDirectory, List<Resource> resources,
220+
List<File> files) throws MalformedURLException {
198221
for (Resource resource : resources) {
199222
File directory = new File(resource.getDirectory());
200223
files.add(directory);

src/main/java/org/seedstack/maven/ConfigMojo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.maven;
910

1011
import org.apache.maven.plugin.MojoExecutionException;
@@ -16,14 +17,16 @@
1617
import org.seedstack.maven.runnables.ToolLauncherRunnable;
1718

1819
/**
19-
* Defines the config goal. This goal runs the config Seed tool which displays all configuration options for the application.
20+
* Defines the config goal. This goal runs the config Seed tool which displays all configuration options for the
21+
* application.
2022
*/
21-
@Mojo(name = "config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
23+
@Mojo(name = "config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE,
24+
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
2225
@Execute(phase = LifecyclePhase.PROCESS_CLASSES)
2326
public class ConfigMojo extends AbstractExecutableMojo {
2427
@Override
2528
public void execute() throws MojoExecutionException, MojoFailureException {
26-
runnable = new ToolLauncherRunnable("config", getArgs(), getMonitor(), getLog());
27-
super.execute();
29+
execute(new ToolLauncherRunnable("config", getArgs(), getMonitor(), getLog()), false);
30+
waitForShutdown();
2831
}
2932
}

src/main/java/org/seedstack/maven/CryptMojo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.maven;
910

1011
import org.apache.maven.plugin.MojoExecutionException;
@@ -19,12 +20,13 @@
1920
* Defines the crypt goal. This goal runs the crypt Seed tool which crypts the given argument using a key/pair in
2021
* the master keystore of the application.
2122
*/
22-
@Mojo(name = "crypt", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
23+
@Mojo(name = "crypt", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE,
24+
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
2325
@Execute(phase = LifecyclePhase.PROCESS_CLASSES)
2426
public class CryptMojo extends AbstractExecutableMojo {
2527
@Override
2628
public void execute() throws MojoExecutionException, MojoFailureException {
27-
runnable = new ToolLauncherRunnable("crypt", getArgs(), getMonitor(), getLog());
28-
super.execute();
29+
execute(new ToolLauncherRunnable("crypt", getArgs(), getMonitor(), getLog()), false);
30+
waitForShutdown();
2931
}
3032
}

src/main/java/org/seedstack/maven/EffectiveConfigMojo.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.maven;
910

1011
import org.apache.maven.plugin.MojoExecutionException;
@@ -16,15 +17,17 @@
1617
import org.seedstack.maven.runnables.ToolLauncherRunnable;
1718

1819
/**
19-
* Defines the effective-config goal. This goal runs the effective-config Seed tool which dumps the effective configuration of
20+
* Defines the effective-config goal. This goal runs the effective-config Seed tool which dumps the effective
21+
* configuration of
2022
* the application.
2123
*/
22-
@Mojo(name = "effective-config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
24+
@Mojo(name = "effective-config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE,
25+
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
2326
@Execute(phase = LifecyclePhase.PROCESS_CLASSES)
2427
public class EffectiveConfigMojo extends AbstractExecutableMojo {
2528
@Override
2629
public void execute() throws MojoExecutionException, MojoFailureException {
27-
runnable = new ToolLauncherRunnable("effective-config", getArgs(), getMonitor(), getLog());
28-
super.execute();
30+
execute(new ToolLauncherRunnable("effective-config", getArgs(), getMonitor(), getLog()), false);
31+
waitForShutdown();
2932
}
3033
}

src/main/java/org/seedstack/maven/EffectiveTestConfigMojo.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* License, v. 2.0. If a copy of the MPL was not distributed with this
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
8+
89
package org.seedstack.maven;
910

1011
import org.apache.maven.plugin.MojoExecutionException;
@@ -19,16 +20,13 @@
1920
* Defines the effective-test-config goal. This goal runs the effective-config Seed tool with the test classpath,
2021
* which dumps the effective test configuration.
2122
*/
22-
@Mojo(name = "effective-test-config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST)
23+
@Mojo(name = "effective-test-config", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase
24+
.VALIDATE, requiresDependencyResolution = ResolutionScope.TEST)
2325
@Execute(phase = LifecyclePhase.PROCESS_TEST_CLASSES)
2426
public class EffectiveTestConfigMojo extends AbstractExecutableMojo {
25-
public EffectiveTestConfigMojo() {
26-
enableTestMode();
27-
}
28-
2927
@Override
3028
public void execute() throws MojoExecutionException, MojoFailureException {
31-
runnable = new ToolLauncherRunnable("effective-config", getArgs(), getMonitor(), getLog());
32-
super.execute();
29+
execute(new ToolLauncherRunnable("effective-config", getArgs(), getMonitor(), getLog()), true);
30+
waitForShutdown();
3331
}
3432
}

src/main/java/org/seedstack/maven/PackageMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package org.seedstack.maven;
99

1010
import org.apache.maven.execution.MavenSession;
11-
import org.apache.maven.plugin.AbstractMojo;
1211
import org.apache.maven.plugin.BuildPluginManager;
1312
import org.apache.maven.plugin.MojoExecutionException;
1413
import org.apache.maven.plugin.MojoFailureException;
@@ -187,7 +186,7 @@ private JarOutputStream addManifest(JarOutputStream jar, Map<String, String> add
187186
mainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
188187
mainAttributes.put(Attributes.Name.MAIN_CLASS, SEEDSTACK_CAPLET_CLASS);
189188
mainAttributes.put(new Attributes.Name(PREMAIN_CLASS), SEEDSTACK_CAPLET_CLASS);
190-
mainAttributes.put(new Attributes.Name(APPLICATION_CLASS), SeedStackConstants.mainClassName);
189+
mainAttributes.put(new Attributes.Name(APPLICATION_CLASS), SeedStackUtils.mainClassName);
191190
mainAttributes.put(new Attributes.Name(APPLICATION_NAME), this.getOutputName());
192191

193192
if (allowSnapshots != null) {

0 commit comments

Comments
 (0)