Class AbstractSyncTask

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.commons.vfs2.tasks.VfsTask
org.apache.commons.vfs2.tasks.AbstractSyncTask
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
CopyTask

public abstract class AbstractSyncTask extends VfsTask
An abstract file synchronization task. Scans a set of source files and folders, and a destination folder, and performs actions on missing and out-of-date files. Specifically, performs actions on the following:
  • Missing destination file.
  • Missing source file.
  • Out-of-date destination file.
  • Up-to-date destination file.
  • TODO - Deal with case where dest file maps to a child of one of the source files.
  • TODO - Deal with case where dest file already exists and is incorrect type (not file, not a folder).
  • TODO - Use visitors.
  • TODO - Add default excludes.
  • TOOD - Allow selector, mapper, filters, etc to be specified.
  • TODO - Handle source/dest directories as well.
  • TODO - Allow selector to be specified for choosing which dest files to sync.
  • Field Details

    • srcFiles

      private final ArrayList<AbstractSyncTask.SourceInfo> srcFiles
    • destFileUrl

      private String destFileUrl
    • destDirUrl

      private String destDirUrl
    • srcDirUrl

      private String srcDirUrl
    • srcDirIsBase

      private boolean srcDirIsBase
    • failonerror

      private boolean failonerror
    • filesList

      private String filesList
  • Constructor Details

    • AbstractSyncTask

      public AbstractSyncTask()
  • Method Details

    • setDestFile

      public void setDestFile(String destFile)
      Sets the destination file.
      Parameters:
      destFile - The destination file name.
    • setDestDir

      public void setDestDir(String destDir)
      Sets the destination directory.
      Parameters:
      destDir - The destination directory.
    • setSrc

      public void setSrc(String srcFile)
      Sets the source file.
      Parameters:
      srcFile - The source file name.
    • setSrcDir

      public void setSrcDir(String srcDir)
      Sets the source directory.
      Parameters:
      srcDir - The source directory.
    • setSrcDirIsBase

      public void setSrcDirIsBase(boolean srcDirIsBase)
      Sets whether the source directory should be consider as the base directory.
      Parameters:
      srcDirIsBase - true if the source directory is the base directory.
    • setFailonerror

      public void setFailonerror(boolean failonerror)
      Sets whether we should fail if there was an error or not.
      Parameters:
      failonerror - true if the operation should fail if there is an error.
    • isFailonerror

      public boolean isFailonerror()
      Sets whether we should fail if there was an error or not.
      Returns:
      true if the operation should fail if there was an error.
    • setIncludes

      public void setIncludes(String filesList)
      Sets the files to includes.
      Parameters:
      filesList - The list of files to include.
    • addConfiguredSrc

      public void addConfiguredSrc(AbstractSyncTask.SourceInfo srcInfo) throws org.apache.tools.ant.BuildException
      Adds a nested <src> element.
      Parameters:
      srcInfo - A nested source element.
      Throws:
      org.apache.tools.ant.BuildException - if the SourceInfo doesn't reference a file.
    • execute

      public void execute() throws org.apache.tools.ant.BuildException
      Executes this task.
      Overrides:
      execute in class org.apache.tools.ant.Task
      Throws:
      org.apache.tools.ant.BuildException - if an error occurs.
    • logOrDie

      protected void logOrDie(String message, int level)
    • handleFiles

      private void handleFiles() throws Exception
      Copies the source files to the destination.
      Throws:
      Exception
    • handleFile

      private void handleFile(Set<FileObject> destFiles, FileObject srcFile, FileObject destFile) throws Exception
      Handles a single file, checking for collisions where more than one source file maps to the same destination file.
      Throws:
      Exception
    • handleSingleFile

      private void handleSingleFile() throws Exception
      Copies a single file.
      Throws:
      Exception
    • handleFile

      private void handleFile(FileObject srcFile, FileObject destFile) throws Exception
      Handles a single source file.
      Throws:
      Exception
    • handleOutOfDateFile

      protected void handleOutOfDateFile(FileObject srcFile, FileObject destFile) throws Exception
      Handles an out-of-date file.

      This is a file where the destination file either doesn't exist, or is older than the source file.

      This implementation does nothing.

      Parameters:
      srcFile - The source file.
      destFile - The destination file.
      Throws:
      Exception - Implementation can throw any Exception.
    • handleUpToDateFile

      protected void handleUpToDateFile(FileObject srcFile, FileObject destFile) throws Exception
      Handles an up-to-date file.

      This is where the destination file exists and is newer than the source file.

      This implementation does nothing.

      Parameters:
      srcFile - The source file.
      destFile - The destination file.
      Throws:
      Exception - Implementation can throw any Exception.
    • handleMissingSourceFile

      protected void handleMissingSourceFile(FileObject destFile) throws Exception
      Handles a destination for which there is no corresponding source file.

      This implementation does nothing.

      Parameters:
      destFile - The existing destination file.
      Throws:
      Exception - Implementation can throw any Exception.
    • detectMissingSourceFiles

      protected boolean detectMissingSourceFiles()
      Check if this task cares about destination files with a missing source file.

      This implementation returns false.

      Returns:
      True if missing file is detected.