Categories
Uncategorized

Using a Java 6 based Eclipse with Cocoa

This is somewhat niche, but I’m going to post it anyway in case it helps somebody else

I recently saw a problem with Eclipse and m2eclipse. When I tried to import a Java 6 based project, I got an error in the maven console.

Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6
Usage: javac  
where possible options include:
 -g                         Generate all debugging info
 -g:none                    Generate no debugging info
 -g:{lines,vars,source}     Generate only some debugging info
 -nowarn                    Generate no warnings
 -verbose                   Output messages about what the compiler is doing

This is happening because m2eclipse is trying to run the compiler from within the same JVM that Eclipse is running. And by the eclipse.org downloads only offer Carbon and Cocoa options. Both of these are 32 bit. Which means they’ll only ever run using Java 5, even if you’ve got Java 6 installed (unlike my iMac G5, grumble, grumble).

Thankfully, the 64 cocoa version is available, though it’s only the old “Eclipse SDK” download. But ekke wrote up [galileo] EPP for Cocoa 64-bit, which shows how to go about getting (effectively) the same setup as the eclipse.org downloads.

If you follow along that procedure, you get an eclipse that works well with m2eclipse and Java 6 project. As a bonus, it feels quicker to me.

Hopefully future versions of Eclipse will offer a 64-bit cocoa download.

Categories
Uncategorized

assignment alignment in vim

I’ve just been reading some articles about programming vim from Damian Conway.

* Scripting the Vim editor, Part 1: Variables, values, and expressions
* Scripting the Vim editor, Part 2: User-defined functions

The latter has a very useful example.

function AlignAssignments()
   " Patterns needed to locate assignment operators. "
   let ASSIGN_OP   = '[-+*/%|&]?=@<!=[=~]@!'
   let ASSIGN_LINE = '^(.{-})s*(' . ASSIGN_OP . ')'

   " Locate block of code to be considered (same indentation, no blanks) "
   let indent_pat = '^' . matchstr(getline('.'), '^s*') . 'S'
   let firstline  = search('^%(' . indent_pat . ')@!', 'bnW') + 1
   let lastline   = search('^%(' . indent_pat . ')@!',  'nW') - 1
   if lastline = 0
           let max_align_col = max([max_align_col, left_width])
           let op_width      = strlen(matchstr(linetext, ASSIGN_OP))
           let max_op_width  = max([max_op_width, op_width + 1])
       endif
   endfor

   " Code needed to reformat lines so as to align operators. "
   let FORMATTER = '=printf("%-*s%*s", max_align_col, submatch(1),
                                       max_op_width,  submatch(2))'

   " Reformat lines with operators aligned in the appropriate column. "
   for linenum in range(firstline, lastline)
       let oldline = getline(linenum)
       let newline = substitute(oldline, ASSIGN_LINE, FORMATTER, "")
       call setline(linenum, newline)
   endfor
endfunction

nmap  ;= :call AlignAssignments()

This allows you to line up assignments so that all the the equals appear in a column. I find this much easier to read.

To use this code, paste it into a file ~/.vim/plugin/AlignAssignments.vim. It’ll get loaded automatically. From then on you use it by going to a group of assignments and hitting ;=. Blam!

There are other alignment plugins available in the vim scripts archive, but this one is relatively small & simple.

Categories
Uncategorized

Publishing a subdirectory to github pages

I’ve written some HTML documentation for jslint4java. It lives in jslint4java-docs/src/main/resources in typical maven fashion. I’d like to get it published on github pages.

The starting point is similar to their documentation.

git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
echo "My GitHub Page" > index.html
git add .
git commit -a -m "First pages commit"
git push origin gh-pages

That lands us with a brand spanking new branch to play with. What I’d like to do is make a new commit on that branch, but from a tree which is already in my repository. The magic word is git commit-tree. It needs two things: the id of the tree and the id of the parent commit to attach to.

The parent to attach to is easy. It’s the tip of the gh-pages branch we just made. git show-ref will let us know the id.

$ git show-ref -s refs/heads/gh-pages
0a0c2a4ef1f9421b6f9537472c0f04fd6485d2cc

The next bit is the tree we want to commit. git ls-tree is the tool for the job.

$ git ls-tree -d HEAD jslint4java-docs/src/main/resources
040000 tree 5feb5926c39b5e6af3a51feb04750c819bf08b94	jslint4java-docs/src/main/resources

git commit-tree will return the id of the new commit it just created. All that remains is to update the gh-pages branch to point at it.

Pulling it all together, we have:

#!/bin/bash
parent_sha=$(git show-ref -s refs/heads/gh-pages)
doc_sha=$(git ls-tree -d HEAD jslint4java-docs/src/main/resources | awk '{print $3}')
new_commit=$(echo "Auto-update docs." | git commit-tree $doc_sha -p $parent_sha)
git update-ref refs/heads/gh-pages $new_commit

This isn’t ideal — it won’t automatically track updates to that directory. But it’s easy enough to run this once in a while to publish an update.

The end result is that my documentation is published.