Class AbstractFileGeneratorFallibleCommand

java.lang.Object
com.vaadin.flow.server.frontend.AbstractFileGeneratorFallibleCommand
All Implemented Interfaces:
FallibleCommand
Direct Known Subclasses:
AbstractTaskClientGenerator, TaskCopyFrontendFiles, TaskCopyLocalFrontendFiles, TaskGenerateReactFiles, TaskUpdateThemeImport

public abstract class AbstractFileGeneratorFallibleCommand extends Object implements FallibleCommand
A base class for commands providing helpers for common file generation actions.

By extending this class, commands can track generated files for subsequent processes. In addition, it allows to avoid writes on disk of the file already exists and has exactly the same generated content, preventing file system watchers to trigger unnecessary events.
  • Constructor Details

    • AbstractFileGeneratorFallibleCommand

      public AbstractFileGeneratorFallibleCommand()
  • Method Details

    • setGeneratedFileSupport

      public void setGeneratedFileSupport(GeneratedFilesSupport support)
      Description copied from interface: FallibleCommand
      Accepts GeneratedFilesSupport utility allows to track generated files but write them only when the content is changed, preventing filesystem watchers to be triggered when not required.
      Specified by:
      setGeneratedFileSupport in interface FallibleCommand
      Parameters:
      support - the generated file support utility to use.
    • writeIfChanged

      protected boolean writeIfChanged(File file, List<String> content) throws IOException
      Writes the given content into the given file unless the file already contains that content.
      Parameters:
      file - the file to write to
      content - the lines to write
      Returns:
      true if the content was written to the file, false otherwise
      Throws:
      IOException - if something went wrong
    • writeIfChanged

      protected boolean writeIfChanged(File file, String content) throws IOException
      Writes the given content into the given file unless the file already contains that content.
      Parameters:
      file - the file to write to
      content - the content to write
      Returns:
      true if the content was written to the file, false otherwise
      Throws:
      IOException - if something went wrong
    • track

      protected void track(File file)
      Marks the give file as generated by the task.
      Parameters:
      file - the file to be marked as generated.
    • track

      protected void track(Collection<File> files)
      Marks the give files as generated by the task.
      Parameters:
      files - the collection of files to be marked as generated.