title: Compare two source code files using EMF models
body: <p>In my application I should compare two source code files to see if something has changed and then highlight those changes. For that i thought of using EMF compare. My application is a standalone application and is not used as a plugin or something similar. It should run without eclipse. Therefore I linked all the necessary libraries and tried to use EMF compare.</p>
  
  <p>The problem now is that I don´t know how to build the two models that I have to use to compare the two source code files against each other. In the following code snippet I wrote as a first approach, the source code files are passed as files (Test1.java and Test2.java) but actually the source code of both files are stored in a string as the method parameters indicate.</p>
  
  <p>So my question is basically how can I generate two models based on String that contain Java source code so that I can use these two models to compare against each other?</p>
  
  <pre><code>public void compare(String source1, String source2) throws IOException, InterruptedException {
  
      Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("java", new ResourceFactoryImpl());
  
      XSDEcoreBuilder builder = new XSDEcoreBuilder();
  
      Collection&lt;EObject&gt; model1 = builder.generate(URI.createFileURI("Test1.java"));
      Collection&lt;EObject&gt; model2 = builder.generate(URI.createFileURI("Test2.java"));
  
      final MatchModel match = MatchService.doMatch(model1.iterator().next(), model2.iterator().next(), Collections.&lt;String, Object&gt; emptyMap());
      final DiffModel diff = DiffService.doDiff(match, false);
  
      final List&lt;DiffElement&gt; differences = new ArrayList&lt;DiffElement&gt;(diff.getOwnedElements());
  
      System.out.println("MatchModel :\n");
          System.out.println(ModelUtils.serialize(match));
          System.out.println("DiffModel :\n");
          System.out.println(ModelUtils.serialize(diff));
  }
  </code></pre>