Wednesday, February 24, 2010

buildr overview

Tonight I spent a couple of hours at Jayway listening to Anders Janmyr talking about buildr - the build system that doesn't suck. buildr is a build system for Java and a whole bunch of other languages. It is written in Ruby and installs as a gem. Build scripts are also Ruby with everything that comes with it. It is built with the good things of maven as role model and with the less fortunate aspects of maven as frightening example. Dependencies are downloaded from maven repos and local builds can be installed to a local maven repo. To try it out I cd'd into a directory with a maven pom.xml and ran buildr. It gave me the choice of creating a build file from the maven pom or from the directory structure. When choosing maven pom the generated build file was about half the size of the pom. Now this was used on a very simple pom and according to Anders it may not work at all with more complex maven projects. buildr can do all the typical tasks of a build system and if something extraordinary is needed it is easy to script it with ruby.

Some advantages of buildr: (1) it is Ruby which enables "real" programming in build files, (2) it is Ruby which makes it possible to write build files that looks really nice (3) it is not XML - anyone tired of scripting in XML? (4) it includes the good parts of maven. Some disadvantages: (1) it is Ruby which may result in Perlish code if not careful, (2) it is not Java and XML (thank God) which may make it hard to introduce in larger organisations with static developers. If I was to pick a build system for my own use I would choose buildr but then I perhaps wouldn't choose Java as and the need wouldn't be there.... For larger organisations with competence problems it may be hard to introduce buildr over maven or ant. The threshold into ruby may be a little bit too high for the average java developer.

Anders also went through cucumber - a really nice testing tool that non-dev people can understand - and rake - Ruby make. "rake -T" will be remembered - it will come in handy when forgetting the howtos when coding rails in spare hours.

UPDATE: Peter Lind pointed in two more alternatives to buildr. If you use JRuby you can use Ant and Rake interchangeable as described in this post. Advantages with this approach is that you rely entirely on stable technologies. buildr is a bit new and may not work for all cases yet. And then - of course - there is polyglot maven that promises to: "to leverage the power of Maven through modern JVM language implementations like Groovy, Scala, Clojure and JRuby". Seems like everyone is heading in each others directions.....

PS. Jayway is hiring junior Java developers with 2-5 years of experience. Someone in the audience translated this to "cheap"....

Tuesday, February 23, 2010

Buquebus vs Seacat

If you are in Buenos Aires and you are planning a trip Colonia or Montevideo everyone will tell you that the best way to get there is with Buquebus. Even Lonley Planet would only lists the web address of Buquebus. We used Buquebus back in December for a short trip to Colonia and these guys charged a killing. It seems they can, because they dominated the market. Some people even go so far as to imply Columbian mafia connections ;-)
But there are alternatives and one of them is called Seacat. Ups, now I spilled the beans! We used them just a couple of weekends ago to get to Montevideo and it only cost us a fraction of what the shorter trip to Colonia has cost us earlier. The best part of it all is that Seacat leaves from the same new fancy terminal building in Puerto Madero which all people believe is exclusively used by Buquebus. In fact our taxi driver who brought us there kept telling us during the whole way that he did not think that there are any other boats leaving from there.

Montevideo itself was great for a weekend, but wouldn't have liked to stay much longer. People say that going to Montevideo is like time travel and you see Buenos Aires in the 1940ties, which is partly true. Unfortunately, there are other sides to it gave my experience of Montevideo a negative touch. A certain decay was noticeable in many neighborhoods and it felt that the broken window syndrome was at play, only that people have given up fixing them :(

Nevertheless, there are a few great spots you should visit in case you get the chance.
  • The Mausoleo de Artigas



  • Teatro Solis - make sure to get a tour and enjoy a coffee in the new refurbished cafe. Probably one of the best places in Montevideo to do so


  • Mercado del Puerto - absolute highlight of the trip. I could have spent hours sitting in this market, eat good food and watch people. I in particular can recommend El Palenque were you can sit at the bar and watch the cooks do their business. I had the most delicious chorizo pan there!
Another thing we discovered was real Spanish style Churros. You find churros a lot in Buenos Aires as well, but there they tend to be of the thick and soggy kind. This guy at a local Carneval celebration made them super thin and crispy. Yummi! Believe me - no point to eat them any other way :)


--Hardy



    Tuesday, February 09, 2010

    A MySQL odyssey

    I just started a little side project using Ruby on Rails and decided today to start developing against the database I will be using in production - MySQL. So far I have been using SQLite which worked fine, but it is always good to stay as close as possible to the target environment as possible. Anyways, let my odyssey begin...
    In theory I just have to edit config/database.yml and change the adapter parameter to mysql. Then restart the rails server script/server -e development. Done!
    Well, not so fast. The first restart tells me that mysql is not part of the default rails application anymore. The error message is quite clear and basically recommend to just run gem install mysql. Fair enough, I run the gem install and restart the server. Now I get:
    > script/server -e development

    => Rails 2.3.4 application starting on http://0.0.0.0:3000
    /Users/hardy/.gem/ruby/1.8/gems/radiant-0.8.1/vendor/rails/activesupport/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant MysqlCompat::MysqlRes (NameError)
    Ok, not so funny anymore and quite cryptic. Uninitialized constant that cannot be good.
    A word to my environment. I run Max OS X (Snow Lepard) on a Mac Book Pro. MySQL is installed via MacPorts and can be found somewhere under /opt/local. The MySQL version is 5.1.40.
    What does one do in such a situation? I start googling and end up in some cryptic mail archives. Bugger, worst case scenario. Digging through mail archives is a real pita. Information is often unverified and skimming through through a million >>>>>>>>>> is just no fun. After some searching I suspect that the problem I am experiencing is that the mysql gem needs to be build for 64 bit. I decide to try:
    sudo env ARCHFLAGS="-arch x86_64" gem install mysql –with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
    After that I start the server again. This time I get:
    /Users/hardy/.gem/ruby/1.8/gems/radiant-0.8.1/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:585:in `real_connect': Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2) (Mysql::Error)
    Argh, another error. At least it is something more familiar. MySQL lets you either connect via TCP/IP or via Unix sockets. But why does it try to via /opt/local/var/run/mysql5/mysqld.sock. I am pretty sure I am using a different socket file. I locate my MySQL config file and find that the socket file is /tmp/mysql.sock. Why did that not get picked up? I add:
    socket: /tmp/mysql.sock
    to my config/database.yml. One restart later and I get:
    /Users/hardy/.gem/ruby/1.8/gems/radiant-0.8.1/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:585:in `real_connect': Access denied for user 'foobar'@'localhost' (using password: YES) (Mysql::Error)
    Will this never end? At least it's another classic. MySQL permissions. First step is always the mysql.user table. I probably forgot to add an entry for my user and database. I connect as root and execute:
    CREATE USER 'johndoe'@'localhost' IDENTIFIED BY 'foobar';
    GRANT ALL PRIVILEGES ON mydb.* TO 'johndoe'@'localhost' WITH GRANT OPTION;
    After that I try to start the ruby server again. Same problem. Some quick swearing, but then I remember - flush! Back to the mysql shell:
    FLUSH PRIVILEGES;
    And now I get an error in the mysql shell:
    Table 'mysql.servers' doesn't exist
    WTF! After some more swearing (this time in German) I start googling again. I cannot find a reasonable explanation on why this table is needed or why it is not created in my mysql database. Best I find is a table creation script which I decide to run:
    CREATE TABLE `servers` (
    `Server_name` char(64) NOT NULL,
    `Host` char(64) NOT NULL,
    `Db` char(64) NOT NULL,
    `Username` char(64) NOT NULL,
    `Password` char(64) NOT NULL,
    `Port` int(4) DEFAULT NULL,
    `Socket` char(64) DEFAULT NULL,
    `Wrapper` char(64) NOT NULL,
    `Owner` char(64) NOT NULL,
    PRIMARY KEY (`Server_name`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';
    Ahh, now flushing privileges works. One more script/server -e development - success! Finally I am up and running again, but I wonder:"Do things really have to be so painful?"

    --Hardy

    P.S.: With MySQL permission/user problems I recommend to go through these guides: access- denied and adding-users.

    P.S.S: Another problem which had me puzzled for a while one was that I was not able connect to MySQL using:
    mysql5 -u foobar -p
    Whenever I tried to connect with a password I would get the Access denied for user (using password: YES) error. Connecting without the -p option worked though. I kept looking at the mysql.user table and the entry for foobar. What I did not notice was that I had effectively something like this:
    Host       User      Password       
    localhost
    % foobar
    The first line allows any user to connect from localhost using no password. Since localhost is more specific then the % wildcard this rule was always applied before the actual foobar entry.