Skip to content

Commit f94ef3d

Browse files
committed
Refactoring + java 9
1 parent 762439b commit f94ef3d

23 files changed

+640
-521
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sudo: false
22

33
language: java
44

5-
jdk: oraclejdk8
5+
jdk: oraclejdk9
66

77
cache:
88
directories: "$HOME/.m2/repository"

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Version 2.7.1 (2017-12-15)
1+
# Version 2.7.1 (2018-05-16)
22

3-
* [new] In watch goal, trigger a LiveReload (without app refresh) when a resource change.
3+
* [new] In watch goal, trigger a LiveReload (without app refresh) when a resource changes.
4+
* [chg] Java 9 compatibility: avoid using JDK internal classes for hot-reloading.
5+
* [fix] More reliable check for Cygwin environment.
46

57
# Version 2.7.0 (2017-11-31)
68

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<properties>
2626
<maven.version>3.3</maven.version>
27-
<plexus-component.version>1.6</plexus-component.version>
27+
<plexus-component.version>1.7.1</plexus-component.version>
2828
<maven.compiler.source>1.7</maven.compiler.source>
2929
<maven.compiler.target>1.7</maven.compiler.target>
3030

@@ -140,12 +140,12 @@
140140
<dependency>
141141
<groupId>org.fusesource.jansi</groupId>
142142
<artifactId>jansi</artifactId>
143-
<version>1.16</version>
143+
<version>1.17.1</version>
144144
</dependency>
145145
<dependency>
146146
<groupId>jline</groupId>
147147
<artifactId>jline</artifactId>
148-
<version>2.14.5</version>
148+
<version>2.14.6</version>
149149
</dependency>
150150
<dependency>
151151
<groupId>commons-collections</groupId>

src/license/THIRD-PARTY.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# Please fill the missing licenses for dependencies :
1414
#
1515
#
16-
#Sat Dec 09 19:25:38 CET 2017
16+
#Mon May 14 16:12:41 CEST 2018
1717
classworlds--classworlds--1.1-alpha-2=
18-
dom4j--dom4j--1.6.1=
18+
org.codehaus.plexus--plexus-container-default--1.0-alpha-9-stable-1=
1919
jdom--jdom--1.0=
2020
org.codehaus.plexus--plexus-component-api--1.0-alpha-16=
21-
org.codehaus.plexus--plexus-container-default--1.0-alpha-9-stable-1=
2221
org.codehaus.plexus--plexus-interactivity-api--1.0-alpha-6=
2322
oro--oro--2.0.8=
23+
dom4j--dom4j--1.6.1=

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

Lines changed: 48 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -19,133 +19,56 @@
1919
import java.util.Collection;
2020
import java.util.List;
2121
import org.apache.maven.artifact.Artifact;
22-
import org.apache.maven.execution.MavenSession;
2322
import org.apache.maven.model.Resource;
24-
import org.apache.maven.plugin.BuildPluginManager;
2523
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;
3124

3225
/**
3326
* Provides a common base for mojos that run SeedStack applications.
3427
*/
3528
public abstract class AbstractExecutableMojo extends AbstractSeedStackMojo {
36-
@Parameter(defaultValue = "${project}", required = true, readonly = true)
37-
private MavenProject project;
38-
@Parameter(defaultValue = "${session}", required = true, readonly = true)
39-
private MavenSession mavenSession;
40-
@Component
41-
private BuildPluginManager buildPluginManager;
42-
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
43-
private File classesDirectory;
44-
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
45-
private File testClassesDirectory;
46-
@Parameter(property = "args")
47-
private String args;
4829
private final IsolatedThreadGroup isolatedThreadGroup = new IsolatedThreadGroup("seed-app");
49-
private final Object monitor = new Object();
5030

5131
@SuppressFBWarnings(value = {"UW_UNCOND_WAIT", "WA_NOT_IN_LOOP"}, justification = "Cannot know when the "
5232
+ "application is started")
53-
protected void execute(Runnable runnable, boolean testMode) throws MojoExecutionException, MojoFailureException {
33+
protected void execute(Runnable runnable, boolean testMode) throws MojoExecutionException {
5434
File[] classPathFiles = getClassPathFiles(testMode);
5535

5636
// Set the system property for proper detection of classpath
5737
System.setProperty("java.class.path", buildCpProperty(classPathFiles));
5838

5939
// Start the launcher thread
60-
ClassLoader classLoader = buildClassLoader(classPathFiles);
40+
ClassLoader classLoader;
41+
try {
42+
classLoader = buildClassLoader(classPathFiles);
43+
} catch (MalformedURLException e) {
44+
throw new MojoExecutionException("Unable to build the classloader", e);
45+
}
6146

6247
// Create an isolated thread
6348
Thread bootstrapThread = new Thread(isolatedThreadGroup, runnable, "main");
6449
bootstrapThread.setContextClassLoader(classLoader);
6550
bootstrapThread.start();
6651

6752
// Wait for the application to launch
68-
synchronized (monitor) {
69-
try {
70-
monitor.wait();
71-
} catch (InterruptedException e) {
72-
throw new MojoExecutionException("Interrupted while waiting for Seed");
73-
}
74-
}
53+
getContext().waitForStartup();
7554

7655
// Check for any uncaught exception
7756
synchronized (isolatedThreadGroup) {
7857
if (isolatedThreadGroup.uncaughtException != null) {
79-
throw new MojoExecutionException("An exception occurred while executing Seed",
58+
throw new MojoExecutionException("An exception occurred while executing SeedStack application",
8059
isolatedThreadGroup.uncaughtException);
8160
}
8261
}
8362
}
8463

85-
MavenSession getMavenSession() {
86-
return mavenSession;
87-
}
88-
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) {
64+
URLClassLoader createClassLoader(final URL[] classPathUrls) {
11865
return AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
11966
public URLClassLoader run() {
12067
return new URLClassLoader(classPathUrls);
12168
}
12269
});
12370
}
12471

125-
private ClassLoader buildClassLoader(File[] classPathFiles) throws MojoExecutionException {
126-
URL[] classPathUrls = new URL[classPathFiles.length];
127-
for (int i = 0; i < classPathFiles.length; i++) {
128-
try {
129-
classPathUrls[i] = classPathFiles[i].toURI().toURL();
130-
} catch (MalformedURLException e) {
131-
throw new MojoExecutionException("Unable to create URL from " + classPathFiles[i]);
132-
}
133-
}
134-
return getClassLoader(classPathUrls);
135-
}
136-
137-
private String buildCpProperty(File[] classPathFiles) {
138-
StringBuilder stringBuilder = new StringBuilder();
139-
for (int i = 0; i < classPathFiles.length; i++) {
140-
File classPathFile = classPathFiles[i];
141-
stringBuilder.append(classPathFile);
142-
if (i < classPathFiles.length - 1) {
143-
stringBuilder.append(File.pathSeparator);
144-
}
145-
}
146-
return stringBuilder.toString();
147-
}
148-
14972
void waitForShutdown() {
15073
boolean found = true;
15174

@@ -180,34 +103,32 @@ private Thread[] getGroupThreads(final ThreadGroup group) {
180103
return java.util.Arrays.copyOf(threads, n);
181104
}
182105

183-
private File[] getClassPathFiles(boolean testMode) throws MojoExecutionException {
106+
private File[] getClassPathFiles(boolean testMode) {
184107
List<File> files = new ArrayList<>();
185108

186-
try {
187-
if (testMode) {
188-
// Project test resources
189-
addResources(this.testClassesDirectory, this.project.getTestResources(), files);
109+
if (testMode) {
110+
// Project test resources
111+
addResources(getContext().getTestClassesDirectory(),
112+
getContext().getMavenProject().getTestResources(),
113+
files);
190114

191-
// Project test classes
192-
files.add(this.testClassesDirectory);
193-
}
115+
// Project test classes
116+
files.add(getContext().getTestClassesDirectory());
117+
}
194118

195-
// Project resources
196-
addResources(this.classesDirectory, this.project.getResources(), files);
119+
// Project resources
120+
addResources(getContext().getClassesDirectory(), getContext().getMavenProject().getResources(), files);
197121

198-
// Project classes
199-
files.add(this.classesDirectory);
122+
// Project classes
123+
files.add(getContext().getClassesDirectory());
200124

201-
// Project dependencies (scope is dependent upon the @Mojo annotation and the already executed phase)
202-
addArtifacts(this.project.getArtifacts(), files);
203-
} catch (MalformedURLException e) {
204-
throw new MojoExecutionException("Unable to build classpath", e);
205-
}
125+
// Project dependencies (scope is dependent upon the @Mojo annotation and the already executed phase)
126+
addArtifacts(getContext().getMavenProject().getArtifacts(), files);
206127

207-
return files.toArray(new File[files.size()]);
128+
return files.toArray(new File[0]);
208129
}
209130

210-
private void addArtifacts(Collection<Artifact> artifacts, List<File> files) throws MalformedURLException {
131+
private void addArtifacts(Collection<Artifact> artifacts, List<File> files) {
211132
for (Artifact artifact : artifacts) {
212133
File file = artifact.getFile();
213134
if (file.getName().endsWith(".jar")) {
@@ -217,7 +138,7 @@ private void addArtifacts(Collection<Artifact> artifacts, List<File> files) thro
217138
}
218139

219140
private void addResources(File classesDirectory, List<Resource> resources,
220-
List<File> files) throws MalformedURLException {
141+
List<File> files) {
221142
for (Resource resource : resources) {
222143
File directory = new File(resource.getDirectory());
223144
files.add(directory);
@@ -246,6 +167,26 @@ private void removeDuplicatesFromOutputDirectory(File outputDirectory, File orig
246167
}
247168
}
248169

170+
private ClassLoader buildClassLoader(File[] classPathFiles) throws MalformedURLException {
171+
URL[] classPathUrls = new URL[classPathFiles.length];
172+
for (int i = 0; i < classPathFiles.length; i++) {
173+
classPathUrls[i] = classPathFiles[i].toURI().toURL();
174+
}
175+
return createClassLoader(classPathUrls);
176+
}
177+
178+
private String buildCpProperty(File[] classPathFiles) {
179+
StringBuilder stringBuilder = new StringBuilder();
180+
for (int i = 0; i < classPathFiles.length; i++) {
181+
File classPathFile = classPathFiles[i];
182+
stringBuilder.append(classPathFile);
183+
if (i < classPathFiles.length - 1) {
184+
stringBuilder.append(File.pathSeparator);
185+
}
186+
}
187+
return stringBuilder.toString();
188+
}
189+
249190
private class IsolatedThreadGroup extends ThreadGroup {
250191
private Throwable uncaughtException;
251192

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
package org.seedstack.maven;
1010

11+
import java.io.File;
12+
import org.apache.maven.execution.MavenSession;
1113
import org.apache.maven.plugin.AbstractMojo;
14+
import org.apache.maven.plugin.BuildPluginManager;
15+
import org.apache.maven.plugins.annotations.Component;
16+
import org.apache.maven.plugins.annotations.Parameter;
17+
import org.apache.maven.project.MavenProject;
18+
import org.codehaus.plexus.util.cli.CommandLineUtils;
1219
import org.fusesource.jansi.AnsiConsole;
1320

1421
abstract class AbstractSeedStackMojo extends AbstractMojo {
@@ -21,4 +28,37 @@ public void run() {
2128
}, "uninstall-ansi"));
2229
AnsiConsole.systemInstall();
2330
}
31+
32+
@Parameter(defaultValue = "${project}", required = true, readonly = true)
33+
private MavenProject mavenProject;
34+
@Parameter(defaultValue = "${session}", required = true, readonly = true)
35+
private MavenSession mavenSession;
36+
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
37+
private File classesDirectory;
38+
@Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
39+
private File testClassesDirectory;
40+
@Parameter(property = "args")
41+
private String args;
42+
@Component
43+
private BuildPluginManager buildPluginManager;
44+
private Context context;
45+
46+
public synchronized Context getContext() {
47+
if (context == null) {
48+
try {
49+
context = new Context(
50+
CommandLineUtils.translateCommandline(this.args),
51+
getLog(),
52+
classesDirectory,
53+
testClassesDirectory,
54+
mavenProject,
55+
mavenSession,
56+
buildPluginManager
57+
);
58+
} catch (Exception e) {
59+
throw new RuntimeException("Unable to create execution context", e);
60+
}
61+
}
62+
return context;
63+
}
2464
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.apache.maven.plugins.annotations.LifecyclePhase;
1515
import org.apache.maven.plugins.annotations.Mojo;
1616
import org.apache.maven.plugins.annotations.ResolutionScope;
17-
import org.seedstack.maven.runnables.ToolLauncherRunnable;
17+
import org.seedstack.maven.runnables.ToolRunnable;
1818

1919
/**
2020
* Defines the config goal. This goal runs the config Seed tool which displays all configuration options for the
@@ -26,7 +26,7 @@
2626
public class ConfigMojo extends AbstractExecutableMojo {
2727
@Override
2828
public void execute() throws MojoExecutionException, MojoFailureException {
29-
execute(new ToolLauncherRunnable("config", getArgs(), getMonitor(), getLog()), false);
29+
execute(new ToolRunnable("config", getContext()), false);
3030
waitForShutdown();
3131
}
3232
}

0 commit comments

Comments
 (0)