Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 8c03f35

Browse files
feffijknack
authored andcommitted
fixed minor code issues (jooby-project#1170)
(cherry picked from commit 6cd8e98)
1 parent 00c7c8b commit 8c03f35

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

modules/jooby-gradle-plugin/src/main/java/org/jooby/run/AssetTask.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,8 @@ public void process() throws Throwable {
305305
String env = getEnv();
306306
this.assetFile = new File(getOutput(), "assets." + env + ".conf");
307307
new JoobyContainer(getProject())
308-
.run(getMainClassName(), (app, conf) -> {
309-
compile(getLogger(), app.getClass().getClassLoader(), env, getMaxAge(), getOutput(),
310-
assetFile, getAssemblyOutput(), conf);
311-
}, env);
308+
.run(getMainClassName(), (app, conf) -> compile(getLogger(), app.getClass().getClassLoader(), env, getMaxAge(), getOutput(),
309+
assetFile, getAssemblyOutput(), conf), env);
312310
} catch (CompilationDone ex) {
313311
// done
314312
}
@@ -364,7 +362,7 @@ private static void compile(final Logger logger, final ClassLoader loader,
364362

365363
// move output to fixed location required by zip/war dist
366364
List<File> files = fileset.values().stream()
367-
.flatMap(it -> it.stream())
365+
.flatMap(Collection::stream)
368366
.collect(Collectors.toList());
369367

370368
for (File from : files) {

modules/jooby-gradle-plugin/src/main/java/org/jooby/run/JoobyContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
*/
233233
public class JoobyContainer {
234234

235-
private JoobyProject project;
235+
private final JoobyProject project;
236236

237237
public JoobyContainer(final Project project) {
238238
this.project = new JoobyProject(project);

modules/jooby-gradle-plugin/src/main/java/org/jooby/run/JoobyProject.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234

235235
public class JoobyProject {
236236

237-
private Project project;
237+
private final Project project;
238238

239239
public JoobyProject(final Project project) {
240240
this.project = project;
@@ -254,17 +254,16 @@ public File classes() {
254254
public Set<File> classpath() {
255255
SourceSet sourceSet = sourceSet(project);
256256

257-
Set<File> cp = new LinkedHashSet<>();
258257
// conf & public
259-
sourceSet.getResources().getSrcDirs().forEach(cp::add);
258+
Set<File> cp = new LinkedHashSet<>(sourceSet.getResources().getSrcDirs());
260259

261260
// classes/main, resources/main + jars
262-
sourceSet.getRuntimeClasspath().getFiles().forEach(cp::add);
261+
cp.addAll(sourceSet.getRuntimeClasspath().getFiles());
263262

264263
// provided?
265264
Configuration provided = project.getConfigurations().findByName("provided");
266265
if (provided != null) {
267-
provided.getFiles().forEach(cp::add);
266+
cp.addAll(provided.getFiles());
268267
}
269268

270269
return cp;
@@ -273,9 +272,8 @@ public Set<File> classpath() {
273272
public Set<File> sources() {
274273
SourceSet sourceSet = sourceSet(project);
275274

276-
Set<File> src = new LinkedHashSet<>();
277275
// conf & public
278-
sourceSet.getResources().getSrcDirs().forEach(src::add);
276+
Set<File> src = new LinkedHashSet<>(sourceSet.getResources().getSrcDirs());
279277

280278
// source java: always add parent file: should be src/main
281279
sourceSet.getJava().getSrcDirs().forEach(f -> src.add(f.getParentFile()));
@@ -291,16 +289,15 @@ public File javaSrc() {
291289
}
292290

293291
private SourceSet sourceSet(final Project project) {
294-
SourceSet sourceSet = getJavaConvention(project).getSourceSets()
292+
return getJavaConvention(project).getSourceSets()
295293
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
296-
return sourceSet;
297294
}
298295

299296
public JavaPluginConvention getJavaConvention(final Project project) {
300297
return project.getConvention().getPlugin(JavaPluginConvention.class);
301298
}
302299

303-
public URLClassLoader newClassLoader() throws MalformedURLException {
300+
public URLClassLoader newClassLoader() {
304301
return toClassLoader(
305302
classpath().stream()
306303
.map(throwingFunction(f -> f.toURI().toURL()))

modules/jooby-gradle-plugin/src/main/java/org/jooby/run/JoobyTask.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,8 @@ public void run() throws Exception {
268268

269269
String mId = project.getName();
270270

271-
List<File> cp = new ArrayList<>();
272-
273271
// conf & public
274-
getClasspath().forEach(cp::add);
272+
List<File> cp = new ArrayList<>(getClasspath());
275273

276274
Main app = new Main(mId, getMainClassName(), toFiles(watchDirs),
277275
cp.toArray(new File[cp.size()]));
@@ -286,11 +284,7 @@ public void run() throws Exception {
286284
String compiler = getCompiler();
287285
getLogger().info("compiler is {}", compiler);
288286
if ("on".equalsIgnoreCase(compiler)) {
289-
Path[] watchDirs = getSrc().stream()
290-
.filter(File::exists)
291-
.map(File::toPath)
292-
.collect(Collectors.toList())
293-
.toArray(new Path[0]);
287+
Path[] watchDirs = getSrc().stream().filter(File::exists).map(File::toPath).toArray(Path[]::new);
294288
getLogger().info("watching directories {}", Arrays.asList(watchDirs));
295289

296290
connection = GradleConnector.newConnector()
@@ -304,16 +298,14 @@ public void run() throws Exception {
304298
runTask(connection, path, "classes");
305299
}
306300
}, watchDirs);
307-
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
308-
Try.run(() -> watcher.stop())
309-
.onComplete(() -> connection.close())
310-
.throwException();
311-
}));
301+
Runtime.getRuntime().addShutdownHook(new Thread(() -> Try.run(watcher::stop)
302+
.onComplete(() -> connection.close())
303+
.throwException()));
312304
watcher.start();
313305
}
314306

315307
String[] args = project.getGradle().getStartParameter().getProjectProperties()
316-
.entrySet().stream().map(e -> e.toString()).collect(Collectors.toList())
308+
.entrySet().stream().map(Object::toString).collect(Collectors.toList())
317309
.toArray(new String[0]);
318310
app.run(isBlock(), args);
319311
}

0 commit comments

Comments
 (0)