Griffon
  1. Griffon
  2. GRIFFON-465

Add a shortcut to artifacts and application to load resourdes from the classpath

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.5-rc1
    • Fix Version/s: 0.9.5-rc2
    • Component/s: rt
    • Labels:
      None
    • Number of attachments :
      0

      Description

      The current way to load a resource from a classpath is by accessing the classloader, like this

      app.class.classLoader.getResource(resourceName)
      app.class.classLoader.getResourceAsStream(resourceName)
      

      It would be better if those methods were directly accessible from the application and/or artifact instance. This also helps in adding an abstraction over locating resources, sueful for latter modularization.

        Activity

        Hide
        Andres Almiray added a comment -

        GriffonApplication and GriffonArtifact have a new pair of methods

        URL getResourceAsURL(String resourceName);
        InputStream getResourceAsStream(String resourceName);
        
        Show
        Andres Almiray added a comment - GriffonApplication and GriffonArtifact have a new pair of methods URL getResourceAsURL( String resourceName); InputStream getResourceAsStream( String resourceName);
        Hide
        Edo added a comment -

        sueful for latter modularization

        Lawyers will be thrilled!

        I recently had an issue where the only way I was able to load a couple of images from the resources folder was through findResource(). Any chance we can get that method too?

        Show
        Edo added a comment - sueful for latter modularization Lawyers will be thrilled! I recently had an issue where the only way I was able to load a couple of images from the resources folder was through findResource(). Any chance we can get that method too?
        Hide
        Andres Almiray added a comment -

        Do you mean Enumeration getResources() ? findResources() has protected access in ClassLoader.

        Show
        Andres Almiray added a comment - Do you mean Enumeration getResources() ? findResources() has protected access in ClassLoader.
        Hide
        Andres Almiray added a comment -

        I assumed you meant getResources() so I implemented it too. However instead of returning a dated Enumeration<URL> I decided to use List<URL> instead (as it's Iterable) taking into account the returned list should be immutable.

        Also, there's a new AST xform available @griffon.transform.ResourcesAware which adds these methods to any class.

        Show
        Andres Almiray added a comment - I assumed you meant getResources() so I implemented it too. However instead of returning a dated Enumeration<URL> I decided to use List<URL> instead (as it's Iterable) taking into account the returned list should be immutable. Also, there's a new AST xform available @griffon.transform.ResourcesAware which adds these methods to any class.
        Hide
        Edo added a comment -

        Thanks a ton Andres!

        Show
        Edo added a comment - Thanks a ton Andres!

          People

          • Assignee:
            Andres Almiray
            Reporter:
            Andres Almiray
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: