Class ResourceGeneratorUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addNamedFile
(String resourceName, File file) Publish or override resources named byClientBundle.Source
annotations.static String
Returns the base filename of a resource.static URL[]
findResources
(TreeLogger logger, ResourceContext context, JMethod method) 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 long
getLastModified
(URL[] resources, TreeLogger logger) Returns the most recent value of thelast-modified
header fields of all the Urls in theresources
array.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.static URL
tryFindResource
(TreeLogger logger, GeneratorContext genContext, ResourceContext resourceContext, String resourceName) Try to find a resource with the given resourceName.
-
Method Details
-
addNamedFile
Publish or override resources named byClientBundle.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 offile
should be made availablefile
- the File whose contents are to be provided to the ClientBundle system
-
baseName
Returns the base filename of a resource. The behavior is similar to the unix commandbasename
.- Parameters:
resource
- the URL of the resource- Returns:
- the final name segment of the resource
-
findResources
public static URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException Find all resources referenced by a method in a bundle. The method'sClientBundle.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 aClientBundle.Source
annotation.- Parameters:
logger
- a TreeLogger that will be used to report errors or warningscontext
- the ResourceContext in which the ResourceGenerator is operatingmethod
- the method to examine forClientBundle.Source
annotations- Returns:
- URLs for each
ClientBundle.Source
annotation value defined on the method. - Throws:
UnableToCompleteException
- if ore or more of the sources could not be found. The error will be reported via thelogger
provided to this method
-
findResources
public static URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method, String[] defaultSuffixes) throws UnableToCompleteException Find all resources referenced by a method in a bundle. The method'sClientBundle.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 warningscontext
- the ResourceContext in which the ResourceGenerator is operatingmethod
- the method to examine forClientBundle.Source
annotationsdefaultSuffixes
- if the supplied method does not have anyClientBundle.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:
- URLs for each
ClientBundle.Source
annotation value defined on the method. - Throws:
UnableToCompleteException
- if ore or more of the sources could not be found. The error will be reported via thelogger
provided to this method
-
getLastModified
Returns the most recent value of thelast-modified
header fields of all the Urls in theresources
array. The result is the number of milliseconds since January 1, 1970 GMT. Returns 0 if thelast-modified
header field of one of the resources cannot be determined.- Returns:
- the most recent modification date of the resources present in
resources
or 0 if not known.
-
getMethodByPath
public static JMethod getMethodByPath(JClassType rootType, List<String> pathElements, JType expectedReturnType) throws NotFoundException 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 beginspathElements
- a sequence of no-arg method namesexpectedReturnType
- the expected return type of the method to locate, ornull
if no constraint on the return type is necessary- Returns:
- the requested JMethod
- Throws:
NotFoundException
- if the requested method could not be found
-
tryFindResource
public static URL tryFindResource(TreeLogger logger, GeneratorContext genContext, ResourceContext resourceContext, String resourceName) Try to find a resource with the given resourceName. It will use the default search order to locate the resource as is used byfindResources(com.google.gwt.core.ext.TreeLogger, com.google.gwt.resources.ext.ResourceContext, com.google.gwt.core.ext.typeinfo.JMethod)
.- Parameters:
logger
-genContext
-resourceContext
-resourceName
-- Returns:
- a URL for the resource, if found
-