29 views
Skip to first unread message

Ivo Bellin Salarin

unread,
Feb 6, 2015, 10:02:32 AM2/6/15
to jenkin...@googlegroups.com
In a class derived from Project
the instruction this.getSCMs().add(gitSCM)
causes the compilation error:
    incompatible types: GitSCM cannot be converted to CAP#1
    where CAP#1 is a fresh type-variable:
    CAP#1 extends SCM frpù capture of ? extends SCM

The object gitSCM is being initialized as follows:
    public void addGitRepo(String url, String branch)
    {
        List<UserRemoteConfig> repoList = new ArrayList<UserRemoteConfig>();
        repoList.add(new UserRemoteConfig(url, null, null, null));
        BranchSpec spec = new BranchSpec(branch);
        ArrayList<BranchSpec> specList = new ArrayList<BranchSpec>();
        specList.add(spec);
        ArrayList<GitSCMExtension> scmExtensions = new ArrayList<GitSCMExtension>();
        scmExtensions.add(new CleanCheckout());
        GitSCM gitSCM = new GitSCM(repoList, specList, false, null, null, "", scmExtensions);
        getSCMs().add(gitSCM);
    }

GitSCM extends GitSCMBackwardsCompatibility, which extends SCM.
getSCMs returns a collection of SCM.
Even if I cast GitSCM to SCM I get the same error.

Why am I getting this error?

Thanks for your attention,
Ivo

Jesse Glick

unread,
Feb 6, 2015, 10:18:41 AM2/6/15
to Jenkins Dev
On Fri, Feb 6, 2015 at 10:02 AM, Ivo Bellin Salarin
<ivo.bell...@gmail.com> wrote:
> Why am I getting this error?

Because https://github.com/jenkinsci/jenkins/blob/17baaf7151fb3dbb5c7c79ac61a3bf2769dd82f6/core/src/main/java/hudson/model/Project.java#L120
is intentionally given a signature which makes it impossible to add
anything to the list without @SuppressWarnings("unchecked") (and even
then you would get an UnsupportedOperationException since the list is
immutable).

If you want this functionality in a freestyle-ish project you must use
multiple-scms-plugin.

Ivo Bellin Salarin

unread,
Feb 6, 2015, 10:27:50 AM2/6/15
to jenkin...@googlegroups.com
Thanks Jesse,

I'm thus using setSCM instead of getSCMs.

--
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 jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0_Vd9a8-7RMenhfb4iC0p4%2Bo%3DmLC92mskzWaGQHjLpMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages