Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Identical models have (33) differences(EMF Compare)
Identical models have (33) differences [message #667368] Thu, 28 April 2011 11:36 Go to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
I am computing the DiffModel using the same model as both right and left arguments and would therefore expect to see that the number of differences=0. Instead I get 33 differences using the below code:

    IModel myModel = oldProject.getModel();
    DiffModel diff = null;
    MatchModel match = null;
    try {
      // doContentMatch from current model and down
      match = MatchService.doContentMatch(myModel, myModel, null);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    diff = DiffService.doDiff(match, false);
    List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getDifferences());
    System.out.println("number of differences: " + differences1.size());
    for (DiffElement diffElement1 : differences1) {
      System.out.println("Kind: " + diffElement1.getKind() + "::" + diffElement1);
    }



This prints 1 Move action, 16 Addition actions and 16 Deletion actions a total of 33 differences. Whats the logic behind:

List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getDifferences());

when the input to the MatchService is the same model - expected differences = 0?
Re: Identical models have (33) differences [message #667370 is a reply to message #667368] Thu, 28 April 2011 11:50 Go to previous messageGo to next message
Johannes Tietje is currently offline Johannes Tietje
Messages: 7
Registered: April 2011
Junior Member
Hi, if I use the same model as both inputs to compare them, there are no differences. My code to calculate and print the diffs is:
    private static void compareEMF(final String referenceFile,
            final String compareFile) {
        Resource leftResource = XMI_LOAD_RESOURCESET.getResource(
                URI.createFileURI(compareFile), true);
        Resource rightResource = XMI_LOAD_RESOURCESET.getResource(
                URI.createFileURI(referenceFile), true);

        MatchModel match = null;

        try {
            match = (new StatemachineMatcher()).resourceMatch(leftResource,
                    rightResource, Collections.<String, Object> emptyMap());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        DiffModel diff = DiffService.doDiff(match, false);

        System.out.println("Printing the differences...");

        for (DiffElement diffElement : diff.getDifferences()) {
            System.out.println(diffElement.toString());
        }
    }


With a custom matcher (StatemachineMatcher) and a compare of resources, but otherwise standard code.

Regards,
Johannes


Re: Identical models have (33) differences [message #667376 is a reply to message #667370] Thu, 28 April 2011 12:21 Go to previous messageGo to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
I think the problem is that after the original resource containing the model has been loaded the model has been modified.

This is registered as a change by emf compare indicating that it compares the original resources and not the current model - which I thought could be disabled using:

MatchService.doContentMatch(m,m,opions)


I have now tried this:

IModel myModel0 = oldProject.getModel();
myModel0.setName("m0");
IModel myModel1 = oldProject.getModel();
myModel0.setName("m1");
...
    try {
      // doContentMatch from current model and down
      match = MatchService.doContentMatch(myModel0, myModel1, null);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

//... below is the same as before


And now the change of the name is printed as a change from "null" to "m1". I had hoped for something like:

Differences:
Left (myModel0): name= m0
Right (myModel1): name =m1

instead of a history of the changes.

Is it possible to run emf compare on the current state of the models excluding the changes that has been applied during its lifetime?
Re: Identical models have (33) differences [message #667388 is a reply to message #667376] Thu, 28 April 2011 13:23 Go to previous messageGo to next message
Johannes Tietje is currently offline Johannes Tietje
Messages: 7
Registered: April 2011
Junior Member
Hello,

js wrote on Thu, 28 April 2011 08:21
I have now tried this:

IModel myModel0 = oldProject.getModel();
myModel0.setName("m0");
IModel myModel1 = oldProject.getModel();
myModel0.setName("m1");
...
    try {
      // doContentMatch from current model and down
      match = MatchService.doContentMatch(myModel0, myModel1, null);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

//... below is the same as before



Please re-check your first four lines of code (I think you confuse myModel1 with MyModel0 in the fourth line).

Regards,
Johannes
Re: Identical models have (33) differences [message #667393 is a reply to message #667388] Thu, 28 April 2011 13:44 Go to previous messageGo to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
Sorry! to avoid confusing below is the exact code. It still find differences:

   // Models are identical names updated to the same value - expect no differences.

   IModel myModel0 = oldProject.getModel();
   myModel0.setName("m0");

   IModel myModel1 = oldProject.getModel();
   myModel1.setName("m0");

    DiffModel diff = null;
    MatchModel match = null;

    try {
      // doContentMatch from current model and down
      match = MatchService.doContentMatch(myModel0, myModel1, null);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    diff = DiffService.doDiff(match, false);
    List<DiffElement> differences1 = new ArrayList<DiffElement>(diff.getDifferences());

    System.out.println("number of differences: " + differences1.size());
    System.out.println("number of subDifferences: " + differences1.get(0).getSubDiffElements().size());

    for (DiffElement diffElement1 : differences1) {
      System.out.println("[-- 001 -- ] Kind: " + diffElement1.getKind() + "_::_" + diffElement1);
      EList<DiffElement> subDiffElements2 = diffElement1.getSubDiffElements();
      for (DiffElement diffElement2 : subDiffElements2) {
        System.out.println("[-- 002 -- ] Kind: " + diffElement2.getKind() + "_::_" + diffElement2);
      }
   }


This prints:

number of differences: 2
number of subDifferences: 0

Where :

[-- 001 -- ] Kind: Addition_::_.... (name: m0, description: null) ... has been added
[-- 001 -- ] Kind: Deletion_::_... (name: m0, description: null) ... has been removed

I get the same if I remove the setName calls.

Why does it find two Addtion and Deletion actions when the models are identical?
Re: Identical models have (33) differences [message #667394 is a reply to message #667393] Thu, 28 April 2011 13:55 Go to previous messageGo to next message
Johannes Tietje is currently offline Johannes Tietje
Messages: 7
Registered: April 2011
Junior Member
Hi,

I had a similar problem when working on a model of simple state machines (http:// www.eclipse.org/forums/index.php?t=msg&goto=664646&S =0f5f325e95fc25b206748e6bab035ab6#msg_664646), the problem there was, that the default (generic) matcher did not compared my objects as they had to be compared. Is your "model element" identifiable by its name? Or are there other values which identify it?

Update: as the EList interface is also iterable, you don't have to create a new ArrayList out of the resulting EList of Differences in your code. Wink

[Updated on: Thu, 28 April 2011 13:59]

Report message to a moderator

Re: Identical models have (33) differences [message #667826 is a reply to message #667368] Mon, 02 May 2011 11:10 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
js,

Johannes is right : the Generic Match Engine will not be able to match your elements if they do not hold enough information to. The only exception is if they have IDs (either XMI ID or functionnal ID) in which case you'll need to activate the proper option (see org.eclipse.emf.compare.match.MatchOptions for more information).

If you are in this case, you will need to implement your own MatchEngine (extending the GenericMatchEngine is the easiest way).

Laurent Goubet
Obeo
Re: Identical models have (33) differences [message #670021 is a reply to message #667826] Thu, 12 May 2011 12:38 Go to previous messageGo to next message
js Missing name is currently offline js Missing name
Messages: 73
Registered: July 2009
Member
Ok I will give it a try! Any examples to be found showing what to override and good practices?

[Updated on: Thu, 12 May 2011 13:38]

Report message to a moderator

Re: Identical models have (33) differences [message #670241 is a reply to message #670021] Fri, 13 May 2011 07:47 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
Hi,

The MergeService will merge the differences in the direction you ask it
to (the boolean) in-place. i.e the "merged EObject" is the one you
initially compared by feeding it to the MAtchService. In your case, that
is either "model1" or "model2".

If you need to save this merged model, use EMF to do so :
model1.eResource().save();

Laurent Goubet
Obeo

On 12/05/2011 14:38, js wrote:
> Ok I will give it a try!
>
> But how do I get from the diff model that I pass to the
> MergeService to apply the changes and creating a valid
> merged EObject?
>
> Calling:
>
>
> public static EObject compare(EObject model1, EObject
> model2) {
> DiffModel diff = null;
> MatchModel contentMatch = null;
> Map<String, Object> options = new HashMap<String,
> Object>();
> try {
> // doContentMatch from current model and down
> contentMatch = MatchService.doContentMatch(model1,
> model2, options);
> // doMatch crawls up
> // return MatchService.doMatch(model1, model2,
> options);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> diff = DiffService.doDiff(contentMatch, false);
> // This will merge all references to the right model
> (second argument).
> final List<DiffElement> differences = new
> ArrayList<DiffElement>(diff.getOwnedElements());
> MergeService.merge(differences, true);
>
> // Create the EObject corresponding to the merged model
> corresponding to
> // apply changes from right to left....
> EObject mergedModel = null;
> return mergedModel;
> }
>
>
>
> will merge the differences but how do I compute the
> corresponding merged EObject?
Previous Topic:Simple merge case
Next Topic:Specifying constraints at Model Instance (M0) level.
Goto Forum:
  


Current Time: Fri Oct 31 04:25:12 GMT 2014

Powered by FUDForum. Page generated in 0.17875 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software