@@ -147,32 +147,35 @@ public List<String> styles(final String name) {
147147 public List <AssetProcessor > pipeline (final String dist ) {
148148 List <AssetProcessor > chain = this .pipeline .get (dist );
149149 if (chain == null ) {
150- throw new IllegalArgumentException ("No pipeline for: " + dist );
150+ log .debug ("no pipeline for: {}" , dist );
151+ return Collections .emptyList ();
151152 }
152153 return chain ;
153154 }
154155
155156 public Map <String , List <File >> build (final String dist , final File dir ) throws Exception {
156157 Map <String , List <File >> output = new LinkedHashMap <>();
158+ List <AssetProcessor > pipeline = pipeline (dist );
159+ log .info ("{} pipeline: {}" , dist , pipeline );
157160 for (String fset : keySet ()) {
158161 List <String > files = assets (fset );
159162
160- log .info ("compiling {}: " , fset );
163+ log .info ("compiling {}:" , fset );
161164
162- String css = compile (dist , files .stream ().filter (styles ).iterator (), MediaType .css , "" );
165+ String css = compile (pipeline , files .stream ().filter (styles ).iterator (), MediaType .css , "" );
163166 Path pcss = Paths .get (patterns (styles ).findFirst ().get (), fset + "." + sha1 (css ) + ".css" );
164167 File fcss = dir .toPath ().resolve (pcss ).toFile ();
165168 fcss .getParentFile ().mkdirs ();
166169 Files .write (css , fcss , charset );
167170
168- String js = compile (dist , files .stream ().filter (scripts ).iterator (), MediaType .js , ";" );
171+ String js = compile (pipeline , files .stream ().filter (scripts ).iterator (), MediaType .js , ";" );
169172 Path pjs = Paths .get (patterns (scripts ).findFirst ().get (), fset + "." + sha1 (js ) + ".js" );
170173 File fjs = dir .toPath ().resolve (pjs ).toFile ();
171174 fjs .getParentFile ().mkdirs ();
172175 Files .write (js , fjs , charset );
173176
174- log .info ("{}" , fcss );
175- log .info ("{}" , fjs );
177+ log .info ("{}.css {} ({})" , fset , humanReadableByteCount ( fcss . length ()) , fcss );
178+ log .info ("{}.js {} ({})" , fset , humanReadableByteCount ( fjs . length ()) , fjs );
176179
177180 output .put (fset , Arrays .asList (fcss , fjs ));
178181 }
@@ -196,7 +199,8 @@ public Asset build(final Asset asset) throws Exception {
196199 return asset ;
197200 }
198201
199- String output = compile ("dev" , filename , type , toString (asset .stream (), charset ));
202+ List <AssetProcessor > pipeline = pipeline ("dev" );
203+ String output = compile (pipeline , filename , type , toString (asset .stream (), charset ));
200204
201205 return new InMemoryAsset (asset , output .getBytes (charset ));
202206 }
@@ -214,22 +218,21 @@ private Stream<String> patterns(final Predicate<String> filter) {
214218
215219 }
216220
217- private String compile (final String env , final Iterator <String > files , final MediaType type ,
218- final String sep )
219- throws Exception {
221+ private String compile (final List <AssetProcessor > pipeline , final Iterator <String > files ,
222+ final MediaType type , final String sep ) throws Exception {
220223 StringBuilder buff = new StringBuilder ();
221224 while (files .hasNext ()) {
222225 String file = files .next ();
223226 log .info (" {}" , file );
224- buff .append (compile (env , file , type , readFile (loader , file , charset ))).append (sep );
227+ buff .append (compile (pipeline , file , type , readFile (loader , file , charset ))).append (sep );
225228 }
226229 return buff .toString ();
227230 }
228231
229- private String compile (final String env , final String filename , final MediaType type ,
230- final String input ) throws Exception {
232+ private String compile (final List < AssetProcessor > pipeline , final String filename ,
233+ final MediaType type , final String input ) throws Exception {
231234
232- Iterator <AssetProcessor > it = pipeline ( env ) .iterator ();
235+ Iterator <AssetProcessor > it = pipeline .iterator ();
233236 String contents = input ;
234237 while (it .hasNext ()) {
235238 AssetProcessor processor = it .next ();
@@ -430,4 +433,14 @@ private static String spath(final String path) {
430433 return path .startsWith ("/" ) ? path : "/" + path ;
431434 }
432435
436+ private static String humanReadableByteCount (final long bytes ) {
437+ int unit = 1024 ;
438+ if (bytes < unit ) {
439+ return bytes + "b" ;
440+ }
441+ int exp = (int ) (Math .log (bytes ) / Math .log (unit ));
442+ char pre = "kmgtpe" .charAt (exp - 1 );
443+ return String .format ("%.1f%sb" , bytes / Math .pow (unit , exp ), pre );
444+ }
445+
433446}
0 commit comments