Search in sources :

Example 6 with LESSCompilerException

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

the class LessCompilerScriptService method clearCacheFromSkin.

/**
 * Remove every generated files corresponding to a filesystem skin.
 * The script calling this method needs the programming rights.
 * @param skin name of the filesystem skin
 * @return true if the operation succeed
 *
 * @since 6.4M2
 */
public boolean clearCacheFromSkin(String skin) {
    XWikiContext xcontext = xcontextProvider.get();
    // Check if the current script has the programing rights
    if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), xcontext.getDoc().getDocumentReference())) {
        return false;
    }
    try {
        SkinReference skinReference = skinReferenceFactory.createReference(skin);
        lessCache.clearFromSkin(skinReference);
        colorThemeCache.clearFromSkin(skinReference);
        return true;
    } catch (LESSCompilerException e) {
        return false;
    }
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) SkinReference(org.xwiki.lesscss.internal.skin.SkinReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException)

Example 7 with LESSCompilerException

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

the class LESSSkinFileResourceReferenceTest method getContentWhenFileDoesNotExist.

@Test
public void getContentWhenFileDoesNotExist() throws Exception {
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("not-existing-file.less", templateManager, skinManager);
    // Test
    LESSCompilerException caughtException = null;
    try {
        lessSkinFileResourceReference.getContent("skin");
    } catch (LESSCompilerException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("The template [not-existing-file.less] does not exists.", caughtException.getMessage());
}
Also used : LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Test(org.junit.Test)

Example 8 with LESSCompilerException

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

the class LESSSkinFileResourceReferenceTest method getContentWhenException.

@Test
public void getContentWhenException() throws Exception {
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("file.less", templateManager, skinManager);
    // Mocks
    Template template = mock(Template.class);
    when(templateManager.getTemplate("less/file.less", skin)).thenReturn(template);
    Exception exception = new Exception("exception");
    when(template.getContent()).thenThrow(exception);
    // Test
    LESSCompilerException caughtException = null;
    try {
        lessSkinFileResourceReference.getContent("skin");
    } catch (LESSCompilerException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals("Failed to get the content of the template [file.less].", caughtException.getMessage());
    assertEquals(exception, caughtException.getCause());
}
Also used : LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) Template(org.xwiki.template.Template) Test(org.junit.Test)

Example 9 with LESSCompilerException

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

the class DefaultSkinReferenceFactoryTest method createReferenceWhenSkinOnDBWithException.

@Test
public void createReferenceWhenSkinOnDBWithException() throws Exception {
    // Mocks
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wikiId");
    DocumentReference skinDocRef = new DocumentReference("wikiId", "XWiki", "MySkin");
    when(documentReferenceResolver.resolve(eq("XWiki.MySkin"), eq(new WikiReference("wikiId")))).thenReturn(skinDocRef);
    when(xwiki.exists(skinDocRef, xcontext)).thenReturn(true);
    Exception exception = new XWikiException();
    when(xwiki.getDocument(skinDocRef, xcontext)).thenThrow(exception);
    // Test
    LESSCompilerException caughtException = null;
    try {
        mocker.getComponentUnderTest().createReference("XWiki.MySkin");
    } catch (LESSCompilerException e) {
        caughtException = e;
    }
    // Verify
    assertNotNull(caughtException);
    assertEquals(exception, caughtException.getCause());
    assertEquals("Unable to read document [wikiId:XWiki.MySkin]", caughtException.getMessage());
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException) XWikiException(com.xpn.xwiki.XWikiException) Test(org.junit.Test)

Example 10 with LESSCompilerException

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

the class LessCompilerScriptService method clearCacheFromColorTheme.

/**
 * Remove every generated files corresponding to a color theme.
 * The script calling this method needs the programming rights.
 * @param colorTheme fullname of the color theme
 * @return true if the operation succeed
 */
public boolean clearCacheFromColorTheme(String colorTheme) {
    XWikiContext xcontext = xcontextProvider.get();
    // Check if the current script has the programing rights
    if (!authorizationManager.hasAccess(Right.PROGRAM, xcontext.getDoc().getAuthorReference(), xcontext.getDoc().getDocumentReference())) {
        return false;
    }
    try {
        ColorThemeReference colorThemeReference = colorThemeReferenceFactory.createReference(colorTheme);
        lessCache.clearFromColorTheme(colorThemeReference);
        colorThemeCache.clearFromColorTheme(colorThemeReference);
        return true;
    } catch (LESSCompilerException e) {
        return false;
    }
}
Also used : ColorThemeReference(org.xwiki.lesscss.internal.colortheme.ColorThemeReference) XWikiContext(com.xpn.xwiki.XWikiContext) LESSCompilerException(org.xwiki.lesscss.compiler.LESSCompilerException)

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