Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.compare.doc/tutorials/Using_Compare_Services.html')
-rw-r--r--plugins/org.eclipse.emf.compare.doc/tutorials/Using_Compare_Services.html97
1 files changed, 97 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.doc/tutorials/Using_Compare_Services.html b/plugins/org.eclipse.emf.compare.doc/tutorials/Using_Compare_Services.html
new file mode 100644
index 000000000..8782c2021
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.doc/tutorials/Using_Compare_Services.html
@@ -0,0 +1,97 @@
+<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body><h1 id="UsingtheCompareServices">Using the Compare Services</h1><p><code>Authors</code> Cédric Brun <br/><code>Contact</code> cedric.brun@obeo.fr</p><p>Copyright 2007-2010, Obeo &#169;</p><ol style="list-style: none;"><li><a href="#UsingtheCompareServices">Using the Compare Services</a><ol style="list-style: none;"><li><a href="#Introduction">Introduction</a></li><li><a href="#Gettingthedifferencesoftwomodels">Getting the differences of two models</a></li><li><a href="#Mergingthedifferences">Merging the differences</a></li><li><a href="#UsingEMFCompareinstandalonemode">Using EMF Compare in standalone mode</a><ol style="list-style: none;"><li><a href="#Compilation">Compilation</a></li><li><a href="#Launch">Launch</a></li></ol></li></ol></li></ol><h2 id="Introduction">Introduction</h2><p>All the following examples will use a simple (some would say &#8220;stupid&#8221;) domain model used to keep personal information, here <br/>contact lists.</p><p>Here is the diagram:</p><p><img border="0" src="images/AddressBookMM.png"/></p><p>The whole comparison process is divided in two phases :</p><ol><li>matching both versions of the elements and providing a match model.</li><li>computing the diff (delta) model from this match.</li></ol><p>When comparing (using the user interface) two models conformed to the AddressBook metamodel you&#8217;ll get:</p><p>images/AddressBookComparaison1.png!</p><p>This is an emfdiff model displayed using the emf compare editor. Both match and delta information are kept in this model, let&#8217;s have <br/>a further look on the match part:</p><p><img border="0" src="images/AddressBookMatch.png"/></p><p>The match model weave elements from both versions of the model.</p><p><img border="0" src="images/AddressBookMatchDetail.png"/></p><p>From this match model EMF compare is able to compute the delta (diff):</p><p><img border="0" src="images/AddressBookDiffDetail.png"/></p><h2 id="Gettingthedifferencesoftwomodels">Getting the differences of two models</h2><p>Getting these differences using some code is easy, here is the snippet::</p><pre>
+ private DiffModel getDiff(AddressBook v1, AddressBook v2) throws Exception {
+ Map options = new HashMap();
+ MatchModel match = MatchService.doContentMatch(v1, v2, options);
+ // ...
+</pre><p>And you&#8217;ll get the Match model which you can browse like any other EMF model.<br/>Let&#8217;s now produce the diff from this match information::</p><pre>
+ DiffModel diff = DiffService.doDiff(match);
+ return diff;
+ }
+</pre><p>Both Diff and Match services leverage the Eclipse architecture to find the best match/diff engine from the file extension.<br/>But EMF Compare can be used to get the differences of two models within Eclipse or out of Eclipse (standalone mode) and using it in standalone mode you&#8217;ll loose the ability of &#8220;auto-picking&#8221; the right match/diff engine considering the file extension : you&#8217;ll have to call the engines yourself. Here the generic one::</p><pre>
+ private DiffModel getDiff(AddressBook v1, AddressBook v2) throws Exception {
+ Map options = new HashMap();
+ MatchModel match = new GenericMatchEngine().contentMatch(v1,v2,options);
+ DiffModel diff = new GenericDiffEngine().doDiff(match);
+ return diff;
+ }
+</pre><p>The generic match engine can be parameterized thanks to some options available in the MatchOptions interface:</p><table><tr><td> Name </td><td> Description </td><td> Type </td></tr><tr><td>OPTION_DISTINCT_METAMODELS </td><td>If set to true, the engine will be able to compare two models from different metamodel and find similarities. </td><td> Boolean </td></tr><tr><td>OPTION_IGNORE_ID </td><td>If set to true, the engine will ignore the Ecore ID&#8217;s and will consider the elements data to match them. </td><td> Boolean </td></tr><tr><td>OPTION_IGNORE_XMI_ID </td><td>If set to true, the engine will ignore the XMI ID&#8217;s and will consider the elements data to match them. </td><td> Boolean </td></tr><tr><td>OPTION_SEARCH_WINDOW </td><td>The search window is the number of elements the engine will consider at the same time, the bigger it is, more precise is the result, but slower is the process. </td><td> Integer </td></tr><tr><td>OPTION_PROGRESS_MONITOR </td><td>If set with an IProgressMonitor instance, this one will</td><td>IProgressMonitor be used to monitor the match process. </td></tr></table>bq.
+ please note that all these calls can be done with 3 models, left, right and the ancestor one. Then you&#8217;ll be able to detect conflicts.<h2 id="Mergingthedifferences">Merging the differences</h2><p>Once you get the differences you can merge them. You can merge every detected delta from the diff model using the merge service::</p><pre>
+ AddModelElement add = DiffHelper.isAdded(alice, changes);
+ MergeService.merge(add, false);
+</pre><p>Here is a quick view of all the diff elements:</p><p><img border="0" src="images/DiffMM.jpg"/></p><h2 id="UsingEMFCompareinstandalonemode">Using EMF Compare in standalone mode</h2><p>You can setup your environment to use EMF Compare in standalone mode. The will looks like this ::</p><pre>
+ /**
+ * This application will try and launch an headless model comparison.
+ *
+ * @author Cedric Brun &lt;a href="mailto:cedric.brun@obeo.fr">cedric.brun@obeo.fr&lt;/a>
+ */
+ public final class ExampleLauncher {
+ /**
+ * This class doesn't need to be instantiated.
+ */
+ private ExampleLauncher() {
+ // prevents instantiation
+ }
+
+ /**
+ * Launcher of this application.
+ *
+ * @param args
+ * Arguments of the launch.
+ */
+ public static void main(String[] args) {
+ if (args.length == 2 &amp;&amp; new File(args[0]).canRead() &amp;&amp; new File(args[1]).canRead()) {
+ // Creates the resourceSet where we'll load the models
+ final ResourceSet resourceSet = new ResourceSetImpl();
+ // Register additionnal packages here. For UML2 for instance :
+ // Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION,
+ // UMLResource.Factory.INSTANCE);
+ // resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
+
+ try {
+ System.out.println("Loading resources.\n"); //$NON-NLS-1$
+ // Loads the two models passed as arguments
+ final EObject model1 = ModelUtils.load(new File(args[0]), resourceSet);
+ final EObject model2 = ModelUtils.load(new File(args[1]), resourceSet);
+
+ // Creates the match then the diff model for those two models
+ System.out.println("Matching models.\n"); //$NON-NLS-1$
+ final MatchModel match = MatchService.doMatch(model1, model2, Collections
+ .&lt;String, Object> emptyMap());
+ System.out.println("Differencing models.\n"); //$NON-NLS-1$
+ final DiffModel diff = DiffService.doDiff(match, false);
+
+ System.out.println("Merging difference to args[1].\n"); //$NON-NLS-1$
+ final List&lt;DiffElement> differences = new ArrayList&lt;DiffElement>(diff.getOwnedElements());
+ // This will merge all references to the right model (second argument).
+ MergeService.merge(differences, true);
+
+ // Prints the results
+ try {
+ System.out.println("MatchModel :\n"); //$NON-NLS-1$
+ System.out.println(ModelUtils.serialize(match));
+ System.out.println("DiffModel :\n"); //$NON-NLS-1$
+ System.out.println(ModelUtils.serialize(diff));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ // Serializes the result as "result.emfdiff" in the directory this class has been called from.
+ System.out.println("saving emfdiff as \"result.emfdiff\""); //$NON-NLS-1$
+ final ModelInputSnapshot snapshot = DiffFactory.eINSTANCE.createModelInputSnapshot();
+ snapshot.setDate(Calendar.getInstance().getTime());
+ snapshot.setMatch(match);
+ snapshot.setDiff(diff);
+ ModelUtils.save(snapshot, "result.emfdiff"); //$NON-NLS-1$
+ } catch (IOException e) {
+ // shouldn't be thrown
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ } else {
+ System.out.println("usage : ExampleLauncher &lt;Model1> &lt;Model2>"); //$NON-NLS-1$
+ }
+ }
+ }
+
+</pre><p></p><h3 id="Compilation">Compilation</h3><p>The following list of libraries will need to be in the classpath in order to compile:</p><ul><li>org.eclipse.emf.common 2.3 or higher</li><li>org.eclipse.emf.ecore 2.3 or higher</li><li>org.eclipse.emf.compare 0.8 or higher</li><li>org.eclipse.emf.compare.diff 0.8 or higher</li><li>org.eclipse.emf.compare.match 0.8 or higher</li></ul><h3 id="Launch">Launch</h3><p>All six aforementionned libraries will be required to be in the classpath for this class to run. Additionally, the following libraries <br/> are required:</p><ul><li>org.eclipse.emf.ecore.xmi 2.3 or higher</li></ul></body></html> \ No newline at end of file

Back to the top