@Override
  protected List<DiffElement> detectDifferences(EObject left, EObject right)
      throws InterruptedException {
    Map<String, Object> options = Collections.emptyMap();

    // We need here to detect and merge "local" changes. We'll use the "right" as ancestor
    Resource rightRes = right.eResource();
    Resource ancestorRes = null;
    if (rightRes != null) {
      try {
        ancestorRes = rightRes.getClass().newInstance();
        ancestorRes.setURI(rightRes.getURI());
      } catch (InstantiationException e) {
        fail("Couldn't copy '" + rightRes.getURI() + "' resource");
      } catch (IllegalAccessException e) {
        fail("Couldn't copy '" + rightRes.getURI() + "' resource");
      }
    }
    EObject ancestor = EcoreUtil.copy(right);
    if (ancestorRes != null) {
      ancestorRes.getContents().add(ancestor);
    }

    MatchModel match = MatchService.doMatch(left, right, ancestor, options);
    DiffModel diff = DiffService.doDiff(match, true);

    EList<DiffElement> differences = diff.getDifferences();
    return differences;
  }
Beispiel #2
0
  @Test
  @Ignore
  public void shouldCreateEpatchForMovedElement() throws Exception {
    // given
    ResourceSet rs = new ResourceSetImpl();
    rs.getResourceFactoryRegistry()
        .getExtensionToFactoryMap()
        .put("ecore", new EcoreResourceFactoryImpl());
    rs.getResourceFactoryRegistry()
        .getExtensionToFactoryMap()
        .put("xmi", new XMIResourceFactoryImpl());
    // ...loaded metamodel
    Resource meta = rs.getResource(URI.createFileURI("res/in/movebug/MoveBug.ecore"), true);
    meta.load(null);

    // register package nsuri
    EPackage pckage = (EPackage) meta.getContents().get(0);
    rs.getPackageRegistry().put(pckage.getNsURI(), pckage);
    // ...loaded models
    Resource originModel = rs.getResource(URI.createFileURI("res/in/movebug/Original.xmi"), true);
    originModel.load(null);
    Resource changedModel = rs.getResource(URI.createFileURI("res/in/movebug/Moved.xmi"), true);
    changedModel.load(null);

    // when
    MatchModel matchModel = MatchService.doResourceMatch(originModel, changedModel, null);
    DiffModel diffModel = DiffService.doDiff(matchModel);
    // then
    // ... epatch creation fails because of move between different containers
    Epatch epatch = DiffEpatchService.createEpatch(matchModel, diffModel, "buggyPatch");
  }
  @Override
  protected List<DiffElement> detectDifferences(EObject left, EObject right)
      throws InterruptedException {

    Map<String, Object> options = Collections.emptyMap();

    leftRes = left.eResource();
    rightRes = right.eResource();
    EcoreUtil.resolveAll(left);
    EcoreUtil.resolveAll(right);
    left.eResource().getContents().clear();
    right.eResource().getContents().clear();

    MatchModel match = MatchService.doMatch(left, right, options);
    DiffModel diff = DiffService.doDiff(match);

    EList<DiffElement> differences = diff.getDifferences();
    return differences;
  }