![](/img/trans.png)
[英]Sonarqube - How to exchange data with Compute Engine MeasureComputer implementation from Sensor
[英]MeasureComputer extensions not called in SonarQube plugin
我正在尝试开发SonarQube插件。我已经配置并安装了SonarQube 5.3,我正在使用SonarQube Scanner 2.5启动器来分析SonarQube项目。我已经使用RandomMeasureComputer类实现了MeasureComputer来聚合测量。
public class RandomMeasureComputer implements MeasureComputer {
@Override
public MeasureComputerDefinition define(MeasureComputerDefinitionContext defContext) {
return defContext.newDefinitionBuilder()
.setOutputMetrics(ExampleMetrics.RANDOMMETRIC.getKey())
.build();
}
@Override
public void compute(MeasureComputerContext context) {
// This method is executed on the whole tree of components.
// Bottom-up traversal : files -> directories -> modules -> project
double value;
if (context.getComponent().getType() == Component.Type.FILE) {
// set a random value on files
value = RandomUtils.nextDouble();
} else {
// directory, module or project: sum values of children
value = 0.0;
for (Measure childMeasure : context.getChildrenMeasures(ExampleMetrics.RANDOMMETRIC.getKey())) {
value += childMeasure.getDoubleValue();
}
}
context.addMeasure(ExampleMetrics.RANDOMMETRIC.getKey(), value);
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}
我还在org.sonar.api.SonarPlugin#getExtensions()方法中添加了这个类。
public final class ExamplePlugin extends SonarPlugin {
@Override
public List getExtensions() {
List extensions = new ArrayList();
extensions.addAll(ExampleProperties.definitions());
extensions.add(ExampleMetrics.class);
extensions.addAll(asList(FooLintRulesDefinition.class, FooLintProfile.class, MyCustomJavaRulesDefinition.class));
extensions.addAll(asList(ExampleSensor.class, RandomMeasureComputer.class, IssueSensor.class, ListAllIssuesPostJob.class, FooLintIssuesLoaderSensor.class));
return extensions;
}
}
但是当我尝试使用SonarQube插件分析项目时,我没有在RandomMeasureComputer类中进行调用。
我浏览了http://docs.sonarqube.org/display/DEV/Developing+Plugins,但我不确定我错过了什么。请帮助我。
从SonarQube 5.2开始,项目分析会在服务器端触发后台任务 。 测量计算机在此服务器端任务中执行,这解释了为什么在客户端(运行分析的位置)没有看到调用类的原因。
对于服务器端的调试,来自Julien L.的贡献:
是的,可以调试MeasureComputer类。 为此你需要将服务器放在DEBUG中:在sonar.properties文件中设置以下参数:
sonar.web.javaAdditionalOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.