use of org.eclipse.core.resources.mapping.ModelProvider 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.ModelProvider in project egit by eclipse.
the class GitChangeSetModelProvider method getProvider.
/**
* @return provider instance or <code>null</code> if provider was not
* initialized
*/
public static GitChangeSetModelProvider getProvider() {
if (provider == null) {
ModelProvider modelProvider;
try {
modelProvider = ModelProvider.getModelProviderDescriptor(ID).getModelProvider();
provider = (GitChangeSetModelProvider) modelProvider;
} catch (CoreException e) {
Activator.logError(e.getMessage(), e);
}
}
return provider;
}
use of org.eclipse.core.resources.mapping.ModelProvider 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()]);
}
use of org.eclipse.core.resources.mapping.ModelProvider in project egit by eclipse.
the class ModelTestCase method prepareModelContext.
protected IMergeContext prepareModelContext(Repository repository, IFile workspaceFile, String srcRev, String dstRev) throws Exception {
Set<IResource> includedResources = new HashSet<IResource>(Arrays.asList(workspaceFile));
Set<IResource> newResources = new HashSet<IResource>(includedResources);
Set<ResourceMapping> allMappings = new HashSet<ResourceMapping>();
ResourceMappingContext mappingContext = ResourceMappingContext.LOCAL_CONTEXT;
ModelProvider provider = ModelProvider.getModelProviderDescriptor(SampleModelProvider.SAMPLE_PROVIDER_ID).getModelProvider();
do {
Set<IResource> copy = newResources;
newResources = new HashSet<IResource>();
for (IResource resource : copy) {
ResourceMapping[] mappings = provider.getMappings(resource, mappingContext, new NullProgressMonitor());
allMappings.addAll(Arrays.asList(mappings));
newResources.addAll(collectResources(mappings, mappingContext));
}
} while (includedResources.addAll(newResources));
ResourceMapping[] mappings = allMappings.toArray(new ResourceMapping[allMappings.size()]);
GitSynchronizeData gsd = new GitSynchronizeData(repository, srcRev, dstRev, true, includedResources);
GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsds);
subscriber.init(new NullProgressMonitor());
GitSubscriberResourceMappingContext resourceMappingContext = new GitSubscriberResourceMappingContext(subscriber, gsds);
SubscriberScopeManager manager = new SubscriberScopeManager(subscriber.getName(), mappings, subscriber, resourceMappingContext, true);
manager.initialize(new NullProgressMonitor());
GitSubscriberMergeContext mergeContext = new GitSubscriberMergeContext(subscriber, manager, gsds);
// Wait for asynchronous update of the diff tree to end
Job.getJobManager().join(mergeContext, new NullProgressMonitor());
return mergeContext;
}
use of org.eclipse.core.resources.mapping.ModelProvider in project egit by eclipse.
the class GitModelSynchronizeParticipant method getEnabledModelProviders.
@Override
public ModelProvider[] getEnabledModelProviders() {
ModelProvider[] avaliableProviders = super.getEnabledModelProviders();
for (ModelProvider provider : avaliableProviders) if (provider.getId().equals(GitChangeSetModelProvider.ID))
return avaliableProviders;
int capacity = avaliableProviders.length + 1;
ArrayList<ModelProvider> providers = new ArrayList<>(capacity);
providers.add(GitChangeSetModelProvider.getProvider());
return providers.toArray(new ModelProvider[providers.size()]);
}
Aggregations