简体   繁体   中英

MeasureComputer extensions not called in SonarQube plugin

I am trying to develop a SonarQube plugin.I have configured and installed SonarQube 5.3 and I am using SonarQube Scanner 2.5 launcher to analyze a project with SonarQube.I have done a sample with a class RandomMeasureComputer implementing MeasureComputer to aggregate measures.

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();
}
}

I have also added this class in the method 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;
}
}

But when I try to analyze a project with my SonarQube plugin I am not getting a call inside RandomMeasureComputer class.

I went through http://docs.sonarqube.org/display/DEV/Developing+Plugins but I am not sure what I have missed .Please help me with that.

Since SonarQube 5.2, project analyses trigger a Background Task on the server side. Measure Computer are executed within this server-side task, which explains why you don't see your class called on the client side (where the analysis is ran).

For debugging on the server side, from Julien L. contribution:

Yes, it's possible to debug a MeasureComputer class. For that you need to put the server in DEBUG : set the following parameter in the sonar.properties file : sonar.web.javaAdditionalOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend‌​=n,address=8001

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM