Posts tagged Java

it’s a crazy world

Yes, I can said that after that two weeks – I’ve been finishing my largest project – building my own home! 😀 I spend that time moving out from my tiny flat (43 square meters) and moving in to my brand new home. I never supposed how many things I have – lost of them useless 😉 And I had to move them all and sorted later – not the best solution, but the fastest 😀

Ok, that’s one part – the second was that Warszawa JUG has it’s own server – running with Java, Jetty, Apache 2 web server, Hudson, Git and Mercurial! Lot’s of stuff! And it was awesome to install and configure them all – everything on Ubuntu server Linux! I like that 😀 So if you have some questions regarding that I will be please to answer them. Especially regarding setting up Git repository with secure access – it was the painful experience! Maybe I should write some article about that on Knowledge Base site?

Right now we’re moving javarsovia.pl web site to it – as we were starting preparation for out annual conference – Javarsovia 2010! We have some plans to write dedicated software to runs that site but that just plans 😉

And at the end – the work! Nothing special – we’re going to production (again) with our long-term project, preparing some new functionality to implements it next year and preparing ourself for Christmas!

two days at once

I hadn’t have any particular tasks for last two days. Some minor updates to print layout – that’s it! So I had time to work with Apache Struts2 project and with Xwork project. Also I prepared another presentation from Javarsovia 2009 conference and uploaded it on beta.parleys.com.watch film Lady Macbeth now

Today we had Code Review – it was a bit to long, over three hours! Code Reviews are great if they are organized more often, but hopefully we will have another Code Review soon 😉

community day

I spent the whole day working with Apache Struts 2 Maven archetypes – it’s an open source project hosted at struts.apache.org – basically Action Base Java Web framework.

During that I discovered strange Maven behaviour – when I lunched it with -o option (work in offline mode) it wasn’t be able to find installed archetypes. To clarify – I prepared a script that will build up the archetype from source code, install it in my local Maven repository, then create basic application base on that archetype and lunch them, the source is below:

#!/bin/sh
if [ -e demo ] ; then
    rm -R demo
fi
cd $1
mvn clean install
cd ..
mvn -o archetype:generate -DgroupId=org.demo
    -DartifactId=demo -Dversion=1.0-SNAPSHOT
    -DpackageName=org.demo
    -DarchetypeArtifactId=$1
    -DarchetypeGroupId=org.apache.struts -DarchetypeVersion=2.1.8
    -DinteractiveMode=false
cd demo
mvn jetty:run
cd ..

$1 – it’s a command line parameter specifying archetype folder which is also archetype name

So it shouldn’t be needed to access remote archetype repository to download archetype – it’s already in local repository! I tried that with different Maven versions – the latest 2.2.1 and with 2.0.10 – with both was the same.

After some time and many experiments I found the solution – do not use -o option used -B instead! And that I was able to test one archetype – another 3 are waiting!

divide by int

I made very stupid mistake – I had to prepare some simple calculation to show some figures on print out. It was something like this:

figure = round( (index / 4) + 0.4 )

As you see quit easy and simple to implement – business rule from Excel sheet 😉 I thought the same – 10 minutes and I finished, without unit test and some deep testing – I couldn’t make mistake, it’s so easy! You probably know what happened next! A Bug!

It was matter of time when I’ve got bug report from tester – the figure is wrong – it wasn’t following the guidance! Impossible – that what I first thought! I started making some tests and the figure was calculated wrongly for some index values. It was like a magic! Magic in coding? Impossible again! So, I write a unit test to just test that one method. I’ve started playing with different values and I very quickly discovered that for index below 4 the figure is 0!

It was a blast! I was dividing by int! In Java! That was the origin of my problems! As you may know when dividing by int the result is automatically cast to int. All I had to do, it was turn the routine into:

figure = round( (index / 4.0) + 0.4 )

and finish the unit test for a all possible values. What I did and it took me about 20 minutes – I should do that at first time!

tests on roids

Finally I was able to speed-up tests in our project. I had to made some dirty trick with XmlBeans. XmlBeans are not so efficient as other Xml marshalling libraries, but our whole technology stack is using them, so there’s no option 🙂

Anyway, I solved that but “borrowing” SchemaTypeSystem implementation from other project. The whole trick is to remove eager static initialization! That’s the problem, XmlBeans doing lot of static initialization when some class from hierarchy is going to be loaded. Maybe it’s a good idea in server environment, but it’s killing unit tests.

Right now the whole test task run takes around 9 minutes and previously it was 30 minutes! So I can say it was a very efficient day!

And at the end – I discovered two nice demos about how IntelliJ IDEA (my lovely ide) supports Java, Groovy and Scala development, they are fantastic! You have to take a look:

Go to Top