Maven ignore failed tests

Sometimes, it’s handy to be able to continue you’re maven build even when the tests have failed, for example to want to see some generated reports.

You get maven to ignore test failure by setting this property on the command line

mvn test -Dmaven.test.failure.ignore=true

Android Development Part 2

In the previous android post, we setup the android environment and the android emulator. This example will use maven to build a android application. Download the helloworld example.

Making sure you’ve your in the helloworld folder on the command line type:

– To deploy to an emulator

mvn android:emulator-start
mvn clean install android:deploy

– Or to deploy to a usb connected android device

mvn clean install android:deploy -Dandroid.device=usb

Using Sonar for your .Net project

Please note: Sonar .net plugins have been rewritten and version 1.0 has been released. Information on this blog relates to version 0.6 of the plugin. More information on the updated plugin can be found here

In my previous post, I covered how to install sonar, followed by how to setup a Java maven project to use sonar. You can also use sonar for your .net project – it’s not quite as straightforward as using it for Java, as you need to have various tools installed on the machine as prerequisites.

Firstly you need to install some plugins on the Sonar server. If your sonar server is running. You’ll need to stop it and then download the sonar .net plugins from the sonar .net plugin site and copy the jar files into you sonar extensions plugin folder.

The machine that will actually run the maven sonar analysis, will need to have a few prerequisites installed.

(1) Install Gallio onto your machine – With Gallio you can run different types of test frameworks, NUnit, MSTest, MBunit etc.. all under the one tool.

(2) Install FXCop 10, unfortunately this a little bit tricky, as only Visual Studio Premium comes shipped with FXCop 10, however, if you download and install the Windows SDK vers 7.1 (warning though, it’s a big download/install), you can install FXCop from the bin folder of the Windows SDK, follow instructions here

(3) Install PartCover 4 and install onto the machine (this allows you to get code coverage stats).

(4) Install source monitor onto your machine

The way sonar-net plugin works, is that it’s a maven plugin, so to build your Visual Studio solution, you actually have to use maven and create a pom.xml for your visual studio solution. So basically you will run maven and it will build your visual studio project for you and generate the sonar metrics for you.

Note if you are using 64 bit OS..

If you are using a 64 bit OS, currently you have to patch PartCover.exe and Gallio.Echo.exe to be 32 bits, otherwise you will not get any code coverage stats. You can patch the binaries using the tool CoreFlags.exe (this is provided in the windows sdk tool).

So open up a command prompt (but you have to open using “Run as Administrator” otherwise you’ll get a message unable to open file if you don’t).

path=C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;%PATH%
cd "C:\Program Files (x86)\PartCover\PartCover .NET 4.0"
corFlags.exe PartCover.exe /32BIT+ /Force

cd "C:\Program Files (x86)\Gallio\bin"
corFlags.exe Gallio.Echo.exe /32BIT+ /Force

32 bit OS users can ignore the above step.

Here is the DistanceConverter-Net project to use, (again like the Java version, nothing much in it but enough to do a sonar analsysis). Note, this sample project is using NUnit for the unit tests, you will need to have NUnit installed on the machine to run sonar analysis. Unzip that to a directory run the command

mvn clean install -Psonar-dotnet sonar:sonar

If you’re running for the first time, expect it to take a while for the all maven dependencies to be downloaded. If all goes well, your sonar dashboard should be updated

Using sonar in your Java Maven project

In my previous post, I went through how to get sonar up and running, now this guide is a quick how to running sonar for your java maven project.

So here is simple maven project DistanceConverter (hardly anything in this project, but enough to run sonar). If you look at the pom.xml file for this project, you will a sonar profile and some properties required for the sonar plugin. To run the sonar code metrics, you need to run

mvn clean install -Psonar sonar:sonar

The “-Psonar” activates the sonar profile and “sonar:sonar” executes the sonar goal in the sonar plugin. If your running this for the first time, expect a long wait as quite a few dependencies may need to be downloaded.

If all goes well, if you go back to the sonar webpage, you will see it’s been updated. You’ll see various metrics e.g. code coverage, the violations reported by checkstyle, pmd and findbugs.

Setting up Sonar

Sonar is great tool for static code analysis. This is a quick how to guide on setting up sonar..
Prerequisites, make sure you have Java SDK installed.

(1) Download sonar from sonar

(2) Unzip the the zip to a folder of your choice.

(3) In the how to for sonar, they advice you use mysql as the database – which is a good advice, but if you just want to use the derby database provided out of the box, the derby database is good enough.

Useful tip to save you some time, I want to setup my sonar server on different host to where the build system is. If you also want to do this, then you need to go to the conf folder,

Edit the file: sonar.properties

and uncomment the line

# uncomment to accept connections from remote hosts. Ba default it only accepts localhost connections.
sonar.derby.drda.host: 0.0.0.0

by uncommenting the above line you allow clients on other boxes to connect to the derby database.

Next startup sonar by going to bin\windows-x86-32 (or the appropriate folder for the OS you are using) and run “StartSonar.bat” ( if you plan to run sonar as a service, it’s worthwhile running the InstallNTService.bat so that Sonar appears in your windows service list). If it’s the first time you starting sonar, you have to be a little patient as it creates the database under the data folder in sonar. To see what’s happening, can tail the log file under logs directory.

You should lots of activity in the sonar.log file and hopefully when sonar is up and running, you will see see lines appearing in your log.


2011.06.11 17:51:11 INFO org.sonar.INFO Register quality models…
2011.06.11 17:51:11 INFO org.sonar.INFO Register quality models done: 2 ms
2011.06.11 17:51:11 INFO org.sonar.INFO Start services done: 18139 ms
2011.06.11 17:51:11 INFO org.sonar.INFO Loading web services…
2011.06.11 17:51:11 INFO org.sonar.INFO Loading web services…
2011.06.11 17:51:12 INFO org.sonar.INFO Sonar started: http://0.0.0.0:9000/

That’s a good sign! 🙂 You should now be able to browse to the sonar page on port 9000 and see something like the following..

Congratulations you have sonar up and running!

Obviously not very exciting, in the next post, I will go through how to to do static analysis of an existing maven project using sonar. Stay tuned!

How to debug Java Webstart application

Useful tip I came across for remote debugging java webstart application.

Run the following two lines from the command line (or from your bat file).

set JAVAWS_VM_ARGS="-Xdebug  -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=4145"
javaws http://URL/JNLP_DESCRIPTOR.jnlp

Browser Component in JavaFX Beta2

Played with the JavaFX2 Beta SDK and was impressed with what they done with it so far! I was eager to see what acid3 score the webview component would get and this my result..

That’s cool. (In swing we are just limited to html 3.2! )

The code for the above I took from this blog (shows how to embed javafx controls inside Swing)

http://a1o1.posterous.com/java-fx20-embedding-webview-in-swing

But made the following change… (guessing the API must have changed slightly for the beta sdk)

Sequence<Node> children = root.getChildren();
children.add(browser);

ObservableList<Node> children = root.getChildren();
children.add(browser);

I guess, now that we have this Webcomponent in JavaFX2, this RFE (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4296022)  will never the see the light of day! 🙂

 

Android Development Part 1

There a couple of android tutorials floating around using eclipse and or ant but I my preferred tools are Intellij and Maven. This how I got started on my android development..

Download the JDK and run the setup.

Download the Android SDK and install/unzip to a desired location.

Download IntelliJ version 10.5 and run the setup.

Download Maven zip File and unzip to a desired location.

Setup some environment variables on your machine.

Set JAVA_HOME environment variable to where the JDK is installed.

Set ANDROID_HOME environment variable to where you’ve installed android

Set MAVEN_HOME environment variable to where maven is located.

Update your existing PATH variable to include the following (%JAVA_HOME%\bin , %ANDROID_HOME% , %MAVEN_HOME%\bin  – NOTE: No bin directory for ANDROID_HOME )

Launch a CMD prompt and type android to check that it launches correctly (if not, double-check you’ve correctly setup ANDROID_HOME and updated your PATH variable correctly)

 

If all goes well, you should see the android avd and sdk manager being launched.

This tool is used to download the Android SDK platform for different versions and also to create virtual android devices with different capabilities, it allows you to test/deploy your code to the various virtual devices with different capabilities and get an idea how it will run.

Click on “Available Packages” on the left and then expand the “Android Repository” on the right and tick the SDK platforms you are interested in installing,  its also good idea to install a sample package aswell – this contains sample code to help you learn how to use the different Android API (the sample code folder will be located under  %ANDROID_HOME%/samples).

After you’ve installed the packages, you’ll want to create the virtual android device which is done by clicking on “Virtual Devices” on the left hand side and then click “New..” button.

Enter the name for your virtual device and from the Target select the API version (the target drop-down is populated by the SDK you’ve chosen to install in the previous step).

Well done! You now have the Android SDK installed and you’ve created a virtual device to test your code against.

In part 2 we have and example maven build for the hello world app.