Jump to: navigation, search

Hint on retaining backward compatibility

Retaining backward compatibility


You decide to extend a class and create new choosable classes, e.g. more browsers for a SCM-plugin. The old data structure looked like this when you had only one class SCMBrowser:



Now you decide to add a new NewSCMBrowser, all your SCMBrowsers are extending SCMBrowserBase and your XML suddenly looks like this:

        <browser class="hudson.plugins.foo.NewSCMBrowser">


        <browser class="hudson.plugins.foo.SCMBrowser">

With new jobs, no problem. Old jobs however will probably break. In your SCMBrowserBase class add a method readResolve (see XStream FAQ):

       // compatibility with earlier plugins
        public Object readResolve() {        
            if (!this.getClass().equals(SCMBrowserBase.class)) {
                return this;
            // make sure to return the default SCMBrowser only if we no class is given in config.
            try {
                return new SCMBrowser(url.toExternalForm());
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);