Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EMF Compare FAQ"

(Is EMF Compare, as EMF, able to run outside of Eclispe ?)
(Redirecting to EMF Compare/FAQ)
 
(29 intermediate revisions by 6 users not shown)
Line 1: Line 1:
=Users=
+
#REDIRECT[[EMF_Compare/FAQ]]
====My model is compared as a text-file, how can EMF compare know what file it should handle ?====
+
'''Q''' : My model is compared as a text-file, how can EMF compare know what file it should handle ?
+
 
+
'''A''' : EMF compare uses a content-type to know if it should be started or not. By default this content-type is composed of *.ecore and *.uml file but you may add your own extension using the <tt>Preferences view / Global / Content-types</tt> and adding your file extension in the "Model File" content-type.
+
 
+
 
+
[[Image:EMFComparePreferences-content-type.png]]
+
 
+
=Developpers=
+
====How can I programatically add my model file extension in EMF Compare so that it is called automatically ? ====
+
'''Q''' : How can I programatically add my model file extension in EMF Compare so that it is called automatically ?
+
 
+
'''A''' : Using the "Model File" content-type defined with EMF Compare, here is a sample from a plugin.xml:
+
<pre>
+
<extension
+
        point="org.eclipse.core.contenttype.contentTypes">
+
    <file-association
+
          content-type="org.eclipse.emf.compare.ui.contenttype.ModelContentType"
+
          file-extensions="uml13"
+
          file-names="*"/>
+
  </extension>
+
</pre>
+
 
+
====Is EMF Compare, as EMF, able to run outside of Eclispe ? ====
+
'''Q''' : Is EMF Compare able to compare "in-memory" objects, and can it be run without Eclispe ?
+
 
+
'''A''': Yes, here is a snippet doing that:
+
<pre>
+
/**
+
* This application will try and launch an headless model comparison.
+
*
+
* @author Cedric Brun <a href="mailto:cedric.brun@obeo.fr">cedric.brun@obeo.fr</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 && new File(args[0]).canRead() && new File(args[1]).canRead()) {
+
// Creates the resourceSet where we'll load the models
+
final ResourceSet resourceSet = new ResourceSetImpl();
+
try {
+
// 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
+
final MatchModel match = new DifferencesServices().modelMatch(model1, model2, new NullProgressMonitor());
+
final DiffModel diff = new DiffMaker().doDiff(match);
+
+
// Prints the results
+
try {
+
System.out.println(ModelUtils.serialize(match));
+
System.out.println(ModelUtils.serialize(diff));
+
} catch (IOException e) {
+
e.printStackTrace();
+
}
+
+
// System.out.println("saving diff as \"result.diff\"");
+
// ModelUtils.save(diff, "result.diff");
+
// System.out.println("saving match as \"result.match\"");
+
// ModelUtils.save(match, "result.match");
+
+
// 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 : Launcher <Model1> <Model2>"); //$NON-NLS-1$
+
}
+
}
+
}
+
</pre>
+

Latest revision as of 09:48, 26 July 2010

Redirect to:

Back to the top