private int compile(final List<AssetProcessor> pipeline, final Iterator<String> files, final MediaType type, final AssetWriter writer, Predicate<String> process, int progress, int total) throws Exception { int count = 0; while (files.hasNext()) { String file = files.next(); if (process.test(file)) { String chunk = compile(pipeline, file, type, readFile(loader, file, charset)); writer.write(file, chunk); } else { writer.add(file); } count += 1; if (this.progress != null) { this.progress.accept(progress + count, total); } } return count; }
count += compile(pipeline, files.stream().filter(styles).iterator(), MediaType.css, css, shouldProcess, count, total); List<File> result = new ArrayList<>(css.getResult()); count += compile(pipeline, files.stream().filter(scripts).iterator(), MediaType.js, js, shouldProcess, count, total); result.addAll(js.getResult());
/** * Apply the processor pipeline to the given asset. Like {@link #build(String, File)} but for a * single file or asset. * * @param filename Asset to build. * @return Processed asset. * @throws Exception If something goes wrong. */ public File buildOne(String filename, File dir) throws Exception { String dist = "dev"; final MediaType type; AssetWriter writer; if (scripts.test(filename)) { type = MediaType.js; writer = new AssetWriter(dist, null, dir, ".js", ";", charset, this.fileset, scripts); } else if (styles.test(filename)) { type = MediaType.css; writer = new AssetWriter(dist, null, dir, ".css", "", charset, this.fileset, styles); } else { return null; } List<AssetProcessor> pipeline = pipeline(dist); compile(pipeline, ImmutableList.of(filename).iterator(), type, writer, path -> true, 0, 0); return new File(dir, filename); }
private int compile(final List<AssetProcessor> pipeline, final Iterator<String> files, final MediaType type, final AssetWriter writer, Predicate<String> process, int progress, int total) throws Exception { int count = 0; while (files.hasNext()) { String file = files.next(); if (process.test(file)) { String chunk = compile(pipeline, file, type, readFile(loader, file, charset)); writer.write(file, chunk); } else { writer.add(file); } count += 1; if (this.progress != null) { this.progress.accept(progress + count, total); } } return count; }
count += compile(pipeline, files.stream().filter(styles).iterator(), MediaType.css, css, shouldProcess, count, total); List<File> result = new ArrayList<>(css.getResult()); count += compile(pipeline, files.stream().filter(scripts).iterator(), MediaType.js, js, shouldProcess, count, total); result.addAll(js.getResult());
/** * Apply the processor pipeline to the given asset. Like {@link #build(String, File)} but for a * single file or asset. * * @param filename Asset to build. * @return Processed asset. * @throws Exception If something goes wrong. */ public File buildOne(String filename, File dir) throws Exception { String dist = "dev"; final MediaType type; AssetWriter writer; if (scripts.test(filename)) { type = MediaType.js; writer = new AssetWriter(dist, null, dir, ".js", ";", charset, this.fileset, scripts); } else if (styles.test(filename)) { type = MediaType.css; writer = new AssetWriter(dist, null, dir, ".css", "", charset, this.fileset, styles); } else { return null; } List<AssetProcessor> pipeline = pipeline(dist); compile(pipeline, ImmutableList.of(filename).iterator(), type, writer, path -> true, 0, 0); return new File(dir, filename); }