Search in sources :

Example 1 with ResourceScriptSource

use of org.springframework.scripting.support.ResourceScriptSource in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithStaticPointcut.

@Test
public void manualGroovyBeanWithStaticPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("execution(* %s.TestService+.*(..))", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with ResourceScriptSource

use of org.springframework.scripting.support.ResourceScriptSource in project grails-core by grails.

the class GroovyPagesTemplateEngine method createTemplate.

public Template createTemplate(ScriptSource scriptSource) {
    if (scriptSource instanceof GroovyPageCompiledScriptSource) {
        // handle pre-compiled
        return createTemplateFromPrecompiled((GroovyPageCompiledScriptSource) scriptSource);
    }
    if (scriptSource instanceof ResourceScriptSource) {
        ResourceScriptSource resourceSource = (ResourceScriptSource) scriptSource;
        Resource resource = resourceSource.getResource();
        return createTemplate(resource, true);
    }
    try {
        return createTemplate(scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
    } catch (IOException e) {
        throw new RuntimeException("IOException in createTemplate", e);
    }
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) IOException(java.io.IOException)

Example 3 with ResourceScriptSource

use of org.springframework.scripting.support.ResourceScriptSource in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithDynamicPointcut.

@Test
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 4 with ResourceScriptSource

use of org.springframework.scripting.support.ResourceScriptSource in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithUnconditionalPointcut.

@Test
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "GroovyServiceImpl");
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 5 with ResourceScriptSource

use of org.springframework.scripting.support.ResourceScriptSource in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithDynamicPointcutProxyTargetClass.

@Test
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)8 Test (org.junit.Test)7 ClassPathResource (org.springframework.core.io.ClassPathResource)7 DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)4 AspectJExpressionPointcut (org.springframework.aop.aspectj.AspectJExpressionPointcut)3 ScriptEvaluator (org.springframework.scripting.ScriptEvaluator)3 StandardScriptEvaluator (org.springframework.scripting.support.StandardScriptEvaluator)2 IOException (java.io.IOException)1