Quantcast

[sonar-dev] Can't get my measure

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

[sonar-dev] Can't get my measure

Janis Kivitis
This post was updated on .
Hi!

While trying to make a plugin to Sonar I have encountered following problem:
I save a measure in analysis if it's not set, but next time it is supposed to be set, but when calling "context.getMeasure(myMetric)" the variable which I assign this measure remains null.
So my question is: Is this is supposed to happen cause it's some kind of security, or am I doing something wrong?

Thanks in advance!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Can't get my measure

Simon Brandhof
Hi,

That's the expected behavior. The objet "context" relates to the current analysis.
Past numeric metrics are available through http://docs.sonarsource.org/3.1/apidocs/index.html?org/sonar/api/batch/TimeMachine.html

Regards
Simon

On 18 June 2012 14:08, Janis Kivitis <[hidden email]> wrote:
Hi!

While trying to make a plugin to Sonar I have encountered following problem:
I save a measure in analysis if it's not set, but next time it is supposed
to be set, but when calling "context.getMeasure(myMetric)" the variable
which I assign this measure is remains null.
So my question is: Is this is supposed to happen cause it's some kind of
security, or am I doing something wrong?

Thanks in advance!

--
View this message in context: http://sonar.15.n6.nabble.com/sonar-dev-Can-t-get-my-measure-tp4999865.html
Sent from the Sonar dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Can't get my measure

Patroklos Papapetrou
In reply to this post by Janis Kivitis
Hi Janis
Regards
Patroklos

2012/6/18 Janis Kivitis <[hidden email]>
Hi!

While trying to make a plugin to Sonar I have encountered following problem:
I save a measure in analysis if it's not set, but next time it is supposed
to be set, but when calling "context.getMeasure(myMetric)" the variable
which I assign this measure is remains null.
So my question is: Is this is supposed to happen cause it's some kind of
security, or am I doing something wrong?

Thanks in advance!

--
View this message in context: http://sonar.15.n6.nabble.com/sonar-dev-Can-t-get-my-measure-tp4999865.html
Sent from the Sonar dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Can't get my measure

Janis Kivitis
My problem is, that I want to store some string measures for some time to compare them, so in some time i don't have to change it. I thought "@dependsUpon" could work fine, but i can't make it working, my variable still is null.
Is this the way I should use dependsUpon ?

@DependsUpon
        public Metric dependsOnFiveDays() {
          return FastTryMetrics.FASTTRY_FIVE_DAYS;
        }
public void decorate(Resource resource, DecoratorContext context) {
       Measure test = context.getMeasure(dependsOnFiveDays());
}

And about TimeMachine, I was sure I could use it, but i wasn't able to find some examples on how to.

Best regards
Janis

Papapetrou P.Patroklos wrote
Hi Janis
I think this thread
http://sonar.15.n6.nabble.com/sonar-dev-help-in-plugin-development-why-some-metrics-of-Sonar-are-empty-tc4999846.html
might help you
Regards
Patroklos

2012/6/18 Janis Kivitis <[hidden email]>

> Hi!
>
> While trying to make a plugin to Sonar I have encountered following
> problem:
> I save a measure in analysis if it's not set, but next time it is supposed
> to be set, but when calling "context.getMeasure(myMetric)" the variable
> which I assign this measure is remains null.
> So my question is: Is this is supposed to happen cause it's some kind of
> security, or am I doing something wrong?
>
> Thanks in advance!
>
> --
> View this message in context:
> http://sonar.15.n6.nabble.com/sonar-dev-Can-t-get-my-measure-tp4999865.html
> Sent from the Sonar dev mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [sonar-dev] Can't get my measure

thomas sermier
Hi Janis, this is not the way to use DependsUpon. You have not to use the dependsOnMethod in the decorate method.
But I think your problem isn't here.

For each crossing in the decorator, the context changes. Your metric can contain as many measures as context. So, the measure you saved must be saved in an other context.
With the resource, you can get the scope. Scopes are : BlockUnit < ProgramUnit < File < directory < Package < project

If you are in a program Unit (a java class), you can get the collection of the measures of the blockUnits (methods) of this class with "context.getChildrenMeasures(YourMetric)". It's the same mechanism for other scopes.

I expect I gave you ways to resolve your problem. The problem is that we don't know precisely your goal in your develoment.

Regards,
Thomas

2012/6/18 Janis Kivitis <[hidden email]>
My problem is, that I want to store some string measures for some time to
compare them, so in some time i don't have to change it. I thought
"@dependsUpon" could work fine, but i can't make it working, my variable
still is null.
Is this the way I should use dependsUpon ?

@DependsUpon
       public Metric dependsOnFiveDays() {
         return FastTryMetrics.FASTTRY_FIVE_DAYS;
       }
public void decorate(Resource resource, DecoratorContext context) {
      Measure test = context.getMeasure(dependsOnFiveDays());
}

And about TimeMachine, I was sure I could use it, but i wasn't able to find
some examples on how to.

Best regards
Janis


Papapetrou P.Patroklos wrote
>
> Hi Janis
> I think this thread
> http://sonar.15.n6.nabble.com/sonar-dev-help-in-plugin-development-why-some-metrics-of-Sonar-are-empty-tc4999846.html
> might help you
> Regards
> Patroklos
>
> 2012/6/18 Janis Kivitis &lt;xkimanx@&gt;
>
>> Hi!
>>
>> While trying to make a plugin to Sonar I have encountered following
>> problem:
>> I save a measure in analysis if it's not set, but next time it is
>> supposed
>> to be set, but when calling "context.getMeasure(myMetric)" the variable
>> which I assign this measure is remains null.
>> So my question is: Is this is supposed to happen cause it's some kind of
>> security, or am I doing something wrong?
>>
>> Thanks in advance!
>>
>> --
>> View this message in context:
>> http://sonar.15.n6.nabble.com/sonar-dev-Can-t-get-my-measure-tp4999865.html
>> Sent from the Sonar dev mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>>
>


--
View this message in context: http://sonar.15.n6.nabble.com/sonar-dev-Can-t-get-my-measure-tp4999865p4999885.html
Sent from the Sonar dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Loading...