Reviewers: bobv,

Description:
The strategy for finding resources in ResourceGeneratorUtil limits
package relative resources to files contained directly in that package.
This patch make it possible to use arbitrary paths relative to the
package (i.e. "resources/background.png").

Please review this at http://gwt-code-reviews.appspot.com/803

Affected files:
   src/com/google/gwt/libideas/resources/ext/ResourceGeneratorUtil.java


Index: src/com/google/gwt/libideas/resources/ext/ResourceGeneratorUtil.java
===================================================================
--- src/com/google/gwt/libideas/resources/ext/ResourceGeneratorUtil.java        
 
(revision 1273)
+++ src/com/google/gwt/libideas/resources/ext/ResourceGeneratorUtil.java        
 
(working copy)
@@ -20,6 +20,7 @@
  import com.google.gwt.core.ext.TreeLogger;
  import com.google.gwt.core.ext.UnableToCompleteException;
  import com.google.gwt.core.ext.typeinfo.JMethod;
+import com.google.gwt.core.ext.typeinfo.JPackage;
  import  
com.google.gwt.libideas.resources.client.ImmutableResourceBundle.Resource;
  import  
com.google.gwt.libideas.resources.client.ImmutableResourceBundle.Transform;
  import com.google.gwt.libideas.resources.rebind.Transformer;
@@ -216,17 +217,16 @@
      boolean error = false;
      int tagIndex = 0;
      for (String resource : resources) {
+      // Try to find the resource relative to the package.
+      URL resourceURL = tryFindResource(classLoader,  
getPathRelativeToPackage(
+          method.getEnclosingType().getPackage(), resource), locale);

-      // Make sure the name is either absolute or package-relative.
-      if (resource.indexOf("/") == -1) {
-        String pkgName = method.getEnclosingType().getPackage().getName();
-
-        // This construction handles the default package correctly, too.
-        resource = pkgName.replace('.', '/') + "/" + resource;
+      // If we didn't find the resource relative to the package, assume it  
is
+      // absolute.
+      if (resourceURL == null) {
+        resourceURL = tryFindResource(classLoader, resource, locale);
        }
-
-      URL resourceURL = tryFindResource(classLoader, resource, locale);
-
+
        if (resourceURL == null) {
          logger.log(TreeLogger.ERROR, "Resource " + resource
              + " not found on classpath. Is the name specified as "
@@ -253,6 +253,17 @@
    }

    /**
+   * Converts a package relative path into an absolute path.
+   *
+   * @param pkg the package
+   * @param path a path relative to the package
+   * @return an absolute path
+   */
+  private static String getPathRelativeToPackage(JPackage pkg, String  
path) {
+    return pkg.getName().replace('.', '/') + '/' + path;
+  }
+
+  /**
     * This performs the locale lookup function for a given resource name.
     *
     * @param classLoader the ClassLoader to use to load the resources



--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to