Search in sources :

Example 31 with GitSynchronizeData

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

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

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

the class GitModelSynchronizeParticipant method saveState.

@Override
public void saveState(IMemento memento) {
    super.saveState(memento);
    for (GitSynchronizeData gsd : gsds) {
        Repository repo = gsd.getRepository();
        RepositoryMapping mapping = RepositoryMapping.findRepositoryMapping(repo);
        if (mapping != null) {
            IMemento child = memento.createChild(DATA_NODE_KEY);
            child.putString(CONTAINER_PATH_KEY, getPathForResource(mapping.getContainer()));
            child.putString(SRC_REV_KEY, gsd.getSrcRev());
            child.putString(DST_REV_KEY, gsd.getDstRev());
            child.putBoolean(INCLUDE_LOCAL_KEY, gsd.shouldIncludeLocal());
            Set<IResource> includedResources = gsd.getIncludedResources();
            if (includedResources != null && !includedResources.isEmpty()) {
                IMemento paths = child.createChild(INCLUDED_PATHS_NODE_KEY);
                for (IResource resource : includedResources) {
                    String path = getPathForResource(resource);
                    paths.createChild(INCLUDED_PATH_KEY).putString(INCLUDED_PATH_KEY, path);
                }
            }
        }
    }
    memento.putBoolean(FORCE_FETCH_KEY, gsds.forceFetch());
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IMemento(org.eclipse.ui.IMemento) IResource(org.eclipse.core.resources.IResource)

Example 34 with GitSynchronizeData

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

the class GitModelSynchronizeParticipant method restoreSynchronizationData.

private void restoreSynchronizationData(IMemento[] children) {
    for (IMemento child : children) {
        String containerPath = child.getString(CONTAINER_PATH_KEY);
        Repository repo = getRepositoryForPath(containerPath);
        if (repo == null)
            continue;
        String srcRev = child.getString(SRC_REV_KEY);
        String dstRev = child.getString(DST_REV_KEY);
        boolean includeLocal = getBoolean(child.getBoolean(INCLUDE_LOCAL_KEY), true);
        Set<IResource> includedResources = getIncludedResources(child);
        try {
            GitSynchronizeData data = new GitSynchronizeData(repo, srcRev, dstRev, includeLocal);
            if (includedResources != null)
                data.setIncludedResources(includedResources);
            gsds.add(data);
        } catch (IOException e) {
            Activator.logError(e.getMessage(), e);
            continue;
        }
    }
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException) IMemento(org.eclipse.ui.IMemento) IResource(org.eclipse.core.resources.IResource)

Example 35 with GitSynchronizeData

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

the class GitModelSynchronizeParticipant method run.

@Override
public void run(final IWorkbenchPart part) {
    boolean fetchPossible = false;
    for (GitSynchronizeData data : gsds) if (data.getDstRemoteName() != null)
        fetchPossible = true;
    boolean launchFetch = Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.SYNC_VIEW_FETCH_BEFORE_LAUNCH);
    if (fetchPossible && (launchFetch || gsds.forceFetch())) {
        Job fetchJob = new SynchronizeFetchJob(gsds);
        fetchJob.setUser(true);
        fetchJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                GitModelSynchronizeParticipant.super.run(part);
            }
        });
        fetchJob.schedule();
    } else
        super.run(part);
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)42 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)26 Test (org.junit.Test)15 Repository (org.eclipse.jgit.lib.Repository)14 IResource (org.eclipse.core.resources.IResource)13 IFile (org.eclipse.core.resources.IFile)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)9 IOException (java.io.IOException)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 HashSet (java.util.HashSet)7 IProject (org.eclipse.core.resources.IProject)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)5 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 GitResourceVariantTreeSubscriber (org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber)3 GitSubscriberResourceMappingContext (org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext)3