Archive for 2004

Using JUnit in Eclipse Ant Builds Comments Off

Just a quick note so that it gets into the Google help engine. By default the copy of Ant that is included with Eclipse does not reference it’s own internal copy of JUnit on it’s class path, to change this open up the preferences window (hit command-comma if you’re on a Mac) and open the Ant/Runtime node then add the JUnit location to the global path. If you’re doing full-source editing (which is highly recommended for all Eclipse users!) then you can just add a workspace reference and it will work fine.

TextMate Revisited Comments Off

After a bit more usage, some pros and cons of TextMate. To evaluate it’s features I’ve been writing a bundle to work with Mono/C# development. First the good things:

  • Shell Commands automatically run external commands, this can be used to kick off a compile or run a program for example. These are defined in a custom format but are basically shell scripts embedded in a property list file. I feel it would be a better approach to just use the property list for metadata and have a pointer to a real shell script, but I suppose you could do that anyway;
  • Macros these should be a standard feature in any application, even so, it’s good to see them included;
  • Code Snippets you can set up small text fragments to be inserted when you type a few characters and hit the tab key. More than this however, you can include positional parameters in your code snippets and hitting tab again will step through them. I use Eclipse as my IDE and it has a similar feature, so I’m right at home with this and it’s a great time saver for lazy typists like me. The only down side is that there is no way to have custom text entered in to multiple locations. I’d really like to be able to have a code snippet like this:
1
2
3
for (int $1 = 0; $1 < $2; ++$1) {
// do something with myArray[$1] here...
}

and have it fill in the variable name every place it appears; * Syntax Highlighting not too many language syntaxes are provided by default, but it’s easy to create you own. I had a workable C# syntax defined in about 15 minutes; * File Templates like snippets but for entire files. They can reference any shell environment variables, as well as a few special variables that are supplied by TextMate. You can add your own variables to this list as well. I haven’t used this much yet, but I expect it will be reasonably useful; * Bundles of Goodness you can define your own ‘feature bundles’ grouping together the features listed above. All of the features are described in standard property list files, so you can also edit them by hand if you want to. What would be a nice addition would be a way to enable and disable entire bundles, at the moment you have to manually remove them from the search path to do this; and * Projects this allows you to group multiple files together. A nice addition to this feature would be the ability to add custom variables to a project, maybe with some kind of dialog to accomplish this when you select ‘New Project…’.

And a couple of gripes I have:

  • No Preferences Dialog apparently it’s a design decision on the part of the developers. Their preferred approach is to take all of the preferences and scatter them around the menus, maybe to make it look like there are loads of extra features or something. This sucks. Looking at the mailing list archives I’m not alone in thinking this;
  • No OSA Integration although commands let you call out to AppleScript, the editor itself isn’t scriptable at all. There are a few things which stand out as non-Mac-like actually. Sometimes this is for a good reason (for example, not using NSTextView enables it to have much better text handling than most other editors) but other times it just seems odd (for example not using Apple Script for scripting but instead including two alternative automation systems in macros and commands).

TextMate Comments Off

I’ve been looking for a good text editor for the Mac for a few weeks now, since I just can’t seem to get the hang of BBEdit, and $180 seems a bit steep for a text editor (or maybe I’m just a tightwad). Just released though is TextMate, which seems to fit the bill so far, and is reasonably customisable.

One of the neat features is the ability to group files together into projects, which I expect to be a big time saver. Another win is the fact that it’s easy to set up custom syntax highlighting and add additional commands to the editor. After a couple of hours of use I had a custom syntax mode for C# defined, and commands to compile and run the current file using Mono. I’ll post them here once they’re a bit more polished.

Dynamic Classpaths in Eclipse Comments Off

In Eclipse your plug-ins normally have their classpath’s based upon their dependencies. I’m playing around with an RCP based application that will need to reference external libraries to avoid onerous licensing requirements. Here’s the somewhat convoluted code required to do this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Context getContext() {
	if (context != null) { return context; }
	final Properties props = new Properties();
	props.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactory());
	props.put(Context.PROVIDER_URL, getProviderURL());
	props.put(Context.SECURITY_PRINCIPAL, getDirectoryPrincipal());
	props.put(Context.SECURITY_CREDENTIALS, getDirectoryCredentials());
	URL[] classpath = null;
	Plugin plugin = JmsPlugin.getPlugin();
	try {
		String stringList = plugin.getPluginPreferences().getString(PreferencesInitializer.CLASS_PATH);
		StringTokenizer st = new StringTokenizer(stringList, File.pathSeparator);
		ArrayList v = new ArrayList();
		while (st.hasMoreElements()) {
			v.add(new URL("file://" + st.nextElement()));
		}
		classpath = (URL[]) v.toArray(new URL[v.size()]);
	} catch (MalformedURLException e) {
		String msg = e.getMessage();
		Debug.error(plugin, 0, msg != null ? msg : "", e);
		throw new RuntimeException(e);
	}
	ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
	ClassLoader newClassLoader = new URLClassLoader(classpath, getClass().getClassLoader());
	try {
		Thread.currentThread().setContextClassLoader(newClassLoader);
		context = new InitialDirContext(props);
	} catch (NamingException e) {
		String msg = e.getMessage();
		Debug.error(plugin, 0, msg != null ? msg : "", e);
		throw new RuntimeException(e);
	} finally {
		Thread.currentThread().setContextClassLoader(oldClassLoader);
	}
	return context;
}

The relevant code is in the first try... catch block. Then I can have this plug-in rely on a second plug in which includes the JMS interfaces only, and have a preference page which allows the user to select a third party JMS provider by URL. At the moment it won’t handle JMS providers that reply on native methods, but that could be fixed the same way if needed. The Debug.error(...) is just a utility class to log an Eclipse IStatus.ERROR message. As an added benefit of this approach, because I use the latest API version in my JMS plugin, I can check for a JMS version at runtime using the metadata returned by Connection.getMetaData() and then only call JMS 1.1 supplied methods when they are available.

Interactive Programming Comments Off

After playing around with Lisp for a few days I’ve diverted myself back to a small Java project. Almost immediately I’m missing the Lisp environment! To be sure there are some things that I prefer about my Java environment, which is Eclipse, but I just miss having an interactive top-level so much! It’s just amazingly convenient to be able to try sunning a fragment of code, and the ability to tweak it and try again if you hit any problems is such a productvity boost.

Markup Cleanup Comments Off

Cleaned up some stupid markup errors that were preventing the main and (so far empty) articles pages from validating as strict XHTML, I’ve also added validator tags to the bottom of the pages.

First Gallery Comments Off

I’ve finally got around to uploading the first gallery, from when I went to Spain a couple of weeks ago. I should get araound to putting another couple of galleries on line in the next week or so.

Word Press Comments Off

As you can see the site now uses Word Press as it’s content management system. It’s going to take me a couple of days to getting around to fixing up the templates so that it looks the same as the rest of the pages here, but bear with me.

Entry Archives Broken Comments Off

The individual entry archives seem to be screwed at the moment, since I’m planning to move over to using Word Press in a couple of days I’m not going to waste time trying to fix them right now.

Gimp UI Blooper Comments Off

Why would the developers of Gimp want to offer LZW compression as an option in the save as tiff dialog of said application? When you try to select this it just whines about a patent issue and then the save fails. It seems to me that it would be far better to just not offer the option, or only offer the option when it can be fulfilled.

Let’s hope that they’ll fix this in an upcoming release, it doesn’t seem like it would be much work for somebody alreay familiar with the code base.

Next Page »