Search in sources :

Example 1 with IResourceVariant

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

the class GitRemoteFolder method members.

GitRemoteResource[] members(IProgressMonitor monitor) {
    Collection<GitSyncObjectCache> members = cachedData.members();
    if (members == null || members.size() == 0)
        return new GitRemoteResource[0];
    List<IResourceVariant> result = new ArrayList<IResourceVariant>();
    monitor.beginTask(NLS.bind(CoreText.GitRemoteFolder_fetchingMembers, getPath()), cachedData.membersCount());
    try {
        for (GitSyncObjectCache member : members) {
            ThreeWayDiffEntry diffEntry = member.getDiffEntry();
            String memberPath = diffEntry.getPath();
            GitRemoteResource obj;
            ObjectId id = diffEntry.getRemoteId().toObjectId();
            if (diffEntry.isTree())
                obj = new GitRemoteFolder(repo, member, getCommitId(), id, memberPath);
            else
                obj = new GitRemoteFile(repo, getCommitId(), id, memberPath);
            result.add(obj);
            monitor.worked(1);
        }
    } finally {
        monitor.done();
    }
    return result.toArray(new GitRemoteResource[result.size()]);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant)

Example 2 with IResourceVariant

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

the class GitResourceVariantComparatorTest method shouldReturnTrueWhenLongContentLengthIsDifferent.

/**
 * Compare two 'large' files that have same content length and content
 * should return true.
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnTrueWhenLongContentLengthIsDifferent() throws Exception {
    // when
    byte[] localContent = new byte[8192];
    Arrays.fill(localContent, (byte) 'a');
    byte[] remoteContent = new byte[8192];
    Arrays.fill(remoteContent, (byte) 'a');
    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
    assertTrue(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 3 with IResourceVariant

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

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenLongContentLengthIsDifferent.

/**
 * Comparing two 'large' files that have different length but same content
 * should return false.
 * <p>
 * This and previous three test cases cover almost the same functionality
 * but they are covering all return points in compare methods that can be
 * used when comparing files content
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenLongContentLengthIsDifferent() throws Exception {
    // when
    byte[] localContent = new byte[8192];
    Arrays.fill(localContent, (byte) 'a');
    byte[] remoteContent = new byte[8200];
    Arrays.fill(remoteContent, (byte) 'a');
    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 4 with IResourceVariant

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

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenRemoteDoesNotExist2.

@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenRemoteDoesNotExist2() throws Exception {
    // when
    GitResourceVariantComparator grvc = new GitResourceVariantComparator(null);
    // given
    IResource local = mock(IResource.class);
    when(local.exists()).thenReturn(false);
    IResourceVariant remote = new GitRemoteFolder(repo, null, null, null, "./");
    // then
    assertFalse(grvc.compare(local, remote));
}
Also used : IResource(org.eclipse.core.resources.IResource) IResourceVariant(org.eclipse.team.core.variants.IResourceVariant) Test(org.junit.Test)

Example 5 with IResourceVariant

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

the class GitResourceVariantComparatorTest method shouldReturnFalseWhenContentLengthIsDifferent.

/**
 * Compare() should return false when comparing two files with different
 * content length
 *
 * @throws Exception
 */
@Test
@SuppressWarnings("boxing")
public void shouldReturnFalseWhenContentLengthIsDifferent() throws Exception {
    // when
    byte[] shortContent = "short content".getBytes("UTF-8");
    byte[] longContent = "very long long content".getBytes("UTF-8");
    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(longContent));
    IStorage storage = mock(IStorage.class);
    when(storage.getContents()).thenReturn(new ByteArrayInputStream(shortContent));
    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)

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