public final class ModelDiscovery
extends java.lang.Object
META-INF/smithy/manifest
files on the class path and loading all of the newline separated relative
model files referenced from the manifest.
The URLs discovered through model discovery are imported into a
ModelAssembler
when ModelAssembler.discoverModels(java.lang.ClassLoader)
is
called, providing a mechanism for discovering Smithy models on the
classpath at runtime.
The format of a META-INF/smithy/manifest
file is a newline
separated UTF-8 text file in which each line is a resource that is
relative to the manifest file. A line is considered to be terminated
by any one of a line feed ('\n'), a carriage return ('\r'), a carriage
return followed immediately by a line feed, or by reaching the end-of-file
(EOF). The resources referenced by a manifest are loaded by resolving the
relative resource against the URL that contains each META-INF/smithy/manifest
file found using ClassLoader.getResources(java.lang.String)
.
The following restrictions and interpretations apply to the names of model resources that can be placed on manifest lines:
For example, given the following META-INF/smithy/manifest
file
discovered at jar:file:///C:/foo/baz/bar.jar!/META-INF/smithy/manifest
on the class path,
smithy.example.traits.smithy foo/another.file.smithy
Smithy will attempt to discover the following models:
jar:file:///C:/foo/baz/bar.jar!/META-INF/smithy/smithy.example.traits.smithy
jar:file:///C:/foo/baz/bar.jar!/META-INF/smithy/foo/another.file.smithy
Models defined in META-INF/smithy
should be named after the
namespace that is defined within the file. Files that define multiple
namespaces are free to use whatever naming scheming they choose, but
model files should be globally unique in an application.
Modifier and Type | Method and Description |
---|---|
static java.net.URL |
createSmithyJarManifestUrl(java.lang.String fileOrUrl)
Creates a URL that points to the Smithy manifest file of a JAR.
|
static java.util.List<java.net.URL> |
findModels()
Finds Smithy models using the thread context
ClassLoader . |
static java.util.List<java.net.URL> |
findModels(java.lang.ClassLoader loader)
Finds Smithy models using the given
ClassLoader . |
static java.util.List<java.net.URL> |
findModels(java.net.URL jarManifestUrl)
Parse the Smithy models from the given URL that points to a Smithy
manifest file in a JAR.
|
static java.lang.String |
getSmithyModelPathFromJarUrl(java.net.URL modelUrl)
Extracts the relative name of a Smithy model from a URL that points to
a Smithy model returned from
findModels() . |
public static java.util.List<java.net.URL> findModels()
ClassLoader
.public static java.util.List<java.net.URL> findModels(java.lang.ClassLoader loader)
ClassLoader
.loader
- ClassLoader used to discover models.public static java.util.List<java.net.URL> findModels(java.net.URL jarManifestUrl)
The provided URL is expected to point to a manifest stored in JAR (e.g., "jar:file:/example.jar!/META-INF/smithy/manifest).
jarManifestUrl
- Manifest URL to parse line by line.public static java.lang.String getSmithyModelPathFromJarUrl(java.net.URL modelUrl)
findModels()
.
For example, given "jar:file:/example.jar!/META-INF/smithy/example.json", this method will return "example.json".
modelUrl
- Model URL to get the name from.public static java.net.URL createSmithyJarManifestUrl(java.lang.String fileOrUrl)
The provided fileOrUrl
string can be an absolute path
to a file, (e.g., "/foo/baz.jar"), a file URL (e.g., "file:/baz.jar"),
or a JAR URL (e.g., "jar:file:/baz.jar").
fileOrUrl
- Filename or URL that points to a JAR.