Class VaadinPlugin

java.lang.Object
com.vaadin.quarkus.deployment.vaadinplugin.VaadinPlugin

public final class VaadinPlugin extends Object
Implementation of the Vaadin plugin.

This class is a porting of Vaadin Maven prepare-frontend and build-frontend mojos.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    buildFrontend(BiConsumer<String,byte[]> emitter)
    Builds the frontend bundle.
    void
    Cleans up generated frontend files if the corresponding configuration setting is enabled.
    createGeneratedResourceEmitter(Iterable<Path> packagedRootDirectories, io.quarkus.deployment.annotations.BuildProducer<io.quarkus.deployment.builditem.GeneratedResourceBuildItem> producer)
    Creates the emitter that registers the generated Vaadin files with the application.
    of(VaadinBuildTimeConfig vaadinConfig, io.quarkus.bootstrap.model.ApplicationModel applicationModel, Path outputTarget)
    Creates a new instance of the VaadinPlugin based on the provided configuration and application model.
    void
    Checks that node and npm tools are installed and creates or updates `package.json` and the frontend build tool configuration files.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • of

      public static VaadinPlugin of(VaadinBuildTimeConfig vaadinConfig, io.quarkus.bootstrap.model.ApplicationModel applicationModel, Path outputTarget) throws io.quarkus.builder.BuildException
      Creates a new instance of the VaadinPlugin based on the provided configuration and application model. If necessary, it attempts to load workspace information for the plugin.
      Parameters:
      vaadinConfig - the Vaadin build time configuration.
      applicationModel - the application model representing the current application.
      outputTarget - the target directory for output operations.
      Returns:
      an instance of VaadinPlugin initialized with the given parameters.
      Throws:
      io.quarkus.builder.BuildException - if workspace information cannot be loaded or an error occurs during the process.
    • prepareFrontend

      public void prepareFrontend() throws io.quarkus.builder.BuildException
      Checks that node and npm tools are installed and creates or updates `package.json` and the frontend build tool configuration files.

      Copies frontend resources available inside `.jar` dependencies to `node_modules` when building a jar package.
      Throws:
      io.quarkus.builder.BuildException - if any error occurs.
    • buildFrontend

      public void buildFrontend(BiConsumer<String,byte[]> emitter) throws io.quarkus.builder.BuildException
      Builds the frontend bundle.

      It performs the following actions when creating a package:
      • Update Constants.PACKAGE_JSON file with the NpmPackage annotations defined in the classpath,
      • Copy resource files used by flow from `.jar` files to the `node_modules` folder
      • Install dependencies by running npm install
      • Update the FrontendUtils.IMPORTS_NAME file imports with the JsModule Theme and JavaScript annotations defined in the classpath,
      • Update FrontendUtils.VITE_CONFIG file.

      Once the build is done the generated files are handed to the emitter and the build info token file is deleted from the build output directory. Nothing is deleted before the files that have to reach the application whichever way it is packaged are known to have reached it: a file that cannot be read fails the build, and so does one that was not emitted. Deleting the token file after it failed to reach the application would package an application without a flow-build-info.json while the build reports success.

      Parameters:
      emitter - generated files emitter.
      Throws:
      io.quarkus.builder.BuildException - if any error occurs.
    • createGeneratedResourceEmitter

      public BiConsumer<String,byte[]> createGeneratedResourceEmitter(Iterable<Path> packagedRootDirectories, io.quarkus.deployment.annotations.BuildProducer<io.quarkus.deployment.builditem.GeneratedResourceBuildItem> producer)
      Creates the emitter that registers the generated Vaadin files with the application.

      The emitter skips the files that packaging already copies into the artifact by itself, so that they are not added a second time.

      Parameters:
      packagedRootDirectories - the directories Quarkus packages the application from, as reported by ArchiveRootBuildItem.getRootDirectories().
      producer - the producer registering the files with the application.
      Returns:
      the emitter to pass to buildFrontend(BiConsumer).
      See Also:
      • GeneratedResourceEmitter
    • clean

      public void clean()
      Cleans up generated frontend files if the corresponding configuration setting is enabled. The process involves creating a new cleaning task with specific options derived from the plugin adapter's configuration and executing it. If an error occurs during the execution of the clean task, it is logged for debugging purposes.

      The cleanup operation ensures the following: - Deletes the generated frontend files in the `node_modules` folder. - Utilizes the directory configurations such as frontend directory, npm folder, and generated TypeScript folder to locate the files. - Makes use of the `TaskCleanFrontendFiles` for cleanup operations.

      Unlike the Vaadin Maven plugin, which only cleans when a frontend bundle has been built, this runs after every successful build. This plugin always reports frontend hotdeploy as enabled, so even a build that reuses a prebuilt production bundle writes package.json, the Vite configuration files, tsconfig.json and types.d.ts into the project directory. Skipping the cleanup for those builds would leave the files behind.

      Errors are logged rather than propagated, including unchecked ones. This method runs as a Quarkus build closeable, which cannot fail the build and logs anything thrown out of here at debug level only, so an error that is not caught here goes unnoticed.