Wednesday, August 31, 2011

Mac OSX Global Git Ignore - XCode Project and State Files.

With my recent switch to Mac, Objective C and XCode and XCode using Git as it's default VCS (Version control system), I figured it would probably be a good time to switch over to using Git. I registered with GitHub purchased the base 5 private repo plan and uploaded my projects and images. I didn't realize at the time then what pain I would cause myself.

A little later, my wife joined me in working with those projects only to discover that under certain scenarios we could never actually merge or sync the branches from XCode. There were always couple files that would be "uncommited" in XCode. Nasty XCode project state files.

I had not worked with Git before this actually, so after reading up a bit about project files and the like and how a ".ignore" file would do the trick.
After I little bit of struggling, I realized that for ignore to work, the files needed to be removed from the repository first. Thankfully I did not have any important history so I could simply recreate them. You can also remove them from git with: git rm --cached

To go about creating, editing configuring a global ignore file on OSX I did the following:

First problem on a Mac, any "." files are seen as system files and those are automatically hidden from you.

To get around that open "Terminal" and use the commands below to show and hide system files (you'll need to either restart or force quit Finder for the changes to take effect).

Show:
defaults write com.apple.finder AppleShowAllFiles -bool true

Hide:
defaults write com.apple.finder AppleShowAllFiles -bool false


Once I had done that I simply went searching for a couple example ignore files and combined them into the example below.

Create a file in your user directory called ".gitignore_global", populate it with the contents required, (below is mine, that does take care of the XCode problem files)
Then in Terminal run:
git config --global core.excludesfile ~/.gitignore_global

My global ignore file:

Wednesday, August 24, 2011

Java / XML UTF-8 marshalling and validating pains

This is a post on the little pains I am sure most people have endured while working with Java and XML from different sources, with 'funny' characters...

If you use a FileWriter instead of a FileOutputStream it will use your OS encoding (So cp1252, ISO-8859-1 or US-ASCII and not UTF-8... ):

A way to ensure that you are using UTF-8 is:

If you are reading XML from a stream, it is probably safer to do something like:

When validating a schema note the .getBytes("UTF-8"):


When marshalling (Use a stream rather than a writer):


Lastly if you are getting XML from some unknown source there are some chars that are outside the legal XML Unicode limits that you can not encode. To remove those:
Code below from another blog :





Popular Posts

Followers