@Test public void computeSkinFileWhenException() throws Exception { LESSResourceReference resource = mock(LESSSkinFileResourceReference.class); when(resource.getContent(eq("skin"))).thenReturn("Some LESS content"); when(xwiki.evaluateVelocity(eq("Some LESS content"), eq("SomeContextDocument"))). thenReturn("Some Velocity-rendered LESS content"); Less4jException lessCompilerException = mock(Less4jException.class); when(less4jCompiler.compile(eq("Some Velocity-rendered LESS content"), eq("skin"), eq(false))). thenThrow(lessCompilerException); LESSCompilerException caughtException = null; try { mocker.getComponentUnderTest().compute(resource, false, true, true, "skin"); } catch(LESSCompilerException e) { caughtException = e; } assertNotNull(caughtException); assertEquals(lessCompilerException, caughtException.getCause()); assertEquals("Failed to compile the resource ["+resource.toString()+"] with LESS.", caughtException.getMessage()); }
@Override public String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean useLESS, String skin) throws LESSCompilerException { StringWriter source = new StringWriter(); try { semaphore.acquire(); if (lessResourceReference instanceof LESSSkinFileResourceReference || includeSkinStyle) { if (includeSkinStyle) { source.write(String.format("@import (reference) \"%s\";%s", MAIN_SKIN_STYLE_FILENAME, System.lineSeparator())); } source.write(lessResourceReference.getContent(skin)); } String lessCode = source.toString(); if (useVelocity) { lessCode = executeVelocity(lessCode, skin); } if (useLESS) { return less4JCompiler.compile(lessCode, skin, lessConfiguration.isGenerateInlineSourceMaps()); } return lessCode; } catch (Less4jException | InterruptedException e) { throw new LESSCompilerException(String.format("Failed to compile the resource [%s] with LESS.", lessResourceReference), e); } finally { semaphore.release(); } }
CachedLESSCompiler implements CachedCompilerInterface<String>, Initializable { @Override public String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean useLESS, String skin) throws LESSCompilerException { StringWriter source = new StringWriter(); try { semaphore.acquire(); if (lessResourceReference instanceof LESSSkinFileResourceReference || includeSkinStyle) { if (includeSkinStyle) { source.write(String.format("@import (reference) \"%s\";%s", MAIN_SKIN_STYLE_FILENAME, System.lineSeparator())); } source.write(lessResourceReference.getContent(skin)); } String lessCode = source.toString(); if (useVelocity) { lessCode = executeVelocity(lessCode, skin); } if (useLESS) { return less4JCompiler.compile(lessCode, skin, lessConfiguration.isGenerateInlineSourceMaps()); } return lessCode; } catch (Less4jException | InterruptedException e) { throw new LESSCompilerException(String.format("Failed to compile the resource [%s] with LESS.", lessResourceReference), e); } finally { semaphore.release(); } } }
CachedLESSCompiler implements CachedCompilerInterface<String>, Initializable { @Override public String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean useLESS, String skin) throws LESSCompilerException { StringWriter source = new StringWriter(); try { semaphore.acquire(); if (lessResourceReference instanceof LESSSkinFileResourceReference || includeSkinStyle) { if (includeSkinStyle) { source.write(String.format("@import (reference) \"%s\";%s", MAIN_SKIN_STYLE_FILENAME, System.lineSeparator())); } source.write(lessResourceReference.getContent(skin)); } String lessCode = source.toString(); if (useVelocity) { lessCode = executeVelocity(lessCode, skin); } if (useLESS) { return less4JCompiler.compile(lessCode, skin, lessConfiguration.isGenerateInlineSourceMaps()); } return lessCode; } catch (Less4jException | InterruptedException e) { throw new LESSCompilerException(String.format("Failed to compile the resource [%s] with LESS.", lessResourceReference), e); } finally { semaphore.release(); } }  }
CachedLESSCompiler implements CachedCompilerInterface<String>, Initializable { @Override public String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean useLESS, String skin) throws LESSCompilerException { StringWriter source = new StringWriter(); try { semaphore.acquire(); if (lessResourceReference instanceof LESSSkinFileResourceReference || includeSkinStyle) { if (includeSkinStyle) { source.write(String.format("@import (reference) \"%s\";%s", MAIN_SKIN_STYLE_FILENAME, System.lineSeparator())); } source.write(lessResourceReference.getContent(skin)); } String lessCode = source.toString(); if (useVelocity) { lessCode = executeVelocity(lessCode, skin); } if (useLESS) { return less4JCompiler.compile(lessCode, skin, lessConfiguration.isGenerateInlineSourceMaps()); } return lessCode; } catch (Less4jException | InterruptedException e) { throw new LESSCompilerException(String.format("Failed to compile the resource [%s] with LESS.", lessResourceReference), e); } finally { semaphore.release(); } }  @Override void initialize(); @Override String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,
        boolean useLESS, String skin); }
CachedLESSCompiler implements CachedCompilerInterface<String>, Initializable { @Override public String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity, boolean useLESS, String skin) throws LESSCompilerException { StringWriter source = new StringWriter(); try { semaphore.acquire(); if (lessResourceReference instanceof LESSSkinFileResourceReference || includeSkinStyle) { if (includeSkinStyle) { source.write(String.format("@import (reference) \"%s\";%s", MAIN_SKIN_STYLE_FILENAME, System.lineSeparator())); } source.write(lessResourceReference.getContent(skin)); } String lessCode = source.toString(); if (useVelocity) { lessCode = executeVelocity(lessCode, skin); } if (useLESS) { return less4JCompiler.compile(lessCode, skin, lessConfiguration.isGenerateInlineSourceMaps()); } return lessCode; } catch (Less4jException | InterruptedException e) { throw new LESSCompilerException(String.format("Failed to compile the resource [%s] with LESS.", lessResourceReference), e); } finally { semaphore.release(); } }  @Override void initialize(); @Override String compute(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,
        boolean useLESS, String skin); static final String MAIN_SKIN_STYLE_FILENAME; }