Resources Module

Provides file access for workspace and file system resources. Methods accepting location objects can deal with String, URI, IFile and File instances.

Constants

Constant Description
APPEND Access modifier for append mode (4).
READ Access modifier for read mode (1).
WRITE Access modifier for write mode (2).

Method Overview

Method Description
closeFile() Close a file.
copyFile() Copies a file from location to targetLocation.
createFile() Create a new file in the workspace or the file system.
createFolder() Create a new folder in the workspace or the file system.
createProblemMarker() Create a problem marker on a file resource.
createProject() Create a new workspace project.
deleteFile() Delete a file from the workspace or local file system.
deleteFolder() Delete a folder from the workspace or local file system.
deleteProject() Delete a project from the workspace.
fileExists() Verifies that a specific file exists.
findFiles() Return files matching a certain pattern.
getFile() Get a workspace or file system file.
getProject() Get a project instance.
getWorkspace() Get the workspace root.
linkProject() Links a project into the current workspace.
openFile() Opens a file from the workspace or the file system.
readFile() Read data from a file.
readLine() Read a single line from a file.
readStream() Read from an InputStream into a string.
refreshResource() Refresh a given resource and all its child elements.
showFileSelectionDialog() Opens a file dialog.
showFolderSelectionDialog() Opens a dialog box which allows the user to select a container (project or folder).
writeFile() Write data to a file.
writeLine() Write a line of data to a file.

Methods

closeFile

void closeFile(org.eclipse.ease.modules.platform.IFileHandle handle)

Close a file. Releases system resources bound by an open file.

handle
handle to be closed

copyFile

void copyFile(java.lang.Object sourceLocation, java.lang.Object targetLocation)

Copies a file from location to targetLocation.

sourceLocation
targetLocation
file location, file handle or file instance
Exception
problems on file access

createFile

java.lang.Object createFile(java.lang.Object location)

Create a new file in the workspace or the file system.

location
file location

IFile, File or null in case of error

Exception
problems on file access

createFolder

java.lang.Object createFolder(java.lang.Object location)

Create a new folder in the workspace or the file system.

location
folder location

IFolder, File or null in case of error

CoreException

createProblemMarker

void createProblemMarker(java.lang.String severity, java.lang.Object location, int lineNumber, java.lang.String message, [java.lang.String type], [boolean permanent])

Create a problem marker on a file resource.

severity
one of error/warning/info
location
file resource to create marker for
lineNumber
line number to set marker on
message
message to be added to the marker
type
marker type to create, needs to match an existing typeOptional: defaults to <"org.eclipse.core.resources.problemmarker">.
permanent
true for permanent markers, false for temporary markersOptional: defaults to <true>.
CoreException
when marker cannot be created

createProject

org.eclipse.core.resources.IProject createProject(java.lang.String name)

Create a new workspace project. Will create a new project if it now already exists. If creation fails, null is returned.

name
name or project to create

null or project

deleteFile

void deleteFile(java.lang.Object source)

Delete a file from the workspace or local file system.

source
file to be deleted
CoreException
on deletion errors

deleteFolder

void deleteFolder(java.lang.Object source)

Delete a folder from the workspace or local file system.

source
folder to be deleted
CoreException
on deletion errors

deleteProject

void deleteProject(java.lang.Object source)

Delete a project from the workspace.

source
project to be deleted
CoreException
on deletion errors

fileExists

boolean fileExists(java.lang.Object location)

Verifies that a specific file exists.

location
file location to verify

true if file exists

findFiles

java.lang.Object findFiles(java.lang.String pattern, [java.lang.Object rootFolder], [boolean recursive])

Return files matching a certain pattern.

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 rootOptional: defaults to <null>.
recursive
searches subfolders when set to trueOptional: defaults to <true>.

An array of all matching files

getFile

java.lang.Object getFile(java.lang.String location, [boolean exists])

Get a workspace or file system file. Resolves relative and absolute file locations. Relative files are resolved against the current script file. If exists is false this method also returns files that do not exist yet. If true only existing instances are returned.

location
file location/path to resolve
exists
whether the resolved file needs to existOptional: defaults to <true>.

resolved IFile or File instance

getFile("workspace://my project/some folder/file.txt")
to get the file.txt resource from the workspace
getFile("project://some folder/file.txt")
to get the file.txt resource as a project relative path

getProject

org.eclipse.core.resources.IProject getProject(java.lang.String name)

Get a project instance.

name
project name

project or null

getWorkspace

org.eclipse.core.resources.IWorkspaceRoot getWorkspace()

Get the workspace root.

workspace root

linkProject

boolean linkProject(java.lang.String location)

Links a project into the current workspace. Does not copy resources to the workspace.

location
location of project (needs to contain .project file)

link result

openFile

org.eclipse.ease.modules.platform.IFileHandle openFile(java.lang.Object location, [int mode], [boolean autoClose])

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.

location
file location
mode
one of READ, WRITE, APPENDOptional: defaults to <1>.
autoClose
automatically close resource when script engine is terminatedOptional: defaults to <true>.

file handle instance to be used for file modification commands

Exception
problems on file access

readFile

java.lang.String readFile(java.lang.Object location, [int bytes])

Read data from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.

location
file location, file handle or file instance
bytes
amount of bytes to read (-1 for whole file)Optional: defaults to <-1>.

file data or null if EOF is reached

Exception
problems on file access

readLine

java.lang.String readLine(java.lang.Object location)

Read a single line from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.

location
file location, file handle or file instance

line of text or null if EOF is reached

Exception
problems on file access

readStream

java.lang.String readStream(java.io.InputStream input)

Read from an InputStream into a string. Consumes an InputStream and stores all available data in a string. Usually a stream is only readable once.

input
input stream to read from

string content of stream.

IOException
on read error on the stream

refreshResource

void refreshResource(org.eclipse.core.resources.IResource resource)

Refresh a given resource and all its child elements.

resource
IFile, IFolder, IProject or workspace root to update
CoreException
if this method fails. Reasons include:
  • Resource changes are disallowed during certain types of resource change event notification. See IResourceChangeEvent for more details.
updateResource(getProject("my project"))
to update the project and all its subfolders

showFileSelectionDialog

java.lang.String showFileSelectionDialog([java.lang.Object rootFolder], [int type], [java.lang.String title], [java.lang.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 WRITE or APPEND a save dialog will be shown instead of the default open dialog.

rootFolder
root folder path to useOptional: defaults to <null>.
type
dialog type to use (WRITE/ APPEND for save dialog, other for open dialog)Optional: defaults to <0>.
title
dialog titleOptional: defaults to <null>.
message
dialog messageOptional: defaults to <null>.

full path to selected file

showFolderSelectionDialog

java.lang.String showFolderSelectionDialog([java.lang.Object rootFolder], [java.lang.String title], [java.lang.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.

rootFolder
root folder to display: for workspace paths this will set the default selectionOptional: defaults to <null>.
title
dialog titleOptional: defaults to <null>.
message
dialog messageOptional: defaults to <null>.

path to selected folder

writeFile

org.eclipse.ease.modules.platform.IFileHandle writeFile(java.lang.Object location, java.lang.Object data, [int mode], [boolean autoClose])

Write data to a file. When not using an IFileHandle, 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 closeFile() command

location
file location
data
data to be written
mode
write mode (WRITE/APPEND)Optional: defaults to <2>.
autoClose
automatically close resource when script engine is terminatedOptional: defaults to <true>.

file handle to continue write operations

Exception
problems on file access

writeLine

org.eclipse.ease.modules.platform.IFileHandle writeLine(java.lang.Object location, java.lang.String data, [int mode], [boolean autoClose])

Write a line of data to a file. When not using an IFileHandle, previous file content will be overridden. Files that do not exist yet will be automatically created.

location
file location
data
data to be written
mode
write mode (WRITE/APPEND)Optional: defaults to <2>.
autoClose
automatically close resource when script engine is terminatedOptional: defaults to <true>.

file handle to continue write operations

Exception
problems on file access