Sonar's "result returns more than one elements"

We have been hitting the dreaded Sonar error lately, resulting in constantly broken Hudson builds:

Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements

The only workaround I could find was Pti’s database clean up. Doing this manually was a pain, especially after coming back from holidays, when a couple of weeks of records had been created.

So I have come up with a quick JRuby script to semi-automate this. And here is how to use it:

  • Save this script in clean_sonar.rb,
  • Update the Sonar database details with the correct values,
  • Download mysql connector jar, and save it in the same folder as your ruby script,
  • Backup your database,
  • Make sure your database backup is ok,
  • Check again (I guess you’re now warned),
  • Run the script as follows:
$ jruby clean_sonar.rb

And here is the (quick’n‘dirty) script.

Comment

 
---

UTF-8 Euro Symbol in LaTeX

XeLaTeX

XeLaTeX is the easiest approach, it works out of the box:

\documentclass[a4paper,10pt]{article}

\usepackage{xltxtra}
\usepackage[french]{polyglossia}

\begin{document}
Donne-moi 5\,€.
\end{document}

“Classic” LaTeX

LaTeX requires the use of textcomp to get the euro symbol:

\documentclass[a4paper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}

\begin{document}
Donne-moi 5\,€.
\end{document}

Comment

 
---

JMenuBar Support in Rubeus

I have added JMenuBar support to Rubeus. It is not released yet, but you can clone the git repo and play with it. The implementation is rather naive, but it works well for my needs.

Comment [1]

 
---

Packaging EAR file for JBoss 5.1 with Maven

The dependencies in a JBoss ear file go into the lib folder at the root of the archive;

      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.5</version>
        <configuration>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
          <modules>
            <ejbModule>
              <groupId>com.example.core</groupId>
              <artifactId>core-business</artifactId>
            </ejbModule>
            <webModule>
              <groupId>${project.parent.groupId}</groupId>
              <artifactId>example-web</artifactId>
              <uri>mydnb-web.war</uri>
            </webModule>
          </modules>
          <jboss>
            <version>5</version>
            <loader-repository>${project.parent.groupId}:archive=example-ear.ear</loader-repository>
          </jboss>
        </configuration>
      </plugin>

defaultLibBundleDir ensures that the dependencies get copied into the lib folder, whilst leaving the modules core-business and example-web.war at the root.

Comment

 
---

Look What Arrived Today?!

Yay!!

JRuby book cover

If only I had received it before my DnB JRuby presentation

Comment

 
---

Mrs Rabbit in Peppa Pig is a workaholic

And I’m glad I’m not the only one to worry about her numerous jobs: she sales ice cream, she is a librarian, she works at the fire station…

Comment

 
---

Monaco Font on Emacs

Add the following to your .emacs;

(set-face-attribute 'default nil :font "Monaco-9")

and then M-x eval-buffer.

Comment

 
---

Running Maven from Emacs

New job, and I’m back on Maven duties (hopefully I’ll have a better experience than the first time). This blog post explains how to run maven commands from Emacs.

Comment

 
---

Maven and JRuby on Rails

I am currently investigating using JRuby on Rails with Maven 3, and whilst I am still far away from getting a proper running application, I think it is worth summarizing what I have found so far.

JRuby Maven Plugins

An excellent starting point is the set of plugins called JRuby Maven plugins (not to be confused with jruby-maven-plugin to write JRuby mojos, rather than using Jelly). The information is a bit sparse and outdated, but after while tinkering with them, I found them pretty easy to use. To use them, you must first have a JRuby on Rails project:

sebastien@greystones:/tmp$ rvm list 

rvm rubies

=> ruby-1.9.2-head [ x86_64 ]
   jruby-1.5.6 [ amd64-java ]

sebastien@greystones:/tmp$ rvm jruby 
sebastien@greystones:/tmp$ ruby -v 
jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2010-12-03 9cf97c3) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [amd64-java]
sebastien@greystones:/tmp$ rails new myapp
      create  
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/controllers/application_controller.rb
. . .

Once the rails project is created, you can now use the jruby-maven-archetype:

sebastien@greystones:/tmp$ mvn archetype:generate -DrailsVersion=3.0.3

(Documentation says it is -Drails.version=3.0.3, but it is incorrect). The jruby-maven-archetype currently is number 21, so you can enter its number at the prompt, as well as its current version number (0.23.0), and then the groupId, the artifactId of your app (here myapp, like the rails app), the version, and the package name.

Once the application is set up, you should be able to run it with the following command:

sebastien@greystones:/tmp$ cd myapp
sebastien@greystones:/tmp$ mvn rails3:server

You should then be able to access your app at http://localhost:3000/.

bundle command

bundle is a great addition to rails 3; unfortunately, it is not available from maven commands provided by JRuby maven plugins yet. That’s why I wrote the following addition to these plugins, bundle-maven-plugin. It is still ongoing work, so it is still a bit rough, but it should do the trick for bundle install, update, package, exec and config commands.

Making a war

This is the next step in the process… and I haven’t had the chance to get to it yet. However, it looks like warbler is the tool for this task, so I’m guessing this will be another post.

Comment [1]

 
---

Installing RVM on Ubuntu

Excellent notes by Chris Irish to install RVM on Ubuntu.

One extra thing to mention (as this has caused me some issues) is that when using rvm, you should avoid installing jruby as the first ruby, as it looks like it tries to use it to compile the following ones — causing troubles to install 1.9.2-head. If you have installed jruby as the first ruby, you can delete it with rvm remove, then install MRI, or ree, and only then install jruby.

(It is very likely that this is caused by the fact my “system” ruby was actually a ruby I had compiled myself…)

Comment

 
---

Don’t bother programmers with this legal nonsense

So programmers don’t want to read a lot of legal questions?!

I have been looking into licensing problems lately, in particular regarding the GPL — I guess its copyleft approach is what makes it so confusing. There is a lot of information on the GNU website, enough to get you started. But what I can’t get my head around is how to go about forking a GPL project, especially with the advent of github-like websites where projects and their forks1 can now live happy lives on their own: do you have to rename the project (or is the name itself is covered by the GPL and you change it as you want, as long as you maintain the copyright/licensing notices — but then isn’t the name part of the licensing notice)? Do you add your copyright to the files you modified, or to all of them (heck, just renaming the project is enough to modify all files)? In a word, forking a GPL project is not a trivial thing to do.

As there are bucket loads of open-source projects out there, I thought that all these legal matters had already been tackled by other programmers (presumably chatting with their solicitors), and that asking these questions would quickly and easily find an answer. Nah. Don’t bother programmers with this legal nonsense. Let’s paddle with leaves down an ecstatic line of light, and bring Mono to Ubuntu, and see how big a bang that can do.

It is then interesting to have a look at what other projects have done… And clearly, programmers have no clue when it comes to licensing and copyright issues, and dos and don’ts, which is very worrying for the companies or the open-source project they work for. The first project I looked at, the forked project had altered all the copyright notices from the original files, and as far as I understand the whole thing, this is in breach of the GPL (I could be wrong, mind you, but I haven’t been able to get a proper answer yet).

So the standard answer is “talk to your solicitor.” But how many developers have done so, that we can’t bloody find answers to common legal issues? If they haven’t, how many projects out there are actually… not legit? What are the risks in turn for companies and OSS projects that use or derive work from these projects? I mean, what is to stop them from bringing some (GPL) third party library into the codebase, unbeknownst to the legal team, and then put the whole company into jeopardy? Easily done. Especially if said developers would rather put their head into the sand to avoid seeing this.

IMO, that is extremely worrying, and even more worrying that programmers actually think this is not their problem. And disasters like this don’t really surprise me anymore…

[1] Obviously, not all git forks are forks in the traditional sense, but some are. Some github projects are also “forks” from sourceforge projects. The good thing about the git “fork” approach is that it removes the stigmas associated with forking, which, for some reason, was regarded as a bad thing — and it probably was, given that the most notable ones arose mostly from bitterness.

Comment

 
---

Ruby turns you into McGyver

Having a scripting language in the toolbox is invaluable; and if the scripting language happens to be Ruby, you’re armed with the Swiss knife that’ll turn you into McGyver.

As a Java developer, you need to know more than Java to be able to work efficiently:

  • you need to know an editor like Emacs or Vi,
  • you need to know a fair bit of Linux/Unix commands, and of shell script,
  • you need to know a scripting language.

Why the scripting language? Because there are lots of stuff you need to do on a daily basis, and Java is far too big a tool to do them (understand, far too slow to code, far too slow to compile, far too slow to deploy, etc.):

  • build scripts,
  • deployment scripts,
  • generated scripts via regexp (like creating SQL delete from SQL insert),
  • scripts to modify a group of files,
  • scripts to check the state of the JVM,
  • etc., etc., etc.

Ant (or even more pathological, Maven) uses XML to alleviate some of these issues, but XML is just not “appropriate” for these tasks: the build scripts size explodes and are very hard to maintain, unless you resort to some macrodef trickery that are just symptomatic of the fact that you actually really need a proper scripting language…

The two recent examples I have is actually producing reports in a quick fashion. The first example is actually something I wrote, as I was asked to create a list of users of an application by querying the LDAP directory. On the very first day of work in my very first company, I worked with LDAP, and have been ever since, so doing an ldapsearch for this kind of query was easy stuff; formatting the report is always a bit more tricky, because you have to sed the hell out of the output, and let’s face it, I don’t speak sed very well. The Java/JNDI option is far far too heavy for a simple report (and it does make you look a bit stupid if it takes you like half a day to produce a report listing all your users…), so the scripting option is ideal.

Having never used the ruby-ldap extension, I was a bit worried that its installation would be hard, especially behind an overzealous proxy, but it went very smoothly on Cygwin — here are the command in the unpacked archive:

$ ruby extconf
$ make
$ make install

Once installed, the script itself was a pleasure:

require 'ldap'

ldap_host = 'ldap_server'
ldap_port = 389
ldap_base_dn = 'dc=myformercompany,dc=ie'
ldap_filter='(objectclass=appusers)'
ldap_attrs=nil

def print_entry(entry)
  puts "#{entry.vals('uid')},#{entry.vals('givenName')}, #{entry.vals('sn')}, #{entry.vals('mail')}"
end

puts "uid, first name, surname, email"
ldap_conn = LDAP::Conn.new(ldap_host, ldap_port)
ldap_conn.bind('cn=Directory Manager', 'xxxxx') {
  ldap_conn.search(ldap_base_dn, LDAP::LDAP_SCOPE_SUBTREE,
                   ldap_filter, ldap_attrs){ |entry| print_entry(entry) }
}

All put together in 5 min. The cool thing about this was that the people who were requesting this report asked for different versions with different attributes, and the turnaround was almost instantaneous!

The second example is a script I came across whilst browsing snipplr, which solves problems I have seen solved with XML/XSL in the past: extracting the substantifique moëlle of an XML report to produce a summary on a CI report. Using Nokogiri, it just becomes trivial to parse an XML document (here a JUnit XML log) to produce a report. Think of all the applications! Creating code coverage reports, creating dashboards, providing querying features to end users via DSLs (piece of cake with ruby)…

Ruby (and more specifically JRuby) has really become for me one of the most useful tools, and it has that extra-special feature that it makes me feel like McGyver whenever I come up with a solution to a problem within minutes in a very minimal amount of code. And Holy Richard Dean Anderson knows that if the following were to happen, life would be even happier:

  • Rakify all Java projects, and ditch Ant (Maven),
  • Create a Ruby implementation of Emacs, where you can write Ruby scripts rather than ELisp,
  • Write a Ruby version of eclipsemonkey (I know the project is actually parked, but I just cannot. understand. why, the JS version being already so absolutely essential) — Aptana may have that in their drawers, actually, I never really checked.

And there you go, I just cannot resist:

Comment

 
---

Play it like Tufte

During dexy’s presentation at last night’s Ruby Ireland meetup, that amazing package was mentioned: tufte-latex, a package to produce documents to the style of Edward R. Tufte and Richard Feynman.

And the result is pretty pleasing!

Comment

 
---

Install Emacs packages with ELPA

ELPA makes the installation of Emacs packages very easy! The description below is for Emacs 23, and I use Ctrl+ and Alt+ rather than the classic C- and M-.

Install ELPA

In a buffer, paste the following:

 (let ((buffer (url-retrieve-synchronously
	       "http://tromey.com/elpa/package-install.el")))
  (save-excursion
    (set-buffer buffer)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (eval-region (point) (point-max))
    (kill-buffer (current-buffer))))

and evaluate with Ctrl+J. This automatically downloads ELPA and installs it.

Run ELPA

Type Alt+X package-list-packages, this opens a buffer with a list of packages that can be installed. Here are the commands:

  • n: go to next line,
  • i: select package for installation,
  • u: de-select package,
  • r: refresh package list,
  • x: actually install all the marked packages,
  • h: help,
  • q: close ELPA.

Example

To install ruby-mode, do Ctrl+S ruby-mode and press Enter. Select package for installation with i , and do the installation with x.

Comment [2]

 
---

Friday Night 80s on Today FM

What were we listening to on the radio in the 80s when there wasn’t the 80s?

Comment

 
---

← Older Newer →