Identical models have (33) differences [message #667368] |
Thu, 28 April 2011 07:36  |
Eclipse User |
|
|
|
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 07:50   |
Eclipse User |
|
|
|
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 #670241 is a reply to message #670021] |
Fri, 13 May 2011 03:47  |
Eclipse User |
|
|
|
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?
|
|
|
Powered by
FUDForum. Page generated in 0.23931 seconds