Search in sources :

Example 6 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class ArtefactHandlerAdapter method isArtefact.

/**
     * Default implementation of {@link grails.core.ArtefactHandler#isArtefact(org.codehaus.groovy.ast.ClassNode)} which returns true if the ClassNode passes the
     * {@link #isArtefactResource(org.grails.io.support.Resource)} method and the name of the ClassNode ends with the {@link #artefactSuffix}
     *
     * @param classNode The ClassNode instance
     * @return True if the ClassNode is an artefact of this type
     */
@Override
public boolean isArtefact(ClassNode classNode) {
    int modifiers = classNode.getModifiers();
    URL url = GrailsASTUtils.getSourceUrl(classNode);
    if (url == null)
        return false;
    try {
        UrlResource resource = new UrlResource(url);
        if (!isArtefactResource(resource))
            return false;
    } catch (IOException e) {
        return false;
    }
    if (isValidArtefactClassNode(classNode, modifiers)) {
        String name = classNode.getName();
        if (name != null && this.artefactSuffix != null && name.endsWith(artefactSuffix)) {
            return true;
        }
    }
    return false;
}
Also used : UrlResource(org.grails.io.support.UrlResource) IOException(java.io.IOException) URL(java.net.URL)

Example 7 with UrlResource

use of org.grails.io.support.UrlResource in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetClassNameResource.

public void testGetClassNameResource() throws Exception {
    Resource r = new UrlResource(new URL(TEST_URL));
    assertEquals("Test", GrailsResourceUtils.getClassName(r));
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource) URL(java.net.URL)

Aggregations

UrlResource (org.grails.io.support.UrlResource)7 Resource (org.grails.io.support.Resource)5 URL (java.net.URL)3 IOException (java.io.IOException)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockServletContext (org.springframework.mock.web.MockServletContext)1