Class ResourceUtil
- java.lang.Object
-
- org.eclipse.emf.compare.ide.utils.ResourceUtil
-
public final class ResourceUtil extends Object
This class will be used to provide various utilities aimed at IResource manipulation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.common.base.Function<org.eclipse.core.resources.IStorage,URI>asURI()static booleanbinaryIdentical(org.eclipse.core.resources.IStorage left, org.eclipse.core.resources.IStorage right)Checks whether the two given storages point to binary identical data.static booleanbinaryIdentical(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 URIcreateURIFor(org.eclipse.core.resources.IFile file)Create the URI with which we'll load the given IFile as an EMF resource.static URIcreateURIFor(org.eclipse.core.resources.IStorage storage)Create the URI with which we'll load the given IStorage as an EMF resource.protected static voiddeleteResource(Resource resource)Delete the given resource.static org.eclipse.core.runtime.IPathgetAbsolutePath(org.eclipse.core.resources.IStorage storage)Returns an absolute path for this storage if one exists.static org.eclipse.core.resources.IStoragegetAssociatedStorage(Resource resource)Returns the storageassociatedwith 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.IPathgetFixedPath(org.eclipse.core.resources.IStorage storage)Returns a path for this storage after fixing from anIStoragePathProviderif one exists.static org.eclipse.core.resources.IResourcegetResourceFromURI(URI uri)Tries and retrieve theIResourceassociated with the givenURI.static booleanhasContentType(String contentTypeId, List<org.eclipse.core.runtime.content.IContentType> contentTypes)This will returntrueif the given contentTypeId represents a content-type contained in the given array.static booleanhasModelType(org.eclipse.core.resources.IFile file)Checks whether the given file has one of the content types described inMODEL_CONTENT_TYPES.static ResourceloadResource(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 correspondingResourceif at all possible.protected static booleanmustDelete(Resource resource)Check if the given resource must be deleted.static voidsaveAllResources(ResourceSet resourceSet, Map<?,?> options)This can be called to save all resources contained by the resource set.static voidsaveAllResources(ResourceSet resourceSet, Map<?,?> options, StorageTraversal leftTraversal, StorageTraversal rightTraversal, StorageTraversal originTraversal)This can be called to save all resources contained by the resource set.static voidsaveResource(Resource resource, Map<?,?> options)This can be called to save the given resource.static voidsetAssociatedStorage(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 Detail
-
asURI
public static com.google.common.base.Function<org.eclipse.core.resources.IStorage,URI> asURI()
- Returns:
- A
Functionthat converts anIStorageinto aURI. This function transforms anullstorage into anullURI. - 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 correspondingResourceif 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
filewas a model,nullotherwise.
-
getAssociatedStorage
public static org.eclipse.core.resources.IStorage getAssociatedStorage(Resource resource)
Returns the storageassociatedwith the resource.- Parameters:
resource- the resource.- Returns:
- the associated storage or
nullif there isn't one. - See Also:
setAssociatedStorage(Resource, IStorage)
-
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:
trueifleftandrightare 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:
trueifleft,rightandoriginare binary identical.
-
createURIFor
public static URI createURIFor(org.eclipse.core.resources.IFile file)
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
public static URI createURIFor(org.eclipse.core.resources.IStorage storage)
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
public static org.eclipse.core.resources.IResource getResourceFromURI(URI uri)
Tries and retrieve theIResourceassociated 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
IResourceif 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 anIStoragePathProviderif 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, aPathwill 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
public static void saveAllResources(ResourceSet resourceSet, Map<?,?> options)
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
public static void saveResource(Resource resource, Map<?,?> options)
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
protected static boolean mustDelete(Resource resource)
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
protected static void deleteResource(Resource resource)
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 returntrueif 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:
trueif 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:
trueif 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
-
-