martes, 8 de julio de 2008

Working with DWR sources

By now there's no doubt inside the software industry that the Open Source movement is here to stay. And the most valuable asset it provides is *hint* full access to the source code! And it's a shame that not that many people share this perception as for the majority of developers OSS just means free (read gratis) software.

Of course, being free (gratis) is handy characteristic but it should not be one that bothers much to the gross of us, as we work for companies that can afford it anyway. On the contrary, source code should be of interest for you. Let me just list some of the most useful perks:
  • It enables debugging
    Otherwise it becomes a blind and unproductive task. And believe me, the time spent debugging will be worth it.
  • It's the best learning tool any programmer can access
    It's code written by very proficient hackers revolving common but hard to solve problems.
  • It allows customizations
    And I include bug fixes here!
  • It makes you part of a community
    Share your code, discuss problems, hear other viewpoints, propose solutions et al!
IMHO fear is the main reason that prevents many programmers to contribute to the scene. But if you're by now convinced of the utility let me demystify the myths! Just follow with me this step by step tutorial to work with DWR source code :-)

Our first task is gaining access to the source code. DWR as many other projects stores the code in a repository. Beware that repositories are not like open wikis and people have different access rights. Anonymous access is the best we can hope for by now. There are many different server types (SCM), DWR has used CVS in the past but right now uses Subversion. We need to have a client installed to access a SVN repository and I can recommend Tortoise.

The repository is available at http://svn.directwebremoting.org/dwr/. It's huge as it includes all the versions ever released so it's probably better to point to the trunk folder (the latest code is available there) or, may be, branches/Branch_2_0/ (where the the code for the previous version lies).

To download the code to our machine we use the checkout command. The export command can be an option if there's no interest in having later updates. DWR has a page with detailed explanations for this step at their site.

Once we have it there we can explore it a little bit further. There are three important subfolders: core (DWR), serverside (different plugins) and ui (client side code).

There's also there a folder named etc that contains project files for different IDEs (netbeans, eclipse, IDEA). Opening DWR inside an IDE is as easy as navigating to the correct folder and opening the matching project. Opening the project in an IDE has the added benefit of allowing quick debugging of changes and their influence in your application.

Alternatively, DWR can be compiled using Ant (by just typing ant at the top of the hierarchy!). Regardless of the method, the compiled classes are always put in the (automatically) created target folder.

Some projects have an extensive documentation available. DWR does not particularly shine in this area (intentionally many times!) but, at least, things are organized so finding something should be manageable. For example, all the Spring integration classes are available inside the serverside/spring folder and are bound to just one package.

And that's all basically. Some simple steps that have configured DWR inside your workspace and facilitate your development needs. And once it's there nothing prevents you to dive a little and improve the tool ;-)

Happy hacking!