Search in sources :

Example 1 with Resource

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

the class GrailsResourceUtilsTests method testGetTestNameResource.

public void testGetTestNameResource() throws Exception {
    Resource r = new UrlResource(new URL(UNIT_TESTS_URL));
    assertEquals("SomeTests", 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)

Example 2 with Resource

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

the class GrailsResourceUtilsTests method testGetAppDir.

public void testGetAppDir() throws Exception {
    Resource appDir = GrailsResourceUtils.getAppDir(new UrlResource(TEST_CONTROLLER_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app"), appDir.getURL().toString());
    appDir = GrailsResourceUtils.getAppDir(new UrlResource(TEST_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app"), appDir.getURL().toString());
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource)

Example 3 with Resource

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

the class GrailsResourceUtilsTests method testGetDirWithinWebInf.

public void testGetDirWithinWebInf() throws Exception {
    Resource viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_CONTROLLER_URL));
    Resource pluginViews = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_PLUGIN_CTRL));
    Resource webInfViews = GrailsResourceUtils.getViewsDir(new UrlResource(WEBINF_CONTROLLER));
    Resource webInfPluginViews = GrailsResourceUtils.getViewsDir(new UrlResource(WEBINF_PLUGIN_CTRL));
    assertEquals(toFileUrl("/test/grails/app/grails-app/views"), viewsDir.getURL().toString());
    assertEquals(toFileUrl("/test/grails/app/plugins/myplugin/grails-app/views"), pluginViews.getURL().toString());
    assertEquals(toFileUrl("/test/grails/app/WEB-INF/grails-app/views"), webInfViews.getURL().toString());
    assertEquals(toFileUrl("/test/grails/app/WEB-INF/plugins/myplugin/grails-app/views"), webInfPluginViews.getURL().toString());
    assertEquals("/WEB-INF/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(webInfViews));
    assertEquals("/WEB-INF/plugins/myplugin/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(webInfPluginViews));
    assertEquals("/WEB-INF/plugins/myplugin/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(pluginViews));
    assertEquals("/WEB-INF/grails-app/views", GrailsResourceUtils.getRelativeInsideWebInf(viewsDir));
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource)

Example 4 with Resource

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

the class GrailsResourceUtilsTests method testGetViewsDirForURL.

public void testGetViewsDirForURL() throws Exception {
    Resource viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_CONTROLLER_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app/views"), viewsDir.getURL().toString());
    viewsDir = GrailsResourceUtils.getViewsDir(new UrlResource(TEST_URL));
    assertEquals(toFileUrl("/test/grails/app/grails-app/views"), viewsDir.getURL().toString());
}
Also used : UrlResource(org.grails.io.support.UrlResource) Resource(org.grails.io.support.Resource) UrlResource(org.grails.io.support.UrlResource)

Example 5 with Resource

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

the class GrailsASTUtils method getSourceUrl.

/**
     * Find URL of SourceUnit
     *
     * source.getSource().getURI() fails in Groovy-Eclipse compiler
     *
     * @param source
     * @return URL of SourceUnit
     */
public static URL getSourceUrl(SourceUnit source) {
    URL url = null;
    final String filename = source.getName();
    if (filename == null) {
        return null;
    }
    Resource resource = new FileSystemResource(filename);
    if (resource.exists()) {
        try {
            url = resource.getURL();
        } catch (IOException e) {
        // ignore
        }
    }
    return url;
}
Also used : Resource(org.grails.io.support.Resource) FileSystemResource(org.grails.io.support.FileSystemResource) FileSystemResource(org.grails.io.support.FileSystemResource) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

Resource (org.grails.io.support.Resource)8 UrlResource (org.grails.io.support.UrlResource)5 URL (java.net.URL)4 IOException (java.io.IOException)3 FileSystemResource (org.grails.io.support.FileSystemResource)3 ClassInjector (grails.compiler.ast.ClassInjector)2 GlobalClassInjector (grails.compiler.ast.GlobalClassInjector)2 InputStream (java.io.InputStream)1 PathMatchingResourcePatternResolver (org.grails.io.support.PathMatchingResourcePatternResolver)1 AnnotationVisitor (org.springframework.asm.AnnotationVisitor)1 ClassReader (org.springframework.asm.ClassReader)1 ClassVisitor (org.springframework.asm.ClassVisitor)1