|
Re: Identical models have (33) differences [message #667370 is a reply to message #667368] |
Thu, 28 April 2011 11:50 |
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 #667826 is a reply to message #667368] |
Mon, 02 May 2011 11:10 |
|
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 #670241 is a reply to message #670021] |
Fri, 13 May 2011 07:47 |
|
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.05202 seconds