public final class

ResourceGeneratorUtil

extends Object
java.lang.Object
   ↳ com.google.gwt.resources.ext.ResourceGeneratorUtil

Class Overview

Utility methods for building ResourceGenerators.

Summary

Public Methods
static void addNamedFile(String resourceName, File file)
Publish or override resources named by ClientBundle.Source annotations.
static String baseName(URL resource)
Returns the base filename of a resource.
static URL[] findResources(TreeLogger logger, ClassLoader classLoader, ResourceContext context, JMethod method, String[] defaultSuffixes)
Find all resources referenced by a method in a bundle.
static URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method, String[] defaultSuffixes)
Find all resources referenced by a method in a bundle.
static URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method)
Find all resources referenced by a method in a bundle.
static JMethod getMethodByPath(JClassType rootType, List<String> pathElements, JType expectedReturnType)
Finds a method by following a dotted path interpreted as a series of no-arg method invocations from an instance of a given root type.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static void addNamedFile (String resourceName, File file)

Publish or override resources named by ClientBundle.Source annotations. This method is intended to be called by Generators that create ClientBundle instances and need to pass source data to the ClientBundle system that is not accessible through the classpath.

Parameters
resourceName the path at which the contents of file should be made available
file the File whose contents are to be provided to the ClientBundle system

public static String baseName (URL resource)

Returns the base filename of a resource. The behavior is similar to the unix command basename.

Parameters
resource the URL of the resource
Returns
  • the final name segment of the resource

public static URL[] findResources (TreeLogger logger, ClassLoader classLoader, ResourceContext context, JMethod method, String[] defaultSuffixes)

Find all resources referenced by a method in a bundle. The method's ClientBundle.Source annotation will be examined and the specified locations will be expanded into URLs by which they may be accessed on the local system.

This method is sensitive to the locale deferred-binding property and will attempt to use a best-match lookup by removing locale components.

Loading through a ClassLoader with this method is much slower than the other findResources methods which make use of the compiler's ResourceOracle.

Parameters
logger a TreeLogger that will be used to report errors or warnings
classLoader the ClassLoader to use when locating resources
context the ResourceContext in which the ResourceGenerator is operating
method the method to examine for ClientBundle.Source annotations
defaultSuffixes if the supplied method does not have any ClientBundle.Source annotations, act as though a Source annotation was specified, using the name of the method and each of supplied extensions in the order in which they are specified
Returns
Throws
UnableToCompleteException if ore or more of the sources could not be found. The error will be reported via the logger provided to this method

public static URL[] findResources (TreeLogger logger, ResourceContext context, JMethod method, String[] defaultSuffixes)

Find all resources referenced by a method in a bundle. The method's ClientBundle.Source annotation will be examined and the specified locations will be expanded into URLs by which they may be accessed on the local system.

This method is sensitive to the locale deferred-binding property and will attempt to use a best-match lookup by removing locale components.

The compiler's ResourceOracle will be used to resolve resource locations. If the desired resource cannot be found in the ResourceOracle, this method will fall back to using the current thread's context ClassLoader. If it is necessary to alter the way in which resources are located, use the overload that accepts a ClassLoader.

Parameters
logger a TreeLogger that will be used to report errors or warnings
context the ResourceContext in which the ResourceGenerator is operating
method the method to examine for ClientBundle.Source annotations
defaultSuffixes if the supplied method does not have any ClientBundle.Source annotations, act as though a Source annotation was specified, using the name of the method and each of supplied extensions in the order in which they are specified
Returns
Throws
UnableToCompleteException if ore or more of the sources could not be found. The error will be reported via the logger provided to this method

public static URL[] findResources (TreeLogger logger, ResourceContext context, JMethod method)

Find all resources referenced by a method in a bundle. The method's ClientBundle.Source annotation will be examined and the specified locations will be expanded into URLs by which they may be accessed on the local system.

This method is sensitive to the locale deferred-binding property and will attempt to use a best-match lookup by removing locale components.

The compiler's ResourceOracle will be used to resolve resource locations. If the desired resource cannot be found in the ResourceOracle, this method will fall back to using the current thread's context ClassLoader. If it is necessary to alter the way in which resources are located, use the overload that accepts a ClassLoader.

If the method's return type declares the DefaultExtensions annotation, the value of this annotation will be used to find matching resource names if the method lacks a ClientBundle.Source annotation.

Parameters
logger a TreeLogger that will be used to report errors or warnings
context the ResourceContext in which the ResourceGenerator is operating
method the method to examine for ClientBundle.Source annotations
Returns
Throws
UnableToCompleteException if ore or more of the sources could not be found. The error will be reported via the logger provided to this method

public static JMethod getMethodByPath (JClassType rootType, List<String> pathElements, JType expectedReturnType)

Finds a method by following a dotted path interpreted as a series of no-arg method invocations from an instance of a given root type.

Parameters
rootType the type from which the search begins
pathElements a sequence of no-arg method names
expectedReturnType the expected return type of the method to locate, or null if no constraint on the return type is necessary
Returns
  • the requested JMethod
Throws
NotFoundException if the requested method could not be found