Wednesday, April 15, 2009

Moving into the cloud, loosing your freedom?

clouds.jpg I am a fan of the recent cloud computing hype. I have my own attempts to merge into the cloud.

I am also a fan of opensource software, of which the FSF and GPL are important proponents.

Google, Facebook, Twitter and friends, with all their free cloud applications lured me into thinking that the cloud and opensource are best frinds.


But recently two articles opened my eyes:
  • The JavaScript Trap by Richard Stallman (founder of GNU and FSF):
  • Silently loading and running non-free programs is one among several issues raised by "web applications".
  • GPL's cloudy future by Jeremy Allison (lead Samba developer):
    In such a world, service providers can use GPL-licensed code in proprietary back-end server farms with impunity. This seems contrary to the spirit of the authors of much of the GPL-licensed code used in this way, although it strictly complies with the license.
  • inside-of-a-prison-cell.jpg
    Well, this does not yet stop me from using cloud applications, but I think it is important to realize that there are not just Alphas in this brave new cloudy world...

    Monday, April 13, 2009

    Google App Engine: Guestbook with Groovy Groovlets

    google-app-engine-groovy.png The web is soaring, since Google announced Java support on Google App Engine!

    People are getting ahead of themselves to try out their favorite piece of the Java ecosystem on the Google platform.

    I figured that I also wanted to experience this pre-alpha-geek feeling :-)

    I followed the guidelines to run Groovy appliccations on Google App Engine from glaforge and reimplemented the guestbook example from the Google Appengine SDK with Groovy Groovlets.

    The result is here. Leave me a message ;-)


    The backend classes (Greeting.java, PMF.java) were not changed (however it seems to be possible to datanucleusenhance classes written in Groovy and compiled with groovyc, see here).

    I kicked out the two servlets and the jsp and replaced them with the following two Groovlets.

    hello.goovy
    import com.google.appengine.api.users.User
    import com.google.appengine.api.users.UserService
    import com.google.appengine.api.users.UserServiceFactory
    import javax.jdo.PersistenceManager
    import guestbook.PMF
    import guestbook.Greeting
    
    UserService userService = UserServiceFactory.getUserService()
    User u = userService.getCurrentUser()
    
    PersistenceManager pm = PMF.get().getPersistenceManager()
    String query = "select from " + Greeting.class.getName() + " order by date desc range 0,25"
    List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute()
    
    html.html {
     head {
      title "Hello"
      link(type:"text/css", rel:"stylesheet", href:"/stylesheets/main.css")
     }
     body {
      div(class: "main"){
       div ("Today is: ${new Date()}")
    
       if (u == null) {
        div(class:"login"){
         a (href: userService.createLoginURL(request.getRequestURI()) , "Log in with your Google Account.")
        }
       }
       else {
        div(class:"login"){
         span("Welcome ${u.nickname}. ")
         a (href: userService.createLogoutURL(request.getRequestURI()) , "Log out")
        }
       }
    
       p ("Leave me a message:")  
    
       form(method: "POST", action: "/post.groovy"){
        div(){
         textarea(name: "content", rows: "3", cols: "60", "")
        }
        div(){
         input(type: "submit", value: "Post")
        }
       }
    
       greetings.each{
        def user = "anonymous"
        if(it.author != null) user = it.author
        div(class:"entry-header", "On  ${it.date} ${user} wrote: ")
        div(class:"entry-body", "${it.content}")
       }
      }
     }
    }
    

    post.groovy:
    import com.google.appengine.api.users.User
    import com.google.appengine.api.users.UserService
    import com.google.appengine.api.users.UserServiceFactory
    import javax.jdo.PersistenceManager
    import guestbook.PMF
    import guestbook.Greeting
    
    UserService userService = UserServiceFactory.getUserService()
    User user = userService.getCurrentUser()
    String content = request.getParameter("content")
    Date date = new Date()
    Greeting greeting = new Greeting(user, content, date)
    
    PersistenceManager pm = PMF.get().getPersistenceManager()
    try {
        pm.makePersistent(greeting)
    } finally {
        pm.close()
    }
    
    response.sendRedirect("/hello.groovy")
    

    This was my first take at Groovlets, so it might well be that things are not state of the art...

    Groovlet quick tip: textarea()

    Using textarea with Markup Builder in a Groovlet can be tricky.

    My initial attempt was:
    div()
    {
    	textarea(name: "content", rows: "3", cols: "60")
    }
    

    This however results in invalid html:
    <div>
        <textarea name='content' rows='3' cols='60' />
    </div>
    


    The correct way is to include an empty string (content of the textarea) in the constructor:
    div()
    {
    	textarea(name: "content", rows: "3", cols: "60", "")
    }
    

    Which yields correct html:
    <div>
        <textarea name='content' rows='3' cols='60'></textarea>
    </div>
    

    I hope this helps, since Groovlet documentation is quite sparse.

    Saturday, April 11, 2009

    Quick Look for Groovy with Syntax Highlighting

    In my previous post OS X: Quick Look for Groovy I showed how to enable Quick Look for Groovy source files.
    The result was very cool, but syntax highlighting was missing.

    After playing around a bit I found out how to enable syntax highlighting for Groovy in Quick Look.

    Here is how it works:
  • Install the qlcolorcode-plugin.
    Unfortunately the plugin does not support Groovy out of the box, but we will change that. After installing the plugin you should have the package QLColorCode.qlgenerator in your ~/Library/QuickLook.

  • Go into the QLColorCode.qlgenerator package. Either by right-clicking in Finder and choosing "Show Package Contents" or by navigating into the directory in a shell.

  • Inside the QLColorCode.qlgenerator package edit the script Resources/colorize.sh.

    Extend the case-statement in the middle of the script the following way:
    ...
    case $target in
        *.graffle )
            # some omnigraffle files are XML and get passed to us.  Ignore them.
            exit 1
            ;;
        *.plist )
            lang=xml
            reader=(/usr/bin/plutil -convert xml1 -o - $target)
            ;;
        *.h )
            if grep -q "@interface" $target &> /dev/null; then
                lang=objc
            else
                lang=h
            fi
            ;;
        *.m )
            # look for a matlab-style comment in the first 10 lines, otherwise
            # assume objective-c.  If you never use matlab or never use objc,
            # you might want to hardwire this one way or the other
            if head -n 10 $target | grep -q "^ *%" &> /dev/null; then
                lang=m
            else
                lang=objc
            fi
            ;;
        *.groovy )
        	lang=java
            ;;
        * ) 
            lang=${target##*.}
        ;;
    esac
    ...
    

    This tells Highlight to treat Groovy files as Java source code.

  • Next edit Info.plist inside the QLColorCode.qlgenerator package.
    Add the follwing snippet at the end of Info.plist (just before the ending </array> </dict> </plist>)
    	
    		UTTypeConformsTo
    		
    			public.source-code
    		
    		UTTypeDescription
    		Groovy Source Code
    		UTTypeIdentifier
    		org.codehaus.groovy-source
    		UTTypeTagSpecification
    		
    			public.filename-extension
    			
    				groovy
    			
    		
    		
    

  • Now you need to nudge the system to tell it something has changed. Moving the whole plugin (QLColorCode.qlgenerator) to the desktop then back to its installed location should do the trick.

  • This should be it! The result is Quick Look for Groovy with syntax highlighting:

    Picture 2.png


    The syntax highlighting is still not perfect, since it is Java highlighting... but it is much better than no highlighting.

    Tuesday, March 31, 2009

    Right is right, right?

    Management is doing things right; leadership is doing the right things.

    -- Peter Drucker


    Tuesday, March 24, 2009

    Provocative: MDSD vs. Platform

    http://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Yin_and_Yang.svg/600px-Yin_and_Yang.svg.png
    Two controversial statements about MDSD from the 'Zühlke Late Afternoon Talk: Quo vadis software modeling?':
    If you have a good platform then you don't need a modeling tool.
    If you have a good modeling tool, your platform becomes irrelevant.

    So where lies the truth? Obviously the boundary is flowing ...

    I my opinion 'modeling' is a very broad concept, so I would not necessary agree that you can trade between modeling and platform.
    But when you replace 'modeling' with 'code generation' I am pretty convinced, that both quotes apply, and they represent quite opposite approaches to software development.

    As I stated in Musing about Code Generation, MDSD and DSLs, I think the current trends in enterprise platforms lead to the first statement.

    In my opinion code generation is less and less needed on modern application platforms, and since MDSD currently is so tightly coupled with code generation (at least in my experience) I think MDSD in its current manifestation is getting more and more irrelevant.

    I think MDSD should somehow better adjust to the notion that "the code is the model" and provide additional abstractions (for different intentions) on top of that.
    I think the current DSL-movement is an effort in this direction.
    Visualisation would be another promising aspect.

    I know this is a provocative statement. Many MDSD evangelists are convinced by their approach... but I just have not seen the light until now, that does not mean that I am not open for an epiphany.
    So please leave a comment...

    Monday, March 23, 2009

    Groovy Grape: Problem resolving xalan

    There is a problem in Groovy Grape: It fails resolving xalan 2.7.1.

    The following grape declaration for instance leads to the error:
    @Grab(group='net.sourceforge.htmlunit', module='htmlunit', version='[2.4,)')
    

    The reason is, that htmlunit has a dependency to xalan, and xalan cannot be resolved...

    The problem can also be reproduced on the commandline: grape resolve xalan xalan 2.7.1
    The following error is printed on the console:

    [FAILED ] xalan#xalan;2.7.1!xalan.jar: invalid sha1: expected=sha1(xalan-2.7.1.jar)= computed=75f1d83ce27bab5f29fff034fc74aa9f7266f22a (9927ms)

    The underlying reason is the follwing bug in Ivy 2.0: IVY-1006.

    The bug is supposed to be fixed in Ivy 2.1, but Groovy 1.6 bundles Ivy 2.0.

    Meanwile a workaround is to manually download serializer-2.7.1.jar and xalan-2.7.1.jar from the maven repository and copy it at the place where grape would put it: ~/.groovy/grapes/xalan/serializer/jars/ respective ~/.groovy/grapes/xalan/xalan/jars/ on OS X.

    Related Posts Plugin for WordPress, Blogger...