Re: More Readable Classpaths for Ant Builds

Lance Hankins got annoyed with having to eyeball ant’s output of the long classpaths and wrote a task to do the classpath output in a slightly more readable form.

Neat, but perhaps there is a more generic way to do it. After all, not only ant produces these long semi-column separated monstrosities.

So, I want to show how I do it with Vim (Why Vim…).

Let’s use Lance’s output as given.

  1. Copy and paste it into Vim.
  2. Notice that it is broken into multiple (23) lines. While he probably did it for a better web presentation, this also happens when somebody screen scrapes the classpath from the DOS window.
  3. Let’s combine all the lines back into one long one: :%j!.
This command means:</p> 
  * _in the command-line mode (**:**),_ 
  * _for the whole buffer (**%**)_ 
  * _join lines (**j**)_ 
  * _without inserting or deleting any spaces on the join (**!**)_
  1. Now, let’s split them on the semicolon: :s/;/^M/g.
In here, we are</p> 
  * _in the command mode again (**:**),_ 
  *  _working with the current line (**no range indicated**)_ 
  *  _doing a substitution (**s/FROM/TO/**)_ 
  *  _from semicolon (**/;/**)_ 
  *  _to a line break (**^M**, produced -at least on windows- with CTRL-Q CTRL-M key sequence),_ 
  *  _and repeating this substitution for the whole line (**s/FROM/TO/g**)_ 
  1. Ok, we are done in less than 20 keystrokes including cut and paste and carriage returns!
  2. Let’s see what else we can do. How about sorting and deduping the entries? (after cleaning up the first line to remove the [echo….] bit)
  3. :%!sort -u. This will require Cygwin to be first on the path in the Windows environments.
  4. How about highlighting all the sprint jars in one color and all hibernate jars in another?
  5. :1OTF spring and :2OTF hibernate. This requires OTF Vim plugin.
  6. As an added benefit, the command above immediately highlight spring’s jar for hibernate as it is the only line with two colors on it. Could be useful to keep in mind.

I could go on for a while, but hopefully this will be a more useful and generic way to deal with long classpaths rather than having to write an ant task. KISS, DRY, etc.

BlogicBlogger Over and Out