java 传参给groovy_如何将空值从Groovy传递给带有类型为接口的参数的Java方法?

我正在尝试使用Groovy在Jenkins中编写插件的配置脚本。某些插件(例如GitHub Pull Request

Builder插件)并未提供任何简单的方法来在Jenkins

Web界面(使用名为Stapler的库将HTML表单绑定到对象实例)之外配置插件。

`Stabl

但是,我不能说服Groovy强迫null或NullObject作为的第一个论点configure(request, formData)。

Groovy可以这样做吗?

import org.codehaus.groovy.runtime.NullObject

def descriptor = org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl

net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject() as net.sf.json.JSONObject;

org.kohsuke.stapler.StaplerRequest stapler = NullObject as org.kohsuke.stapler.StaplerRequest

println ("Is it a stapler request? ${stapler instanceof org.kohsuke.stapler.StaplerRequest}.")

println descriptor.configure(stapler, jsonObject)

输出:

Is it a stapler request? true.

groovy.lang.MissingMethodException: No signature of method: static org.jenkinsci.plugins.ghprb.GhprbTrigger$DescriptorImpl.configure() is applicable for argument types: (Class_delegateProxy, net.sf.json.JSONObject) values: [Class_delegateProxy@31433174, [:]]

Possible solutions: configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject), configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject), configure(org.kohsuke.stapler.StaplerRequest)

更新资料

因此,詹金斯(Jenkins)的API可能非常复杂,有时并不明显。我对静态DescriptorImpl类型的引用是错误的。我仍然很想知道以上原因为何失败。

def descriptor = jenkins.model.Jenkins.getInstance().getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)

//def plugin = org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl

net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject();

org.kohsuke.stapler.StaplerRequest stapler = null

println ("Is it a stapler request? ${stapler instanceof org.kohsuke.stapler.StaplerRequest}.")

jsonObject.put("serverAPIUrl", "https://api.github.com");

jsonObject.put("username", "user");

jsonObject.put("password", "1111");

jsonObject.put("accessToken", "accessToken");

jsonObject.put("adminlist", "user");

jsonObject.put("allowMembersOfWhitelistedOrgsAsAdmin", "false");

jsonObject.put("publishedURL", "");

jsonObject.put("requestForTestingPhrase", "test this");

jsonObject.put("whitelistPhrase", "");

jsonObject.put("okToTestPhrase", "ok to test");

jsonObject.put("retestPhrase", "retest this please");

jsonObject.put("skipBuildPhrase", "[skip ci]");

jsonObject.put("cron", "*/1 * * * *");

jsonObject.put("useComments", "true");

jsonObject.put("logExcerptLines", "0");

jsonObject.put("unstableAs", "");

jsonObject.put("testMode", "true");

jsonObject.put("autoCloseFailedPullRequests", "false");

jsonObject.put("msgSuccess", "Success");

jsonObject.put("msgFailure", "Failure");

println descriptor.configure(stapler, jsonObject)

输出量

Is it a stapler request? false.

true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值