public final class ResourceGeneratorUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
addNamedFile(java.lang.String resourceName,
java.io.File file)
Publish or override resources named by
ClientBundle.Source annotations. |
static java.lang.String |
baseName(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 long |
getLastModified(java.net.URL[] resources,
TreeLogger logger)
Returns the most recent value of the
last-modified header fields of all the Urls
in the resources array. |
static JMethod |
getMethodByPath(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.URL |
tryFindResource(TreeLogger logger,
GeneratorContext genContext,
ResourceContext resourceContext,
java.lang.String resourceName)
Try to find a resource with the given resourceName.
|
public static void addNamedFile(java.lang.String resourceName, java.io.File file)
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.resourceName
- the path at which the contents of file
should be made availablefile
- the File whose contents are to be provided to the ClientBundle
systempublic static java.lang.String baseName(java.net.URL resource)
basename
.resource
- the URL of the resourcepublic static java.net.URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException
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.
logger
- a TreeLogger that will be used to report errors or warningscontext
- the ResourceContext in which the ResourceGenerator is
operatingmethod
- the method to examine for ClientBundle.Source
annotationsClientBundle.Source
annotation value defined on the
method.UnableToCompleteException
- if ore or more of the sources could not
be found. The error will be reported via the logger
provided to this methodpublic static java.net.URL[] findResources(TreeLogger logger, ResourceContext context, JMethod method, java.lang.String[] defaultSuffixes) throws UnableToCompleteException
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.
logger
- a TreeLogger that will be used to report errors or warningscontext
- the ResourceContext in which the ResourceGenerator is
operatingmethod
- the method to examine for ClientBundle.Source
annotationsdefaultSuffixes
- 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 specifiedClientBundle.Source
annotation value defined on the
method.UnableToCompleteException
- if ore or more of the sources could not
be found. The error will be reported via the logger
provided to this methodpublic static long getLastModified(java.net.URL[] resources, TreeLogger logger)
last-modified
header fields of all the Urls
in the resources
array.
The result is the number of milliseconds since January 1, 1970 GMT.
Returns 0 if the last-modified
header field of one of the resources cannot
be determined.resources
or 0 if not known.public static JMethod getMethodByPath(JClassType rootType, java.util.List<java.lang.String> pathElements, JType expectedReturnType) throws NotFoundException
rootType
- the type from which the search beginspathElements
- a sequence of no-arg method namesexpectedReturnType
- the expected return type of the method to locate,
or null
if no constraint on the return type is
necessaryNotFoundException
- if the requested method could not be foundpublic static java.net.URL tryFindResource(TreeLogger logger, GeneratorContext genContext, ResourceContext resourceContext, java.lang.String resourceName)
findResources(com.google.gwt.core.ext.TreeLogger, com.google.gwt.resources.ext.ResourceContext, com.google.gwt.core.ext.typeinfo.JMethod)
.logger
- genContext
- resourceContext
- resourceName
-