[sonar-dev] DecoratorContext returns null for SCM measures

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[sonar-dev] DecoratorContext returns null for SCM measures

tlueecke

Hi all,

 

currently I am writing a plugin which tries to reuse the metric measure data from the scmactivity plugin. I wrote a Decorator and added a DependsOn annotation returning the list of Metrics required:

 

    @DependsUpon

    public List<Metric> dependsUponScmMetrics() {

        return Arrays.asList(CoreMetrics.SCM_AUTHORS_BY_LINE, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

    }

 

However, when asking the DecoratorContext for these measures it returns null. I debugged the scmactivity and it definitely saves the Measures. They are also in the DB, but not available for the Decorator which also has a different underlying SonarIndex instance, which only contains some basic metric measures such as public_documented_api, nloc, ...

 

Is there something else I must do? If so, what is the correct approach for obtaining persisted measures? Should I use the DatabaseSession and query for the data, or should I implement a Sensor instead, although I do not create any measures on my own?

 

Thanks and regards,

Tim

 

Versions:

SonarQube Version: 4.0

scmactivity Plugin: 1.6




Firma: Capgemini Deutschland GmbH
Geschäftsführer: Dr. Michael Schulte (Sprecher) • Dr. Uwe Dumslaff • Josef Ranner
Aufsichtsratsvorsitzender: Antonio Schnieder
Amtsgericht Berlin-Charlottenburg, HRB 98814
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] DecoratorContext returns null for SCM measures

Julien HENRY
Hi Tim,

2013/11/19 Lüecke, Tim <[hidden email]>
but not available for the Decorator which also has a different underlying SonarIndex instance

The SonarIndex is the same for all decorators of a given SonarQube module. Can you show us the code you are using to read the measure? If you are trying to read measure for a resource that is not part of the same module, it is expected to be null. For example a parent module (or root module) can't access measures of its child modules.

HTH

Julien
Reply | Threaded
Open this post in threaded view
|

AW: [sonar-dev] DecoratorContext returns null for SCM measures

tlueecke

 

Hi Julien,

 

sure, here is the code:

 

 

public class ScmMetricCollector implements Decorator {

 

    private Map<String, Map<Integer, String>> authorMaps = Maps.newHashMap();

    private Map<String, Map<Integer, Date>> dateTimeMaps = Maps.newHashMap();

 

    @Override

    public boolean shouldExecuteOnProject(Project project) {

        return true;

    }

 

    @Override

    public void decorate(Resource resource, DecoratorContext context) {

        Measure authorPerLineMeasure = context.getMeasure(CoreMetrics.SCM_AUTHORS_BY_LINE);

        Map<Integer, String> authorMap = KeyValueFormat.parseIntString(authorPerLineMeasure.getData());

        authorMaps.put(resource.getEffectiveKey(), authorMap);

        Measure datePerLineMeasure = context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

        Map<Integer, Date> dateTimes = KeyValueFormat.parseIntDateTime(datePerLineMeasure.getData());

        dateTimeMaps.put(resource.getEffectiveKey(), dateTimes);

    }

 

    /**

     * Used to define upstream dependencies

     */

    @DependsUpon

    public List<Metric> dependsUponScmMetrics() {

        return Arrays.asList(CoreMetrics.SCM_AUTHORS_BY_LINE, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

    }

}

 

As far as I can see the context should try to access the measures of the given resource, correct? Is the SonarIndex also the same for sensors and decorators? As far as I could see, it was a different instance for the ScmActivitySensor. 

Thanks and brgds,

Tim

_______________________________________________________________________

Tim Lüecke

Custom Solution Development | Application Services

 

Capgemini | Hamburg

Phone: +49 40 254491 314 – Mobile: +49 151 4025 0183

Fax: +49 40 254491 12 – e-mail: [hidden email]

www.de.capgemini.com


Von: Julien HENRY [[hidden email]]
Gesendet: Dienstag, 19. November 2013 14:40
An: [hidden email]
Betreff: Re: [sonar-dev] DecoratorContext returns null for SCM measures

Hi Tim,

2013/11/19 Lüecke, Tim <[hidden email]>
but not available for the Decorator which also has a different underlying SonarIndex instance

The SonarIndex is the same for all decorators of a given SonarQube module. Can you show us the code you are using to read the measure? If you are trying to read measure for a resource that is not part of the same module, it is expected to be null. For example a parent module (or root module) can't access measures of its child modules.

HTH

Julien



Firma: Capgemini Deutschland GmbH
Geschäftsführer: Dr. Michael Schulte (Sprecher) • Dr. Uwe Dumslaff • Josef Ranner
Aufsichtsratsvorsitzender: Antonio Schnieder
Amtsgericht Berlin-Charlottenburg, HRB 98814
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
Reply | Threaded
Open this post in threaded view
|

Re: [sonar-dev] DecoratorContext returns null for SCM measures

Julien HENRY
Maybe your should try to use ResourceUtils.isFile(resource) in your decorator because SCM_AUTHORS_BY_LINE measure will only be available at file level.


2013/11/19 Lüecke, Tim <[hidden email]>

 

Hi Julien,

 

sure, here is the code:

 

 

public class ScmMetricCollector implements Decorator {

 

    private Map<String, Map<Integer, String>> authorMaps = Maps.newHashMap();

    private Map<String, Map<Integer, Date>> dateTimeMaps = Maps.newHashMap();

 

    @Override

    public boolean shouldExecuteOnProject(Project project) {

        return true;

    }

 

    @Override

    public void decorate(Resource resource, DecoratorContext context) {

        Measure authorPerLineMeasure = context.getMeasure(CoreMetrics.SCM_AUTHORS_BY_LINE);

        Map<Integer, String> authorMap = KeyValueFormat.parseIntString(authorPerLineMeasure.getData());

        authorMaps.put(resource.getEffectiveKey(), authorMap);

        Measure datePerLineMeasure = context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

        Map<Integer, Date> dateTimes = KeyValueFormat.parseIntDateTime(datePerLineMeasure.getData());

        dateTimeMaps.put(resource.getEffectiveKey(), dateTimes);

    }

 

    /**

     * Used to define upstream dependencies

     */

    @DependsUpon

    public List<Metric> dependsUponScmMetrics() {

        return Arrays.asList(CoreMetrics.SCM_AUTHORS_BY_LINE, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

    }

}

 

As far as I can see the context should try to access the measures of the given resource, correct? Is the SonarIndex also the same for sensors and decorators? As far as I could see, it was a different instance for the ScmActivitySensor. 

Thanks and brgds,

Tim

_______________________________________________________________________

Tim Lüecke

Custom Solution Development | Application Services

 

Capgemini | Hamburg

Phone: +49 40 254491 314 – Mobile: +49 151 4025 0183

Fax: +49 40 254491 12 – e-mail: [hidden email]

www.de.capgemini.com


Von: Julien HENRY [[hidden email]]
Gesendet: Dienstag, 19. November 2013 14:40
An: [hidden email]
Betreff: Re: [sonar-dev] DecoratorContext returns null for SCM measures

Hi Tim,

2013/11/19 Lüecke, Tim <[hidden email]>
but not available for the Decorator which also has a different underlying SonarIndex instance

The SonarIndex is the same for all decorators of a given SonarQube module. Can you show us the code you are using to read the measure? If you are trying to read measure for a resource that is not part of the same module, it is expected to be null. For example a parent module (or root module) can't access measures of its child modules.

HTH

Julien



Firma: Capgemini Deutschland GmbH
Geschäftsführer: Dr. Michael Schulte (Sprecher) • Dr. Uwe Dumslaff • Josef Ranner
Aufsichtsratsvorsitzender: Antonio Schnieder
Amtsgericht Berlin-Charlottenburg, HRB 98814
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.

Reply | Threaded
Open this post in threaded view
|

AW: [sonar-dev] DecoratorContext returns null for SCM measures

tlueecke

Great, that was the cue I was missing! Thanks for the help!

 

Regards,

Tim

 


Von: Julien HENRY [[hidden email]]
Gesendet: Dienstag, 19. November 2013 15:36
An: [hidden email]
Betreff: Re: [sonar-dev] DecoratorContext returns null for SCM measures

Maybe your should try to use ResourceUtils.isFile(resource) in your decorator because SCM_AUTHORS_BY_LINE measure will only be available at file level.


2013/11/19 Lüecke, Tim <[hidden email]>

 

Hi Julien,

 

sure, here is the code:

 

 

public class ScmMetricCollector implements Decorator {

 

    private Map<String, Map<Integer, String>> authorMaps = Maps.newHashMap();

    private Map<String, Map<Integer, Date>> dateTimeMaps = Maps.newHashMap();

 

    @Override

    public boolean shouldExecuteOnProject(Project project) {

        return true;

    }

 

    @Override

    public void decorate(Resource resource, DecoratorContext context) {

        Measure authorPerLineMeasure = context.getMeasure(CoreMetrics.SCM_AUTHORS_BY_LINE);

        Map<Integer, String> authorMap = KeyValueFormat.parseIntString(authorPerLineMeasure.getData());

        authorMaps.put(resource.getEffectiveKey(), authorMap);

        Measure datePerLineMeasure = context.getMeasure(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

        Map<Integer, Date> dateTimes = KeyValueFormat.parseIntDateTime(datePerLineMeasure.getData());

        dateTimeMaps.put(resource.getEffectiveKey(), dateTimes);

    }

 

    /**

     * Used to define upstream dependencies

     */

    @DependsUpon

    public List<Metric> dependsUponScmMetrics() {

        return Arrays.asList(CoreMetrics.SCM_AUTHORS_BY_LINE, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);

    }

}

 

As far as I can see the context should try to access the measures of the given resource, correct? Is the SonarIndex also the same for sensors and decorators? As far as I could see, it was a different instance for the ScmActivitySensor. 

Thanks and brgds,

Tim


Von: Julien HENRY [[hidden email]]
Gesendet: Dienstag, 19. November 2013 14:40
An: [hidden email]
Betreff: Re: [sonar-dev] DecoratorContext returns null for SCM measures

Hi Tim,

2013/11/19 Lüecke, Tim <[hidden email]>
but not available for the Decorator which also has a different underlying SonarIndex instance

The SonarIndex is the same for all decorators of a given SonarQube module. Can you show us the code you are using to read the measure? If you are trying to read measure for a resource that is not part of the same module, it is expected to be null. For example a parent module (or root module) can't access measures of its child modules.

HTH

Julien



Firma: Capgemini Deutschland GmbH
Geschäftsführer: Dr. Michael Schulte (Sprecher) • Dr. Uwe Dumslaff • Josef Ranner
Aufsichtsratsvorsitzender: Antonio Schnieder
Amtsgericht Berlin-Charlottenburg, HRB 98814
This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.