trust your technolust

Wednesday, May 25, 2005

Remember Your Networks?

When you connect to a wireless network on the Mac, it asks you if you want to remember this network. Unfortunately, at no point does it let you forget said network. The remembered networks are stored in a "data" value in /Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist, which of course makes it hard to edit by hand. Paul Shreiber wrote a script last August to read the data value and output a new plist (in /tmp/com.apple.airport.preferences.plist) which you can then "sudo cp" over the real one.

The script is also a short example of using FoundationKit in perl.

References: http://www.paulschreiber.com/download/getAirPortNetworks-pl.txt

Friday, May 20, 2005

Dependency Injection Frameworks: What Java does to be Interpreted

My current task is customizing JIRA, an enterprise issue tracking system. JIRA is a fine application that makes bug tracking easy and fun. The JIRA source code is 22MB of compressed Java code that makes customization (outside of plugin or JSP modifications) neither easy nor fun. After a week, I managed to get the source into Eclipse in such a way that Eclipse's auto-build feature inserts new class files into the currently running tomcat. Tomcat automatically refreshes modified class files, so after saving some changes in Eclipse, you can go straight to your web browser and test them.

Now that the introduction is out of the way, lets get on to PicoContainer. In a tiny nutshell, Pico is a framework for stuffing methods into Plain Old Java Objects. You create your native objects (Plain Old Java Objects) with constructors that take in any object links - ie an MVC controler takes in view and model objects. Then, you set up a container that defines the object relationships - which objects are related, and their setup parameters. Now when you instantiate the container, you can ask it for one of the POJOs that will now have its relationships fufilled.

The end goal of the system is to fufill abstract object dependencies with objects that implement the abstractions. In Martin Fowler's Constructor Injection example (he covers other related injection methods), a MovieLister class uses a MovieFinder class to return all the movies directed by Sergio Leone. The MovieFinder class is an abstraction implemented by ColonMovieFinder, which takes in a filename of a colon delimited database. They are tied together in a container by a setup function.

What amazes me is that there is a framework for doing this - many frameworks, in fact. PicoContainer, Spring, and Apache Avalon (closed, but a common ancestor of a handful of other projects) all do basically this, either by constructors, setters, or interfaces. If I were working in a language that wasn't statically typed, I could use an advanced factory design pattern. Clearly Java is a statically typed environment - hence the need for these frameworks. But every time someone codes a dynamic extension to a static system, it makes me wonder - why are we using a static system in the first place? To contrast, Objective-C can treat any object as a generic object type ("id"), but can also be statically allocated. Doesn't that sound a lot easier than writing frameworks that ram square pegs into round holes? What were the Java people thinking?

References:
http://www.martinfowler.com/articles/injection.html
http://timothyfisher.javadevelopersjournal.com/read/1232766.htm

Thursday, May 05, 2005

Mavening Your Repository

Maven is a project system (analogous to qmake, or the file organization in IDEs) that complements the ant build system (analogous to make). Maven allows a project to specify dependencies in the form of Jars available from a repository, the default of which is http://www.ibiblio.org/maven. It will get these automagically if you don't already have them. If for some reason you really just want to download them to your computer, type this in your shell:


function maven_repos_get() {
FOLDER=$1; VER=$2; mkdir $1; mkdir $1/jars; pushd $1/jars;
curl -O http://www.ibiblio.org/maven/$1/jars/$1-$2.jar; popd;
}


Then, for each library that you need (if you are like me, you're looking at broken dependencies in Eclipse), change to your Maven repository directory (set when you install maven) and type "maven_repos_get ". If you're wondering how I got these broken dependencies in eclipse, check out "maven eclipse", and don't forget to define MAVEN_REPO.