BlogicBlog: View from the trenches

The blog about Java and XML with focus on troubleshooting issues and tools.

Monday, August 01, 2005

Re: More Readable Classpaths for Ant Builds

Permanent article link

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:

    • in the command-line mode (:),
    • for the whole buffer (%)
    • join lines (j)
    • without inserting or deleting any spaces on the join (!)

  4. Now, let's split them on the semicolon: :s/;/^M/g.
    In here, we are

    • 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)

  5. Ok, we are done in less than 20 keystrokes including cut and paste and carriage returns!
  6. 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)
  7. :%!sort -u. This will require Cygwin to be first on the path in the Windows environments.
  8. How about highlighting all the sprint jars in one color and all hibernate jars in another?
  9. :1OTF spring and :2OTF hibernate. This requires OTF Vim plugin.
  10. 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

0 Comments:

Post a Comment

<< Home