private void processContents() throws CoreException, UnsupportedEncodingException { Set<IFile> files = new HashSet<IFile>(); files.addAll(contentsOrigin.keySet()); files.addAll(contentsSource.keySet()); files.addAll(contentsRemote.keySet()); for (IFile file : files) { String originContent = contentsOrigin.get(file); String remoteContent = contentsRemote.get(file); String sourceContent = contentsSource.get(file); int remoteDiffKind = diffKind(originContent, remoteContent); int sourceDiffKind = diffKind(originContent, sourceContent); ThreeWayDiff threeWayDiff = mock(ThreeWayDiff.class); ITwoWayDiff remoteDiff = mock(ITwoWayDiff.class); ITwoWayDiff sourceDiff = mock(ITwoWayDiff.class); when(remoteDiff.getKind()).thenReturn(remoteDiffKind); when(sourceDiff.getKind()).thenReturn(sourceDiffKind); when(threeWayDiff.getLocalChange()).thenReturn(sourceDiff); when(threeWayDiff.getRemoteChange()).thenReturn(remoteDiff); when(subscriber.getDiff(file)).thenReturn(threeWayDiff); IStorageProvider originProvider = mock(IStorageProvider.class); IStorageProvider remoteProvider = mock(IStorageProvider.class); IStorageProvider sourceProvider = mock(IStorageProvider.class); IStorage originStorage = mock(IStorage.class); IStorage remoteStorage = mock(IStorage.class); IStorage sourceStorage = mock(IStorage.class); when(originProvider.getStorage(any(IProgressMonitor.class))).thenReturn(originStorage); when(remoteProvider.getStorage(any(IProgressMonitor.class))).thenReturn(remoteStorage); when(sourceProvider.getStorage(any(IProgressMonitor.class))).thenReturn(sourceStorage); when(originStorage.getContents()).then(openInputStream(originContent)); when(remoteStorage.getContents()).then(openInputStream(remoteContent)); when(sourceStorage.getContents()).then(openInputStream(sourceContent)); when(accessor.getStorageProvider(file, DiffSide.ORIGIN)).thenReturn(originProvider); when(accessor.getStorageProvider(file, DiffSide.REMOTE)).thenReturn(remoteProvider); when(accessor.getStorageProvider(file, DiffSide.SOURCE)).thenReturn(sourceProvider); } when(subscriber.members(root)).thenReturn(files.toArray(new IFile[0])); }
public DataGit( String zippedRepoLocation, String repoName, String rootProjectName, String modelName) { try { this.disposers = new ArrayList<Runnable>(); String systemTmpDir = System.getProperty("java.io.tmpdir"); Bundle bundle = Platform.getBundle("org.eclipse.emf.compare.tests.performance"); URL entry = bundle.getEntry(zippedRepoLocation); repoFile = new File(systemTmpDir + File.separator + repoName); // Delete repo if it already exists GitUtil.deleteRepo(repoFile); // Unzip repository to temp directory GitUtil.unzipRepo(entry, systemTmpDir, new NullProgressMonitor()); Job importJob = new Job("ImportProjects") { @Override protected IStatus run(IProgressMonitor monitor) { GitUtil.importProjectsFromRepo(repoFile); return Status.OK_STATUS; } }; importJob.schedule(); importJob.join(); Job connectJob = new Job("ConnectProjects") { @Override protected IStatus run(IProgressMonitor monitor) { try { // Connect eclipse projects to egit repository File gitDir = new File(repoFile, Constants.DOT_GIT); repository = Activator.getDefault().getRepositoryCache().lookupRepository(gitDir); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); GitUtil.connectProjectsToRepo(repository, Arrays.asList(projects)); } catch (IOException e) { Throwables.propagate(e); } return Status.OK_STATUS; } }; connectJob.schedule(); connectJob.join(); IProject rootProject = ResourcesPlugin.getWorkspace().getRoot().getProject(rootProjectName); final IFile model = rootProject.getFile(new Path(modelName)); final String fullPath = model.getFullPath().toString(); final Subscriber subscriber = GitUtil.createSubscriberForComparison(repository, MASTER, MODIFIED, model, disposers); final IStorageProviderAccessor accessor = new SubscriberStorageAccessor(subscriber); final IStorageProvider sourceProvider = accessor.getStorageProvider(model, IStorageProviderAccessor.DiffSide.SOURCE); final IStorageProvider remoteProvider = accessor.getStorageProvider(model, IStorageProviderAccessor.DiffSide.REMOTE); final IStorageProvider ancestorProvider = accessor.getStorageProvider(model, IStorageProviderAccessor.DiffSide.ORIGIN); assertNotNull(sourceProvider); assertNotNull(remoteProvider); assertNotNull(ancestorProvider); final IProgressMonitor m = new NullProgressMonitor(); final IStorageProviderAccessor storageAccessor = new SubscriberStorageAccessor(subscriber); final ITypedElement left = new StorageTypedElement(sourceProvider.getStorage(m), fullPath); final ITypedElement right = new StorageTypedElement(remoteProvider.getStorage(m), fullPath); final ITypedElement origin = new StorageTypedElement(ancestorProvider.getStorage(m), fullPath); ModelResolverRegistry mrr = EMFCompareIDEUIPlugin.getDefault().getModelResolverRegistry(); IModelResolver resolver = mrr.getBestResolverFor(sourceProvider.getStorage(m)); final ComparisonScopeBuilder scopeBuilder = new ComparisonScopeBuilder(resolver, new IdenticalResourceMinimizer(), storageAccessor); scope = scopeBuilder.build(left, right, origin, m); resourceSets.add((ResourceSet) scope.getLeft()); resourceSets.add((ResourceSet) scope.getRight()); resourceSets.add((ResourceSet) scope.getOrigin()); } catch (IOException e) { Throwables.propagate(e); } catch (CoreException e) { Throwables.propagate(e); } catch (InterruptedException e) { Throwables.propagate(e); } }