Another approach you could try is to keep the old descriptor declaration so
that it gets read from disk and then return the new implementation from
readResolve
@Deprecated
public static class DescriptorImpl extends SCMDescriptor<DarcsScm> {
public Object readResolve() {
return new DarcsScmDescriptor(whatEverOldDataYouHad);
}
}
The next time the config is saved it should be with the new descriptor instead
of the old.
Robert Sandell
Software Tools Engineer - SW Environment and Product Configuration
Sony Mobile Communications
> -----Original Message-----
> From: [email protected] [mailto:jenkinsci-
> [email protected]] On Behalf Of Sven Strittmatter
> Sent: den 9 mars 2013 08:42
> To: [email protected]
> Subject: Compatibility Alias for Plugin Config doesn't work
>
> Hello list,
>
> as described in earlier mail, I've moved the descriptor implementation
> of my plugin in an other class:
> org.jenkinsci.plugins.darcs.DarcsScm$DescriptorImpl ->
> org.jenkinsci.plugins.darcs.DarcsScmDescriptor.
>
> Problem is the global configuration file in the HUDSON_HOME:
> org.jenkinsci.plugins.darcs.DarcsScm.xml. This file contains:
> <?xml version='1.0' encoding='UTF-8'?>
> <org.jenkinsci.plugins.darcs.DarcsScm_-DescriptorImpl>
> <generation>1</generation>
> <darcsExe>/usr/local/bin/darcs</darcsExe>
> </org.jenkinsci.plugins.darcs.DarcsScm_-DescriptorImpl>
>
> Which will cause error of course. After reading
> https://wiki.jenkins-ci.org/display/JENKINS/Architecture and talkin on
> IRC I came up with this solution:
>
> public class DarcsScm extends SCM implements Serializable {
> // ...
> @Initializer(before = InitMilestone.PLUGINS_STARTED)
> public static void addAliases() {
> Jenkins.XSTREAM2.addCompatibilityAlias(
> "org.jenkinsci.plugins.darcs.DarcsScm.DescriptorImpl",
> DarcsScmDescriptor.class);
> }
> }
>
> But does not work. Jenkins can not deserialize/load XML with the old
> class in the root tag. Always got this exception:
> Error injecting constructor,
> com.thoughtworks.xstream.mapper.CannotResolveClassException:
> org.jenkinsci.plugins.darcs.DarcsScm$DescriptorImpl :
> org.jenkinsci.plugins.darcs.DarcsScm$DescriptorImpl
> at
> org.jenkinsci.plugins.darcs.DarcsScmDescriptor.<init>(DarcsScmDescripto
> r.java:66)
>
> Full exception here: http://pastebin.com/xbq6BAWV
>
> I've also tried this:
> Jenkins.XSTREAM2.addCompatibilityAlias("org.jenkinsci.plugins.darcs.Dar
> csScm_-DescriptorImpl",
> DarcsScmDescriptor.class);
> Jenkins.XSTREAM2.addCompatibilityAlias("org.jenkinsci.plugins.darcs.Dar
> csScm$DescriptorImpl",
> DarcsScmDescriptor.class);
>
> I've also tried Items.XSTREAM2 and Run.XSTREAM2, albeit kohsuke said
> that I should use Jnekins.XSTREAM2. And I've tried @Initializer(before
> =
> InitMilestone.PLUGINS_LISTED) and @Initializer(before =
> InitMilestone.PLUGINS_PREPARED)
>
> I can circumvent the exception if I add the old descriptor extending
> the
> new one in DarcsScm:
>
> @Deprecated
> public static class DescriptorImpl extends DarcsScmDescriptor {}
>
> But the old config will not be loaded. Then in Jenkins configuration
> site always the default values are displayed.
>
> Can someone please point me out what I'm doing wrong?
>
> Full code available here:
> https://github.com/Weltraumschaf/darcs-
> plugin/blob/master/src/main/java/org/jenkinsci/plugins/darcs/DarcsScm.j
> ava
>
> Kind Regards
> -Sven
> --
> About: https://www.weltraumschaf.de/
--
You received this message because you are subscribed to the Google Groups
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.