Skip to content

Commit 8b43655

Browse files
committed
Jooby Run: javadoc+checkstyle
1 parent aea5148 commit 8b43655

File tree

10 files changed

+218
-98
lines changed

10 files changed

+218
-98
lines changed

modules/jooby-gradle-plugin/src/main/java/io/jooby/gradle/JoobyPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
package io.jooby.gradle;
77

8-
import io.jooby.run.JoobyRunConf;
8+
import io.jooby.run.JoobyRunOptions;
99
import org.gradle.api.Plugin;
1010
import org.gradle.api.Project;
1111
import org.gradle.api.Task;
@@ -15,7 +15,7 @@
1515

1616
public class JoobyPlugin implements Plugin<Project> {
1717
@Override public void apply(Project project) {
18-
project.getExtensions().create("joobyRun", JoobyRunConf.class);
18+
project.getExtensions().create("joobyRun", JoobyRunOptions.class);
1919

2020
Map<String, Object> options = new HashMap<>();
2121
options.put(Task.TASK_TYPE, RunTask.class);

modules/jooby-gradle-plugin/src/main/java/io/jooby/gradle/RunTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package io.jooby.gradle;
77

88
import io.jooby.run.JoobyRun;
9-
import io.jooby.run.JoobyRunConf;
9+
import io.jooby.run.JoobyRunOptions;
1010
import org.gradle.api.DefaultTask;
1111
import org.gradle.api.Project;
1212
import org.gradle.api.artifacts.Configuration;
@@ -45,7 +45,7 @@ public class RunTask extends DefaultTask {
4545
public void run() throws Throwable {
4646
try {
4747
Project current = getProject();
48-
JoobyRunConf config = current.getExtensions().getByType(JoobyRunConf.class);
48+
JoobyRunOptions config = current.getExtensions().getByType(JoobyRunOptions.class);
4949
List<Project> projects = Arrays.asList(current);
5050

5151
if (config.getMainClass() == null) {

modules/jooby-maven-plugin/src/main/java/io/jooby/maven/RunMojo.java

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

88
import edu.emory.mathcs.backport.java.util.Collections;
99
import io.jooby.run.JoobyRun;
10-
import io.jooby.run.JoobyRunConf;
10+
import io.jooby.run.JoobyRunOptions;
1111
import org.apache.maven.Maven;
1212
import org.apache.maven.execution.DefaultMavenExecutionRequest;
1313
import org.apache.maven.execution.MavenExecutionRequest;
@@ -145,8 +145,8 @@ public class RunMojo extends AbstractMojo {
145145
}
146146
}
147147

148-
private JoobyRunConf createOptions() {
149-
JoobyRunConf options = new JoobyRunConf();
148+
private JoobyRunOptions createOptions() {
149+
JoobyRunOptions options = new JoobyRunOptions();
150150
options.setMainClass(mainClass);
151151
options.setCompileExtensions(compileExtensions);
152152
options.setPort(port);

modules/jooby-maven-plugin/src/test/java/io/jooby/maven/RunMojoTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.jooby.maven;
22

3-
import io.jooby.run.JoobyRunConf;
3+
import io.jooby.run.JoobyRunOptions;
44
import org.junit.jupiter.api.Test;
55

66
import java.lang.reflect.Field;
@@ -12,7 +12,7 @@ public class RunMojoTest {
1212

1313
@Test
1414
public void ensureConfigurationOptions() {
15-
Stream.of(JoobyRunConf.class.getDeclaredFields())
15+
Stream.of(JoobyRunOptions.class.getDeclaredFields())
1616
.filter(field -> !field.getName().equals("projectName"))
1717
.forEach(field -> {
1818
try {

modules/jooby-run/src/main/java/io/jooby/run/FlattenClasspath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class FlattenClasspath implements ModuleFinder {
2020
private final Set<Path> resources;
2121
private final String name;
2222

23-
public FlattenClasspath(String name, Set<Path> resources, Set<Path> dependencies) {
23+
FlattenClasspath(String name, Set<Path> resources, Set<Path> dependencies) {
2424
this.name = name;
2525
this.resources = new LinkedHashSet<>(resources.size() + dependencies.size());
2626
this.resources.addAll(resources);

modules/jooby-run/src/main/java/io/jooby/run/JoobyRun.java

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@
2626
import java.util.Set;
2727
import java.util.function.BiConsumer;
2828

29+
/**
30+
* Allow to restart an application on file changes. This lets client to listen for file changes
31+
* and trigger a restart.
32+
*
33+
* This class doesn't compile source code. Instead, let a client (Maven/Gradle) to listen for
34+
* changes, fire a compilation process and restart the application once compilation finished.
35+
*
36+
* @author edgar
37+
* @since 2.0.0
38+
*/
2939
public class JoobyRun {
3040

3141
private static class ExtModuleLoader extends ModuleLoader {
3242

33-
public ExtModuleLoader(ModuleFinder... finders) {
43+
ExtModuleLoader(ModuleFinder... finders) {
3444
super(finders);
3545
}
3646

@@ -42,13 +52,13 @@ public void unload(String name, final Module module) {
4252
private static class AppModule {
4353
private final Logger logger;
4454
private final ExtModuleLoader loader;
45-
private final JoobyRunConf conf;
55+
private final JoobyRunOptions conf;
4656
private Module module;
4757
private ClassLoader contextClassLoader;
4858
private int counter;
4959

50-
public AppModule(Logger logger, ExtModuleLoader loader, ClassLoader contextClassLoader,
51-
JoobyRunConf conf) {
60+
AppModule(Logger logger, ExtModuleLoader loader, ClassLoader contextClassLoader,
61+
JoobyRunOptions conf) {
5262
this.logger = logger;
5363
this.loader = loader;
5464
this.conf = conf;
@@ -116,7 +126,7 @@ private void closeServer() {
116126

117127
private final Logger logger = LoggerFactory.getLogger(getClass());
118128

119-
private final JoobyRunConf conf;
129+
private final JoobyRunOptions options;
120130

121131
private final Set<Path> resources = new LinkedHashSet<>();
122132

@@ -128,10 +138,24 @@ private void closeServer() {
128138

129139
private AppModule module;
130140

131-
public JoobyRun(JoobyRunConf conf) {
132-
this.conf = conf;
141+
/**
142+
* Creates a new instances with the given options.
143+
*
144+
* @param options Run options.
145+
*/
146+
public JoobyRun(JoobyRunOptions options) {
147+
this.options = options;
133148
}
134149

150+
/**
151+
* Add the given path to the project classpath. Path must be a jar or file system directory.
152+
* File system directory are listen for changes on file changes this method invokes the given
153+
* callback.
154+
*
155+
* @param path Path.
156+
* @param callback Callback to listen for file changes.
157+
* @return True if the path was added it to the classpath.
158+
*/
135159
public boolean addResource(Path path, BiConsumer<String, Path> callback) {
136160
if (addResource(path)) {
137161
if (Files.isDirectory(path)) {
@@ -142,6 +166,12 @@ public boolean addResource(Path path, BiConsumer<String, Path> callback) {
142166
return false;
143167
}
144168

169+
/**
170+
* Add the given path to the project classpath. Path must be a jar or file system directory.
171+
*
172+
* @param path Path.
173+
* @return True if the path was added it to the classpath.
174+
*/
145175
public boolean addResource(Path path) {
146176
if (Files.exists(path)) {
147177
if (path.toString().endsWith(".jar")) {
@@ -154,27 +184,39 @@ public boolean addResource(Path path) {
154184
return false;
155185
}
156186

187+
/**
188+
* Start the application.
189+
*
190+
* @throws Exception If something goes wrong.
191+
*/
157192
public void start() throws Exception {
158193
this.watcher = newWatcher();
159194
try {
160195
logger.debug("project: {}", toString());
161196

162197
ModuleFinder[] finders = {
163-
new FlattenClasspath(conf.getProjectName(), resources, dependencies)};
198+
new FlattenClasspath(options.getProjectName(), resources, dependencies)};
164199

165200
ExtModuleLoader loader = new ExtModuleLoader(finders);
166-
module = new AppModule(logger, loader, Thread.currentThread().getContextClassLoader(), conf);
201+
module = new AppModule(logger, loader, Thread.currentThread().getContextClassLoader(),
202+
options);
167203
module.start();
168204
watcher.watch();
169205
} catch (ClosedWatchServiceException expected) {
170206
logger.trace("Watcher.close resulted in exception", expected);
171207
}
172208
}
173209

210+
/**
211+
* Restart the application.
212+
*/
174213
public void restart() {
175214
module.restart();
176215
}
177216

217+
/**
218+
* Stop and shutdown the application.
219+
*/
178220
public void shutdown() {
179221
if (module != null) {
180222
module.close();
@@ -203,7 +245,7 @@ private DirectoryWatcher newWatcher() throws IOException {
203245

204246
@Override public String toString() {
205247
StringBuilder buff = new StringBuilder();
206-
buff.append(conf.getProjectName()).append("\n");
248+
buff.append(options.getProjectName()).append("\n");
207249
buff.append(" watch-dirs: ").append("\n");
208250
watchDirs.forEach(
209251
(path, callback) -> buff.append(" ").append(path.toAbsolutePath()).append("\n"));

modules/jooby-run/src/main/java/io/jooby/run/JoobyRunConf.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)