Skip to content

Commit 5f924af

Browse files
feffijknack
authored andcommitted
added swallowing of mkdir() return value (jooby-project#1152)
simplified lambdas simplified if/else removed unused throws clauses
1 parent 6b22052 commit 5f924af

File tree

8 files changed

+30
-39
lines changed

8 files changed

+30
-39
lines changed

modules/jooby-assets/src/main/java/org/jooby/assets/AssetCompiler.java

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,8 @@ public Set<String> fileset() {
353353
* @return Path pattern of the entire fileset.
354354
*/
355355
public Set<String> patterns() {
356-
return patterns(file -> !aggregators.stream()
357-
.filter(it -> it.fileset().contains(file))
358-
.findFirst().isPresent())
356+
return patterns(file -> aggregators.stream()
357+
.noneMatch(it -> it.fileset().contains(file)))
359358
.map(v -> "/" + v + "/**")
360359
.collect(Collectors.toCollection(LinkedHashSet::new));
361360
}
@@ -477,18 +476,17 @@ private Map<String, List<File>> buildInternal(final String dist, final File dir)
477476

478477
log.debug("compiling {}:", fset);
479478

480-
List<File> result = new ArrayList<>();
481479
/** CSS: */
482480
AssetWriter css = new AssetWriter(dist, fset, dir, ".css", "", charset, this.fileset, styles);
483481
count += compile(pipeline, files.stream().filter(styles).iterator(), MediaType.css, css,
484482
shouldProcess, count, total);
485-
css.getResult().forEach(result::add);
483+
List<File> result = new ArrayList<>(css.getResult());
486484

487485
/** JavaScript: */
488486
AssetWriter js = new AssetWriter(dist, fset, dir, ".js", ";", charset, this.fileset, scripts);
489487
count += compile(pipeline, files.stream().filter(scripts).iterator(), MediaType.js, js,
490488
shouldProcess, count, total);
491-
js.getResult().forEach(result::add);
489+
result.addAll(js.getResult());
492490

493491
result.forEach(
494492
it -> log.debug("{} {} ({})", it.getName(), humanReadableByteCount(it.length()), it));
@@ -532,8 +530,7 @@ public File buildOne(String filename, File dir) throws Exception {
532530
List<AssetProcessor> pipeline = pipeline(dist);
533531
compile(pipeline, ImmutableList.of(filename).iterator(), type, writer, path -> true, 0, 0);
534532

535-
File output = new File(dir, filename);
536-
return output;
533+
return new File(dir, filename);
537534
}
538535

539536
/**
@@ -677,8 +674,7 @@ private static String toString(final InputStream in, final Charset charset) thro
677674

678675
private static Predicate<String> predicate(final Config fileset, final String... extension) {
679676
String path = "assets" + extension[0];
680-
Set<String> extensions = new HashSet<>();
681-
extensions.addAll(Arrays.asList(extension));
677+
Set<String> extensions = new HashSet<>(Arrays.asList(extension));
682678
if (fileset.hasPath(path)) {
683679
extensions.addAll(strlist(fileset.getAnyRef(path)));
684680
}
@@ -707,27 +703,21 @@ private static Map<String, List<String>> fileset(final ClassLoader loader,
707703
.splitToList(unquote(e.getKey()));
708704
List<String> candidates = strlist(e.getValue().unwrapped(), v -> basedir + spath(v));
709705
List<String> values = new ArrayList<>();
710-
candidates.forEach(it -> {
711-
Try.run(() -> {
712-
processors(assetconf, loader, engineFactory, null, ImmutableList.of(it.substring(1)),
713-
ImmutableSet.of())
714-
.stream()
715-
.filter(AssetAggregator.class::isInstance)
716-
.forEach(p -> {
717-
AssetAggregator a = (AssetAggregator) p;
718-
aggregators.accept(a);
719-
a.fileset().forEach(f -> values.add(spath(f)));
720-
});
721-
}).onFailure(x -> values.add(it));
722-
});
706+
candidates.forEach(it -> Try.run(() -> processors(assetconf, loader, engineFactory, null, ImmutableList.of(it.substring(1)),
707+
ImmutableSet.of())
708+
.stream()
709+
.filter(AssetAggregator.class::isInstance)
710+
.forEach(p -> {
711+
AssetAggregator a = (AssetAggregator) p;
712+
aggregators.accept(a);
713+
a.fileset().forEach(f -> values.add(spath(f)));
714+
})).onFailure(x -> values.add(it)));
723715
raw.put(key.get(0), values);
724716
graph.put(key.get(0), key);
725717
});
726718

727719
Map<String, List<String>> resolved = new HashMap<>();
728-
graph.forEach((fs, deps) -> {
729-
resolve(fs, deps, raw, graph, resolved);
730-
});
720+
graph.forEach((fs, deps) -> resolve(fs, deps, raw, graph, resolved));
731721
return resolved;
732722
}
733723

@@ -757,7 +747,7 @@ private static Map<String, List<AssetProcessor>> pipeline(final ClassLoader load
757747
processors.put("dev", Collections.emptyList());
758748
if (conf.hasPath("pipeline")) {
759749
Set<String> filter = conf.getConfig("pipeline").entrySet().stream()
760-
.map(e -> e.getKey())
750+
.map(Entry::getKey)
761751
.collect(Collectors.toSet());
762752
filter.add("class");
763753
Set<Entry<String, ConfigValue>> entrySet = conf.getConfig("pipeline").entrySet();

modules/jooby-assets/src/main/java/org/jooby/assets/AssetOptions.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public AssetOptions set(final Config options) {
235235
return this;
236236
}
237237

238-
public Map<String, Object> options() throws Exception {
238+
public Map<String, Object> options() {
239239
return options.withoutPath("excludes").root().unwrapped();
240240
}
241241

@@ -254,9 +254,7 @@ public boolean excludes(final String path) {
254254
String spath = Route.normalize(path);
255255
return excludes.stream()
256256
.map(it -> new RoutePattern("GET", it))
257-
.filter(pattern -> pattern.matcher("GET" + spath).matches())
258-
.findFirst()
259-
.isPresent();
257+
.anyMatch(pattern -> pattern.matcher("GET" + spath).matches());
260258
}
261259

262260
@SuppressWarnings("unchecked")

modules/jooby-assets/src/main/java/org/jooby/assets/Props.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public boolean matches(final MediaType type) {
274274

275275
@Override
276276
public String process(final String filename, final String source, final Config conf,
277-
final ClassLoader loader) throws Exception {
277+
final ClassLoader loader) {
278278
try {
279279
Env env = Env.DEFAULT.build(conf);
280280
List<String> delims = get("delims");

modules/jooby-assets/src/main/java/org/jooby/assets/Replace.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ public class Replace extends AssetProcessor {
243243
return true;
244244
}
245245

246-
@Override public String process(String filename, String source, Config conf, ClassLoader loader)
247-
throws Exception {
246+
@Override public String process(String filename, String source, Config conf, ClassLoader loader) {
248247
Map<String, String> options = new LinkedHashMap<>();
249248
StringBuilder keys = new StringBuilder();
250249
this.options.withoutPath("excludes").entrySet().forEach(e -> {

modules/jooby-assets/src/main/java/org/jooby/internal/assets/AssetVars.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public AssetVars(final AssetCompiler compiler,
231231
}
232232

233233
@Override
234-
public void handle(final Request req, final Response rsp) throws Exception {
234+
public void handle(final Request req, final Response rsp) {
235235
compiler.fileset().forEach(asset -> {
236236
/** Styles */
237237
List<String> css = this.styles.apply(asset);

modules/jooby-assets/src/main/java/org/jooby/internal/assets/AssetWriter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ private String sha1(final CharSequence source) {
309309
}
310310

311311
private void writeFile(File output, String chunk) throws IOException {
312-
output.getParentFile().mkdirs();
312+
if (!output.getParentFile().exists()) {
313+
final boolean mkdirsResult = output.getParentFile().mkdirs();
314+
if (!mkdirsResult) {
315+
throw new IOException("Directory " + output.getCanonicalPath() + " could not be created!");
316+
}
317+
}
313318
try (PrintWriter writer = new PrintWriter(output, "UTF-8")) {
314319
writer.write(chunk);
315320
}

modules/jooby-assets/src/main/java/org/jooby/internal/assets/LiveCompiler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205

206206
import com.google.common.collect.Lists;
207207
import static java.util.Objects.requireNonNull;
208+
208209
import org.jooby.MediaType;
209210
import org.jooby.Request;
210211
import org.jooby.Response;

modules/jooby-assets/src/main/java/org/jooby/internal/assets/Watcher.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,7 @@ private boolean processEvents() {
349349
keys.remove(key);
350350

351351
// all directories are inaccessible
352-
if (keys.isEmpty()) {
353-
return false;
354-
}
352+
return !keys.isEmpty();
355353
}
356354
return true;
357355
}

0 commit comments

Comments
 (0)