Search in sources :

Example 11 with LESSCompilerException

use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.

the class LessCompilerScriptServiceTest method compileSkinFileWithOtherSkinWhenException.

@Test
public void compileSkinFileWithOtherSkinWhenException() throws Exception {
    // Mocks
    LESSResourceReference style = mock(LESSResourceReference.class);
    when(lessResourceReferenceFactory.createReferenceForSkinFile("style.less")).thenReturn(style);
    Exception exception = new LESSCompilerException("Exception with LESS", null);
    when(lessCompiler.compile(style, false, true, "flamingo", false)).thenThrow(exception);
    // Test
    String result = mocker.getComponentUnderTest().compileSkinFile("style.less", "flamingo", false);
    // Verify
    assertEquals("LESSCompilerException: Exception with LESS", result);
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 12 with LESSCompilerException

use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.

the class LessCompilerScriptServiceTest method compileSkinFileWhenException.

@Test
public void compileSkinFileWhenException() throws Exception {
    // Mocks
    LESSResourceReference style = mock(LESSResourceReference.class);
    when(lessResourceReferenceFactory.createReferenceForSkinFile("style.less")).thenReturn(style);
    Exception exception = new LESSCompilerException("Exception with LESS", null);
    when(lessCompiler.compile(style, false, true, false)).thenThrow(exception);
    // Test
    String result = mocker.getComponentUnderTest().compileSkinFile("style.less", false);
    // Verify
    assertEquals("LESSCompilerException: Exception with LESS", result);
}
Also used : LESSResourceReference(org.xwiki.lesscss.resources.LESSResourceReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 13 with LESSCompilerException

use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.

the class LessCompilerScriptServiceTest method getColorThemeFromSkinFileWithException.

@Test
public void getColorThemeFromSkinFileWithException() throws Exception {
    // Mocks
    Exception exception = new LESSCompilerException("Exception with LESS", null);
    when(lessColorThemeConverter.getColorThemeFromSkinFile("style.less", false)).thenThrow(exception);
    // Test
    ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("style.less");
    // Verify
    assertEquals(0, result.size());
}
Also used : ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 14 with LESSCompilerException

use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.

the class LessCompilerScriptServiceTest method getColorThemeFromSkinFileWithOtherSkinAndException.

@Test
public void getColorThemeFromSkinFileWithOtherSkinAndException() throws Exception {
    // Mocks
    Exception exception = new LESSCompilerException("Exception with LESS", null);
    when(lessColorThemeConverter.getColorThemeFromSkinFile("style.less", "flamingo", false)).thenThrow(exception);
    // Test
    ColorTheme result = mocker.getComponentUnderTest().getColorThemeFromSkinFile("style.less", "flamingo");
    // Verify
    assertEquals(0, result.size());
}
Also used : ColorTheme(org.xwiki.lesscss.internal.colortheme.ColorTheme) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 15 with LESSCompilerException

use of org.xwiki.lesscss.compiler.LESSCompilerException in project xwiki-platform by xwiki.

the class DefaultSkinReferenceFactory method createReference.

@Override
public SkinReference createReference(String skinName) throws LESSCompilerException {
    // Get the XWIki Object
    XWikiContext xcontext = xcontextProvider.get();
    XWiki xwiki = xcontext.getWiki();
    String currentWikiId = wikiDescriptorManager.getCurrentWikiId();
    DocumentReference skinDocRef = documentReferenceResolver.resolve(skinName, new WikiReference(currentWikiId));
    if (xwiki.exists(skinDocRef, xcontext)) {
        try {
            XWikiDocument skinDoc = xwiki.getDocument(skinDocRef, xcontext);
            DocumentReference skinClassDocRef = new DocumentReference(skinDocRef.getWikiReference().getName(), "XWiki", "XWikiSkins");
            if (skinDoc.getXObjectSize(skinClassDocRef) > 0) {
                return createReference(skinDocRef);
            }
        } catch (XWikiException e) {
            throw new LESSCompilerException(String.format("Unable to read document [%s]", skinDocRef), e);
        }
    }
    return new FSSkinReference(skinName);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) WikiReference(org.xwiki.model.reference.WikiReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

LESSCompilerException (org.xwiki.lesscss.compiler.LESSCompilerException)16 Test (org.junit.Test)9 LESSResourceReference (org.xwiki.lesscss.resources.LESSResourceReference)5 XWikiContext (com.xpn.xwiki.XWikiContext)4 XWikiException (com.xpn.xwiki.XWikiException)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 WikiReference (org.xwiki.model.reference.WikiReference)3 Less4jException (com.github.sommeri.less4j.Less4jException)2 XWiki (com.xpn.xwiki.XWiki)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 StringWriter (java.io.StringWriter)2 ColorTheme (org.xwiki.lesscss.internal.colortheme.ColorTheme)2 ColorThemeReference (org.xwiki.lesscss.internal.colortheme.ColorThemeReference)2 SkinReference (org.xwiki.lesscss.internal.skin.SkinReference)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 VelocityContext (org.apache.velocity.VelocityContext)1 LESSCompiler (org.xwiki.lesscss.compiler.LESSCompiler)1 DefaultLESSCompiler (org.xwiki.lesscss.internal.compiler.DefaultLESSCompiler)1 LESSSkinFileResourceReference (org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference)1 LESSResourceReferenceFactory (org.xwiki.lesscss.resources.LESSResourceReferenceFactory)1