Class ResourcesModule
java.lang.Object
org.eclipse.ease.modules.AbstractScriptModule
org.eclipse.ease.modules.platform.resources.ResourcesModule
- All Implemented Interfaces:
IExecutionListener
,IScriptModule
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Access modifier for append mode (4).static final String
Module identifier.static final int
Access modifier for read mode (1).static final int
Access 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
closeFile
(IFileHandle handle) Close a file.void
Copies a file from location to targetLocation.createFile
(Object location) Create a new file in the workspace or the file system.createFolder
(Object location) Create a new folder in the workspace or the file system.void
createProblemMarker
(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.IProject
createProject
(String name) Create a new workspace project.void
deleteFile
(Object location) Delete a file.void
deleteFolder
(Object location) Delete a folder recursively.void
deleteProject
(Object source) Delete a project from the workspace.boolean
fileExists
(Object location) Verifies that a specific file exists.String[]
Return files matching a certain pattern.getChecksum
(Object location) Get an MD5 checksum over a readable resource.Get a workspace or file system file.static org.eclipse.core.resources.IProject
getProject
(String name) Get a project instance.static org.eclipse.core.resources.IWorkspaceRoot
Get the workspace root.org.eclipse.core.resources.IProject
importProject
(Object location) Imports a project into the current workspace.org.eclipse.core.resources.IProject
linkProject
(Object location) Links a project into the current workspace.void
notify
(IScriptEngine engine, Script script, int status) Notifies the listeners when script execution started/ended or when the engine itself is started/ended.Opens a file from the workspace or the file system.Read data from a file.Read a single line from a file.readStream
(InputStream input) Read from an InputStream into a string.Read full content from a given URL.void
refreshResource
(Object resource) Refresh a given resource and all its child elements.showFileSelectionDialog
(Object rootFolder, int type, String title, String message) Opens a file dialog.showFolderSelectionDialog
(Object rootFolder, String title, String message) Opens a dialog box which allows the user to select a container (project or folder).Unzip a zip file to the provided target location.Write data to a file.Write a line of data to a file.Create or update a zip file with given resources.Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule
initialize
-
Field Details
-
MODULE_ID
Module identifier.- See Also:
-
READ
public static final int READAccess modifier for read mode (1).- See Also:
-
WRITE
public static final int WRITEAccess modifier for write mode (2).- See Also:
-
APPEND
public static final int APPENDAccess modifier for append mode (4).- See Also:
-
-
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
public Object getFile(String location, @ScriptParameter(defaultValue="true") boolean exists) throws FileNotFoundException Get a workspace or file system file. Resolves relative and absolute file locations. Relative files are resolved against the current script file. If exists isfalse
this method also returns files that do not exist yet. Iftrue
only existing instances are returned.- Parameters:
location
- file location/path to resolveexists
- whether the resolved file needs to exist- Returns:
- resolved
IFile
orFile
instance - Throws:
FileNotFoundException
- when file does not exist and exists istrue
-
createProject
Create a new workspace project. Will create a new project if it not already exists. In case the project already exists, the existing instance will be returned.- Parameters:
name
- name of project to create- Returns:
- project instance
- Throws:
IOException
- when project creation fails
-
createFolder
Create a new folder in the workspace or the file system.- Parameters:
location
- folder location- Returns:
IFolder
orFile
instance- Throws:
IOException
- 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
force
isfalse
. - Resource changes are disallowed during certain types of resource change event notification. See
IResourceChangeEvent
for more details.
-
createFile
Create a new file in the workspace or the file system.- Parameters:
location
- file location- Returns:
IFile
,File
ornull
in case of error- Throws:
IOException
- problems on file access
-
openFile
public IFileHandle openFile(Object location, @ScriptParameter(defaultValue="1") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws IOException Opens 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:
IOException
- problems on file access
-
fileExists
Verifies that a specific file exists.- Parameters:
location
- file location to verify- Returns:
true
if 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 IOException Read data from a file. To repeatedly read from a file retrieve aIFileHandle
first 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
null
if EOF is reached - Throws:
IOException
- 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:
IOException
- problems on file access
-
deleteFile
Delete a file. Does nothing if location cannot be resolved to an existing file.- Parameters:
location
- file to be deleted- Throws:
IOException
- on deletion errors
-
deleteFolder
Delete a folder recursively.- Parameters:
location
- folder to be deleted- Throws:
IOException
- on deletion errors
-
deleteProject
Delete a project from the workspace.- Parameters:
source
- location or name of project to be deleted- Throws:
IOException
- on deletion errors
-
readLine
Read a single line from a file. To repeatedly read from a file retrieve aIFileHandle
first using and use the handle for location.- Parameters:
location
- file location, file handle or file instance- Returns:
- line of text or
null
if EOF is reached - Throws:
IOException
- problems on file access
-
writeFile
public IFileHandle writeFile(Object location, Object data, @ScriptParameter(defaultValue="2") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws IOException Write data to a file. Files that do not exist yet will be created automatically. 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:
IOException
- problems on file access
-
writeLine
public IFileHandle writeLine(Object location, String data, @ScriptParameter(defaultValue="2") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws IOException Write a line of data to a file. Files that do not exist yet will be created automatically. 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:
IOException
- 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) throws IOException 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, for open dialog)title
- dialog titlemessage
- dialog message- Returns:
- full path to selected file either as absolute file system path or as absolute workspace URI. Returns
null
when the dialog is cancelled by the user. - Throws:
IOException
- when root folder cannot be found
-
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) throws IOException 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:
- full path to selected folder either as absolute file system path or as absolute workspace URI. Returns
null
when the dialog is cancelled by the user. - Throws:
IOException
- when root folder cannot be found
-
findFiles
public String[] findFiles(String pattern, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") Object rootFolder, @ScriptParameter(defaultValue="true") boolean recursive) throws IOException 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.null
for workspace rootrecursive
- searches subfolders when set totrue
- Returns:
- An array of all matching file locations
- Throws:
IOException
- when search fails
-
linkProject
Links a project into the current workspace. Does not copy resources to the workspace.- Parameters:
location
- location of project folder (needs to contain .project file)- Returns:
- linked project, throws otherwise
- Throws:
IOException
- when project location cannot be read/linked
-
importProject
Imports 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 folder (needs to contain .project file)- Returns:
- project instance, throws otherwise
- Throws:
IOException
- on any import errors
-
refreshResource
Refresh a given resource and all its child elements.- Parameters:
resource
-IFile
,IFolder
,IProject
or workspace root to update- Throws:
IOException
- if this method fails. Reasons include:- Resource changes are disallowed during certain types of resource change event notification. See
IResourceChangeEvent
for more details.
- Resource changes are disallowed during certain types of resource change event notification. See
-
readStream
Read from an InputStream into a string. Consumes anInputStream
and 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
-
readUrl
Read full content from a given URL.- Parameters:
address
- address to read from- Returns:
- read data
- 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 IOException Create 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
-true
for permanent markers,false
for temporary markers- Throws:
IOException
- when marker cannot be created
-
notify
Description copied from interface:IExecutionListener
Notifies the listeners when script execution started/ended or when the engine itself is started/ended.- Specified by:
notify
in interfaceIExecutionListener
- Parameters:
engine
- Script Enginescript
- Script ornull
status
- Event Status
-
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/appended
-
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:
IOException
- when resource cannot be read
-