Пример #1
0
  public void dispose() {
    comparison = null;
    for (ResourceSet rs : resourceSets) {
      EList<Resource> resources = rs.getResources();
      for (Resource resource : resources) {
        TreeIterator<EObject> allContents = EcoreUtil.getAllProperContents(resource, false);
        while (allContents.hasNext()) {
          final EObject next = allContents.next();
          next.eAdapters().clear();
        }
        resource.eAdapters().clear();
      }

      rs.getResources().clear();
      rs.eAdapters().clear();
    }

    resourceSets = null;

    Job cleanJob =
        new Job("ClearWorkspace") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              // Close & delete projects from workspace
              IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
              for (IProject project : projects) {
                project.close(new NullProgressMonitor());
                project.delete(false, new NullProgressMonitor());
              }
            } catch (CoreException e) {
              Throwables.propagate(e);
            }
            return Status.OK_STATUS;
          }
        };
    cleanJob.schedule();
    try {
      cleanJob.join();
    } catch (InterruptedException e) {
      Throwables.propagate(e);
    }

    if (repository != null) {
      repository.close();
      repository = null;
    }
    for (Runnable disposer : disposers) {
      disposer.run();
    }
    disposers.clear();

    // Delete repository from temp directory
    GitUtil.deleteRepo(repoFile);
  }
Пример #2
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);
    }
  }