Class ResourceUtil
java.lang.Object
org.eclipse.emf.compare.ide.utils.ResourceUtil
This class will be used to provide various utilities aimed at IResource manipulation.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.common.base.Function<org.eclipse.core.resources.IStorage,
URI> asURI()
static boolean
binaryIdentical
(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right) Checks whether the two given storages point to binary identical data.static boolean
binaryIdentical
(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right, org.eclipse.core.resources.IStorage origin) Checks whether the three given storages point to binary identical data.static URI
createURIFor
(org.eclipse.core.resources.IFile file) Create the URI with which we'll load the given IFile as an EMF resource.static URI
createURIFor
(org.eclipse.core.resources.IStorage storage) Create the URI with which we'll load the given IStorage as an EMF resource.protected static void
deleteResource
(Resource resource) Delete the given resource.static org.eclipse.core.runtime.IPath
getAbsolutePath
(org.eclipse.core.resources.IStorage storage) Returns an absolute path for this storage if one exists.static org.eclipse.core.resources.IStorage
getAssociatedStorage
(Resource resource) Returns the storageassociated
with the resource.static org.eclipse.core.runtime.content.IContentType[]
getContentTypes
(org.eclipse.core.resources.IFile file) Returns the whole list of content types of the given IFile, or an empty array if none.static org.eclipse.core.runtime.IPath
getFixedPath
(org.eclipse.core.resources.IStorage storage) Returns a path for this storage after fixing from anIStoragePathProvider
if one exists.static org.eclipse.core.resources.IResource
getResourceFromURI
(URI uri) Tries and retrieve theIResource
associated with the givenURI
.static boolean
hasContentType
(String contentTypeId, List<org.eclipse.core.runtime.content.IContentType> contentTypes) This will returntrue
if the given contentTypeId represents a content-type contained in the given array.static boolean
hasModelType
(org.eclipse.core.resources.IFile file) Checks whether the given file has one of the content types described inMODEL_CONTENT_TYPES
.static Resource
loadResource
(org.eclipse.core.resources.IStorage storage, ResourceSet resourceSet, Map<?, ?> options) This will try and load the given file as an EMF model, and return the correspondingResource
if at all possible.protected static boolean
mustDelete
(Resource resource) Check if the given resource must be deleted.static void
saveAllResources
(ResourceSet resourceSet, Map<?, ?> options) This can be called to save all resources contained by the resource set.static void
saveAllResources
(ResourceSet resourceSet, Map<?, ?> options, StorageTraversal leftTraversal, StorageTraversal rightTraversal, StorageTraversal originTraversal) This can be called to save all resources contained by the resource set.static void
saveResource
(Resource resource, Map<?, ?> options) This can be called to save the given resource.static void
setAssociatedStorage
(Resource resource, org.eclipse.core.resources.IStorage storage) Associates the storage with the resource such thatgetAssociatedStorage(Resource)
will return this storage for the resource.
-
Method Details
-
asURI
- Returns:
- A
Function
that converts anIStorage
into aURI
. This function transforms anull
storage into anull
URI. - Since:
- 3.2
-
loadResource
public static Resource loadResource(org.eclipse.core.resources.IStorage storage, ResourceSet resourceSet, Map<?, ?> options) This will try and load the given file as an EMF model, and return the correspondingResource
if at all possible.- Parameters:
storage
- The file we need to try and load as a model.resourceSet
- The resource set in which to load this Resource.options
- The options to pass toResource.load(java.util.Map)
.- Returns:
- The loaded EMF Resource if
file
was a model,null
otherwise.
-
getAssociatedStorage
Returns the storageassociated
with the resource.- Parameters:
resource
- the resource.- Returns:
- the associated storage or
null
if there isn't one. - See Also:
-
setAssociatedStorage
public static void setAssociatedStorage(Resource resource, org.eclipse.core.resources.IStorage storage) Associates the storage with the resource such thatgetAssociatedStorage(Resource)
will return this storage for the resource.- Parameters:
resource
- the resource.storage
- the associated storage.
-
binaryIdentical
public static boolean binaryIdentical(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right) Checks whether the two given storages point to binary identical data.- Parameters:
left
- First of the two storages which content we are testing.right
- Second of the two storages which content we are testing.- Returns:
true
ifleft
andright
are binary identical.
-
binaryIdentical
public static boolean binaryIdentical(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right, org.eclipse.core.resources.IStorage origin) Checks whether the three given storages point to binary identical data. This could be done by callingbinaryIdentical(IStorage, IStorage)
twice, though this implementation allows us to shortcut whenever one byte differs... and will read one less file from its input stream.- Parameters:
left
- First of the three storages which content we are testing.right
- Second of the three storages which content we are testing.origin
- Third of the three storages which content we are testing.- Returns:
true
ifleft
,right
andorigin
are binary identical.
-
createURIFor
Create the URI with which we'll load the given IFile as an EMF resource.- Parameters:
file
- The file for which we need an EMF URI.- Returns:
- The created URI.
- Since:
- 3.1
-
createURIFor
Create the URI with which we'll load the given IStorage as an EMF resource.- Parameters:
storage
- The storage for which we need an EMF URI.- Returns:
- The created URI.
-
getResourceFromURI
Tries and retrieve theIResource
associated with the givenURI
. This returns a file handle, which might point to a non-existing IResource.- Parameters:
uri
- the URI for which we want theIResource
.- Returns:
- the
IResource
if found, null otherwise. - Since:
- 3.2
-
getFixedPath
public static org.eclipse.core.runtime.IPath getFixedPath(org.eclipse.core.resources.IStorage storage) Returns a path for this storage after fixing from anIStoragePathProvider
if one exists.- Parameters:
storage
- The storage for which we need a fixed full path.- Returns:
- The full path to this storage, fixed if need be.
- Since:
- 3.2
-
getAbsolutePath
public static org.eclipse.core.runtime.IPath getAbsolutePath(org.eclipse.core.resources.IStorage storage) Returns an absolute path for this storage if one exists. If the storage can be adapted toIStoragePathProvider2
, it will call computeAbsolutePath from this interface. If the storage is a File, aPath
will be created and then getAbsolutePath will be called. In other cases, the method will return the full path of the storage.- Parameters:
storage
- The storage for which we need an absolute path.- Returns:
- The absolute path to this storage.
- Since:
- 3.3
-
saveAllResources
This can be called to save all resources contained by the resource set. This will not try and save resources that do not support output.- Parameters:
resourceSet
- The resource set to save.options
- The options we are to pass on toResource.save(Map)
.
-
saveAllResources
public static void saveAllResources(ResourceSet resourceSet, Map<?, ?> options, StorageTraversal leftTraversal, StorageTraversal rightTraversal, StorageTraversal originTraversal) This can be called to save all resources contained by the resource set. This will not try and save resources that do not support output.- Parameters:
resourceSet
- The resource set to save.options
- The options we are to pass on toResource.save(Map)
.leftTraversal
- The traversal corresponding to the left side.rightTraversal
- The traversal corresponding to the right side.originTraversal
- The traversal corresponding to the common ancestor of both other side. Can benull
.- Since:
- 3.3
-
saveResource
This can be called to save the given resource. This will not try and save a resource that does not support output.- Parameters:
resource
- The resource to save.options
- The options we are to pass on toResource.save(Map)
.- Since:
- 3.1
-
mustDelete
Check if the given resource must be deleted.- Parameters:
resource
- The resource to delete, must not be null.- Returns:
- true if the given resource must be deleted, false otherwise.
- Since:
- 3.4
-
deleteResource
Delete the given resource.- Parameters:
resource
- The resource to delete, must not be null.- Since:
- 3.4
-
hasContentType
public static boolean hasContentType(String contentTypeId, List<org.eclipse.core.runtime.content.IContentType> contentTypes) This will returntrue
if the given contentTypeId represents a content-type contained in the given array.- Parameters:
contentTypeId
- Fully qualified identifier of the content type we seek.contentTypes
- The array of content-types to compare against.- Returns:
true
if the given array contains a content-type with this id.- Since:
- 3.1
-
hasModelType
public static boolean hasModelType(org.eclipse.core.resources.IFile file) Checks whether the given file has one of the content types described inMODEL_CONTENT_TYPES
.- Parameters:
file
- The file which contents are to be checked.- Returns:
true
if this file has one of the "model" content types.- Since:
- 3.1
-
getContentTypes
public static org.eclipse.core.runtime.content.IContentType[] getContentTypes(org.eclipse.core.resources.IFile file) Returns the whole list of content types of the given IFile, or an empty array if none.- Parameters:
file
- The file we need the content types of.- Returns:
- All content types associated with the given file, an empty array if none.
- Since:
- 3.1
-