Class ResourcesModule
java.lang.Object
org.eclipse.ease.modules.AbstractScriptModule
org.eclipse.ease.modules.platform.ResourcesModule
- All Implemented Interfaces:
IExecutionListener,IScriptModule
public class ResourcesModule extends AbstractScriptModule implements IExecutionListener
-
Field Summary
Fields Modifier and Type Field Description static intAPPENDAccess modifier for append mode (4).static StringMODULE_IDModule identifier.static intREADAccess modifier for read mode (1).static intWRITEAccess modifier for write mode (2).Fields inherited from interface org.eclipse.ease.IExecutionListener
ENGINE_END, ENGINE_START, SCRIPT_END, SCRIPT_INJECTION_END, SCRIPT_INJECTION_START, SCRIPT_START -
Constructor Summary
Constructors Constructor Description ResourcesModule() -
Method Summary
Modifier and Type Method Description voidcloseFile(IFileHandle handle)Close a file.voidcopyFile(Object sourceLocation, Object targetLocation)Copies a file from location to targetLocation.ObjectcreateFile(Object location)Create a new file in the workspace or the file system.ObjectcreateFolder(Object location)Create a new folder in the workspace or the file system.voidcreateProblemMarker(String severity, Object location, int lineNumber, String message, String type, boolean permanent)Create a problem marker on a file resource.static org.eclipse.core.resources.IProjectcreateProject(String name)Create a new workspace project.voiddeleteFile(Object source)Delete a file from the workspace or local file system.voiddeleteFolder(Object source)Delete a folder from the workspace or local file system.voiddeleteProject(Object source)Delete a project from the workspace.booleanfileExists(Object location)Verifies that a specific file exists.Object[]findFiles(String pattern, Object rootFolder, boolean recursive)Return files matching a certain pattern.StringgetChecksum(Object location)Get an MD5 checksum over a readable resource.ObjectgetFile(String location, boolean exists)Get a workspace or file system file.static org.eclipse.core.resources.IProjectgetProject(String name)Get a project instance.static org.eclipse.core.resources.IWorkspaceRootgetWorkspace()Get the workspace root.org.eclipse.core.resources.IProjectimportProject(Object location)Imports a project into the current workspace.org.eclipse.core.resources.IProjectlinkProject(Object location)Links a project into the current workspace.voidnotify(IScriptEngine engine, Script script, int status)IFileHandleopenFile(Object location, int mode, boolean autoClose)Opens a file from the workspace or the file system.StringreadFile(Object location, int bytes)Read data from a file.StringreadLine(Object location)Read a single line from a file.StringreadStream(InputStream input)Read from an InputStream into a string.voidrefreshResource(Object resource)Refresh a given resource and all its child elements.StringshowFileSelectionDialog(Object rootFolder, int type, String title, String message)Opens a file dialog.StringshowFolderSelectionDialog(Object rootFolder, String title, String message)Opens a dialog box which allows the user to select a container (project or folder).Objectunzip(Object zipLocation, Object targetLocation)Unzip a zip file to the provided target location.IFileHandlewriteFile(Object location, Object data, int mode, boolean autoClose)Write data to a file.IFileHandlewriteLine(Object location, String data, int mode, boolean autoClose)Write a line of data to a file.Objectzip(Object sourceLocation, Object zipLocation)Create or update a zip file with given resources.Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule
getScriptEngine, initialize
-
Field Details
-
MODULE_ID
Module identifier.- See Also:
- Constant Field Values
-
READ
public static final int READAccess modifier for read mode (1).- See Also:
- Constant Field Values
-
WRITE
public static final int WRITEAccess modifier for write mode (2).- See Also:
- Constant Field Values
-
APPEND
public static final int APPENDAccess modifier for append mode (4).- See Also:
- Constant Field Values
-
-
Constructor Details
-
ResourcesModule
public ResourcesModule()
-
-
Method Details
-
getWorkspace
public static org.eclipse.core.resources.IWorkspaceRoot getWorkspace()Get the workspace root.- Returns:
- workspace root
-
getProject
Get a project instance.- Parameters:
name- project name- Returns:
- project or
null
-
getFile
Get a workspace or file system file. Resolves relative and absolute file locations. Relative files are resolved against the current script file. If exists isfalsethis method also returns files that do not exist yet. Iftrueonly existing instances are returned.- Parameters:
location- file location/path to resolveexists- whether the resolved file needs to exist- Returns:
- resolved
IFileorFileinstance
-
createProject
Create a new workspace project. Will create a new project if it not already exists. If creation fails,nullis returned.- Parameters:
name- name or project to create- Returns:
nullor project
-
createFolder
Create a new folder in the workspace or the file system.- Parameters:
location- folder location- Returns:
IFolder,Fileornullin case of error- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- This resource already exists in the workspace.
- The workspace contains a resource of a different type at the same path as this resource.
- The parent of this resource does not exist.
- The parent of this resource is a project that is not open.
- The parent contains a resource of a different type at the same path as this resource.
- The parent of this resource is virtual, but this resource is not.
- The name of this resource is not valid (according to
IWorkspace.validateName). - The corresponding location in the local file system is occupied by a file (as opposed to a directory).
- The corresponding location in the local file system is occupied by a folder and
forceisfalse. - Resource changes are disallowed during certain types of resource change event notification. See
IResourceChangeEventfor more details.
-
createFile
Create a new file in the workspace or the file system. -
openFile
public IFileHandle openFile(Object location, @ScriptParameter(defaultValue="1") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws ExceptionOpens a file from the workspace or the file system. If the file does not exist and we open it for writing, the file is created automatically.- Parameters:
location- file locationmode- one of , ,autoClose- automatically close resource when script engine is terminated- Returns:
- file handle instance to be used for file modification commands
- Throws:
Exception- problems on file access
-
fileExists
Verifies that a specific file exists.- Parameters:
location- file location to verify- Returns:
trueif file exists
-
closeFile
Close a file. Releases system resources bound by an open file.- Parameters:
handle- handle to be closed
-
readFile
public String readFile(Object location, @ScriptParameter(defaultValue="-1") int bytes) throws ExceptionRead data from a file. To repeatedly read from a file retrieve aIFileHandlefirst using and use the handle for location.- Parameters:
location- file location, file handle or file instancebytes- amount of bytes to read (-1 for whole file)- Returns:
- file data or
nullif EOF is reached - Throws:
Exception- problems on file access
-
copyFile
Copies a file from location to targetLocation.- Parameters:
sourceLocation- file location, file handle or file instance for the source objecttargetLocation- file location, file handle or file instance for the target object- Throws:
Exception- problems on file access
-
deleteFile
Delete a file from the workspace or local file system.- Parameters:
source- file to be deleted- Throws:
org.eclipse.core.runtime.CoreException- on deletion errors
-
deleteFolder
Delete a folder from the workspace or local file system.- Parameters:
source- folder to be deleted- Throws:
org.eclipse.core.runtime.CoreException- on deletion errors
-
deleteProject
Delete a project from the workspace.- Parameters:
source- project to be deleted- Throws:
org.eclipse.core.runtime.CoreException- on deletion errors
-
readLine
Read a single line from a file. To repeatedly read from a file retrieve aIFileHandlefirst using and use the handle for location.- Parameters:
location- file location, file handle or file instance- Returns:
- line of text or
nullif EOF is reached - Throws:
Exception- problems on file access
-
writeFile
public IFileHandle writeFile(Object location, Object data, @ScriptParameter(defaultValue="2") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws ExceptionWrite data to a file. When not using anIFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created. After the write operation the file remains open. It needs to be closed explicitly using the command- Parameters:
location- file locationdata- data to be writtenmode- write mode (/)autoClose- automatically close resource when script engine is terminated- Returns:
- file handle to continue write operations
- Throws:
Exception- problems on file access
-
writeLine
public IFileHandle writeLine(Object location, String data, @ScriptParameter(defaultValue="2") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws ExceptionWrite a line of data to a file. When not using anIFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created.- Parameters:
location- file locationdata- data to be writtenmode- write mode (/)autoClose- automatically close resource when script engine is terminated- Returns:
- file handle to continue write operations
- Throws:
Exception- problems on file access
-
showFileSelectionDialog
public String showFileSelectionDialog(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object rootFolder, @ScriptParameter(defaultValue="0") int type, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String title, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String message)Opens a file dialog. Depending on the rootFolder a workspace dialog or a file system dialog will be used. If the folder cannot be located, the workspace root folder is used by default. When type is set to or a save dialog will be shown instead of the default open dialog.- Parameters:
rootFolder- root folder path to usetype- dialog type to use (/ for save dialog, other for open dialog)title- dialog titlemessage- dialog message- Returns:
- full path to selected file
-
showFolderSelectionDialog
public String showFolderSelectionDialog(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object rootFolder, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String title, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") String message)Opens a dialog box which allows the user to select a container (project or folder). Workspace paths will always display the workspace as root object.- Parameters:
rootFolder- root folder to display: for workspace paths this will set the default selectiontitle- dialog titlemessage- dialog message- Returns:
- path to selected folder
-
findFiles
public Object[] findFiles(String pattern, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object rootFolder, @ScriptParameter(defaultValue="true") boolean recursive)Return files matching a certain pattern.- Parameters:
pattern- search pattern: use * and ? as wildcards. If the pattern starts with '^' then a regular expression can be used.rootFolder- root folder to start your search from.nullfor workspace rootrecursive- searches subfolders when set totrue- Returns:
- An array of all matching files
-
linkProject
public org.eclipse.core.resources.IProject linkProject(Object location) throws org.eclipse.core.runtime.CoreException, IOExceptionLinks a project into the current workspace. Does not copy resources to the workspace.- Parameters:
location- location of project (needs to contain .project file)- Returns:
- linked project, throws otherwise
- Throws:
org.eclipse.core.runtime.CoreException- when project description cannot be loaded from .project fileIOException- when project location cannot be read/linked
-
importProject
public org.eclipse.core.resources.IProject importProject(Object location) throws InvocationTargetException, InterruptedException, IOException, org.eclipse.core.runtime.CoreExceptionImports a project into the current workspace. The project needs to be available on the file system and needs to be unpacked. Zipped projects cannot be imported.- Parameters:
location- location of project (needs to contain .project file)- Returns:
- project instance, throws otherwise
- Throws:
InvocationTargetException- on errors during the importInterruptedException- when import task got interruptedIOException- when project cannot be located on diskorg.eclipse.core.runtime.CoreException- when project description cannot be loaded from .project file
-
refreshResource
Refresh a given resource and all its child elements.- Parameters:
resource-IFile,IFolder,IProjector workspace root to update- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- Resource changes are disallowed during certain types of resource change event notification. See
IResourceChangeEventfor more details.
- Resource changes are disallowed during certain types of resource change event notification. See
-
readStream
Read from an InputStream into a string. Consumes anInputStreamand stores all available data in a string. Usually a stream is only readable once.- Parameters:
input- input stream to read from- Returns:
- string content of stream.
- Throws:
IOException- on read error on the stream
-
createProblemMarker
public void createProblemMarker(String severity, Object location, int lineNumber, String message, @ScriptParameter(defaultValue="org.eclipse.core.resources.problemmarker") String type, @ScriptParameter(defaultValue="true") boolean permanent) throws org.eclipse.core.runtime.CoreExceptionCreate a problem marker on a file resource.- Parameters:
severity- one of error/warning/infolocation- file resource to create marker forlineNumber- line number to set marker onmessage- message to be added to the markertype- marker type to create, needs to match an existing typepermanent-truefor permanent markers,falsefor temporary markers- Throws:
org.eclipse.core.runtime.CoreException- when marker cannot be created
-
notify
- Specified by:
notifyin interfaceIExecutionListener
-
zip
Create or update a zip file with given resources.- Parameters:
sourceLocation- source folder/file to zipzipLocation- zip file to use- Returns:
- zip file reference
- Throws:
IOException- when zip file cannot be created
-
unzip
Unzip a zip file to the provided target location.- Parameters:
zipLocation- zip file to unziptargetLocation- folder to unzip to- Returns:
- target location reference
- Throws:
IOException- when zip file cannot be unzipped
-
getChecksum
Get an MD5 checksum over a readable resource.- Parameters:
location- location of resource to create checksum for- Returns:
- file hash as hex encoded string
- Throws:
NoSuchAlgorithmException- when MD5 digest cannot be foundIOException- when resource cannot be read
-