<?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>ITworks &#187; maven</title>
	<atom:link href="http://itworks.hu/tag/maven/feed/" rel="self" type="application/rss+xml" />
	<link>http://itworks.hu</link>
	<description>Random musings in IT</description>
	<lastBuildDate>Mon, 09 Jan 2012 08:01:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Testing mojo generated code in Maven</title>
		<link>http://itworks.hu/2011/11/15/testing-mojo-generated-code-in-maven/</link>
		<comments>http://itworks.hu/2011/11/15/testing-mojo-generated-code-in-maven/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 17:38:46 +0000</pubDate>
		<dc:creator>csak</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://m.itworks.hu/2011/11/15/testing-mojo-generated-code-in-maven/</guid>
		<description><![CDATA[Lately I was assigned a task which involved something that a unit test seemed to be able to solve, but later it turned out to be way more complex than that. Almost a third of our codebase consists of POJOs &#8230; <a href="http://itworks.hu/2011/11/15/testing-mojo-generated-code-in-maven/">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lately I was assigned a task which involved something that a unit test seemed to be able to solve, but later it turned out to be way more complex than that. </p>
<p>Almost a third of our codebase consists of POJOs generated from Xsd descriptors scattered around in our projects. The generation is performed during build, using a Maven plugin that performs the parsing and generation tasks.</p>
<p>These generated classes are no more than simple value objects descending from a common root object, that contains some well-known methods like toString (), that all methods should share. Unfortunately this particular toString does not know about it&#8217;s descendants&#8217; inner structure, so it relies heavily on reflection to perform it&#8217;s task. This springs the idea of generating the classes with their own toString methods, so the resulting code is more efficient. </p>
<p>To do this to be backwards compatible, I would have to generate all known xsds, invoke their old and generated toString implementation and compare the results. Also I&#8217;d have to fill these objects with values, so I&#8217;d have data to compare.</p>
<p>So much for the task, but what&#8217;s the fuss about? Well I want the testing kept inside Maven, so should the generated or  inherited code change, we can see it in the build process. </p>
<p>There seem to exist a vast number of ways to be used for mojo testing, starting from the blunt get a mojo instance, fill it with values, and run execute (), to running a separate Maven instance and use the generated test results. Given that in this particular case I&#8217;d to start the compiler and then the surefire I (eventually ) went for the later approach. </p>
<p>The plugin testing harness is an example of the earlier approach, while it seems from the usage example the former. Avoid if you have to invoke more, than just your own mojo. It only reads the pom.xml you provide, but doesn&#8217;t set up the required Maven environment like builders, project, …etc. It doesn&#8217;t do the setup of the default values of your mojo (not that it could resolve the non-existing values for that) So all you end up with is using a helper method for setting up your mojos and executing them from your testcase. I went as far as generating and compiling my classes, but when it came to the point of actually testing them with a surefire mojo I gave up on it, as setting that up would really have been impossible. </p>
<p>I then realized that from testing point of view it is in fact an integration test, not a &#8220;mere&#8221; unit test, as the testing involves interaction with third party plugins (compiler and surefire) as well. So I converted the package from the plugin testing harness&#8217;s structure to the maven-invoker plugin&#8217;s recommended structure.  It was nothing more than moving a few directories around, but I could simply throw the complicated mojo invocation out and use a well defined and simple pom instead.  This plugin creates a local repository for itself that contains your project&#8217;s dependencies and the artifact to be tested. It&#8217;s advised to create a settings.xml that points to your local repository, to limit the unnecessary fetching from your repositories.  </p>
<p>So far, so good. You should keep in mind however, the invoker plugin has some disadvantages. It&#8217;s way slower than the harness. It doesn&#8217;t aggregate the test results, so all you can see on a failed build, that there were errors in a particular run. Also, since it runs the test in a separate Java environment, you cannot debug your test code, which in my case is quite complex. </p>
<p>So you either create a separate test module and refer to it from the test pom, and create a unit test to test your code with known data, or just be brave write well thought out code and do it properly using log messages to trace your work, just like the good old times. After all repeated failure builds character.  <img src='http://itworks.hu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I actually created a small and a full test environment, testing the particularities of the test separately. To debug the test code you&#8217;ve got to import the generated Maven project in your IDE and start the test execution with the local repository and the generated settings.xml. </p>
<p>What were the results? I achieved a speedup of about 90% for completely empty classes, about 70% for classes with data, when the output buffer is limited, and around 30% for classes recursively and completely filled in a depth of four iterations. Overall I could say it&#8217;s a 50% improvement on the original method, with a proven backwards compatibility. Considering that this is invoked at least 6 million times a day it might bring a favorable impact on the performance of our systems. </p>
<p>In the process I found 3 errors in the current code, that proved that the output of method&#8217;s not used to heavily in the live system. Since the logging it produces is mandatory for regulatory compliance it might just be a good idea to roll it out in the near future. </p>
]]></content:encoded>
			<wfw:commentRss>http://itworks.hu/2011/11/15/testing-mojo-generated-code-in-maven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wicket in action and confusion</title>
		<link>http://itworks.hu/2009/08/29/wicket-in-action-and-confusion/</link>
		<comments>http://itworks.hu/2009/08/29/wicket-in-action-and-confusion/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 22:53:56 +0000</pubDate>
		<dc:creator>csak</dc:creator>
				<category><![CDATA[annoyance]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[java security]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://itworks.hu/?p=68</guid>
		<description><![CDATA[For a recent project lead, we decided to create a mock-up of the application, so the prospective Customer would be able to see that we understand their needs. As I&#8217;m not very good at interactive HTML mock-ups I decided to &#8230; <a href="http://itworks.hu/2009/08/29/wicket-in-action-and-confusion/">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For a recent project lead, we decided to create a mock-up of the application, so the prospective Customer would be able to see that we understand their needs.</p>
<p>As I&#8217;m not very good at interactive HTML mock-ups I decided to go with <a href="http://wicket.apache.org/">Wicket</a>, which seemed to be useful and easy when a friend showed me. The mock-up progressed well, but upon deployment all <a href="http://www.microsoft.com">Hell</a> broke loose.</p>
<p><span id="more-68"></span>I chose <a href="http://wicket.apache.org/">Wicket</a>, because I hate most web frameworks already, Struts is way to old and twisted for anything proper, I have not found a single open source JSF implementation that works properly, and I had nothing concrete against <a href="http://wicket.apache.org/">Wicket</a> yet.</p>
<p>I also wanted to try Maven, since I hate it&#8217;s conception so much, it seemed like a good time to try, after all we had two days on our hands, why not waste it properly? I still hate it, but only on principle, otherwise it to me it&#8221;s a lot like the apt of java. And my world is Debian based. <img src='http://itworks.hu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So the mock-up went well. I&#8217;ve spent hours figuring out how to do a simple menu that shows selected items with the &lt;wicket:link&gt; feature, with mouseovers. I managed to get it working, to realize it would never work on IE. Then I reimplemented it, then again. Finally I threw it all away and added a JavaScript onload and some brute-force to get it working.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fireOnLoad<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// highlight current menu</span>
  <span style="color: #003366; font-weight: bold;">var</span> menuTable <span style="color: #339933;">=</span> window.<span style="color: #660066;">document</span>.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'menuTable'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>menuTable.<span style="color: #660066;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">cells</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> curM <span style="color: #339933;">=</span> menuTable.<span style="color: #660066;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">cells</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>curM.<span style="color: #660066;">children</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">tagName</span> <span style="color: #339933;">!=</span><span style="color: #3366CC;">'A'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> curClassName <span style="color: #339933;">=</span> curM.<span style="color: #660066;">className</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'Selected'</span><span style="color: #339933;">;</span>
      curM.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> curClassName <span style="color: #339933;">;</span>
      curM.<span style="color: #660066;">children</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
      menuTable.<span style="color: #660066;">rows</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">cells</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For the HTML code like</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;table id=&quot;menuTable&quot; class=&quot;menuTable&quot; border=&quot;0&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class=&quot;subMenuItemContainer&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=&quot;subMenuPointer&quot;&gt;
    &lt;img style=&quot;display:none&quot; onclick=&quot;window.location.href='../img/submenu.gif';return false;&quot; src=&quot;../img/submenu.gif&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
...&lt;/tr&gt;
&lt;tr class=&quot;menuItemContainer&quot;&gt;
&lt;td class=&quot;menuItem&quot; onmouseover=&quot;return menuRollOver(this)&quot; onmouseout=&quot;return menuRollOut(this)&quot;&gt;
&lt;div class=&quot;hiddenSubMenu&quot;&gt;
&lt;ul class=&quot;subMenu&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;../pages/AgencyList&quot;&gt;Keresés&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;a href=&quot;../pages/AgencyList&quot;&gt;Ügynökségek&lt;/a&gt;&lt;/td&gt;
...&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</pre></div></div>

<p>It&#8217;s quite ugly, but adequate for the current situation.</p>
<p>After the pages were ready and tested on localhost I decided to move it to our server for presentation. The server runs Debian and has an Apache Tomcat 5.5 running on it for ages. It turned out however, that somehow the project requires Tomcat 6. Not wanting to go over all the project&#8217;s config, I went for the server upgrade. The Tomcat had no applications that were to be effected, so it seemed like an easy choice.</p>
<p>Install from apt went smoothly, the application deployed easily. There was a strange problem though.</p>
<p>Every time I clicked a link it either didn&#8217;t display any images or it displayed some, or none at all. Refreshing the page always changed something. I suspected, it must be an issue with the <a href="http://wicket.apache.org/">Wicket</a> filter, but could not put my hand on it.</p>
<p>Trying to isolate the problem I tried loading a single image from the application. It turned out, that a security exception is thrown every time I try to reload a resource that was previously loaded. Turning of security in Tomcat packaged for Debian did not work out of the box, so I tried to find a solution. I found the page on Java security in <a href="http://wicket.apache.org/">Wicket</a> but adding the values on the page just resulted in another error.</p>
<p>I decided to add all rules found on the <a href="http://cwiki.apache.org/WICKET/java-security-permissions.html">Wicket WIKI</a>, but that wasn&#8217;t enough. So I was adding the rules one-by-one to come up with my version of the security policy for 1.4</p>
<pre>grant {
// For substitution of one object for another during serialization
// or deserialization. This is used in ReplaceObjectOutputStream,
// which is used for page versioning (undoing changes).
//permission java.io.SerializablePermission "enableSubstitution";

// For FilePageStore's custom serialization
//permission java.io.SerializablePermission "enableSubclassImplementation";

// For crypted URL functionality (see WebRequestWithCryptedUrl).
//permission java.security.SecurityPermission "insertProvider.SunJCE";

// The following was required to get Wicket, at least the examples, to work at all
permission java.lang.reflect.ReflectPermission
   "suppressAccessChecks";
permission java.lang.RuntimePermission
   "accessClassInPackage.org.apache.tomcat.util.http";
permission java.util.PropertyPermission
   "org.apache.tomcat.util.http.FastHttpDateFormat.CACHE_SIZE",
   "read";
};</pre>
<p>As it turned out the problem is gone now. At least until I hit another security restriction.</p>
]]></content:encoded>
			<wfw:commentRss>http://itworks.hu/2009/08/29/wicket-in-action-and-confusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

