Subversion and the bash prompt

I recently found this entry that shows how you can update your PS1 value to display certain information about your git workspace.  I don't get to use git too much right now, but I use subversion a lot and wondered what there was for that.  I didn't find anything in the bash-completion entries for svn (though I admittedly didn't look too hard) so I whipped up my own solution late last night. One slight disclaimer before seeing the script:  it was late when i wrote this.  There doesn't appear to be any noticeable performance hits other than the initial run of this script but I make no guarantees.  I'm sure it could be optimized but it's snappy enough and might prove to be mildly useful.  It was interesting enough at midnight at least.  :)  Anyway, the code!

#! /bin/sh
extract() {
	TEXT=$( svn info | grep "$1" )
	echo ${TEXT##$1}
}

if [ -e .svn ]
then
	URL=`extract "URL: "`
	REPROOT=`extract "Repository Root: "`

	echo "\n\033[01;33m[svn: ${URL##$REPROOT}] \033[01;34m"
fi

This can be displayed in your command prompt by setting your PS1 variable like this:

export PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w $(svn_ps1)\$\[\033[00m\] '

The single quotes are important there to prevent immediate execution of the script. If you use double quotes, it will be evaluated immediately and your prompt won't update as you navigate around. You only need to save the first script as svn_ps1 somewhere on your PATH or name it as you wish and update the PS1 variable accordingly. You can, of course, specify the full path in the PS1 var if you'd like. This setting will put the path within the current subversion repository in yellow text on a new line. If you're not in a subversion workspace, your prompt is unaffected. I had some code in there to strip off the relevant portions of the cwd from that display so you essentially only saw what branch or tag you were or if you were in trunk. With the script as it is, there's some redundancy between the subversion info display and the cwd shown, but I can live with that.

I switch between branches and even version control systems often enough that i'll probably expand on this to work for git/svn/hg/cvs accordingly. Next time I'm up late hacking.

Grizzly and WebSockets

As HTML5 lumbers its way through the standardization process, more and more developers are starting to play with the emerging features.  One feature getting some serious attention is that of the websocket.  Full details of the websocket protocol can be found here but I'll lay out the basics of it.  Essentially a websocket is a TCP based socket that can be opened from a webpage via, typically, javascript code allowing bidirectional communication between the browser and the server.  This allows for comet-like interactions but with an extra benefit (or two).  Once the websocket connection is established there are no more protocol negotiations and handshakes unlike your typical AJAX conversations.  And unlike (most?) comet implementations, a websocket can process multiple requests from the client.  Obviously, this can lead to some rather interesting use cases. It's early yet so support for websockets on either end of the browser/server connection is spotty at best.  But we're staring to see browser support emerge and a number of server side options are popping up as well.  This morning I committed an early rough draft, if you will, for support inside the grizzly project and soon glassfish itself.  It's a mostly complete implementation and is ready for some experimentation.  At the moment, the sample in the unit tests that will be of the most interest is a servlet based approach.  What's nice about the current approach is that the servlet is largely unaware that it's involved in a websocket transaction at all.  There's a lot of value in something like that but might limit some other, more powerful, use cases.

For now, though, you can play with the unit tests and see what can be done.  It's preliminary but working and the API will evolve as we get feedback from the community.  We'll be discussing how best to expose this functionality without needing to know all that much about grizzly internals.  We'll be looking at other cases such as jetty and atmosphere to make sure we can provide a smooth, useful API that most people are comfortable with.  There's been talk at various levels of building some form of standard interface to plug in to various websockets implementations on the server side but until then, we'd love your help in building something with grizzly and glassfish that we can all use.

So please join us on the mailing lists and give us a hand.

GlassFish v3 is out

Today marks the official(ish) release of GlassFish v3.  v3 is the product of years of hard work in what is, in some ways, a rewrite of v2.  Built on top of OSGi, v3 offers a modularity and extensibility leap over v2.  It's also the first to fully support the JEE 6 specification.  I've been a spring guy for a long time now but honestly (and employer imposed bias aside)  JEE 6 makes a compelling case for skipping spring altogether.  At least for my uses. GlassFish v3 and JEE 6 offers a number of profiles so you can install as much or as little as you'd like.  Using the web profile gives you everything you need to run many web apps.  You can add additional features via the updatecenter as you need them often without needing to restart the server.  If you're a v2 user most of that should be very familiar to you already.  Borrowing from Eduardo's blog entry:

Key links available now:

• GlassFish v3 Main Product PageJavaEE 6 Hub • JavaEE 6 Downloads (multiple bundles) • Java EE 6 Feature Article (also see Overview White Paper).

You can read more here.  You can also find all the GlassFish v3 related blogs on blogs.sun.com (at least those tagged as such) here.  I'm really quite excited about this release but at the risk of sounding too press releasey about it all, I'll leave the gushing to others.  You can check it for yourself by downloading it.

Download it.  Kick the tires.  Take it for a spin.  I think you're going to like what you find.  Especially if you haven't given glassfish a look in some time.  This is truly a different creature.