<?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>This is my blog &#187; programming</title>
	<atom:link href="http://www.ronniealleva.org/index.php/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ronniealleva.org</link>
	<description>There are many like it but this one is mine</description>
	<lastBuildDate>Mon, 10 May 2010 07:06:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Materialised views and Spring DAO Tests</title>
		<link>http://www.ronniealleva.org/index.php/2010/03/01/materialised-views-and-spring-dao-tests/</link>
		<comments>http://www.ronniealleva.org/index.php/2010/03/01/materialised-views-and-spring-dao-tests/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 07:02:15 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/?p=131</guid>
		<description><![CDATA[So, you have a materialized view in your DB.  That&#8217;s great.  Give yourself a cookie.
You also have created a set of tests in your DAO layer, using the AbstractTransactionalSpringContextTests.  Good for you, again.
But when you try to mix these two together, you may see tests failing and can&#8217;t immediately see why.  This can happen if [...]]]></description>
			<content:encoded><![CDATA[<p>So, you have a materialized view in your DB.  That&#8217;s great.  Give yourself a cookie.</p>
<p>You also have created a set of tests in your DAO layer, using the <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/test/AbstractTransactionalSpringContextTests.html">AbstractTransactionalSpringContextTests</a>.  Good for you, again.</p>
<p>But when you try to mix these two together, you may see tests failing and can&#8217;t immediately see why.  This can happen if you try to get data from the materialized view after attempting to save data to a table that the view accesses.</p>
<p>Well, it&#8217;s very simple, and probably pretty obvious.  It wasn&#8217;t immediately obvious to me why it was failing, and I didn&#8217;t really see anything online about it, so hopefully this will stop your search quickly.</p>
<p>First thing to realize is that running your DAO tests through the AbstractTransactionalSpringContextTests is that every test is run in a transaction.  That&#8217;s great most of the time.  Each test will run in a little isolated environment and the changes to the database will be rolled back at the end. You don&#8217;t have all kinds of test data strewn about afterwards as if it were the island in Cast Away.</p>
<p>The second thing to realize is that a materialized view will only be updated on commit.  There&#8217;s a lot more to it than that, but I am not a DBA and that&#8217;s all you need to know in general.</p>
<p>So, with those two things in mind, you can see how it might be a problem if you try to write tests against code that uses the materialized view.  All is not lost however.  If you put an <strong>endTransaction()</strong> call somewhere in your test, all of the DB calls you&#8217;ve made up to that point will be committed.  Also, any other calls made after that point will also be committed to the database.  Since that happens, you will be on your own to clean up after the test as you see fit.  Also, placing an endTransaction will only affect the test you place it in.  Any other test will still continue to run and rollback in the normal fashion.</p>
<p>What we ended up doing was making the tests that need to commit to the database small as possible.  We then wrapped the <strong>endTransaction()</strong> function in a function called <strong>setTestToCommit()</strong> (my co-worker <a href="http://jlorenzen.blogspot.com/">James&#8217;</a> suggestion), so that it makes more sense to read it, and placed it at the beginning of the test.</p>
<p>There&#8217;s lots more information about how it works <a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/test/AbstractTransactionalSpringContextTests.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2010/03/01/materialised-views-and-spring-dao-tests/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More git-svn fun: working with svn branches</title>
		<link>http://www.ronniealleva.org/index.php/2009/09/16/more-git-svn-fun-working-with-svn-branches/</link>
		<comments>http://www.ronniealleva.org/index.php/2009/09/16/more-git-svn-fun-working-with-svn-branches/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 05:47:05 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/?p=50</guid>
		<description><![CDATA[So, last time I detailed using git to work with your svn trunk.  But many of you asked, &#8220;But Ralph, my svn repo has many branches and many tags because developers love branches and tags!  How can I work with that?&#8221;  Well, since no one reads this blog and no one actually [...]]]></description>
			<content:encoded><![CDATA[<p>So, <a href="http://www.ronniealleva.org/index.php/2008/08/28/using-git-and-subversion-in-5-easy-steps/">last time</a> I detailed using git to work with your svn trunk.  But many of you asked, &#8220;But Ralph, my svn repo has many branches and many tags because developers love branches and tags!  How can I work with that?&#8221;  Well, since no one reads this blog and no one actually asked me that, also misspelling my name in the process, let&#8217;s just pretend that what I write is relevant.</p>
<p>So you want to work with multiple svn branches (not to be confused with git branches).  What you have to do is clone the svn repository in a different way, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ git svn clone https://somesvnrepo/svn/project -T trunk -b branches -t tags</pre></div></div>

<p>This should work in most cases.  The arguments to the -T, -b, and -t switches are the paths that the trunk, branches, and tags are in respectively. Typically, your branches and tags should be what I put above, but just in case it is different in your case, there you go.</p>
<h2>Working with your shiny repo</h2>
<p>After a short time in which humans achieve interstellar travel, git finishes cloning, and you have access to the entire svn repository.  Now, let&#8217;s say you wanted to start working on trunk.  Like before, you should checkout a branch, but this time it&#8217;s going to use trunk as it&#8217;s parent:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ git checkout -b BranchOfTrunk trunk</pre></div></div>

<p>But Lo!  You have the entire repo, so you can checkout that branch from whatever branch you have in subversion.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ git checkout -b BranchOfSubversionBranch subversion-branch</pre></div></div>

<p>Now, you can switch between BranchOfTrunk and BranchOfSubversionBranch, and you&#8217;ll get all the code associated with trunk and subversion-branch respectively.  No more checkout of a branch ever again, wasting precious keystrokes you could use to post to Facebook.  </p>
<p>If a new svn branch is created on the server, make sure to run the following command to see it:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ git svn fetch
. (updating blah blah)
.
.
$ git branch -a</pre></div></div>

<p>The last command will show you all the branches, local (your own branches) and remote (every dumb svn branch), for this repository.</p>
<p>NOTE: <strong>git svn fetch</strong> and <strong>git svn rebase</strong> are almost exactly the same.  <strong>fetch</strong> will update the entire git repository with anything not received from svn.  <strong>rebase</strong> is concerned only with the parent of the branch you have checked out.  If you recall last time, <strong>git svn rebase</strong> was equivalent to <strong>svn update</strong>.  Now you can work with the same workflow as I mentioned before, working, committing locally, rebasing, etc.  </p>
<h2>Merging from subversion branch to trunk?  BALDERDASH!</h2>
<p>Now, let&#8217;s say that you want to commit a series of changes into a subversion branch, but you also want to commit the same changes in trunk also.  What I&#8217;m going to show you is the workflow that I go through most of the time.  I think it&#8217;s the most effective way to accomplish it in git.  </p>
<p>First, you can run a fake dcommit.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ git svn dcommit --dry-run
Committing to https://svnserver/svn/project/branches/subversion-branch ...
diff-tree b64fdc9250bbe04b3246214ade509e0b0d9d912d~1 b64fdc9250bbe04b3246214ade509e0b0d9d912d</pre></div></div>

<p>The <strong>&#8220;&#8211;dry-run&#8221;</strong> is key here, for two reasons.  First, you&#8217;ll be able to see what branch you are actually committing to in subversion. Not a bad idea, since you&#8217;re working in a git repo that has all your subversion branches.</p>
<p>Second, you&#8217;ll see a diff tree with some of the commit hashes, one corresponding to each time you did a commit locally, in order.  You will want to keep the values of the hash around, because next we are going to <strong>&#8220;cherry-pick&#8221;</strong> them into trunk:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ git checkout BranchOfTrunk
Switched to branch &quot;BranchOfTrunk&quot;
$ git cherry-pick b64fdc9
Finished one cherry-pick.
Created commit e4a7971:  Your commit comments here
 12 files changed, 58 insertions(+), 66 deletions(-)</pre></div></div>

<p>You&#8217;ll notice I only used the first 7 digits of the hash (b64fdc9) to do the cherry-pick.  That&#8217;s all you need to use&#8230;git will pick out the revision from just those seven characters.  What this does is pulls the change from the other branch into this branch.  If you have more than one commit, you should do this multiple times, in the order of the commits.  But then you have the things you did on the branch ready to be checked into trunk!  </p>
<p>This is the way I usually work.  You may decide that doing a subversion merge is easier for what you are trying to do (I sometimes do also).  I&#8217;d also like to know if there is an easier way to do this.  This doesn&#8217;t seem the easiest way, but was the easiest way I could find so far.  And I googled for like&#8230;20 minutes.</p>
<p>Hopefully this helps&#8230;someone.  One person, at least.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2009/09/16/more-git-svn-fun-working-with-svn-branches/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Git and Subversion in 5 Easy Steps</title>
		<link>http://www.ronniealleva.org/index.php/2008/08/28/using-git-and-subversion-in-5-easy-steps/</link>
		<comments>http://www.ronniealleva.org/index.php/2008/08/28/using-git-and-subversion-in-5-easy-steps/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 04:44:23 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/index.php/2008/08/28/using-git-and-subversion-in-5-easy-steps/</guid>
		<description><![CDATA[I recently wanted to use a distributed version control system to learn and to try it out, since I have been hearing great things about it.  The only issue is that my team (and like 1 million other teams universe wide) currently uses Subversion, and trying to get them to switch over would be like [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to use a distributed version control system to learn and to try it out, since I have been hearing great things about it.  The only issue is that my team (and like 1 million other teams universe wide) currently uses Subversion, and trying to get them to switch over would be like trying to punch a redwood down.</p>
<p>But! Not all is lost.  You can use git with Subversion.  This can give you some of the benefits of using a DVCS without having to change everything you do.  I believe you can do this also with Mercurial&#8230;I went with git because I had read somewhere it had the best support to working with Subversion. AND RANDOM INTERNET BLOGS ARE ALWAYS RIGHT.</p>
<p>First of all, I will say that I used <a href="http://utsl.gen.nz/talks/git-svn/intro.html">this</a> as a guide when I was working.  It&#8217;s a great start to doing this stuff.  I&#8217;ll also assume you can find and install git on your own, since you&#8217;re all-grow&#8217;d up now.</p>
<h2>Step 1: Creating a local repo</h2>
<p>Ok so let&#8217;s get started.  The first step is to get the subversion library.  That webpage I gave you gives you four different ways of doing it, but I decided to go with the fourth option, which is cloning the entire Subversion repository.  You can do that by doing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git <span style="color: #c20cb9; font-weight: bold;">svn</span> clone https:<span style="color: #000000; font-weight: bold;">//</span>svnserver<span style="color: #000000; font-weight: bold;">/</span>project<span style="color: #000000; font-weight: bold;">/</span>trunk</pre></div></div>

<p>Now, you should know that this could take a while.  You might as well go and eat dinner for the next three days while this completes.  Just kidding, this took me about an hour or so while I was working remotely over a VPN, so it&#8217;s not so bad.  Our project has about 8000 revisions, and about 230 MBs of files.</p>
<p>So you&#8217;re probably wondering &#8220;But now if I have the whole history, isn&#8217;t it going to take like&#8230;a bazillion bytes on my disk?&#8221;  To that I say &#8220;Non&#8221;&#8230;it uses compression, and my git repo ended up being about 1 MB bigger than my subversion one.</p>
<h2>Step 2: Create a branch</h2>
<p>From there, you can start working in git!  The first thing you&#8217;ll probably want to do is create a branch:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git branch someNeatoBranch</pre></div></div>

<p>To change to that branch:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git checkout someNeatoBranch</pre></div></div>

<p>Now you are working on this particular branch.  Note you can do this in one step by doing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git checkout <span style="color: #660033;">-b</span> someNeatoBranch</pre></div></div>

<p>which will create it and put you on it to work.</p>
<h2>Step 3: Commit locally</h2>
<p>Now you can edit the files to your heart&#8217;s content.  And commit locally as often as you like, by doing</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git commit <span style="color: #660033;">-a</span></pre></div></div>

<p>You can commit individual files by specifying them, but -a just grabs them all.</p>
<h2>Step 4: Commit back to Subversion</h2>
<p>Once you&#8217;re ready to commit back into the main Subversion repo, first you need to pull all the changes from there, to make sure there are no conflicts. You can do this by using this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git <span style="color: #c20cb9; font-weight: bold;">svn</span> rebase</pre></div></div>

<p>This will pull down the latest code and apply your code on top of it, merging if necessary.  Then to commit back to Subversion, you use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git <span style="color: #c20cb9; font-weight: bold;">svn</span> dcommit</pre></div></div>

<p>And you will notice that your files are committed back to the repo without any more intervention from you!  But where are your comments?  Well, all the comments from the commits you did locally will be used to commit to Subversion.  It will also do that many commits.  So if you did 5 different commits locally, it will turn into 5 different Subversion commits.  As long as your team members don&#8217;t worry about the revision number spirialing up towards the heavens, it should be ok.</p>
<h2>Step 5: Brunch!</h2>
<p>This is a pretty simple workflow to get you started on using git with Subversion, but it&#8217;s not even half the story.  There&#8217;s so much more powerful stuff with the branching aspect, and I even haven&#8217;t tried it yet to share work with my coworkers before commiting to svn (I&#8217;m kinda like a git island at the moment).  But try it out, and then check out some of the resources below that helped me get started.</p>
<p>Also, you might want to check how my co-worker <a href="http://jlorenzen.blogspot.com/2008/08/me-lovin-git.html">James </a>one-upped me.  He was working on some highly experimental code that he wanted to share with a teammate, and created a true git repo in approximately 8 seconds, from existing code.</p>
<p><strong><br />
</strong></p>
<h2><strong>Resources</strong></h2>
<ul>
<li><a href="http://utsl.gen.nz/talks/git-svn/intro.html">An introduction to git-svn for Subversion/SVK users and deserters</a></li>
<li><a href="http://git.or.cz/course/svn.html">Git &#8211; SVN Crash Course</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2008/08/28/using-git-and-subversion-in-5-easy-steps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to create a tar of files you have updated in SVN</title>
		<link>http://www.ronniealleva.org/index.php/2008/07/29/how-to-create-a-tar-of-files-you-have-updated-in-svn/</link>
		<comments>http://www.ronniealleva.org/index.php/2008/07/29/how-to-create-a-tar-of-files-you-have-updated-in-svn/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 23:35:32 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/index.php/2008/07/29/how-to-create-a-tar-of-files-you-have-updated-in-svn/</guid>
		<description><![CDATA[I had to recently send some modified files to someone so that they could take a look at what I was doing.  OH NOES!  How do I gather them all up at once?

tar cvzf somefile.tar.gz `svn stat &#124; awk '{print &#34;test -f &#34; $2 &#34; &#38;&#38; echo &#34; $2}' &#124; bash`

Word.
To break it down:
The svn [...]]]></description>
			<content:encoded><![CDATA[<p>I had to recently send some modified files to someone so that they could take a look at what I was doing.  OH NOES!  How do I gather them all up at once?</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> cvzf somefile.tar.gz <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print &quot;test -f &quot; $2 &quot; &amp;&amp; echo &quot; $2}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bash</span><span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p><strong>Word.</strong></p>
<p>To break it down:</p>
<p>The svn stat command is getting all the files that have changed obviously.</p>
<p>The awk command its piped to is the real part that&#8217;s doing the work.  The awk command prints</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-f</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #c20cb9; font-weight: bold;">file</span></pre></div></div>

<p>Pipe that through bash, and you have commands, which essentially will echo the file if the file is a file.  Simple?  No?  I mean, it will not print it out if it&#8217;s a directory, so you don&#8217;t have to worry about it adding entire directories.</p>
<p>Surround that whole thing in backquotes (that&#8217;s the one with the tilde (that&#8217;s the one next to the &#8216;1&#8242; key ( I&#8217;m not telling you where the &#8216;1&#8242; key is)))  and give it as the argument to the tar command.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2008/07/29/how-to-create-a-tar-of-files-you-have-updated-in-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the Groovy Maven plugin to do magic</title>
		<link>http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/</link>
		<comments>http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 18:53:47 +0000</pubDate>
		<dc:creator>Ronnie</dc:creator>
				<category><![CDATA[groovy]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/</guid>
		<description><![CDATA[Recently, we had an issue that came up with creating our EAR for our web applications.  We were trying to package up individual WARs in an EAR so they could share the same libraries and such and only load stuff used between them once, to save on memory.
We had it working great and then [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, we had an issue that came up with creating our EAR for our web applications.  We were trying to package up individual WARs in an EAR so they could share the same libraries and such and only load stuff used between them once, to save on memory.</p>
<p>We had it working great and then something ridiculous happened that caused WARs with their complete libraries (as opposed to stripped-down ones) to be included in the EAR, for no apparent reason.  This caused a number of headaches and issues with the application, that we didn&#8217;t know until it was deployed, because we failed to recognize that the EAR had nearly doubled in size.</p>
<p>You may be wondering, &#8220;Hey, I just read two of your dumb paragraphs and I haven&#8217;t seen the word &#8216;groovy&#8217;, &#8216;maven&#8217;, &#8216;magic&#8217;, or &#8216;using&#8217; yet.&#8221;  Well, wouldn&#8217;t it have been nice if we knew instantly that the EAR had grown, when trying to build?  That&#8217;s where the <strong>using </strong>the <strong>groovy maven magic </strong>plugin can help!</p>
<p>My co-worker <a href="http://jlorenzen.blogspot.com/">James </a>and I attempted to use the maven enforcer plugin, but it would have taken too much work and we would have needed to write a custom plugin for it to check the size of the EAR.  So we decided to do it with Groovy.  Here&#8217;s the code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo.groovy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>groovy-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0-beta-4-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>verify<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execute<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
          def ear = new File(&quot;$pom.basedir/target/${project.artifactId}-${project.version}.${project.packaging}&quot;)
          log.info(&quot;${ear?.length()}&quot;);
          def maxsize = project.properties['ear.maxsize'];
          if (ear?.length() &gt; maxsize?.toInteger()) {
            fail(&quot;EAR Exceeds maximum size allowed.&quot;);
          }
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This beginning part essentially defines the groovy plugin, and states run the code during the maven&#8217;s &#8220;verify&#8221; phase, so we know that the EAR is already created:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.mojo.groovy<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>groovy-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0-beta-4-SNAPSHOT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>verify<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>execute<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The groovy code is really straight forward.  First we get a reference to the file:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>13
14
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> ear <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">File</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$pom.basedir/target/${project.artifactId}-${project.version}.${project.packaging}&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
log.<span style="color: #006600;">info</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;${ear?.length()}&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>We&#8217;re using variables defined directly in the POM, so we know the name of the file.  We also print the length of the file out, for sanity&#8217;s sake.</p>
<p>Next we get the max size value:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> maxsize <span style="color: #66cc66;">=</span> project.<span style="color: #006600;">properties</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'ear.maxsize'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">;</span></pre></td></tr></table></div>

<p>This is defined later in the pom.xml file, under properties:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ear.maxsize<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>60000000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ear.maxsize<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>As you can see, it is set to near 60MBs.</p>
<p>Finally, and obviously, we check the two values against each other, and fail the build if the EAR is bigger than the size allowed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>16
17
18
</pre></td><td class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ear<span style="color: #66cc66;">?</span>.<span style="color: #006600;">length</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span> maxsize<span style="color: #66cc66;">?</span>.<span style="color: #006600;">toInteger</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  fail<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;EAR Exceeds maximum size allowed.&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The <code>fail()</code> call in groovy allows you to fail the build with a message attached to it.</p>
<p>So now, if anything fishy happens with the EAR, we&#8217;ll be able to know as soon as our CI environment attempts to build it.  This is a really simple example, but you could see how integrating groovy into maven could allow for some very powerful things to be done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ronniealleva.org/index.php/2008/01/23/using-the-groovy-maven-plugin-to-do-magic/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
