Class TaskGenerateJsDefinitions
- All Implemented Interfaces:
FallibleCommand
FrontendUtils.JS_DEFINITIONS_FILE_NAME, which registers the
JavaScript of every JsDefinition interface on the class path, one
that extends JsInvokers or JsSnippets, as an ordinary
function of the bundle: in one registry for the methods that run their
JavaScript when called, in another for those of them that are annotated with
JsWithExecutionContext and take the execution context as their first
parameter, and in a third for the methods that declare a JsSnippet,
which the client turns into a function when it decodes the snippet. A method
declared by an interface with imports loads their
modules the first time it is called, and its JavaScript gets what they export
as parameters. A definition that does not pass
JsDefinitionProxy.checkDefinition(Class) is left out, with an error
in the log.
A production build that uses the bytecode scanner renders only the
definitions and event types that the scanner reaches from the entry points of
the application, together with those of Flow's own jar (the one that holds
JsDefinition), the same way it collects @JsModule. A class
that is only used through reflection is reached by naming it in @Uses
on a class that is reached.
The snippet registry also holds the EventData values and the
DomEvent.filter() of the DomEvent classes on the class path
that the client would otherwise compile from a string, see
BundledEventData, so that the server can send the identifier of a
function instead of the value.
This is what lets the client run a server-initiated call without compiling
anything from a string: the server sends the identifier of the function to
run, which is a hash of the JavaScript, and the function is already in the
bundle. The call survives a content security policy that does not allow
unsafe-eval, the JavaScript an application can be made to run is
known when it is built, and what declared it in Java stays there.
Outside production mode the file also registers what a developer wrote for each function, so that a message about a call in the browser names it rather than a hash. A production bundle carries the functions alone.
Next to the file it writes the identifiers of the functions it registers, which the stats of a bundle list, so that a build can tell whether a bundle carries every function an application needs.
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.4
-
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Runs the given command.The names of the JavaScript definitions that the generated file names a function of, for a caller that has to find which of them a change of another class affects without scanning for them.findMissingFromGeneratedFile(Options options, Collection<Class<?>> definitions) The JavaScript definitions of the given ones whose JavaScript the generated file does not carry, which is the JavaScript a browser can run of them.protected StringGet file content for writing to the generated file.protected FileGet the generated file where content will be written.protected booleanCheck if it should generate the file or not.updateJsDefinitions(Options options, Collection<Class<?>> definitions) Writes the generated file again so that it carries what the given definitions declare, for a caller that has to update it while the application runs rather than as part of a build.static booleanupdateStringFallbacks(File resourceOutputDirectory, Collection<Class<?>> changedClasses) Brings the list ofJsStringFallbackinterfaces up to date after classes changed while the application runs, without scanning: a changed class is listed when it carries the annotation and left out when it does not any longer.Methods inherited from class com.vaadin.flow.server.frontend.AbstractFileGeneratorFallibleCommand
setGeneratedFileSupport, track, track, writeIfChanged, writeIfChanged
-
Method Details
-
execute
Description copied from interface:FallibleCommandRuns the given command.If execution fails then the command may throw an exception which may give a message and a cause of the failure.
- Specified by:
executein interfaceFallibleCommand- Overrides:
executein classAbstractTaskClientGenerator- Throws:
ExecutionFailedException- if there is an execution error
-
updateStringFallbacks
public static boolean updateStringFallbacks(File resourceOutputDirectory, Collection<Class<?>> changedClasses) Brings the list ofJsStringFallbackinterfaces up to date after classes changed while the application runs, without scanning: a changed class is listed when it carries the annotation and left out when it does not any longer.The list is not checked here, since no build is running that could fail; the server checks it when it reads it.
- Parameters:
resourceOutputDirectory- the folder the list is in, as the build writes it, notnullchangedClasses- the classes that changed, notnull- Returns:
- whether one of the classes is or was listed, or is an interface that a listed interface extends, so that the server has to read the list again, even when only the methods of a listed interface changed
- Throws:
UncheckedIOException- if the list can not be read or written
-
getFileContent
Description copied from class:AbstractTaskClientGeneratorGet file content for writing to the generated file.- Specified by:
getFileContentin classAbstractTaskClientGenerator- Returns:
- content of the file.
-
findMissingFromGeneratedFile
public static List<Class<?>> findMissingFromGeneratedFile(Options options, Collection<Class<?>> definitions) The JavaScript definitions of the given ones whose JavaScript the generated file does not carry, which is the JavaScript a browser can run of them.- Parameters:
options- where the file is, notnulldefinitions- the JavaScript definitions to look for, notnull- Returns:
- those the file does not carry, empty when it carries all of them
-
findDefinitionNamesInGeneratedFile
The names of the JavaScript definitions that the generated file names a function of, for a caller that has to find which of them a change of another class affects without scanning for them. Only a file written for a development build names what declared its functions.- Parameters:
options- where the file is, notnull- Returns:
- the binary names of the definitions, empty when there is no file or it names nothing
-
updateJsDefinitions
Writes the generated file again so that it carries what the given definitions declare, for a caller that has to update it while the application runs rather than as part of a build.What the file already holds is kept: a function it registers is what a browser that has the file can run, and the caller only knows about the definitions it passes in. A function nothing declares any longer stays in the file with nothing calling it, until a build renders the file again.
Goes through the same write as
execute(), which leaves the file alone when its content would not change and writes it atomically otherwise, so a dev server is not told about an update that is not one and never reads a file that is half written.- Parameters:
options- where the file is, notnulldefinitions- the JavaScript definitions to write it for, notnulland not empty- Returns:
- those of them the file does not carry afterwards, empty when it carries all of them
-
getGeneratedFile
Description copied from class:AbstractTaskClientGeneratorGet the generated file where content will be written.- Specified by:
getGeneratedFilein classAbstractTaskClientGenerator- Returns:
- the generated file.
-
shouldGenerate
protected boolean shouldGenerate()Description copied from class:AbstractTaskClientGeneratorCheck if it should generate the file or not.- Specified by:
shouldGeneratein classAbstractTaskClientGenerator- Returns:
- true if it should generate, false otherwise.
-