Class ResourceGeneratorUtil
- java.lang.Object
-
- com.google.gwt.resources.ext.ResourceGeneratorUtil
-
public final class ResourceGeneratorUtil extends java.lang.ObjectUtility methods for building ResourceGenerators.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddNamedFile(java.lang.String resourceName, java.io.File file)Publish or override resources named byClientBundle.Sourceannotations.static java.lang.StringbaseName(java.net.URL resource)Returns the base filename of a resource.static java.net.URL[]findResources(TreeLogger logger, ResourceContext context, JMethod method)Find all resources referenced by a method in a bundle.static java.net.URL[]findResources(TreeLogger logger, ResourceContext context, JMethod method, java.lang.String[] defaultSuffixes)Find all resources referenced by a method in a bundle.static longgetLastModified(java.net.URL[] resources, TreeLogger logger)Returns the most recent value of thelast-modifiedheader fields of all the Urls in theresourcesarray.static JMethodgetMethodByPath(JClassType rootType, java.util.List<java.lang.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 java.net.URLtryFindResource(TreeLogger logger, GeneratorContext genContext, ResourceContext resourceContext, java.lang.String resourceName)Try to find a resource with the given resourceName.
-
-
-
Method Detail
-
addNamedFile
public static void addNamedFile(java.lang.String resourceName, java.io.File file)Publish or override resources named byClientBundle.Sourceannotations. 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 offileshould be made availablefile- the File whose contents are to be provided to the ClientBundle system
-
baseName
public static java.lang.String baseName(java.net.URL resource)
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 java.net.URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException
Find all resources referenced by a method in a bundle. The method'sClientBundle.Sourceannotation 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
localedeferred-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
DefaultExtensionsannotation, the value of this annotation will be used to find matching resource names if the method lacks aClientBundle.Sourceannotation.- 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.Sourceannotations- Returns:
- URLs for each
ClientBundle.Sourceannotation value defined on the method. - Throws:
UnableToCompleteException- if ore or more of the sources could not be found. The error will be reported via theloggerprovided to this method
-
findResources
public static java.net.URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method, java.lang.String[] defaultSuffixes) throws UnableToCompleteException
Find all resources referenced by a method in a bundle. The method'sClientBundle.Sourceannotation 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
localedeferred-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.SourceannotationsdefaultSuffixes- if the supplied method does not have anyClientBundle.Sourceannotations, 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.Sourceannotation value defined on the method. - Throws:
UnableToCompleteException- if ore or more of the sources could not be found. The error will be reported via theloggerprovided to this method
-
getLastModified
public static long getLastModified(java.net.URL[] resources, TreeLogger logger)Returns the most recent value of thelast-modifiedheader fields of all the Urls in theresourcesarray. The result is the number of milliseconds since January 1, 1970 GMT. Returns 0 if thelast-modifiedheader field of one of the resources cannot be determined.- Returns:
- the most recent modification date of the resources present in
resourcesor 0 if not known.
-
getMethodByPath
public static JMethod getMethodByPath(JClassType rootType, java.util.List<java.lang.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, ornullif 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 java.net.URL tryFindResource(TreeLogger logger, GeneratorContext genContext, ResourceContext resourceContext, java.lang.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
-
-