Search in sources :

Example 6 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenLongContentIsDifferent.

/**
 * Comparing two 'large' files that have same length and almost identical
 * content should return false.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenLongContentIsDifferent() throws Exception {
    // when
    byte[] localContent = new byte[8192];
    Arrays.fill(localContent, (byte) 'a');
    byte[] remoteContent = new byte[8192];
    Arrays.fill(remoteContent, (byte) 'a');
    remoteContent[8101] = 'b';
    GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, true);
    GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data);
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(dataSet);
    // given
    IFile local = mock(IFile.class);
    when(local.exists()).thenReturn(true);
    when(local.getProject()).thenReturn(project.getProject());
    when(local.getContents()).thenReturn(new ByteArrayInputStream(localContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(remoteContent));
    IResourceVariant remote = mock(IResourceVariant.class);
    when(remote.isContainer()).thenReturn(false);
    when(remote.getStorage(any(IProgressMonitor.class))).thenReturn(storage);
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : GitSynchronizeData(org.eclipse.egit.core.synchronize.dto.GitSynchronizeData) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) GitSynchronizeDataSet(org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet) ByteArrayInputStream(java.io.ByteArrayInputStream) IStorage(org.eclipse.core.resources.IStorage) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 7 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantTreeSubscriberTest method testSyncLocalAndBranch.

@Test
public void testSyncLocalAndBranch() throws Exception {
    // Note that HEAD is on master
    GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD, BRANCH, true);
    grvts.init(new NullProgressMonitor());
    IResourceVariant actualSource = getSourceVariant(grvts, changedFile, true);
    IResourceVariant actualBase = getBaseVariant(grvts, changedFile);
    IResourceVariant actualRemote = getRemoteVariant(grvts, changedFile);
    assertVariantIsLocal(actualSource, changedFile);
    assertVariantMatchCommit(actualBase, initialCommit);
    assertVariantMatchCommit(actualRemote, commitBranch);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 8 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantTreeSubscriberTest method getSourceVariant.

private IResourceVariant getSourceVariant(GitResourceVariantTreeSubscriber subscriber, IResource resource, boolean includeLocal) throws TeamException {
    IResourceVariantTree tree = subscriber.getSourceTree();
    assertNotNull(tree);
    assertTrue(tree instanceof GitSourceResourceVariantTree);
    IResourceVariant resourceVariant = tree.getResourceVariant(resource);
    assertNotNull(resourceVariant);
    if (includeLocal)
        assertTrue(resourceVariant instanceof GitLocalResourceVariant);
    else
        assertTrue(resourceVariant instanceof GitRemoteResource);
    return resourceVariant;
}
Also used : IResourceVariantTree(org.eclipse.team.core.variants.IResourceVariantTree) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant)

Example 9 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project egit by eclipse.

the class GitResourceVariantTreeSubscriberTest method testSyncBranchAndMaster.

@Test
public void testSyncBranchAndMaster() throws Exception {
    GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(BRANCH, MASTER, false);
    grvts.init(new NullProgressMonitor());
    IResourceVariant actualSource = getSourceVariant(grvts, changedFile, false);
    IResourceVariant actualBase = getBaseVariant(grvts, changedFile);
    IResourceVariant actualRemote = getRemoteVariant(grvts, changedFile);
    assertVariantMatchCommit(actualSource, commitBranch);
    assertVariantMatchCommit(actualBase, initialCommit);
    assertVariantMatchCommit(actualRemote, commitMaster);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 10 with IResourceVariant

use of org.eclipse.team.core.variants.IResourceVariant in project ecf by eclipse.

the class RemoteShare method sendFetchVariantsResponse.

private void sendFetchVariantsResponse(ID fromId, IContainer container) {
    // the container will be null if an invalid resource type was provided
    if (container == null) {
        sendMessage(fromId, new FetchResponse());
        return;
    }
    try {
        IResource[] members = container.members();
        List variants = new ArrayList();
        for (int i = 0; i < members.length; i++) {
            if (!members[i].isDerived()) {
                variants.add(new RemoteResourceVariant(members[i]));
            }
        }
        IResourceVariant[] variantsArray = (IResourceVariant[]) variants.toArray(new IResourceVariant[variants.size()]);
        sendMessage(fromId, new FetchResponse(variantsArray));
    } catch (CoreException e) {
        TeamSynchronization.log(// $NON-NLS-1$
        "Could not retrieve container members: " + container.getFullPath(), e);
    }
}
Also used : RemoteResourceVariant(org.eclipse.team.internal.ecf.core.variants.RemoteResourceVariant) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant)

Aggregations

IResourceVariant (org.eclipse.team.core.variants.IResourceVariant)21 Test (org.junit.Test)13 IFile (org.eclipse.core.resources.IFile)9 GitSynchronizeData (org.eclipse.egit.core.synchronize.dto.GitSynchronizeData)9 GitSynchronizeDataSet (org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataSet)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IStorage (org.eclipse.core.resources.IStorage)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IResourceVariantTree (org.eclipse.team.core.variants.IResourceVariantTree)4 IResource (org.eclipse.core.resources.IResource)3 File (java.io.File)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RemoteResourceVariant (org.eclipse.team.internal.ecf.core.variants.RemoteResourceVariant)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 IContainer (org.eclipse.core.resources.IContainer)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 CoreException (org.eclipse.core.runtime.CoreException)1