Thursday, February 26, 2009

Mercurial "case-folding collision" More Explanation on the fix

I've run into this error now a few times. What happens is you rename a file, changing only the case of one or more characters in the file name. This causes confusion. Now you can read here and here about the fix to this problem. I'm going to give a little more info on how to make this work, just because it might not be crystal clear reading those two sources.

You got this error either by checking out the project, or pulling changesets into your project and trying the 'update' command. So run these commands:

hg debugsetparents <revision>

The revision should be the one you are attempting to update to.

hg debugrebuildstate

now you want to remove all the files in error, you can use 'hg manifest tip' to check for the files in error. I've had more than one before after doing numerous renames that camel cased a number of files. use:

hg rm -A <filename>

to remove files, you can list multiple files to delete using spaces between each.

Once you've removed the files you should commit the changes:

hg ci -m "Fixed case problems"

Then do a clean check out the tip revision:

hg co -C tip

thats it, hope this helps to shed a little extra light on the process.

Tuesday, February 24, 2009

Using sort and uniq to find duplicate lines in a file

I love my Mac, mostly because I can run all those great Unix utilities that make tasks easy. Today I want to point out a pair of tools that come in handy often. They are sort and uniq.

sort can be used to sort the lines in a given file. A simple use would be

echo -e "c\na\nb" | sort

which produces:


Sweet! Now lets look at the sort program:

echo -e "a\na\nb\nc\nb" | uniq



Removing the duplicate a, but not the b! The tool only removes any consecutive duplicate lines. So what if you want to remove all duplicates? Easy:

echo -e "a\na\nb\nc\nb" | sort | uniq



Taa Dah! Thats easy!

Now this duo can be used in very many useful ways. Just the other day I needed to find two XML elements that had the same value. I used 'sed' to pull out all the values in the given element, sort to put these values in lexographically sorted order, and uniq to tell me the duplicates found:

sed -n 's/.*<tag>\(.*\)<\/tag>/\1/p' | sort | uniq -d

For the 'sed' part you could put any tag name in there you need to find duplicate value for. should be the name of the file you are using. Notice that each XML element was on it's own line, so this wouldn't work for documents that are not formatted nicely (for that see xmllint :).

Friday, February 20, 2009

Memory settings when using Jetty inside of Eclipse

If you like to debug and run your webapps inside of Eclipse you've got two options. First there is Tomcat, which running will require a plugin like Sysdeo. Second, you can write a simple class to start up your web application using Jetty. I like to use Jetty rather than the old school Sysdeo Tomcat plugin. I've found that it is simpler to configure the application to run in a test or stage mode this way inside of Eclipse.

If you run Jetty inside of Eclipse you may need to increase the memory being used by the process (Jetty is fast to start up and doesn't requires much memory, but your web app may!). So if you have a process to start your web app in Eclipse you'll have a run configuration. If you open this (click the item menu drop down to the right of the green circle w/ a triangle in it) configuration in the right pane select the 'Arguments' tab.

As you can see in the image above you then will want to fill in the VM arguments to contain the needed memory settings. In the above configuration I've added settings to increase the minimum heap to 256 mb and the max heap to 512 mb. Thats all I needed for my webapp to run smoothly, you may require more or less.

Thursday, February 19, 2009

OAuth Library for Java & Groovy

I've released a latest version of a simple OAuth client I developed. You can find version 1.1 of the jar here. Also the site for the project is here, and finally the source is here. I should have some documentation on basic usage up later.

So far the library only supports the HMAC-SHA1 method of signing, and is using query parameters to send the OAuth information. Soon I'll add support for using headers and POST data to send the OAuth information.

Maven and Mercurial: tips on performing a release

If you are using Maven 2 and have a project in source control via Mercurial then you might need this tip. If you do a 'mvn release:prepare' then Maven will try and push the changes and will need auth. Use the sys properties -Dusername= -Dpassword=' to get authenticated. I don't think this is very secure because the properties seem to be plaintext, but eh what can you do?