Showing posts from November, 2011

Mass find and replace on Mac OSX with SED

Lets say you are doing some grand refactoring, and you want to change a class name from Dog to Pooch in multiple files.
There are a couple of ways you can do it with the sed command. One uses the -exec argument and the other uses the xargs program. Though I'm not sure why, I favor the xargs strategy. In Linux to do a mass find and replace for our Dog to Pooch example you could do something like:
find . -name "*.php" -print | xargs sed -i 's/Dog/Pooch/g'

But if you try this same command In Mac OSX you will see an error like this:
extra characters at the end of g command

The reason for this is the command in Mac OSX the command doesn't trust you. I wonder if rm -rf / works in Mac OSX? Well I'm not going to find out ;-) Mac OSX will create a backup file in case you mess up your find and replace, and it requires an extension for this file. With that in mind, the following command will work in Mac OSx:
find . -name "*.php" -print | xargs sed -i.bak …

Debugging dependencies in Grails

In Grails, and indeed large Java projects generally, dependency resolution can become quite a headache. Tools like Maven and Ivy are a huge help of course, but even they can't prevent tedious days trying to fix that conflict where two classes of the same name are loaded by the same class loader. Grails provides a feature that helps navigate through the complex web of depencies that your web application will no doubt accrue.

Issue the command: grails dependency-report
or if your using the maven-grails plugin: mvn grails:exec -Dcommand="dependency-report"

This will generate a number of reports in the /target/dependency-reports folder for you. The html reports can of course be opened in the browser of your choice. The graph reports (in graphml format) however need a special and - to me at least - uncommon tool. The tool that seems most popular is yEd. Fortunately yEd is available for Linux, Mac, and Windows.

After you have download and installed yEd, open one of the generated …