Search in sources :

Example 21 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.

the class ModelTestCase method prepareContext.

protected IMergeContext prepareContext(Repository repository, IFile workspaceFile, String srcRev, String dstRev) throws Exception {
    GitSynchronizeData gsd = new GitSynchronizeData(repository, srcRev, dstRev, true, Collections.<IResource>singleton(workspaceFile));
    GitSynchronizeDataSet gsds = new GitSynchronizeDataSet(gsd);
    GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsds);
    subscriber.init(new NullProgressMonitor());
    ResourceMapping mapping = AdapterUtils.adapt(workspaceFile, ResourceMapping.class);
    SubscriberScopeManager manager = new SubscriberScopeManager(subscriber.getName(), new ResourceMapping[] { mapping }, subscriber, 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 : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)

Example 22 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping 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 23 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.

the class ModelAwareGitSynchronizer method synchronize.

@Override
protected void synchronize(IResource[] resources, Repository repository, String leftRev, String rightRev, boolean includeLocal) throws IOException {
    if (rightRev.equals(GitFileRevision.INDEX)) {
        openGitTreeCompare(resources, leftRev, CompareTreeView.INDEX_VERSION, includeLocal);
    } else {
        final Set<IResource> includedResources = new HashSet<>(Arrays.asList(resources));
        final Set<ResourceMapping> allMappings = new HashSet<>();
        Set<IResource> newResources = new HashSet<>(includedResources);
        do {
            final Set<IResource> copy = newResources;
            newResources = new HashSet<>();
            for (IResource resource : copy) {
                Assert.isNotNull(resource);
                ResourceMapping[] mappings = ResourceUtil.getResourceMappings(resource, context);
                allMappings.addAll(Arrays.asList(mappings));
                newResources.addAll(collectResources(mappings));
            }
        } while (includedResources.addAll(newResources));
        if (GitFileRevision.INDEX.equals(leftRev)) {
            // Even git tree compare cannot handle index as
            // source...
            // Synchronize using the local data for now.
            final ResourceMapping[] mappings = allMappings.toArray(new ResourceMapping[allMappings.size()]);
            final GitSynchronizeData data = new GitSynchronizeData(repository, leftRev, rightRev, true, includedResources);
            GitModelSynchronize.launch(new GitSynchronizeDataSet(data), mappings);
        } else {
            final ResourceMapping[] mappings = allMappings.toArray(new ResourceMapping[allMappings.size()]);
            final GitSynchronizeData data = new GitSynchronizeData(repository, leftRev, rightRev, includeLocal, includedResources);
            GitModelSynchronize.launch(new GitSynchronizeDataSet(data), mappings);
        }
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IResource(org.eclipse.core.resources.IResource) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.

the class GitChangeSetContentProvider method getTraversals.

@Override
protected ResourceTraversal[] getTraversals(ISynchronizationContext context, Object object) {
    if (object instanceof IAdaptable) {
        if (traversalCache.containsKey(object)) {
            return traversalCache.get(object);
        }
        ResourceMapping rm = getResourceMapping(object);
        if (rm == null) {
            return null;
        }
        GitSubscriberMergeContext ctx = (GitSubscriberMergeContext) getContext();
        ResourceMappingContext rmCtx = new GitSubscriberResourceMappingContext((GitResourceVariantTreeSubscriber) ctx.getSubscriber(), ctx.getSyncData());
        try {
            ResourceTraversal[] traversals = rm.getTraversals(rmCtx, new NullProgressMonitor());
            traversalCache.put(object, traversals);
            return traversals;
        } catch (CoreException e) {
            Activator.logError(e.getMessage(), e);
        }
    }
    return null;
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) IAdaptable(org.eclipse.core.runtime.IAdaptable) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) ResourceMappingContext(org.eclipse.core.resources.mapping.ResourceMappingContext) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) CoreException(org.eclipse.core.runtime.CoreException) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)

Example 25 with ResourceMapping

use of org.eclipse.core.resources.mapping.ResourceMapping in project egit by eclipse.

the class GitScopeUtil method createScopeManager.

/**
 * Creates a new {@link SubscriberScopeManager} for the given set of
 * {@link IResource}s
 *
 * @param resources
 * @param monitor
 * @return {@link SubscriberScopeManager}
 */
private static SubscriberScopeManager createScopeManager(final IResource[] resources, IProgressMonitor monitor) {
    ResourceMapping[] mappings = GitScopeUtil.getResourceMappings(resources);
    GitSynchronizeDataSet set = new GitSynchronizeDataSet();
    final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(set);
    monitor.setTaskName(UIText.GitModelSynchronize_fetchGitDataJobName);
    subscriber.init(monitor);
    SubscriberScopeManager manager = new SubscriberScopeManager(UIText.GitScopeOperation_GitScopeManager, mappings, subscriber, true);
    return manager;
}
Also used : GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)

Aggregations

ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)28 IResource (org.eclipse.core.resources.IResource)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 JavaElementResourceMapping (org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping)7 CoreException (org.eclipse.core.runtime.CoreException)6 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)6 HashSet (java.util.HashSet)5 LinkedHashSet (java.util.LinkedHashSet)5 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)5 IFile (org.eclipse.core.resources.IFile)4 ResourceTraversal (org.eclipse.core.resources.mapping.ResourceTraversal)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 Change (org.eclipse.ltk.core.refactoring.Change)4 File (java.io.File)3 IProject (org.eclipse.core.resources.IProject)3 ResourceMappingContext (org.eclipse.core.resources.mapping.ResourceMappingContext)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberMergeContext (org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3 ResourceChange (org.eclipse.ltk.core.refactoring.resource.ResourceChange)3