Archive

Archive for the ‘tech’ Category

Running cucumber on JRuby+Maven

October 29, 2008 8 comments

Cucumber is an interesting offshoot of the popular BDD tool Rspec developed by Aslak Hellesoy. Cucumber executes plain-text feature specifications against code implementing those features and verifies it. Take a look at the cucumber examples to understand what this means in practice.

This post explains how you can configure it to write specifications for a Java project using Maven and JRuby.

1. Add JRuby as a dependency in your POM:

<project>
    ...
   <dependencies>
       <dependency>
           <groupId>org.jruby</groupId>
           <artifactId>jruby-complete</artifactId>
           <version>1.1.4</version>
       </dependency>
   </dependencies>
   ...
</project>

2. Configure the exec-maven-plugin to run cucumber during integration-test phase.

<project>
...
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
            <execution>
                <id>run-cucumber</id>
                <phase>integration-test</phase>
                <goals>
                    <goal>java</goal>
                </goals>
                <configuration>
                    <mainClass>org.jruby.Main</mainClass>
                    <arguments>
                        <argument>-S</argument>
                        <argument>rake</argument>
                        <argument>features</argument>
                    </arguments>
                </configuration>
            </execution>
        </executions>
    </plugin>
...
</project>

3. Configure a profile to install cucumber if it is not already locally available:

<project>
...
    <profiles>
        <profile>
            <id>first.time</id>
            <activation>
                <file>
                    <missing>${user.home}/.jruby/lib/ruby/gems/1.8/gems/cucumber-0.1.8</missing>
                </file>
            </activation>
            
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.1</version>
                        <executions>
                            <execution>
                                <id>install-diff-lcs-gem</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>org.jruby.Main</mainClass>
                                    <arguments>
                                        <argument>-S</argument>
                                        <argument>gem</argument>
                                        <argument>install</argument>
                                        <argument>diff-lcs</argument>
                                        <argument>--no-ri</argument>
                                        <argument>--no-rdoc</argument>
                                        <argument>--no-test</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-hoe-gem</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>org.jruby.Main</mainClass>
                                    <arguments>
                                        <argument>-S</argument>
                                        <argument>gem</argument>
                                        <argument>install</argument>
                                        <argument>hoe</argument>
                                        <argument>--no-ri</argument>
                                        <argument>--no-rdoc</argument>
                                        <argument>--no-test</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>install-cucumber-gem</id>
                                <phase>initialize</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>org.jruby.Main</mainClass>
                                    <arguments>
                                        <argument>-S</argument>
                                        <argument>gem</argument>
                                        <argument>install</argument>
                                        <argument>cucumber</argument>
                                        <argument>--no-ri</argument>
                                        <argument>--no-rdoc</argument>
                                        <argument>--no-test</argument>
                                    </arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
...
</project>

4. Create a file named Rakefile as a sibling of your pom.xml, with the following contents:

require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
  t.cucumber_opts = "--format pretty"
end

5. Running

mvn integration-test

should run cucumber now on your project. Cucumber looks for feature specifications to run in the features directory.

Please see this maven project for a test project configured with cucumber.

Categories: jruby, maven, ruby, tech

The Haskell School Of Expression: Getting Started on Ubuntu

May 26, 2008 8 comments

PC sent me a copy of Hudak’s The Haskell School of Expression for my birthday. I was trying to get started with some of the code in the book and could not find a good writeup on it. Here is how I got it going on my Ubuntu Gutsy laptop.

First, install GHC and HGL as:

sudo apt-get install ghc6
sudo apt-get install libghc6-hgl-dev

Then, copy the following code to a file simple.hs somewhere on the disk. This code is from Chapter 3 of the book.

import Graphics.SOE
main0
   = runGraphics $
     do w <- openWindow "My First Graphics Program" (300, 300)
        drawInWindow w (text (100, 200) "HelloGraphicsWorld")
        k <- getKey w
        closeWindow w

Launch GHC interpreter and load the code into it.

$ ghci
   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 6.6.1, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type : ? for help.

Loading package base ... linking ... done.
Prelude> :l /path/to/simple.hs
[1 of 1] Compiling Main             ( /path/to/simple.hs, interpreted )
Ok, modules loaded: Main.

Now, run the application as:

*Main> main0
Loading package X11-1.2.1 ... linking ... done.
Loading package HGL-3.1.1 ... linking ... done.
*Main>

If everything is set up properly, this should show a GUI window with the text ‘HelloGraphicsWorld’ written on it. Pressing any key should dismiss this window.

Categories: tech

Forcing NetBeans to use Metal LAF on Ubuntu

April 30, 2008 3 comments

I just installed NetBeans 6.1 on my Ubuntu Gutsy running Sun’s Java 6. The default L&F used is GTK. I personally prefer Metal with Ocean theme. Here is how you get those:

  1. Edit NETBEANS_HOME/etc/netbeans.conf
  2. Add --laf javax.swing.plaf.metal.MetalLookAndFeel -J-Dswing.aatext=true -J-Dswing.metalTheme=ocean to netbeans_default_options variable

Thats it!

Categories: software, tech

Want a good Lisp tutorial?

September 21, 2007 Leave a comment

Here is a great Lisp tutorial.

I first heard of Lisp in my programming languages class, but never paid much attention to it. Well, you could still pass that exam if you never learned a thing about Lisp (or any of the programming languages “taught” there), so I never bothered. Later when I started reading blogs and technical articles, I started hearing more about Lisp.

My first attempt at learning Lisp was from David S. Touretzky’s online book Common Lisp: A Gentle Introduction to Symbolic Computation. The book did not interest me and I never completed it. Later that year, I spotted Stephen Slade’s Object-Oriented Common LISP at Gangaram’s and bought it. That book went way above my head and I still did not get Lisp.

It was in late 2004 that I heard of Peter Seibel’s Practical Common Lisp. Peter was in the process of writing the books and he had put the content on the web. I started reading the online copy of the book but without much hope. I was pleasantly surprised! The book was actually a very good read and all those parenthesis started to make sense finally. Later when I ran into difficulties with a few examples in the book, I wrote to Peter. He was kind enough to reply and make minor fixes to the code in the book.

I still haven’t programmed much in Lisp besides a few toy programs. But I understand why people rave so much about Lisp – and I am grateful to Peter Seibel for opening my eyes. So when he made this request, I thought I owed it to him.

PS: Someone, I can’t remember who, borrowed the Slade book from me in 2004 and never returned it. If anyone reading this have it, please drop me a note. 🙂

Categories: books, tech

Formatting source in blogs hosted on WordPress

September 6, 2007 8 comments

I sometimes post snippets of code on this blog. I have been searching for a way to provide proper syntax highlighting for the code I post here. There are many wordpress plugins which provide proper syntax highlighting, but since I use the hosted WordPress service, I cannot use any of those. GNU Sourcehighlight is the standard program people use of generating source highlighting, but for some strange reason I could not get that to compile on my iBook.

While looking for alternatives on the web, I noticed a package called Highlight. Highlight can generate syntax highlighted HTML files from program source files. It supports over 120 programming languages! I tried it few months ago, but soon ran into a limitation. Highlight output uses CSS classes and style definitions; to make it convenient to post code here, I needed a package that generated inline CSS styles.

I wrote to André Simon, the author of Highlight, requesting this feature. Today I got an email from André informing me that the new 2.6.3 release of Highlight has an option to generate inline css! I tried it out and it works well.

$  highlight -i HelloWorld.java -o HelloWorld.html --inline-css

And here is the snippet Highlight generated for me:

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("Hello, World");
    }
}

Thanks and congratulations to André Simon!

Categories: blog, tech, wordpress

Yet Another Certification

July 4, 2007 Leave a comment

This time from Raganwald. Of course, we might soon see training centers in Hyderabad. 🙂

Categories: links, software, tech

StandoutJobs.com

June 11, 2007 Leave a comment

StandoutJobs.com posts their recruitment advertisement …. on youtube!

Neat! 🙂

Categories: software, tech

Installing Mozart on Mac OS X PPC

June 9, 2007 2 comments

I was trying to install the Mozart Programming System on Mac OS X. The installation instructions on the Mozart website was very cryptic. Googling did not turn up good pointers initially, but I eventually managed to find the information. Here are the steps I followed to get Mozart installed on my Mac OS X (PPC) 10.4.9:

  1. Download Mozart PPC package, uncompress it and run the .pkg installer. By default this installs to the /usr/local/oz directory
  2. Download Aquamacs, mount the .dmg image and copy the binary into the Applications folder
  3. Install GMP. Download the source from GMP website, uncompress it onto the disk, cd into the directory and run the following commands:
    
    gmp-4.2.1$ ./configure --enable-cxx --enable-shared
    gmp-4.2.1$ make
    gmp-4.2.1$ make check
    gmp-4.2.1$ sudo make install
    
  4. Create a file named .emacs in your home directory (if it is not there already)
  5. Add the following lines to .emacs file:
    
    (add-to-list 'load-path "/usr/local/oz/share/elisp")
    (require 'oz)
    
  6. Add the following lines to the .bash_profile file in your home directory:
    
    export PATH=/usr/local/oz/bin:$PATH
    export OZEMACS="/Applications/Aquamacs Emacs.app/Contents/MacOS/Aquamacs Emacs"
    
  7. Open a new command window and start Oz Programming Interface by running the command oz

The above assumes that you have installed Oz at /usr/local/oz and Aquamacs at /Applications directories.

Categories: tech

London 2012 Olympics Logo

June 4, 2007 2 comments

The logo for Olympics 2012 was announced earlier today and was soundly trashed.

London 2012 Olympics Logo

Sebastian Coe introduced the logo with the following blurb:

 “This is the vision at the very heart of our brand,” said London 2012 organising committee chairman Seb Coe.

“It will define the venues we build and the Games we hold and act as a reminder of our promise to use the Olympic spirit to inspire everyone and reach out to young people around the world.

“It is an invitation to take part and be involved.

Sorry Seb; despite all that trash-talk it still looks like a jagged picture. If you think you can do better, BBC invites submissions.

Categories: tech

JAX India 2007 – Day 4 Report

May 31, 2007 2 comments

After yesterday, most of my friend’s dropped out of the conference today. Me and Kannan went to catch the post-lunch session.

We reached the auditorium in time to catch the last 10 minutes of the session Introduction to GMF by Raj Madhuram. From whatever little I saw it was a sensible no-nonsense introduction to GMF. I worked on GMF about a year ago, and one of the big pain points then was to export a GMF-generated editor as a standalone RCP application. From Raj’s talk it looks like that problem is solved now. GMF is a very interesting technology; it enables rapid development of high quality graphical editors for a model. I should take another look at GMF sometime soon.

The next session we attended was Groovy and Grails Tutorial by Harshad Oak. Many things went wrong with this session. Firstly, the talk was all over the place; Harshad tried to introduce too many topics spreading it real thin. Closures, builders, dynamic typing, string interpolation, literal syntax for lists and maps and higher-order functions in the space of 10 minutes confused the audience. It did not occur to me then, but many people seem to have had trouble understanding the notion of the Java platform – and Harshad, unfortunately, skipped over this key concept. Secondly, Harshad took question during the session. When a bunch of Java programmers are introduced to a modern language like Groovy for the first time, people would have gazillion questions popping up in the mind – encouraging them to voice them loudly is simply asking for trouble. 🙂 Thirdly, Harshad himself was very disorganized in his talk – and one of his demos went wrong during the session. Harshad might do well to watch seasoned speakers like Neal Ford and get his sessions a bit more organized. Overall, I got to see how Grails development looks like – I should be checking it out some time soon. (This is a recurring theme, isnt it? 🙂 My backlog is quite full!)

During tea-time I got to speak to Harshad. I really appreciate his writing. It was nice to meet him finally in person. I also got to meet couple of gentlemen who were talking to Harshad and Sangeetha. One of them was working with Sun; I have no idea about the other person. Here is an interesting tidbit of conversation I overheard between these two:

Sun guy: In Java 6 the class verification phase is significantly improved. They are using split bytecode verification, which was first tried in J2ME. This should improve the startup times significantly.

Other guy (with a funny accent): Oh like using an MD5 hash blah blah blah blah

Sun guy: Like what?

Other guy (with a funny accent): You know, information verification? Verifying that some information is not tampered with. blah blah blah

The rest of the audience (me, Harshad and Sangeetha) had to politely suppress the giggles. From the conversation it looked like this guy is in charge of making technical decisions; it was amusing that he had not even heard of byte code verification. The Sun guy was repeatedly trying to say how cool Sun was, which was really annoying. I eventually tried to be equally annoying by asking “Now that Sun has lost the IDE race to Eclipse, what is the feeling within Sun? Do you guys think you can still make it with NetBeans?” – it was fun to watch him stare back at me with his mouth agape 🙂

After tea we went to the SOA Industry Panel. We were looking forward to some honest discussion on SOA, but when an HP guy came up to pimp his product we realized that it was going to be a vendor-pitch-fest. We left the conference by then.

So, that was my day.

Categories: conference, tech