Hi Simon,
I am working on this sonar plugin which I want to collect the svn url and svn checksum for each java source file in the project and store it as a measure in sonar. I have a question about how to use the Sensor extension point.
My project consists of 3 parts
1. An application called "svninfo".
This standalone java application traverses the directory of an svn working copy and generates an "svninfo.xml" file with details of each file in the directory.
The output xml file has the following format
<info>
<entry>
<kind>file</kind>
<path>/home/cmoraes/code/dev/sonar/test-project-sonar/src/main/java/com/symcor/sonar/test/SVNTest.java</path>
<url>svn://localhost/repos/repo1/trunk/test-project-sonar/src/main/java/com/symcor/sonar/test/SVNTest.java</url>
<checksum>42e6d5c210e09a4f9f3206da750f068c</checksum>
<rev>14</rev>
</entry>
<entry>
<kind>file</kind>
<path>/home/cmoraes/code/dev/sonar/test-project-sonar/src/main/java/com/symcor/sonar/test/Sample.java</path>
<url>svn://localhost/repos/repo1/trunk/test-project-sonar/src/main/java/com/symcor/sonar/test/Sample.java</url>
<checksum>63d34b14bb2b093a7202cbcf4952208c</checksum>
<rev>14</rev>
</entry>
</info>
2. A "maven-svninfo-plugin" - that invokes the svninfo application with the project source directory as the parameter. This plugin is invoked as "mvn svninfo:svninfo".
3. The sonar-plugin-svninfo.
I want this plugin to invoke the maven-svinfo-plugin, read the output xml file generated, and then store the svn url and checksum for each source file in the project - in a measure.
I have gone through the sonar sources for checkstyle and squid, and I have created the
i) Plugin class
ii) MavenPluginHandler class
I'm not sure what should be done in the Sensor class. I know I can read the svninfo.xml file in the analyse() method, but am not sure how I should store these as measures, as you've suggested below. I guess I need one measure per file (in the source)?
In the example you gave below, is the parameter "myfile" any string that identifies a file? Would the following be correct ?
myfile = "com.symcor.sonar.test.Sample.java";
Would appreciate if you could explain this.
Thanks and regards,
Chris
On Wed, Oct 28, 2009 at 8:19 AM, Simon Brandhof
<[hidden email]> wrote:
Can I use this Metric at a source file level or is this only one metric per project? I would like to store the svn checksum and svn url for each file in the source tree.
Indeed you can save this measure on files only.
Example :
Metric SCM_URL = new Metric("scm_url", "SCM URL", "SCM URL", Metric.ValueType.DATA, Metric.DIRECTION_NONE, false, null);
measure=new Measure(SCM_URL, "svn:....");
sensorContext.saveMeasure(myFile, measure);