use of org.eclipse.core.resources.mapping.IModelProviderDescriptor 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()]);
}
use of org.eclipse.core.resources.mapping.IModelProviderDescriptor in project polymap4-core by Polymap4.
the class ModelProviderManager method lazyInitialize.
protected void lazyInitialize() {
if (descriptors != null)
return;
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_MODEL_PROVIDERS);
IExtension[] extensions = point.getExtensions();
descriptors = new HashMap(extensions.length * 2 + 1);
for (int i = 0, imax = extensions.length; i < imax; i++) {
IModelProviderDescriptor desc = null;
try {
desc = new ModelProviderDescriptor(extensions[i]);
} catch (CoreException e) {
Policy.log(e);
}
if (desc != null)
descriptors.put(desc.getId(), desc);
}
// do cycle detection now so it only has to be done once
// cycle detection on a graph subset is a pain
detectCycles();
}
use of org.eclipse.core.resources.mapping.IModelProviderDescriptor in project che by eclipse.
the class ResourceChangeValidator method getProviders.
private ModelProvider[] getProviders(IResource[] resources) {
IModelProviderDescriptor[] descriptors = ModelProvider.getModelProviderDescriptors();
List<ModelProvider> result = new ArrayList<ModelProvider>();
for (int i = 0; i < descriptors.length; i++) {
IModelProviderDescriptor descriptor = descriptors[i];
try {
IResource[] matchingResources = descriptor.getMatchingResources(resources);
if (matchingResources.length > 0) {
result.add(descriptor.getModelProvider());
}
} catch (CoreException e) {
Policy.log(e.getStatus().getSeverity(), NLS.bind("Could not instantiate provider {0}", descriptor.getId()), //$NON-NLS-1$
e);
}
}
return result.toArray(new ModelProvider[result.size()]);
}
Aggregations