protected String postcss ( HttpServletRequest request , String css , IResource res ) throws IOException { if ( threadScopes == null ) { return css ; } Context cx = Context . enter ( ) ; Scriptable threadScope = null ; String result = null ; try { threadScope = threadScopes . poll ( SCOPE_POOL_TIMEOUT_SECONDS , TimeUnit . SECONDS ) ; if ( threadScope == null ) { throw new TimeoutException ( "Timeout waiting for thread scope" ) ; //$NON-NLS-1$ } Scriptable scope = cx . newObject ( threadScope ) ; scope . setParentScope ( threadScope ) ; Scriptable postcssInstance = ( Scriptable ) threadScope . get ( POSTCSS_INSTANCE , scope ) ; Function postcssProcessor = ( Function ) postcssInstance . getPrototype ( ) . get ( PROCESS , postcssInstance ) ; Object processed = postcssProcessor . call ( cx , scope , postcssInstance , new Object [ ] { css , postcssOptions } ) ; result = Context . toString ( processed ) ; } catch ( JavaScriptException e ) { // Add module info String message = "Error parsing " + res . getURI ( ) + "\r\n" + e . getMessage ( ) ; //$NON-NLS-1$ //$NON-NLS-2$ throw new IOException ( message , e ) ; } catch ( InterruptedException e ) { throw new RuntimeException ( e ) ; } catch ( TimeoutException e ) { throw new RuntimeException ( e ) ; } finally { if ( threadScope != null ) { // put the thread scope back in the queue now that we're done with it threadScopes . add ( threadScope ) ; } Context . exit ( ) ; } return result ; }
Runs given CSS through PostCSS processor for minification and any other processing by configured plugins .