Search in sources :

Example 21 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.

the class GitResourceVariantTreeTest method shouldReturnOneRoot.

/**
 * roots() method should return list of projects that are associated with
 * given repository. In this case there is only one project associated with
 * this repository therefore only one root should be returned.
 *
 * @throws Exception
 */
@Test
public void shouldReturnOneRoot() throws Exception {
    // when
    try (Git git = new Git(repo)) {
        git.commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call();
    }
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    // given
    GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null, null);
    // then
    assertEquals(1, grvt.roots().length);
    IResource actualProject = grvt.roots()[0];
    assertEquals(this.project.getProject(), actualProject);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Git(org.eclipse.jgit.api.Git) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) IResource(org.eclipse.core.resources.IResource) Test(org.junit.Test)

Example 22 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet 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 23 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet 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 24 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet 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 25 with GitSynchronizeDataSet

use of org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet in project egit by eclipse.

the class PullAction method getSubscriberOperation.

@Override
protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) {
    return new SynchronizeModelOperation(configuration, elements) {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            GitSynchronizeDataSet gsds = (GitSynchronizeDataSet) getConfiguration().getProperty(SYNCHRONIZATION_DATA);
            Set<Repository> repositories = new HashSet<>();
            for (GitSynchronizeData gsd : gsds) repositories.add(gsd.getRepository());
            PullOperationUI pull = new PullOperationUI(repositories);
            pull.execute(monitor);
        }
    };
}
Also used : SynchronizeModelOperation(org.eclipse.team.ui.synchronize.SynchronizeModelOperation) GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) PullOperationUI(org.eclipse.egit.ui.internal.pull.PullOperationUI) HashSet(java.util.HashSet)

Aggregations

GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)29 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)26 Test (org.junit.Test)15 IFile (org.eclipse.core.resources.IFile)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)8 IResource (org.eclipse.core.resources.IResource)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 HashSet (java.util.HashSet)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)6 IOException (java.io.IOException)4 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)4 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)4 Git (org.eclipse.jgit.api.Git)4 Repository (org.eclipse.jgit.lib.Repository)4 File (java.io.File)3 SubscriberScopeManager (org.eclipse.team.core.subscribers.SubscriberScopeManager)3 LinkedHashSet (java.util.LinkedHashSet)2