我正在尝试开发 SonarQube (Compute Engine) 插件,我需要使用凭据 (sonar.user // sonar.password) 才能从插件本身调用 Web 服务。
我尝试在 Plugin 类中声明它们的使用,例如:
@Override
public void define(Plugin.Context context) {
...
context.addExtensions(asList(
PropertyDefinition.builder(SONAR_USER)
.name("Sonar user")
.description("SonarQube user")
.onQualifiers(Qualifiers.PROJECT)
.type(PropertyType.STRING)
.defaultValue("admin")
.build()
...
然后在钩子里:
public class Hook implements PostProjectAnalysisTask {
private final Server server;
private final Settings settings;
public Hook(Server server, Settings settings) {
this.server = server;
this.settings = settings;
}
@Override
public void finished(ProjectAnalysis projectAnalysis) {
final HttpConnector httpConnector =
HttpConnector.newBuilder()
.url(server.getURL())
.credentials(
settings.getString(CePlugin.SONAR_USER), // null
settings.getString(CePlugin.SONAR_PASSWORD) // null
).build();
final WsClient wsClient = WsClientFactories.getDefault().newClient(httpConnector);
}
}
但是当我在钩子内注入时Settings
,该属性不可用。
如何检索sonar.user
并sonar.password
调用 Web 服务 API?