Sunday, August 24, 2008

Interesting String behavior in Groovy

I've been writing some Groovy code in the last week. I did something silly that the Java compiler would have caught and scolding me for doing:

def body
// ....
body += someContent
What happened was my body strings were all prefixed with the character string "null." Apparently doing a concatenation on a null String causes "null" to be produced.

I do not claim this to be good or bad - I just think it's interesting.

getResourceAsStream() depends on what you're calling it on...

In writing some unit tests I ran into something I didn't expect. I had a .properties file that I was using to state metadata. In this case, the full path to a file my "Class Unit Test" was creating.

It seems that calling getResourceAsStream() off of getClass() does not return the resource. It's unfortunately that the Class class has a getResourceAsStream() method if it's not going to actually work.

So...
InputStream input = getClass().getResourceAsStream("./test.properties")
returns null.

If you use ResourceBundle to fetch "test" - it works.

I thought that was odd. I made a mention to my friend and he suggested that I need to be asking the ClassLoader to fetch the resource, not the class.

So...
InputStream input = getClass().getClassLoader().getResourceAsStream("./test.properties")
returns the resource.

Now - I am executing this from a GroovyTestCase instance. I do not know the reason for this. But either way, it's frustrating.


Install Git/Gitosis on a server (Debian) - Part 2

So I ran into some more issues before getting my Git hosting (via Gitosis) all working.

The first hurdle was getting past an error thrown when attempting to do a `git clone` of the gitosis-admin repository. The error was being thrown by os.py (remember that gitosis-admin is python based). The error message looked like this:

Traceback (most recent call last):

File ”/usr/bin/gitosis-serve”, line 7, in ?
sys.exit( File ”/usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg/gitosis/app.py”, line 24, in run return app.main()
File ”/usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg/gitosis/app.py”, line 38, in main self.handle_args(parser, cfg, options, args)
File ”/usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg/gitosis/serve.py”, line 205, in handle_args os.execvp(‘git-shell’, [‘git-shell’, ‘-c’, newcmd])
File ”/usr/lib/python2.4/os.py”, line 341, in execvp _execvpe(file, args) File ”/usr/lib/python2.4/os.py”, line 379, in _execvpe func(fullname, *argrest)
OSError: [Errno 2] No such file or directory
The root cause of this is that the executable `git-shell` is missing from your install directory (be /usr/bin or /usr/local/bin). I've done a install locally and all the 140-some executables were places in my install directory (/usr/bin).

Originally, I just copied `git-shell` into /usr/bin. That's hack-ish, what I ended up doing was creating a symlink to `git-shell` from where I have git (in my case, /opt/git-1.6.0, with a symlink to it named /opt/git).

So now we can do our clone of the repository:

`git clone git@YOUR_SERVER:gitosis-admin.git`

This appears in both tutorials I looked at [urban puddle] [scie.nti.st]

Now we want to create a new repository. That was my next hurdle; and you won't need to overcome it if you follow directions. Notably, the simple directions in either. Which is that you need to modify the gitosis.conf (which is Step 6 in the Urban Puddle tutorial and "Creating new repositories" in the scie.nti.st tutorial).

I attempted to simply do something like initialize a git repository, do some commits, add a remote (origin) to the server, and then push to that remote (origin).

If you have gone awry - like me - you'll run into the following error:

ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

If you add the following under [gitosis] in the gitosis.conf:

loglevel = DEBUG

You'll get some helpful debug output.
lenards@deedee:~/devel/cs453/project$ git push origin master:refs/heads/master
DEBUG:gitosis.serve.main:Got command "git-receive-pack 'cs453-project.git'"
DEBUG:gitosis.access.haveAccess:Access check for 'lenards@deedee' as 'writable' on 'cs453-project.git'...
DEBUG:gitosis.access.haveAccess:Stripping .git suffix from 'cs453-project.git', new value 'cs453-project'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'gitosis-admin'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'cs453-project'
DEBUG:gitosis.access.haveAccess:Access check for 'lenards@deedee' as 'writeable' on 'cs453-project.git'...
DEBUG:gitosis.access.haveAccess:Stripping .git suffix from 'cs453-project.git', new value 'cs453-project'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'gitosis-admin'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'cs453-project'
DEBUG:gitosis.access.haveAccess:Access check for 'lenards@deedee' as 'readonly' on 'cs453-project.git'...
DEBUG:gitosis.access.haveAccess:Stripping .git suffix from 'cs453-project.git', new value 'cs453-project'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'gitosis-admin'
DEBUG:gitosis.group.getMembership:found 'lenards@deedee' in 'cs453-project'
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly
I missed the step in the directions about adding a new group to the gitosis.conf, which is why when doing your `git push origin master:refs/heads/master` it complains about not have readonly access. There is *no* group to access, so you don't have writable or readonly access.

After doing Step 6 from Urban Puddle tutorial - I was able to push my new repository for my compiler project.

I hope this helps someone.

Andy

Thursday, August 21, 2008

Installing Git on a server (Debian)

http://www.urbanpuddle.com/articles/2008/07/11/installing-git-on-a-server-ubuntu-or-debian

First off - a thank you to Vincent for pulling all these things together.

I ran into an issue that seem to be related to the version of the git-core package (I'm running debian etch stable). The version of git-core is 1.4.4, and apparently they had not introduced `git-init` until 1.5.* - so my calls to `gitosis-init` were erroring out (like this gentlemen's: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473908).

So - I just did an install from source for git-1.6.0 ... there are instructions out there, so I bother pointing to those.

Thank again! I really did appreciate using this.

The only thing I'd mention after that is the call to `gitosis-init` looks like this for debian:

su - git -c gitosis-init < /home/joeuser/.ssh/authorized_keys

I tried to post this as a comment on Vincent's blog but I kept getting Apache errors.

Thursday, August 14, 2008

Late again...

I've missed my self-made deadline again. I had a horrible time trying to get my initial site done with the toolset I use daily (which is depressing, and makes me think about the toolset I use).

Right now, I'm back to looking at Grails. It still have issues with getting things to work in Grails. There is something I'm missing, or it's just not clear that how I approach things is wrong. But I've decided to invest time in learning more about Grails and Groovy for the time being.

I've also been learning as much as possible about Git. I recently gave a talk at the local Java Users Group about Git. It seems to be definite improvement over Subversion. And if you're thinking about all those posts ripping on Git's implementation or internal design, being a user at the porcelain I honestly don't care how it's implemented underneath.

Plugging on ... we'll see if I can post more than every four months.