Version control for the solo programmer

You know the situation:you’re the only programmer on what is supposed to be a very small project. So small, it seems overkill to install a version control server. And it’s too much trouble to install the server software on your workstation.

So you start working in a local folder without version control. But soon enough you wish you’d used version control. Maybe because you’d like to read your old commit logs to find out why you made that change some weeks ago. Or maybe because you wish you’d be able to undo that change that didn’t really fix the problem.

Today i was reading up on some of the new distributed version control systems, where every developer can have his own repository. Dave Dribin has written some interesting posts comparing Git, Mercurial and Bazaar: Choosing a Distributed Version Control System and Why I Chose Mercurial.

I used to think that distributed version control systems were mostly useful for very large projects, with large numbers of developers. But creating a local repository with mercurial is so easy, you don’t even have to install some server repository process, that it’s also ideal for solo programmers. Basically you just create a folder for your sources, initialize it for version control, and now you have a version controlled project.

You can download the windows version of Mercurial (or Hg as it’s also called) here: Mercurial binary packages for Windows and Mac OS X. There are also versions available that include Tortoise for Hg.

Run the installer, and then open a command prompt. Create a folder for your project and initialize it for Mercurial:

> mkdir myproject
> cd myproject
> hg init

Mercurial will create a .hg folder where it will store all version information. You can now add and commit files like you’re used to with any other version control system. For example:

> notepad readme.txt
> hg add readme.txt
> hg commit -m "Initial release"

There’s no excuse not to use version control on every project! For more information on Mercurial you can start here: Mercurial Quickstart, and Distributed revision control with Mercurial (book).

Creating a simple SCA component

SCA is a relative new technology that’s bound to take off next year. The apache Tuscany project released the 1.0 version of the java implementation in September, and Oracle will include it in the upcoming SOA Suite 11. Time for some research into this technology.

In the following example I’m using version 1.0.1 of Apache Tuscany. You can download it from the Tuscany website.

First step will be to implement a service component which consist of one service. The component endpoint will be exposed as a web service. First the service. The service consists of an interface and an implementation. The interface:

package nl.iteye.patient;

import org.osoa.sca.annotations.Remotable;
import org.osoa.sca.annotations.Service;

@Remotable
public interface PatientService {

    public String ping(String message);
}

The Remotable annotation indicates that is a service which can be called remotely. The implementation is as follows:

package nl.iteye.patient;

import org.osoa.sca.annotations.Service;

@Service(PatientService.class)
public class PatientServiceImpl implements PatientService {
    public PatientServiceImpl() {
    }

    public String ping(String message) {
        System.out.println("received ping request: " + message);
        return "hello: " + message;
    }
}

Just a simple ping as you can see. The Service annotation indicates that this is the implementation of the previously defined remotable interface.

Next I have to define a Service Component in a composite configuration file. A composite can actually consist of a large number of components, including java services, bpel processes, etc. You use the composite configuration file to wire all these components together. This enables you to created coarse grained SOA modules, which also makes management and deployment easier than having all these components as separate deployables. Back to the configuration file, here it is:

< ?xml version="1.0" encoding="windows-1252" ?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
           targetNamespace="http://patient.iteye.nl" xmlns:pws="http://patient.iteye.nl"
           name="patient">
    <component name="PatientServiceComponent">
        <implementation .java class="nl.iteye.patient.PatientServiceImpl"/>
        <service name="PatientService">
            <interface .java interface="nl.iteye.patient.PatientService"/>
            <binding .ws/>
        </service>
    </component>
</composite>

That’s it. You now have a composite application consisting of one service which is exposed as a web service.

To test the application I created the following unit test:

package tests.nl.iteye.patient;

import java.io.IOException;
import junit.framework.TestCase;
import nl.iteye.patient.PatientService;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.junit.Test;

public class ScaContainerStarterTestCase extends TestCase {
    public ScaContainerStarterTestCase() { }

    @Test
    public void testPing() throws IOException {

        SCADomain scaDomain;
        scaDomain = SCADomain.newInstance("patient.composite");
        PatientService patSvc =
            scaDomain.getService(PatientService.class, "PatientServiceComponent");
        String result = patSvc.ping("hello world!");
        System.out.println("result: " + result);
        scaDomain.close();
    }

}

To build the project I used the following maven pom.xml:

< ?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelversion>4.0.0</modelversion>
    <parent>
        <groupid>nl.iteye</groupid>
        <artifactid>patient-example</artifactid>
        <version>1.0-SNAPSHOT</version>
        <relativepath>../pom.xml</relativepath>
    </parent>
    <repositories>
        <repository>
            <id>apache.incubator</id>
            <url>http://people.apache.org/repo/m2-incubating-repository</url>
        </repository>
    </repositories>
    <artifactid>patient-service</artifactid>
    <name>Patient Service</name>
    <dependencies>
        <dependency>
            <groupid>org.apache.tuscany.sca</groupid>
            <artifactid>tuscany-host-embedded</artifactid>
            <version>1.0.1-incubating</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupid>org.apache.tuscany.sca</groupid>
            <artifactid>tuscany-implementation-java-runtime</artifactid>
            <version>1.0.1-incubating</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupid>org.apache.tuscany.sca</groupid>
            <artifactid>tuscany-binding-ws-axis2</artifactid>
            <version>1.0.1-incubating</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupid>org.apache.tuscany.sca</groupid>
            <artifactid>tuscany-host-jetty</artifactid>
            <version>1.0.1-incubating</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupid>org.apache.derby</groupid>
            <artifactid>derby</artifactid>
            <version>10.3.1.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupid>junit</groupid>
            <artifactid>junit</artifactid>
            <version>4.4</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <finalname>${artifactId}</finalname>
    </build>
</project>

As you can see in the pom, i have a parent project. The current project implements a service, in another project i will implement a client application. So to sum up, the service project contains the following files:

Service project files

Please ignore PatientDbInstaller.java, ScaContainerStarter.java (we’ll come to this later), build.cmd (i use this to run maven), and patient-service.jpr (this is the jdeveloper project file).

Now when you run maven (mvn clean package), it will compile and package the composite application and it will also run your test class. The output (just the test part) should be something like:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running tests.nl.iteye.patient.ScaContainerStarterTestCase
Dec 19, 2007 2:06:31 PM org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping
INFO: Added Servlet mapping: http://localhost:8085/PatientServiceComponent
received ping request: hello world!
result: hello: hello world!

When you create a sca domain, the jetty web container is started to host the web service. Now you can invoke the webservices in your composite application.

Another way to test the application is to start your composite application and test it by calling the webservice, for example using soapUI. Start your application as follows:

package nl.iteye.patient;

import org.apache.tuscany.sca.host.embedded.SCADomain;

public class ScaContainerStarter {
    public ScaContainerStarter() {
        try {
            SCADomain scaDomain;

            scaDomain = SCADomain.newInstance("patient.composite");
            System.in.read();
            scaDomain.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ScaContainerStarter scaContainerStarter = new ScaContainerStarter();
    }
}

When you run this you should be able to open the wsdl of your application at http://localhost:8085/PatientServiceComponent?wsdl. Open the wsdl in soapUI and it will create a request for you which you can execute to invoke the web service. The result should look like this:

Composite service soapUI test

One warning, i noticed that you may get some weird exceptions when using the wrong classpath. When you download the binary version of tuscany SCA, you’ll notice a large number of jars in the directories lib and modules. Don’t put every jar on your classpath. It’s enough to include tuscany-sca-manifest.jar in the lib folder. When i included the jars in the modules folder i got some null pointer and classcast exceptions.

Oracle Vm

Today oracle announced Oracle VM (Data sheet), a server virtualization product. According to what i’ve read it’s based on Xen. This shouldn’t be a big surprise as RedHat Enterprise Linux 5 includes Xen, and Oracle’s Linux is, let’s put this nicely, based on RedHat Enterprise Linux.

The good news is that Oracle is supporting their products in virtualized servers. In the past we’ve had problems getting support for vmware based virtual servers. At least now we have a supported solution, which makes it a lot easier to roll out virtual environments.

The Oracle VM FAQ contains some surprising info. For one, Oracle claims that their virtualization product is three times more efficient than existing x86 server virtualizing products. This means that they’ve been improving Xen, as i thought that vmware had a better performance than Xen.

Oracle VM also supports moving live virtual machine from one physical host to another. I didn’t know Xen could do this, but Xen’s wiki page tells me differently.

More info, and a screenshot of the management console on Rittman’s blog.

Update:
Xen in Oracle Enterprise Linux must be different from Oracle VM, as virtualization is only supported for products running on Oracle VM. Running Oracle RDBMS, Oracle Application Server or any of the other products on Xen in Oracle Enterprise Linux isn’t supported. Weird. Do you think that there is a reason why these products could be supported when running on Oracle Enterprise Linux as a virtualization host?

Btw, the Oracle VM press release confirms that Oracle VM is based on Xen. Which makes you think, what did Citrix buy?

Here’s a screenshot of the Oracle VM manager interface taken from the Data sheet:
Oracle VM manager

Another thing i just noticed: Oracle Application Server is supported on Oracle VM, but Oracle SOA Suite isn’t included in the list of supported software.

Another update
Here’s another good writeup about Oracle VM: Path Shuf on Oracle VM.

A database in your browser

Surfin’ Safari is writing about a new HTML 5 feature just implemented in WebKit, the core of Safari: Client-side database storage. It enables you to create a database on the client, and execute sql statements in javascript.
I guess it’s now up to Firefox to have an even better implementation. A distributed database by opening multiple tabs, Firefox RAC.

Developing Resolution Independent Java Applications

Most applications aren’t resolution independent. This causes really irritating situations. Most of our laptops have 15 inch screens with a resolution of 1920 by 1200 pixels. Hardly readable if you use small fonts. This means you have two options: either you turn on large fonts or you decrease the resolution.

Both solutions are far from perfect. There are many applications (including JDeveloper 10) that can’t handle large fonts, quite often because they don’t allow you to resize a window. And decreasing the resolution makes everything look fuzzy on a lcd monitor. But i still see some people do this, because it keeps your applications usable.

Microsoft Vista en Mac OSX 10.5 have support for resolution independent applications (see for example the images in this article: Windows Vista: more than just a pretty face), so now it’s up to application developers to make sure their applications are also resolution independent.

Resolution Independent GUIs. How to Do It, and How It Looks describes how you can achieve resolution independent Java Swing applications. For look and feel you can use the Substance Look&Feel. Layout can be handled using MigLayout. A tool is also available to test the resolution independence of your Swing applications.

One more browser to test…

I’ll admit, i have never really tested any website i created in safari. I don’t have an Apple computer, and i’ve never seen one at one of our clients. So no testing on apple. I would have, if i could run mac osx in vmware. But apple doesn’t allow you to vitualize mac os x. (With virtualization becoming such a big thing, i think this is a very bad decision by apple. But that’s a different story). But safari’s support for standards is pretty good, so i expect whatever works in firefox also to work in safari. Today apple released a beta of safari for windows, so now we can also test web applications in Safari. My first tests show that Safari still needs some work. The IT-eye website doesn’t work, google portal doesn’t work.

Why do we need another browser on windows? We don’t. But Safari is the runtime container for custom applications on iphone. Which means that developing for iphone will be a bit easier if you have safari running on your development machine. And apple wants developers for iphone, so i guess it’s in their best interest to have safari everywhere. It’s all about developers, developers, developers…

Maven, Ant, Buildr, or what?

Last week Apache released ODE 1.0. ODE is an open source BPEL engine, which supports BPEL 2.0. While browsing the ODE website I noticed that one item on the roadmap mentions migration from maven2 to buildr. I haven’t worked with Maven yet, we are still using Ant on our projects, mostly because it’s a better fit for JDeveloper. Maven has a different folder structure than JDeveloper for projects, which means you have to do some work to make it fit. JDeveloper has support for Ant out of the box, so it’s less effort to use it. But I always thought that at some point we would migrate to Maven.

But recently I’ve noticed projects moving away from Maven. Some people complain that it’s too hard to do non standard stuff. It supposedly it’s also pretty hard to debug when your build isn’t working: Introducing buildr or how we cured our maven blues.

I think maven has three strong benefits: 1) standardization (directory structure, naming, etc), 2) out of the box functionality (documentation generation, etc), and 3) dependency management. But we’ve got all those issues solved in Ant, so there really is no real need to migrate to Maven. Using Ant’s import and macro tasks, I’ve created some default Ant functionality which provides out of the box functionality for new projects, and handles the standardization. Dependency management can be handled using Apache Ivy. So I think I’ll stick with Ant for now, and see how maven and buildr will develop. No need to rush into a new build tool.

Microsoft wants royalties from open source users

Today everybody is talking about this article in fortune: Microsoft takes on the free world. According to Microsoft Linux is violating 235 patents, with the Linux kernel violating 42 Microsoft patents. (Nice number, Douglas Adams would be proud of the linux developers. Maybe Linux is the ultimate answer to everything?) You can find a lot of the reactions on Techmeme.

Im my opinion, software patents have become more or less without value because of the large number of nonsense patents. According to one commenter on Scobleizer, Microsoft about to enter into patent war?:

Royalties are an accepted way to be compensated for your IP…. Doesn’t it seem fair for them to be able to seek compensation for the results achieved from their R&D efforts? It happens in every other industry.

I agree, if someone is using you R&D efforts, it’s fair to be paid. But so many software patents are based on zero R&D efforts, just some people who translated common practice to software. Also, many innovations are thought of by many people at the same time. Which means that they all put in a lot of R&D effort. Why would only one party profit from all this R&D investment? I don’t think a lot of opensource programmers copied Microsoft R&D into Linux, they were just clever enough to think of it themselves. Of course, this is not how the legal world works.

I work mainly with Oracle and Java software, both contain a lot of opensource components. Two thoughts come to mind. One, we’ll finally see what Oracle’s indemnification for Linux is worth. Personally, i find this a very scary sentence in their indemnification document:

Oracle may choose to either modify the material to be non-infringing (while substantially preserving its utility or functionality) or obtain a license to allow for continued use, or if these alternatives are not commercially reasonable, then Oracle may, upon 30 days notice to you terminate your right to receive indemnification for your further use of the materials specified; and refund any prepaid Enterprise Linux support fees you have paid for the covered programs.

So what they are basically saying is that you may get your money back, and not be indemnified at all.

And the second thought is about Mono, the opensource implementation of the Java alternative .Net. How is this impacting them? Many people have warned about using Mono, because they might be exceptionally vulnerable to Microsoft Patent threads. Are any of those 235 patents violated by .Net?

Oracle open sources Toplink

The part of Toplink which implements JPA, Toplink Essentials, was already open source, and part of the JEE 5 reference implementation, but today Oracle announced that it will completely open source Toplink (pressrelease ). Toplink not only implements JPA, it also support JAXB, SDO and JCA, which means that it’s a pretty complete persistency solution. Oracle is also increasing it’s contribution to Eclipse, by joining the board of directors of the Eclipse foundation, and by creating an Eclipse project called Eclipse Persistence Platform based on Toplink (FAQ (pdf)).

What does this mean? That Oracle is still focusing on the open source part of the Java world. They are not converting a lot of java programmers to JDeveloper and ADF, with ADF being tied to JDeveloper. Instead, open source java programmers are targeted through Eclipse, by adding all the Oracle technologies that may interest 3gl java programmers this IDE.

It also means there is less of a barrier to use Toplink extensions on projects. I always prefer to stick to the standards whenever possible. But JPA does have some missing pieces, which Toplink, but also Hibernate, fixes by included some non standard functionality. Support for stored procedures is one example. In the past I’ve hesitated to use these extensions, because it limits you how you can distribute your application. For example, we have a development server virtual appliance we use on most projects, which includes version control, bug database, build server, etc. This is all based on open source, because it allows you to take it to all your customers. Now we can include applications based on Toplink in this vmware machine.