2009/02/01

HTML crosslinked documentation from source code files

I know that modern IDEs can navigate through source code files very easily. But...what if I want to browse through source code files in my Palm TX ? Netbeans, Eclipse and other IDEs are not available for it, but I can read HTML pages offline easily with Plucker. Maybe I simply don't want to open an IDE only to browse the source code, without actually coding.

There are tools that can generate HTML pages from source code, so you can browse through them easily. They can even beautify the code with syntax highlighting and (this is my favourite) provide links between the different elements of the documentation. So, when you browse class Foo and it extends from BaseFoo, you can simply click on the word BaseFoo and you navigate to the class BaseFoo, and so on.

I've been searching for tools of this kind and I found some of them.

I like Doxygen a lot, it can make a wonderful and complete documentation of the source code, including this crosslinking source code navigation. It can optionally use another tool called htags to include the source code with this crosslinking navigation (instead of its own system). And this little tool attracted my attention...htags. It is an extremely simple and fast yet powerful tool that can generate HTML crosslinked documentation from source code.

If you have a Linux (or other *nix), you can simply install htags with a package manager, the whole package where it belongs is global. If you use Windows, you can download global from this site. There are other binaries in the download page of global.

With htags you can go to the source code root directory, write:

htags -g

...and that's all! You have your browsable crosslinked HTML documentation in a directory called HTML. I have tested it with Java files, but it supports other languages as well (C, C++, Yacc, PHP and Assembler).

If you want more features (like class diagrams, Javadoc-style complementary documentation, more flexibility with configuration, etc.), you can use Doxygen. It also supports more languages (C++, C, Java, Objective-C, Python, IDL, Fortran, VHDL, PHP, C#, and to some extent D). But if you only need plain source code with syntax highlighting and crosslinked navigation, give htags a try!

2008/11/08

Calling Eclipse Ant builds from the command line

I usually use Eclipse for my software projects and I wanted to do Continuous Integration (CI), so after choosing a CI tool (I chose Hudson, a very powerful yet easy to use tool) I decided to make an Ant build file from my sample Eclipse project.

Even if you only want to make a very simple Ant task, like compiling and JUnit testing, a difficult problem will arise: the classpath. An Eclipse project can have a complex classpath, full of variable references (which are defined in the Preferences of your workspace), references to other projects, and so on. There are some Eclipse ant tasks in Eclipse itself that may be added, like projectBuild, and they take into account the classpath defined in the project, but when you try to add a JUnit task, you have to specify the classpath by hand in the task parameter. This classpath creation is tedious and time-consuming.

I thought it should be easier the creation of an Ant build from an Eclipse project, because the classpath information is in the .classpath project file. After googling a little, I found this great Eclipse Plugin, called eclipse2ant, which "tries to create a buildfile that matches the Eclipse project as close as possible". And it really works. I could very easily create an Ant build file from my Eclipse project, with the usual targets of compilation and it also exported my last JUnit runs! (the ones that you see in the "Run history..." menu of Eclipse).

All the classpath variables were imported in the Ant file, and I could execute the tests of my project without problems with Eclipse closed. Of course, you may want to tweak a little bit the Ant file to make it more portable or to organize better the variables, but with eclipse2ant you have a very good starting point that saves you a lot of time!

Happy continuous integration!