Class ToolAdapterIO
java.lang.Object
org.esa.snap.core.gpf.operators.tooladapter.ToolAdapterIO
Utility class for performing various operations needed by ToolAdapterOp.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathbackupOperator(ToolAdapterOperatorDescriptor operatorDescriptor) Creates a copy of the adapter folder.static voidconvertAdapter(Path modulePath) Converts adapter descriptor (prior to 4.0) to the new formatstatic voidstatic ToolAdapterOpSpicreateOperatorSpi(Path operatorFolder) Constructs an OperatorSpi from a given folder.static voiddeleteFolder(Path location) Deletes the given folder and its content.static voidfixPermissions(Path path) Ensure that the given path has all the permissions set.static PathReturns the location of the user-defined adapters.static StringReturns the current operating system.static StringReturns the OS-dependend shell script extension.static Filestatic StringgetVariableValue(String name, String defaultValue, boolean isShared) Returns the value of the named variable.static ToolAdapterOpSpiregisterAdapter(File adapterFolder) static ToolAdapterOpSpiregisterAdapter(Path adapterFolder) Register a tool adapter as an operator.static voidremoveOperator(ToolAdapterOperatorDescriptor operator) Removes the operator both from the SPI registry and also tries to remove the adapter folder from disk.static voidremoveOperator(ToolAdapterOperatorDescriptor operator, boolean removeOperatorFolder) Unregisters an adapter operator and, optionally, removes its folder from file system.static PathrestoreOperator(ToolAdapterOperatorDescriptor operatorDescriptor, Path backupPath) Restores the folder of a descriptor from a backup folder.static voidSaves any changes to the operator and registers it (in case of newly created ones).static voidsaveFileContent(File file, String content) Writes the given content in the specified file.static voidsaveVariable(String name, String value) Scans for adapter folders in the system and user paths.static Collection<ToolAdapterOpSpi> 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.static voidsetAdaptersPath(Path path) static voidunzip(Path sourceFile, Path destination, ProgressMonitor progressMonitor, int totalTasks) Uncompress the source zip file into the destination path.static Path
-
Constructor Details
-
ToolAdapterIO
public ToolAdapterIO()
-
-
Method Details
-
setAdaptersPath
-
saveVariable
-
getVariableValue
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 variabledefaultValue- Default value for the variable if not existsisShared- If this is a shared variable (i.e. shared among adapters)- Returns:
- The value (existing or default) of the variable
-
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
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
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 folderbackupPath- 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
Register a tool adapter as an operator.- Parameters:
adapterFolder- the folder of the tool adapter- Throws:
OperatorException- in case of an error
-
registerAdapter
- Throws:
OperatorException
-
scanForAdapters
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
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
-
saveFileContent
Writes the given content in the specified file.- Parameters:
file- The target filecontent- 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 unregisteredremoveOperatorFolder- Iftrue, deletes the operator folder.
-
getShellExtension
Returns the OS-dependend shell script extension.- Returns:
- For Windows: .bat, for Linux and MacOSX: .sh, for other OS: empty string
-
getOsFamily
Returns the current operating system. -
convertAdapter
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
Deletes the given folder and its content.- Parameters:
location- The folder to delete- Throws:
IOException- in case of an IO error
-
fixPermissions
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
- Throws:
IOException
-
zip
- 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 filedestination- The destination directory- Throws:
IOException
-