Search in sources :

Example 1 with IgnoreInGitSynchronizations

use of org.eclipse.egit.core.synchronize.IgnoreInGitSynchronizations in project egit by eclipse.

the class ResourceUtil method getResourceMappings.

/**
 * This will query all model providers for those that are enabled on the
 * given resource and list all mappings available for that resource.
 *
 * @param resource
 *            The resource for which we need the associated resource
 *            mappings.
 * @param context
 *            Context from which remote content could be retrieved.
 * @return All mappings available for that file.
 */
public static ResourceMapping[] getResourceMappings(@NonNull IResource resource, ResourceMappingContext context) {
    final IModelProviderDescriptor[] modelDescriptors = ModelProvider.getModelProviderDescriptors();
    final Set<ResourceMapping> mappings = new LinkedHashSet<ResourceMapping>();
    for (IModelProviderDescriptor candidate : modelDescriptors) {
        try {
            final IResource[] resources = candidate.getMatchingResources(new IResource[] { resource });
            if (resources.length > 0) {
                // get mappings from model provider if there are matching resources
                final ModelProvider model = candidate.getModelProvider();
                IgnoreInGitSynchronizations adapter = model.getAdapter(IgnoreInGitSynchronizations.class);
                if (adapter != null) {
                    continue;
                }
                final ResourceMapping[] modelMappings = model.getMappings(resource, context, new NullProgressMonitor());
                for (ResourceMapping mapping : modelMappings) mappings.add(mapping);
            }
        } catch (CoreException e) {
            Activator.logError(e.getMessage(), e);
        }
    }
    return mappings.toArray(new ResourceMapping[mappings.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ModelProvider(org.eclipse.core.resources.mapping.ModelProvider) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IModelProviderDescriptor(org.eclipse.core.resources.mapping.IModelProviderDescriptor) IgnoreInGitSynchronizations(org.eclipse.egit.core.synchronize.IgnoreInGitSynchronizations) IResource(org.eclipse.core.resources.IResource)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 IResource (org.eclipse.core.resources.IResource)1 IModelProviderDescriptor (org.eclipse.core.resources.mapping.IModelProviderDescriptor)1 ModelProvider (org.eclipse.core.resources.mapping.ModelProvider)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IgnoreInGitSynchronizations (org.eclipse.egit.core.synchronize.IgnoreInGitSynchronizations)1