SEARCH WEB


Monday 19 September 2011

Issue in Sonar when Analyse with Ant Task


Had you install the Build Stability Plugin in Sonar and try to run the sonar anlayze( http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task) You may Come Across a NullPointerExceptio as below.

build-sonar.xml:56: java.lang.NullPointerException

at org.sonar.plugins.buildstability.BuildStabilitySensor.getCiUrl(BuildStabilitySensor.java:60)

at org.sonar.plugins.buildstability.BuildStabilitySensor.shouldExecuteOnProject(BuildStabilitySensor.java:51)

at org.sonar.api.batch.BatchExtensionDictionnary.shouldKeep(BatchExtensionDictionnary.java:105)

at org.sonar.api.batch.BatchExtensionDictionnary.getFilteredExtensions(BatchExtensionDictionnary.java:95)


To Overcome This you need to define below ant property


<property name="sonar.build-stability.url" value="<ANY String need not to be a Valid URL"/>


I got the same issue last week and was unable to resolve the issue So I jus down load the Code for above plugin and look at it.
This is the actual root cause for this. To integrate sonar with CI Agent using sonar.build-stability.url or CiManagement of pom of the project. Pom is present only if this is a maven project. So if you don't specify the above property then it will try to load CiManagement using POM since ant projets does not have POM this will throw NullPointerException.
CiManagement ci = project.getPom().getCiManagement();


public class BuildStabilitySensor implements Sensor {
..........

..........
..........

public static final String CI_URL_PROPERTY = "sonar.build-stability.url";

..........
..........




protected String getCiUrl(Project project) {

String url = project.getConfiguration().getString(CI_URL_PROPERTY);
if (StringUtils.isNotEmpty(url)) {
return url;
}

CiManagement ci = project.getPom().getCiManagement();
if (ci != null && StringUtils.isNotEmpty(ci.getSystem()) && StringUtils.isNotEmpty(ci.getUrl())) {
return ci.getSystem() + ":" + ci.getUrl();
}
return null;

}