AssetCompiler compiler = new AssetCompiler(loader, assetConf); compiler.setProgressBar((progress, total) -> { if (pb.get() == null) { pb.set(new ProgressBar("Compiling assets", total).start().stepTo(progress)); Map<String, List<File>> fileset = compiler.build(env, output); pb.get().stop(); .summary(fileset, output.toPath(), env, end - start, " " + assemblyOutput, "Assets: " + distFile); logger.info(summary.toString());
/** * Build assets using the given distribution and write output to the provided directory. * * Build process is defined as follow: * * 1. First, it runs all the aggregators (if any) * 2. Then iterates each fileset and per each file in the fileset it apply the processor pipeline. * 3. Finally, it merge all the files into one file and compressed/optimized if need it. * * @param dist Distribution's name (usually dev or dist). * @param dir Output directory. * @return Map with fileset name as key and list of generated assets. * @throws Exception If something goes wrong. */ public Map<String, List<File>> build(final String dist, final File dir) throws Exception { log.debug("{} aggregators: {}", dist, aggregators); aggregators(aggregators, conf); return buildInternal(dist, dir); }
/** * Get all the javascript (or derived) for the provided fileset. Example: * * <pre> * { * assets { * fileset { * mypage: [mypage.js, mypage.css] * } * } * } * </pre> * * <p> * This method returns <code>mypage.js</code> for <code>mypage</code> fileset. * </p> * * @param fileset Fileset name. * @return All the scripts for a fileset. */ public List<String> scripts(final String fileset) { return assets(fileset) .stream() .filter(scripts) .collect(Collectors.toList()); }
@SuppressWarnings("unchecked") private static <T extends AssetOptions> List<T> processors(final Config conf, final ClassLoader loader, final EngineFactory engineFactory, final String env, final List<String> names, final Set<String> filter) throws Exception { Map<String, Class<AssetOptions>> classes = new LinkedHashMap<>(); for (Entry<String, String> entry : bind(conf, names).entrySet()) { classes.put(entry.getKey(), (Class<AssetOptions>) loader.loadClass(entry.getValue())); } return (List<T>) processors(conf, loader, engineFactory, env, filter, classes); }
String cpath = config.getString("application.path"); ClassLoader assetClassLoader = AssetClassLoader.classLoader(loader); AssetCompiler compiler = new AssetCompiler(assetClassLoader, conf); compiler.setProgressBar(progressBar); Future<Map<String, List<File>>> future = liveCompiler.sync(); env.onStarted(() -> { long end = System.currentTimeMillis(); log.info("{}", compiler .summary(result, workdir, "dev", end - start)); compiler.patterns().forEach(pattern -> routes.get(pattern, handler));
private void onChange(final Kind<?> kind, final Path path) { File outputdir = workdir.toFile(); String filename = Route .normalize(Try.apply(() -> path.subpath(1, path.getNameCount()).toString()) .orElse(path.toString())); try { if (kind == StandardWatchEventKinds.ENTRY_DELETE) { errors.remove(filename); } else { if (Files.isDirectory(path)) { errors.clear(); compiler.build("dev", outputdir); } else { compiler.buildOne(filename, outputdir); errors.remove(filename); } } } catch (AssetException ex) { String localname = ex.getProblems().stream() .findFirst() .map(AssetProblem::getFilename) .orElse(filename); errors.put(localname, rewrite(ex)); } catch (Exception ex) { AssetException assetEx = rewrite(new AssetException("compiler", new AssetProblem(filename, -1, -1, ex.getMessage(), null), ex)); errors.put(filename, assetEx); } }
public Future<Map<String, List<File>>> sync() { return executor.submit(() -> compiler.build("dev", workdir.toFile())); }
String cpath = config.getString("application.path"); ClassLoader assetClassLoader = AssetClassLoader.classLoader(loader); AssetCompiler compiler = new AssetCompiler(assetClassLoader, conf); compiler.setProgressBar(progressBar); Future<Map<String, List<File>>> future = liveCompiler.sync(); env.onStarted(() -> { long end = System.currentTimeMillis(); log.info("{}", compiler .summary(result, workdir, "dev", end - start)); compiler.patterns().forEach(pattern -> routes.get(pattern, handler));
private void onChange(final Kind<?> kind, final Path path) { File outputdir = workdir.toFile(); String filename = Route .normalize(Try.apply(() -> path.subpath(1, path.getNameCount()).toString()) .orElse(path.toString())); try { if (kind == StandardWatchEventKinds.ENTRY_DELETE) { errors.remove(filename); } else { if (Files.isDirectory(path)) { errors.clear(); compiler.build("dev", outputdir); } else { compiler.buildOne(filename, outputdir); errors.remove(filename); } } } catch (AssetException ex) { String localname = ex.getProblems().stream() .findFirst() .map(AssetProblem::getFilename) .orElse(filename); errors.put(localname, rewrite(ex)); } catch (Exception ex) { AssetException assetEx = rewrite(new AssetException("compiler", new AssetProblem(filename, -1, -1, ex.getMessage(), null), ex)); errors.put(filename, assetEx); } }
public Future<Map<String, List<File>>> sync() { return executor.submit(() -> compiler.build("dev", workdir.toFile())); }
@SuppressWarnings("unchecked") private static <T extends AssetOptions> List<T> processors(final Config conf, final ClassLoader loader, final EngineFactory engineFactory, final String env, final List<String> names, final Set<String> filter) throws Exception { Map<String, Class<AssetOptions>> classes = new LinkedHashMap<>(); for (Entry<String, String> entry : bind(conf, names).entrySet()) { classes.put(entry.getKey(), (Class<AssetOptions>) loader.loadClass(entry.getValue())); } return (List<T>) processors(conf, loader, engineFactory, env, filter, classes); }
AssetCompiler compiler = new AssetCompiler(assetLoader, assetConf); compiler.setProgressBar((progress, total) -> { if (pb.get() == null) { pb.set(new ProgressBar("Compiling assets", total).start().stepTo(progress)); Map<String, List<File>> fileset = compiler.build(env, output); pb.get().stop(); StringBuilder dist = new StringBuilder(); .summary(fileset, output.toPath(), env, end - start, " " + assemblyOutput, "Assets: " + distFile); getLog().info(summary); Files.copy(from, to); compiler.stop(); } catch (InvocationTargetException ex) { throw Throwing.sneakyThrow(ex.getCause());
/** * Build assets using the given distribution and write output to the provided directory. * * Build process is defined as follow: * * 1. First, it runs all the aggregators (if any) * 2. Then iterates each fileset and per each file in the fileset it apply the processor pipeline. * 3. Finally, it merge all the files into one file and compressed/optimized if need it. * * @param dist Distribution's name (usually dev or dist). * @param dir Output directory. * @return Map with fileset name as key and list of generated assets. * @throws Exception If something goes wrong. */ public Map<String, List<File>> build(final String dist, final File dir) throws Exception { log.debug("{} aggregators: {}", dist, aggregators); aggregators(aggregators, conf); return buildInternal(dist, dir); }
/** * Get all the css files (or derived) for the provided fileset. Example: * * <pre> * { * assets { * fileset { * mypage: [mypage.js, mypage.css] * } * } * } * </pre> * * <p> * This method returns <code>mypage.js</code> for <code>mypage</code> fileset. * </p> * * @param fileset Fileset name. * @return All the scripts for a fileset. */ public List<String> styles(final String fileset) { return assets(fileset) .stream() .filter(styles) .collect(Collectors.toList()); }
/** * Get all the javascript (or derived) for the provided fileset. Example: * * <pre> * { * assets { * fileset { * mypage: [mypage.js, mypage.css] * } * } * } * </pre> * * <p> * This method returns <code>mypage.js</code> for <code>mypage</code> fileset. * </p> * * @param fileset Fileset name. * @return All the scripts for a fileset. */ public List<String> scripts(final String fileset) { return assets(fileset) .stream() .filter(scripts) .collect(Collectors.toList()); }
/** * Get all the css files (or derived) for the provided fileset. Example: * * <pre> * { * assets { * fileset { * mypage: [mypage.js, mypage.css] * } * } * } * </pre> * * <p> * This method returns <code>mypage.js</code> for <code>mypage</code> fileset. * </p> * * @param fileset Fileset name. * @return All the scripts for a fileset. */ public List<String> styles(final String fileset) { return assets(fileset) .stream() .filter(styles) .collect(Collectors.toList()); }