Grails Weirdness 2

Posted by Warner Onstine on December 18, 2006

So, I was more than a little disappointed to discover that the Grails developers are using Ant for most of the command-line stuff (partly because I was hoping to learn some cool tricks for starting up HSQLDB and Jetty for Chama). It just seems a little weird to me to rely on Ant tasks to do something that in my mind should be handled as part of the class (or Groovy file in this case).

Here are some examples of what I’m talking about:

    <target name="run-app:impl">
        <basename property="project.dir" file="."/>

        <groovy>
            import org.mortbay.jetty.*
            import org.mortbay.http.*

            System.setProperty('org.mortbay.xml.XmlParser.NotValidating', 'true')
            def server = new Server()
            project.addReference('server', server)
            try {
                def listener = new SocketListener()
                listener.setPort(properties.'server.port'.toInteger())
                server.addListener(listener)
                server.addWebApplication("/" + properties."project.dir", 'tmp/war')
                server.start()
            } catch(Throwable t) {
                t.printStackTrace()
            }
        </groovy>
    </target>

I can understand, to a certain degree, why one would do something like this, but this seems like a bit overkill. I have a real problem with adding scripting into Ant files, it just seems like you are really pushing Ant to do something that it was never meant to do, but that’s just my opinion.

Also, to be fair, the Grails developers seem to have realized this and are now moving towards a true command line interface with the GrailsScriptRunner.groovy. Again though they are tying themselves to Ant unnecessarily. My personal preference is to create a true standalone command line interface (which is what I’m doing with Chama).

These are, of course, my opinions but I thought that others not familiar with Grails might be interested. And also note that I loathe Ant ;-) , I’m a true Maven convert.

Share and Enjoy:
  • Print
  • Digg
  • Reddit
  • del.icio.us
  • Twitter
  • Facebook
  • Google Bookmarks
  • DZone

Krugle rocks 1

Posted by Warner Onstine on December 18, 2006

Ok, if you haven’t heard of Krugle yet and you do any kind of programming you should read this.

No, I don’t work for them (although they seem like a cool company for sure), but I have been using their service for a little while and have been very impressed. So what is Krugle anyways? Krugle is an online index of Open Source Software source code that is searchable.

How is this different from just plain google? First, it has indexed the source by language and by project so if you know what language you are searching for that eliminates a lot right off the bat, plus if you know the project (or projects) you expect to find your source in then that narrows it down quite a bit more. Plus you can also choose whether you want to search just class files or other files within a given project (very handy for html templates and the like).

Alright, but how is this different from Google’s Code Search? Google’s Code Search also allows you to search via language type, but not really project. Additionally Krugle’s search interface is more geared towards exploration, with all of the class files listed cleanly and once you drill down you haven’t lost your search results and can easily build up a shopping cart of classes you are investigating. Another cool thing they did is to actually show you the tree of the project that you are in once you are viewing the class file so you can navigate around the rest of the project easily.

About the only thing I would like to see them add would be a source cross-reference so that I could easily navigate to other classes defined within a class-file. But I could see how that type of thing would get tricky very quickly with all of the different languages they are supporting.

So far I’ve had Krugle save me 3 or 4 times and Google’s Code Search only once, so I’ll definitely head back to Krugle first (now if I could only remember the name ;-) .

Share and Enjoy:
  • Print
  • Digg
  • Reddit
  • del.icio.us
  • Twitter
  • Facebook
  • Google Bookmarks
  • DZone

Yaml with JYaml

Posted by Warner Onstine on December 18, 2006

So, I decided to use Yaml for all of my configuration needs, in order to use this I needed a library to interface with it, I found JYaml which seems to fit the bill nicely. Here’s a short example of what I’ve used it for in Chama.

--- !org.chama.db.DBConfiguration
dev: !org.chama.db.DBConnection
  dbName: chama_dev
  driver: org.hsqldb.jdbcDriver
  url: "jdbc:hsqldb:mem:"
  username: sa
production: !org.chama.db.DBConnection
  dbName: chama_production
  driver: org.hsqldb.jdbcDriver
  url: "jdbc:hsqldb:mem:"
  username: sa
test: !org.chama.db.DBConnection
  dbName: chama_test
  driver: org.hsqldb.jdbcDriver
  url: "jdbc:hsqldb:mem:"
  username: sa

DBConfigurationTest.groovy
class DBConfigurationTest extends GroovyTestCase {

    void testReadConfigFile() {
        DBConfiguration config = Yaml.load(new File("src/test/conf/db.yml"))
            assert config.test.dbName == "chama_test"
            assert config.dev.dbName == "chama_dev"
            assert config.production.dbName = "chama_production"
    }

}

I also found another package when I was having some difficulty with JYaml called JvYaml, but when I tried to save my configuration class it gave me a nested object exception telling me that I couldn’t save nested objects into my Yaml file. That seemed kinda stupid to me so perhaps I was doing something wrong, but I didn’t have time to try and figure out what it was and went back to JYaml.

Share and Enjoy:
  • Print
  • Digg
  • Reddit
  • del.icio.us
  • Twitter
  • Facebook
  • Google Bookmarks
  • DZone

Easy AdSense by Unreal