Class TaskGenerateJsDefinitions

All Implemented Interfaces:
FallibleCommand

public class TaskGenerateJsDefinitions extends AbstractTaskClientGenerator
Generates FrontendUtils.JS_DEFINITIONS_FILE_NAME, which registers the JavaScript of every JsDefinition interface on the class path as an ordinary function of the bundle.

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.

For internal use only. May be renamed or removed in a future release.

Since:
25.4
  • Method Details

    • getFileContent

      protected String getFileContent()
      Description copied from class: AbstractTaskClientGenerator
      Get file content for writing to the generated file.
      Specified by:
      getFileContent in class AbstractTaskClientGenerator
      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, not null
      definitions - the JavaScript definitions to look for, not null
      Returns:
      those the file does not carry, empty when it carries all of them
    • updateJsDefinitions

      public static List<Class<?>> 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.

      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 AbstractTaskClientGenerator.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, not null
      definitions - the JavaScript definitions to write it for, not null and not empty
      Returns:
      those of them the file does not carry afterwards, empty when it carries all of them
    • getGeneratedFile

      protected File getGeneratedFile()
      Description copied from class: AbstractTaskClientGenerator
      Get the generated file where content will be written.
      Specified by:
      getGeneratedFile in class AbstractTaskClientGenerator
      Returns:
      the generated file.
    • shouldGenerate

      protected boolean shouldGenerate()
      Description copied from class: AbstractTaskClientGenerator
      Check if it should generate the file or not.
      Specified by:
      shouldGenerate in class AbstractTaskClientGenerator
      Returns:
      true if it should generate, false otherwise.