public class ResourcesModule
extends org.eclipse.ease.modules.AbstractScriptModule
implements org.eclipse.ease.IExecutionListener
String
, URI
, IFile
and
File
instances.Modifier and Type | Field and Description |
---|---|
static int |
APPEND
Access modifier for append mode (4).
|
static java.lang.String |
MODULE_ID
Module identifier.
|
static int |
READ
Access modifier for read mode (1).
|
static int |
WRITE
Access modifier for write mode (2).
|
Constructor and Description |
---|
ResourcesModule() |
Modifier and Type | Method and Description |
---|---|
void |
closeFile(IFileHandle handle)
Close a file.
|
void |
copyFile(java.lang.Object sourceLocation,
java.lang.Object targetLocation)
Copies a file from location to targetLocation.
|
java.lang.Object |
createFile(java.lang.Object location)
Create a new file in the workspace or the file system.
|
java.lang.Object |
createFolder(java.lang.Object location)
Create a new folder in the workspace or the file system.
|
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.
|
static IProject |
createProject(java.lang.String name)
Create a new workspace project.
|
void |
deleteFile(java.lang.Object source)
Delete a file from the workspace or local file system.
|
void |
deleteFolder(java.lang.Object source)
Delete a folder from the workspace or local file system.
|
void |
deleteProject(java.lang.Object source)
Delete a project from the workspace.
|
boolean |
fileExists(java.lang.Object location)
Verifies that a specific file exists.
|
java.lang.Object[] |
findFiles(java.lang.String pattern,
java.lang.Object rootFolder,
boolean recursive)
Return files matching a certain pattern.
|
java.lang.Object |
getFile(java.lang.String location,
boolean exists)
Get a workspace or file system file.
|
static IProject |
getProject(java.lang.String name)
Get a project instance.
|
static IWorkspaceRoot |
getWorkspace()
Get the workspace root.
|
IProject |
importProject(java.lang.Object location)
Imports a project into the current workspace.
|
IProject |
linkProject(java.lang.Object location)
Links a project into the current workspace.
|
void |
notify(org.eclipse.ease.IScriptEngine engine,
org.eclipse.ease.Script script,
int status) |
IFileHandle |
openFile(java.lang.Object location,
int mode,
boolean autoClose)
Opens a file from the workspace or the file system.
|
java.lang.String |
readFile(java.lang.Object location,
int bytes)
Read data from a file.
|
java.lang.String |
readLine(java.lang.Object location)
Read a single line from a file.
|
java.lang.String |
readStream(java.io.InputStream input)
Read from an InputStream into a string.
|
void |
refreshResource(java.lang.Object resource)
Refresh a given resource and all its child elements.
|
java.lang.String |
showFileSelectionDialog(java.lang.Object rootFolder,
int type,
java.lang.String title,
java.lang.String message)
Opens a file dialog.
|
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).
|
java.lang.Object |
unzip(java.lang.Object zipLocation,
java.lang.Object targetLocation)
Unzip a zip file to the provided target location.
|
IFileHandle |
writeFile(java.lang.Object location,
java.lang.Object data,
int mode,
boolean autoClose)
Write data to a file.
|
IFileHandle |
writeLine(java.lang.Object location,
java.lang.String data,
int mode,
boolean autoClose)
Write a line of data to a file.
|
java.lang.Object |
zip(java.lang.Object sourceLocation,
java.lang.Object zipLocation)
Create or update a zip file with given resources.
|
public static final java.lang.String MODULE_ID
public static final int READ
public static final int WRITE
public static final int APPEND
public static IWorkspaceRoot getWorkspace()
public static IProject getProject(java.lang.String name)
name
- project namenull
public java.lang.Object getFile(java.lang.String location, @ScriptParameter(defaultValue="true") boolean exists)
false
this method also returns files that do not exist yet. If true
only existing instances are returned.location
- file location/path to resolveexists
- whether the resolved file needs to existIFile
or File
instancepublic static IProject createProject(java.lang.String name)
null
is returned.name
- name or project to createnull
or projectpublic java.lang.Object createFolder(java.lang.Object location) throws CoreException
location
- folder locationIFolder
, File
or null
in case of errorCoreException
- if this method fails. Reasons include:
IWorkspace.validateName
).force
is false
.IResourceChangeEvent
for
more details.public java.lang.Object createFile(java.lang.Object location) throws java.lang.Exception
location
- file locationIFile
, File
or null
in case of errorjava.lang.Exception
- problems on file accesspublic IFileHandle openFile(java.lang.Object location, @ScriptParameter(defaultValue="1") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws java.lang.Exception
location
- file locationmode
- one of , , autoClose
- automatically close resource when script engine is terminatedjava.lang.Exception
- problems on file accesspublic boolean fileExists(java.lang.Object location)
location
- file location to verifytrue
if file existspublic void closeFile(IFileHandle handle)
handle
- handle to be closedpublic java.lang.String readFile(java.lang.Object location, @ScriptParameter(defaultValue="-1") int bytes) throws java.lang.Exception
IFileHandle
first using and use the handle for
location.location
- file location, file handle or file instancebytes
- amount of bytes to read (-1 for whole file)null
if EOF is reachedjava.lang.Exception
- problems on file accesspublic void copyFile(java.lang.Object sourceLocation, java.lang.Object targetLocation) throws java.lang.Exception
sourceLocation
- file location, file handle or file instance for the source objecttargetLocation
- file location, file handle or file instance for the target objectjava.lang.Exception
- problems on file accesspublic void deleteFile(java.lang.Object source) throws CoreException
source
- file to be deletedCoreException
- on deletion errorspublic void deleteFolder(java.lang.Object source) throws CoreException
source
- folder to be deletedCoreException
- on deletion errorspublic void deleteProject(java.lang.Object source) throws CoreException
source
- project to be deletedCoreException
- on deletion errorspublic java.lang.String readLine(java.lang.Object location) throws java.lang.Exception
IFileHandle
first using and use the
handle for location.location
- file location, file handle or file instancenull
if EOF is reachedjava.lang.Exception
- problems on file accesspublic IFileHandle writeFile(java.lang.Object location, java.lang.Object data, @ScriptParameter(defaultValue="2") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws java.lang.Exception
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 commandlocation
- file locationdata
- data to be writtenmode
- write mode (/)autoClose
- automatically close resource when script engine is terminatedjava.lang.Exception
- problems on file accesspublic IFileHandle writeLine(java.lang.Object location, java.lang.String data, @ScriptParameter(defaultValue="2") int mode, @ScriptParameter(defaultValue="true") boolean autoClose) throws java.lang.Exception
IFileHandle
, previous file content will be overridden. Files that do not exist yet will be
automatically created.location
- file locationdata
- data to be writtenmode
- write mode (/)autoClose
- automatically close resource when script engine is terminatedjava.lang.Exception
- problems on file accesspublic java.lang.String showFileSelectionDialog(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object rootFolder, @ScriptParameter(defaultValue="0") int type, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.String title, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.String message)
rootFolder
- root folder path to usetype
- dialog type to use (/ for save dialog, other for open dialog)title
- dialog titlemessage
- dialog messagepublic java.lang.String showFolderSelectionDialog(@ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object rootFolder, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.String title, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.String message)
rootFolder
- root folder to display: for workspace paths this will set the default selectiontitle
- dialog titlemessage
- dialog messagepublic java.lang.Object[] findFiles(java.lang.String pattern, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") java.lang.Object rootFolder, @ScriptParameter(defaultValue="true") boolean recursive)
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 to true
public IProject linkProject(java.lang.Object location) throws CoreException, java.io.IOException
location
- location of project (needs to contain .project file)CoreException
- when project description cannot be loaded from .project filejava.io.IOException
- when project location cannot be read/linkedpublic IProject importProject(java.lang.Object location) throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException, java.io.IOException, CoreException
location
- location of project (needs to contain .project file)java.lang.reflect.InvocationTargetException
- on errors during the importjava.lang.InterruptedException
- when import task got interruptedjava.io.IOException
- when project cannot be located on diskCoreException
- when project description cannot be loaded from .project filepublic void refreshResource(java.lang.Object resource) throws CoreException
resource
- IFile
, IFolder
, IProject
or workspace root to updateCoreException
- if this method fails. Reasons include:
IResourceChangeEvent
for more
details.public java.lang.String readStream(java.io.InputStream input) throws java.io.IOException
InputStream
and stores all available data in a string. Usually a stream is only readable
once.input
- input stream to read fromjava.io.IOException
- on read error on the streampublic void createProblemMarker(java.lang.String severity, java.lang.Object location, int lineNumber, java.lang.String message, @ScriptParameter(defaultValue="org.eclipse.core.resources.problemmarker") java.lang.String type, @ScriptParameter(defaultValue="true") boolean permanent) throws CoreException
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 markersCoreException
- when marker cannot be createdpublic void notify(org.eclipse.ease.IScriptEngine engine, org.eclipse.ease.Script script, int status)
notify
in interface org.eclipse.ease.IExecutionListener
public java.lang.Object zip(java.lang.Object sourceLocation, java.lang.Object zipLocation) throws java.io.IOException
sourceLocation
- source folder/file to zipzipLocation
- zip file to usejava.io.IOException
- when zip file cannot be createdpublic java.lang.Object unzip(java.lang.Object zipLocation, java.lang.Object targetLocation) throws java.io.IOException
zipLocation
- zip file to unziptargetLocation
- folder to unzip tojava.io.IOException
- when zip file cannot be unzipped