Class ToolAdapterIO

java.lang.Object
org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO

public class ToolAdapterIO extends Object
Utility class for performing various operations needed by ToolAdapterOp.
  • Constructor Details

    • ToolAdapterIO

      public ToolAdapterIO()
  • Method Details

    • setAdaptersPath

      public static void setAdaptersPath(Path path)
    • saveVariable

      public static void saveVariable(String name, String value)
    • getVariableValue

      public static String getVariableValue(String name, String defaultValue, boolean isShared)
      Returns the value of the named variable. If the variable doesn't exist, it will be created with the given default value.
      Parameters:
      name - The name of the variable
      defaultValue - Default value for the variable if not exists
      isShared - If this is a shared variable (i.e. shared among adapters)
      Returns:
      The value (existing or default) of the variable
    • searchAndRegisterAdapters

      public static Collection<ToolAdapterOpSpi> searchAndRegisterAdapters()
      Scans for adapter folders in the system and user paths and registers all the adapters that have been found by adding an OperatorSpi for each adapter into the OperatorSpi registry.
      Returns:
      A list of registered OperatorSPIs
    • createOperatorSpi

      public static ToolAdapterOpSpi createOperatorSpi(Path operatorFolder) throws OperatorException
      Constructs an OperatorSpi from a given folder.
      Parameters:
      operatorFolder - The path containing the file/folder operator structure
      Returns:
      An SPI for the read operator.
      Throws:
      OperatorException - in case of an erro
    • removeOperator

      public static void removeOperator(ToolAdapterOperatorDescriptor operator)
      Removes the operator both from the SPI registry and also tries to remove the adapter folder from disk.
      Parameters:
      operator - The operator descriptor to be removed
    • backupOperator

      public static Path backupOperator(ToolAdapterOperatorDescriptor operatorDescriptor) throws IOException
      Creates a copy of the adapter folder.
      Parameters:
      operatorDescriptor - The operator descriptor for which to backup the folder
      Returns:
      The path of the backup folder
      Throws:
      IOException - in case of an IO error
    • restoreOperator

      public static Path restoreOperator(ToolAdapterOperatorDescriptor operatorDescriptor, Path backupPath) throws IOException
      Restores the folder of a descriptor from a backup folder.
      Parameters:
      operatorDescriptor - The operator descriptor for which to restore the folder
      backupPath - The path from which to restore the folder
      Returns:
      The path of the resored folder
      Throws:
      IOException - in case of an IO error
    • saveAndRegisterOperator

      public static void saveAndRegisterOperator(ToolAdapterOperatorDescriptor operator) throws IOException
      Saves any changes to the operator and registers it (in case of newly created ones).
      Parameters:
      operator - The operator descriptor
      Throws:
      IOException - in case of an IO error
    • registerAdapter

      public static ToolAdapterOpSpi registerAdapter(Path adapterFolder) throws OperatorException
      Register a tool adapter as an operator.
      Parameters:
      adapterFolder - the folder of the tool adapter
      Throws:
      OperatorException - in case of an error
    • registerAdapter

      public static ToolAdapterOpSpi registerAdapter(File adapterFolder) throws OperatorException
      Throws:
      OperatorException
    • scanForAdapters

      public static List<File> scanForAdapters() throws IOException
      Scans for adapter folders in the system and user paths.
      Returns:
      A list of adapter folders.
      Throws:
      IOException - in case of an IO error
    • getAdaptersPath

      public static Path getAdaptersPath()
      Returns the location of the user-defined adapters. Also, in this location packed jar adapters may be found.
      Returns:
      The location of user-defined modules.
    • getUserAdapterPath

      public static File getUserAdapterPath()
    • saveFileContent

      public static void saveFileContent(File file, String content) throws IOException
      Writes the given content in the specified file.
      Parameters:
      file - The target file
      content - The content to be written
      Throws:
      IOException - in case of an IO error
    • removeOperator

      public static void removeOperator(ToolAdapterOperatorDescriptor operator, boolean removeOperatorFolder)
      Unregisters an adapter operator and, optionally, removes its folder from file system.
      Parameters:
      operator - The operator descriptor to be unregistered
      removeOperatorFolder - If true, deletes the operator folder.
    • getShellExtension

      public static String getShellExtension()
      Returns the OS-dependend shell script extension.
      Returns:
      For Windows: .bat, for Linux and MacOSX: .sh, for other OS: empty string
    • getOsFamily

      public static String getOsFamily()
      Returns the current operating system.
    • convertAdapter

      public static void convertAdapter(Path modulePath) throws IOException
      Converts adapter descriptor (prior to 4.0) to the new format
      Parameters:
      modulePath - The adapter path
      Throws:
      IOException - in case of an IO error
    • deleteFolder

      public static void deleteFolder(Path location) throws IOException
      Deletes the given folder and its content.
      Parameters:
      location - The folder to delete
      Throws:
      IOException - in case of an IO error
    • fixPermissions

      public static void fixPermissions(Path path) throws IOException
      Ensure that the given path has all the permissions set. This is especially useful for Linux/MacOsX executables.
      Parameters:
      path - The path to fix permissions for.
      Throws:
      IOException
    • copy

      public static void copy(Path source, Path destination) throws IOException
      Throws:
      IOException
    • zip

      public static Path zip(Path source, Path zipFile) throws IOException
      Throws:
      IOException
    • unzip

      public static void unzip(Path sourceFile, Path destination, ProgressMonitor progressMonitor, int totalTasks) throws IOException
      Uncompress the source zip file into the destination path.
      Parameters:
      sourceFile - The zip file
      destination - The destination directory
      Throws:
      IOException