<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MDA, MDSD, MDE, MDWhatever! &#187; Eclipse</title>
	<atom:link href="http://mdwhatever.free.fr/index.php/category/eclipse-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://mdwhatever.free.fr</link>
	<description>About model driven engineering</description>
	<lastBuildDate>Mon, 12 Mar 2012 19:56:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Quality analysis on Eclipse plugins with Tycho, Sonar, Jacoco and SWTBot</title>
		<link>http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/</link>
		<comments>http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 13:25:45 +0000</pubDate>
		<dc:creator>xavier</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Intégration continue]]></category>

		<guid isPermaLink="false">http://mdwhatever.free.fr/?p=209</guid>
		<description><![CDATA[Building tools brings a lot more that compilation. You can go much further. For instance, have a look at maven : there&#8217;s a plugin for almost everything (Here, here, and here). And with the rise of Tycho, you can bring all the power of maven to build OSGI/Eclipse based projects. Let&#8217;s see how to leverage]]></description>
			<content:encoded><![CDATA[<p>Building tools brings a lot more that compilation. You can go much further.</p>
<p>For instance, have a look at maven : there&#8217;s a plugin for almost everything (<a title="Here" href="http://maven.apache.org/plugins/index.html" target="_blank">Here</a>, <a title="here" href="http://mojo.codehaus.org/plugins.html" target="_blank">here</a>, <a title="and here" href="http://code.google.com/hosting/search?q=maven+plugin+label%3Amaven&amp;projectsearch=Search+Projects" target="_blank">and here</a>). And with the rise of <a href="http://www.eclipse.org/tycho/" target="_blank">Tycho</a>, you can bring all the power of maven to build OSGI/Eclipse based projects.</p>
<p>Let&#8217;s see how to leverage the use of <a href="http://www.sonarsource.org/" target="_blank">Sonar</a> (a great open source quality analysis tool) to deal with the QA of your project.<br />
<span id="more-209"></span></p>
<h2><span style="line-height: 28px;">Install the Jacoco plugin for Sonar</span></h2>
<p>I assume you have a running instance of Sonar. (If not, have a look here : <a href="http://docs.codehaus.org/display/SONAR/Install+Sonar" target="_blank">Install Sonar</a>).</p>
<p>Since Eclipse convention is to separate plugin and test in two separate projects (in order to not pollute plugin dependencies with test dependencies), &#8220;traditional&#8221; code coverage tools (such as Cobertura) won&#8217;t be able instrument Eclipse plugin classes because test classes are not in their classpath.</p>
<p><a href="http://www.eclemma.org/jacoco/trunk/index.html" target="_blank">Jacoco</a> adopts &#8220;on the fly instrumentation&#8221; by the means of a JavaAgent (<a href="http://www.eclemma.org/jacoco/trunk/doc/implementation.html" target="_blank">http://www.eclemma.org/jacoco/trunk/doc/implementation.html</a>), this enables the ability to maintain plugin code and test code in separated project : that just what we need in our case! Great!</p>
<p>So to install Jacoco plugin just follow that guide : <a href="http://docs.codehaus.org/display/SONAR/JaCoCo+Plugin" target="_blank">http://docs.codehaus.org/display/SONAR/JaCoCo+Plugin</a>.</p>
<p>Now we are ready to configure our Tycho build.</p>
<h2>Tycho build</h2>
<p>I assume you have a running tycho build. So you just need to add the following section in the <strong>pluginManagement</strong> section of the parent pom :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- Testing --&gt;
&lt;plugin&gt;
   &lt;groupId&gt;org.eclipse.tycho&lt;/groupId&gt;
   &lt;artifactId&gt;tycho-surefire-plugin&lt;/artifactId&gt;
   &lt;version&gt;${tycho.version}&lt;/version&gt;
   &lt;configuration&gt;
      &lt;useUIHarness&gt;false&lt;/useUIHarness&gt;
      &lt;includes&gt;
         &lt;include&gt;**/*Test.java&lt;/include&gt;
      &lt;/includes&gt;
      &lt;!-- Kill test JVM if tests take more than 10 minutes (600 seconds) to finish --&gt;
      &lt;forkedProcessTimeoutInSeconds&gt;600&lt;/forkedProcessTimeoutInSeconds&gt;
   &lt;/configuration&gt;
&lt;/plugin&gt;
</pre>
<p>And then provide the following profile :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- This profile is used to gather code coverage for Sonar --&gt;
&lt;profile&gt;
  &lt;id&gt;codeCoverage&lt;/id&gt;
  &lt;properties&gt;
    &lt;!-- Properties to enable jacoco code coverage analysis --&gt;
    &lt;sonar.core.codeCoveragePlugin&gt;jacoco&lt;/sonar.core.codeCoveragePlugin&gt;
    &lt;sonar.dynamicAnalysis&gt;reuseReports&lt;/sonar.dynamicAnalysis&gt;
    &lt;sonar.jacoco.reportPath&gt;../org.demo.camp.nantes.parent/target/jacoco.exec&lt;/sonar.jacoco.reportPath&gt;
  &lt;/properties&gt;

  &lt;build&gt;
    &lt;plugins&gt;
      &lt;!-- Enabling use of jacoco --&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
        &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
        &lt;version&gt;0.5.3.201107060350&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;goals&gt;
              &lt;goal&gt;prepare-agent&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
              &lt;!-- Where to put jacoco coverage report --&gt;
              &lt;destFile&gt;${sonar.jacoco.reportPath}&lt;/destFile&gt;
            &lt;/configuration&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/profile&gt;
</pre>
<p>And that&#8217;s all for the parent pom configuration.</p>
<p>For unit testing you do not need to do more that providing the right packaging :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;packaging&gt;eclipse-test-plugin&lt;/packaging&gt;
</pre>
<p>But for UI testing with <a href="http://www.eclipse.org/swtbot/" target="_blank">SWTBot</a>, you need some more configuration.</p>
<h2>Tycho configuration for UI testing project with SWTBot</h2>
<p>In order to execute your UI tests, you need to specify which product/application you need to start. Basically, for an Eclipse plugin, you&#8217;ll need to run the following couple :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;product&gt;org.eclipse.sdk.ide&lt;/product&gt;
&lt;application&gt;org.eclipse.ui.ide.workbench&lt;/application&gt;
</pre>
<p>So you just need to add the following section to your UI test plugin :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;build&gt;
	&lt;plugins&gt;
		&lt;plugin&gt;
	        &lt;groupId&gt;org.eclipse.tycho&lt;/groupId&gt;
	        &lt;artifactId&gt;tycho-surefire-plugin&lt;/artifactId&gt;
	        &lt;version&gt;${tycho.version}&lt;/version&gt;
	        &lt;configuration&gt;
	          &lt;useUIHarness&gt;true&lt;/useUIHarness&gt;
	          &lt;useUIThread&gt;false&lt;/useUIThread&gt;
	          &lt;product&gt;org.eclipse.sdk.ide&lt;/product&gt;
	          &lt;application&gt;org.eclipse.ui.ide.workbench&lt;/application&gt;
	        &lt;/configuration&gt;
      	&lt;/plugin&gt;
	&lt;/plugins&gt;
&lt;/build&gt;
</pre>
<p>Now your UI test can run through Tycho and being analyzed by Sonar. Great!</p>
<h2>Limitations</h2>
<p>Wokring on Mac has some advantages, and some drawbacks, here we are facing a drawback. Running SWT applications on Mac require the following JVM argument : <strong>-XstartOnFirstThread (</strong><a href="http://www.eclipse.org/swt/macosx/" target="_blank">http://www.eclipse.org/swt/macosx/</a>).</p>
<p>So you need to configure the the tycho-surefire-plugin as below in the parent pom :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;plugin&gt;
	&lt;groupId&gt;org.eclipse.tycho&lt;/groupId&gt;
	&lt;artifactId&gt;tycho-surefire-plugin&lt;/artifactId&gt;
	&lt;version&gt;${tycho.version}&lt;/version&gt;
	&lt;configuration&gt;
		&lt;useUIHarness&gt;false&lt;/useUIHarness&gt;
		&lt;includes&gt;
			&lt;include&gt;**/*Test.java&lt;/include&gt;
		&lt;/includes&gt;
		&lt;!-- Kill test JVM if tests take more than 10 minutes (600 seconds) to finish --&gt;
		&lt;forkedProcessTimeoutInSeconds&gt;600&lt;/forkedProcessTimeoutInSeconds&gt;
		&lt;argLine&gt;-XstartOnFirstThread&lt;/argLine&gt;
	&lt;/configuration&gt;
&lt;/plugin&gt;
</pre>
<p>But if you do that, the tycho-surefire-plugin argLine <strong>will overwrite</strong> the Jacoco instrumentation argLine.</p>
<p>But thanks to this following tycho-surefire-plugin configuration parameter : <strong>appArgLine</strong> you can add other arguments without overwriting the ones from the <strong>argLine</strong> configuration parameter. So you can define your MacOs profile as below :</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- MacOS specific vm arguments for UI testing --&gt;
&lt;profile&gt;
	&lt;id&gt;osx&lt;/id&gt;
	&lt;activation&gt;
		&lt;property&gt;
			&lt;name&gt;java.vendor.url&lt;/name&gt;
			&lt;value&gt;http://www.apple.com/&lt;/value&gt;
		&lt;/property&gt;
	&lt;/activation&gt;
	&lt;build&gt;
		&lt;pluginManagement&gt;
			&lt;plugins&gt;
				&lt;plugin&gt;
					&lt;groupId&gt;org.eclipse.tycho&lt;/groupId&gt;
					&lt;artifactId&gt;tycho-surefire-plugin&lt;/artifactId&gt;
					&lt;version&gt;${tycho.version}&lt;/version&gt;
					&lt;configuration&gt;
						&lt;appArgLine&gt;-XstartOnFirstThread&lt;/appArgLine&gt;
					&lt;/configuration&gt;
				&lt;/plugin&gt;
			&lt;/plugins&gt;
		&lt;/pluginManagement&gt;
	&lt;/build&gt;
&lt;/profile&gt;
</pre>
<p>You now can handle the execution of your UI tests seamlessly on any platform.</p>
<h2>To be done</h2>
<p>If you have a look at the Sonar analysis, you&#8217;ll see that code coverage is calculated from source code and test code (<a href="http://ec2-79-125-43-108.eu-west-1.compute.amazonaws.com:8080/sonar/drilldown/measures/1?metric=coverage" target="_blank">Sonar analysis</a>).</p>
<p>So we need to use the sonar.exclusions pom property : <a href="http://docs.codehaus.org/display/SONAR/Advanced+parameters" target="_blank">http://docs.codehaus.org/display/SONAR/Advanced+parameters</a></p>
<p>Another thing to investigate is to differentiate <strong>Code coverage</strong> and <strong>IT coverage</strong> : <a href="http://www.sonarsource.org/measure-code-coverage-by-integration-tests-with-sonar/" target="_blank">http://www.sonarsource.org/measure-code-coverage-by-integration-tests-with-sonar/</a></p>
<p>Add continuous integration (Jenkins or Hudson) : here is a good explanation on how to run UI test on a headless server : <a href="http://blog.dahanne.net/2011/07/18/run-ui-tests-on-a-headless-jenkins-hudson-continuous-integration-server-running-ubuntu/" target="_blank">http://blog.dahanne.net/2011/07/18/run-ui-tests-on-a-headless-jenkins-hudson-continuous-integration-server-running-ubuntu/</a> by <a href="http://twitter.com/#!/anthonydahanne" target="_blank">@anthonydahanne</a></p>
<h2>Resources</h2>
<p>You can have a look to the source code of a small sample : <a href="https://github.com/xseignard/tycho-demo-camp" target="_blank">https://github.com/xseignard/tycho-demo-camp</a></p>
<p>You can run <strong>mvn clean install -PcodeCoverage</strong> and then <strong>mvn sonar:sonar -PcodeCoverage</strong> from the parent project.</p>
<p>And check the sonar analysis here: <a href="http://ec2-79-125-43-108.eu-west-1.compute.amazonaws.com:8080/sonar/">http://ec2-79-125-43-108.eu-west-1.compute.amazonaws.com:8080/sonar/</a> It should work out of the box.</p>
<p>You can edit/remove the sonar connection settings in order to use your own Sonar instance.</p>
<p>Feel free to provide pull request in order to ameliorate the project and/or drop a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
