Search in sources :

Example 1 with ModelProvider

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()]);
}
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)

Example 2 with ModelProvider

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ModelProvider(org.eclipse.core.resources.mapping.ModelProvider)

Example 3 with ModelProvider

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()]);
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ModelProvider(org.eclipse.core.resources.mapping.ModelProvider) ArrayList(java.util.ArrayList) IModelProviderDescriptor(org.eclipse.core.resources.mapping.IModelProviderDescriptor) IResource(org.eclipse.core.resources.IResource)

Example 4 with ModelProvider

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) ModelProvider(org.eclipse.core.resources.mapping.ModelProvider) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) ResourceMappingContext(org.eclipse.core.resources.mapping.ResourceMappingContext) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet)

Example 5 with ModelProvider

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()]);
}
Also used : ModelProvider(org.eclipse.core.resources.mapping.ModelProvider) ArrayList(java.util.ArrayList)

Aggregations

ModelProvider (org.eclipse.core.resources.mapping.ModelProvider)5 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 ArrayList (java.util.ArrayList)2 IModelProviderDescriptor (org.eclipse.core.resources.mapping.IModelProviderDescriptor)2 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ResourceMappingContext (org.eclipse.core.resources.mapping.ResourceMappingContext)1 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)1 GitSubscriberMergeContext (org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)1 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)1 IgnoreInGitSynchronizations (org.eclipse.egit.core.synchronize.IgnoreInGitSynchronizations)1 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)1 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)1 SubscriberScopeManager (org.eclipse.team.core.subscribers.SubscriberScopeManager)1