public class ResourcesModule extends AbstractScriptModule
Modifier and Type | Field and Description |
---|---|
static int |
APPEND
Access modifier for append mode (4).
|
static 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 |
---|---|
static void |
closeFile(IFileHandle handle)
Close a file.
|
void |
copyFile(Object sourceLocation,
Object targetLocation)
Copies a file from location to targetLocation.
|
Object |
createFile(Object location)
Create a new file in the workspace or the file system.
|
Object |
createFolder(Object location)
Create a new folder in the workspace or the file system.
|
static IProject |
createProject(String name)
Create a new workspace project.
|
void |
deleteFile(Object source)
Delete a file from the workspace or local file system.
|
void |
deleteFolder(Object source)
Delete a folder from the workspace or local file system.
|
void |
deleteProject(Object source)
Delete a project from the workspace.
|
boolean |
fileExists(Object location)
Verifies that a specific file exists.
|
Object[] |
findFiles(String pattern,
Object rootFolder,
boolean recursive)
Return files matching a certain pattern.
|
Object |
getFile(String location,
boolean exists)
Get a workspace or file system file.
|
static IProject |
getProject(String name)
Get a project instance.
|
static IWorkspaceRoot |
getWorkspace()
Get the workspace root.
|
boolean |
linkProject(String location)
Links a project into the current workspace.
|
IFileHandle |
openFile(Object location,
int mode)
Opens a file from the workspace or the file system.
|
String |
readFile(Object location,
int bytes)
Read data from a file.
|
String |
readLine(Object location)
Read a single line from a file.
|
String |
readStream(InputStream input)
Read from an InputStream into a string.
|
void |
refreshResource(IResource resource)
Refresh a given resource and all its child elements.
|
String |
showFileSelectionDialog(Object rootFolder,
int type,
String title,
String message)
Opens a file dialog.
|
String |
showFolderSelectionDialog(Object rootFolder,
String title,
String message)
Opens a dialog box which allows the user to select a container (project or folder).
|
IFileHandle |
writeFile(Object location,
String data,
int mode)
Write data to a file.
|
IFileHandle |
writeLine(Object location,
String data,
int mode)
Write a line of data to a file.
|
getScriptEngine, initialize
public static final 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(String name)
name
- project namenull
public Object getFile(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.public static IProject createProject(String name)
null
is returned.name
- name or project to createnull
or projectpublic Object createFolder(Object location) throws CoreException
location
- folder locationIFolder
, File
or null
in case of errorCoreException
public Object createFile(Object location) throws Exception
public IFileHandle openFile(Object location, @ScriptParameter(defaultValue="1") int mode) throws Exception
location
- file locationmode
- one of , , Exception
- problems on file accesspublic boolean fileExists(Object location)
location
- file location to verifytrue
if file existspublic static void closeFile(IFileHandle handle)
handle
- handle to be closedpublic String readFile(Object location, @ScriptParameter(defaultValue="-1") int bytes) throws 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 reachedException
- problems on file accesspublic void copyFile(Object sourceLocation, Object targetLocation) throws Exception
location
- file location, file handle or file instancetargetLocation
- file location, file handle or file instanceException
- problems on file accesspublic void deleteFile(Object source) throws CoreException
source
- file to be deletedCoreException
- on deletion errorspublic void deleteFolder(Object source) throws CoreException
source
- folder to be deletedCoreException
- on deletion errorspublic void deleteProject(Object source) throws CoreException
source
- project to be deletedCoreException
- on deletion errorspublic String readLine(Object location) throws Exception
IFileHandle
first using and use the
handle for location.location
- file location, file handle or file instancenull
if EOF is reachedException
- problems on file accesspublic IFileHandle writeFile(Object location, String data, @ScriptParameter(defaultValue="2") int mode) throws 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 (/)Exception
- problems on file accesspublic IFileHandle writeLine(Object location, String data, @ScriptParameter(defaultValue="2") int mode) throws 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 (/)Exception
- problems on file accesspublic 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)
rootFolder
- root folder path to usetype
- dialog type to use (/ for save dialog, other for open dialog)title
- dialog titlemessage
- dialog messagepublic 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)
rootFolder
- root folder to display: for workspace paths this will set the default selectiontitle
- dialog titlemessage
- dialog messagepublic Object[] findFiles(String pattern, @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null") 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 boolean linkProject(String location)
location
- location of project (needs to contain .project file)public void refreshResource(IResource resource) throws CoreException
resource
- IFile
, IFolder
, IProject
or workspace root to updateCoreException
- if this method fails. Reasons include:
IResourceChangeEvent
for more
details.public String readStream(InputStream input) throws IOException
InputStream
and stores all available data in a string. Usually a stream is only readable
once.input
- input stream to read fromIOException
- on read error on the stream