Class PublicResourcesLiveUpdater

java.lang.Object
com.vaadin.base.devserver.PublicResourcesLiveUpdater
All Implemented Interfaces:
Closeable, AutoCloseable

public class PublicResourcesLiveUpdater extends Object implements Closeable
Watches source public resource folders for CSS changes and pushes updates to the browser via the debug window connection.

Watched source roots map to public static resources in the running application, such as:

  • src/main/resources/META-INF/resources
  • src/main/resources/resources
  • src/main/resources/static
  • src/main/resources/public
  • src/main/webapp

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

Since:
25.0
  • Constructor Details

    • PublicResourcesLiveUpdater

      public PublicResourcesLiveUpdater(List<String> roots, VaadinContext context)
      Starts watching the given list of source folders for CSS changes.
      Parameters:
      roots - the list of source folders to watch; non-existing ones are ignored
      context - the current Vaadin context
  • Method Details

    • suspend

      public static void suspend(VaadinContext context)
      Stops this watcher from pushing CSS changes for the given context.

      For a tool that owns the edit-to-running-app loop, watching on save is the wrong trigger: the loop decides when a change goes live, and a second watcher pushing on its own makes "what is the state of my last change?" unanswerable. Such a tool suspends this and performs the resource leg itself.

      A context attribute rather than a field, so it can be set before or after the watcher is created - the check happens when a file changes.

      Parameters:
      context - the current Vaadin context
      Since:
      25.3
    • push

      public static int push(VaadinContext context, List<File> extraRoots)
      Re-bundles every active @StyleSheet URL and pushes the result to the browser, which is what the watcher does when a public CSS file is saved.

      Separate from the watcher so a tool that owns the apply loop can perform exactly the same update at the moment it decides a change goes live, rather than reimplementing the bundling and the URL. See suspend(VaadinContext), and ThemeLiveUpdater.push(java.io.File, com.vaadin.flow.server.VaadinContext) for the theme leg's equivalent.

      Every active URL rather than only the file that changed, because an @import means the stylesheet the browser knows is not the file that was edited - and the URL the browser knows it by is what the update has to be keyed on.

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

      Parameters:
      context - the current Vaadin context
      extraRoots - public resource roots to resolve against in addition to this project's own, for a caller that knows of roots this watcher does not - a reactor sibling's, say. Empty for the watcher itself.
      Returns:
      how many stylesheets reached the browser
      Since:
      25.3
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException