Setting measures on Modules

6 messages Options
Embed this post
Permalink
Alexander von Zitzewitz () Setting measures on Modules
Reply Threaded More More options
Print post
Permalink
Hi !

My sensor is working on the root pom and needs to set measures on modules.
(The SonarJ xml report is written on the level of the root pom) I can¹t get
any modules by calling sensorContext.getResource(³groupId:artifactId²), it
always returns null.

But I can find the module over the project:

    private Project findModule(Project mod, String name)
   {
        Project result = null;
        if (mod.getArtifactId().equalsIgnoreCase(name))
        {
            result = mod;
        }
        else
        {
            for (Project child : mod.getModules())
            {
                result = findModule(child, name);
                if (result != null)
                {
                    break;
                }
            }
        }
        return result;
    }

    @SuppressWarnings("unchecked")
    private Resource<Project> findModule(String name)
    {
        Resource result = findModule(project, name);
        if (result != null)
        {
            LOG.info("Key: "+result.getKey());
            //result = sensorContext.getResource(result.getKey());
->null
         }
       
         return result;
    }

But saving measures with the returned resource has no effect. How do I set
measures on modules correctly?

Regards

Alexander von Zitzewitz



www.hello2morrow.com

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327





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

    http://xircles.codehaus.org/manage_email


Simon Brandhof () Re: Setting measures on Modules
Reply Threaded More More options
Print post
Permalink
Hi Alexander,
Sensors have only visibility on the module, not the whole multi-modules project. For example a sensor is executed 3 times in a project with 2 modules.

On the other hand decorators parse the whole tree of resources bottom-up (from classes to packages, modules, root project).

Generally sensors are used to inject core data, consolidated afterwards by decorators. For example a sensor saves the number of lines of java files, then a decorator calculates the sum on packages and modules.

Hope it helps,
Simon


On Thu, Oct 29, 2009 at 12:47 AM, Alexander von Zitzewitz <[hidden email]> wrote:
Hi !

My sensor is working on the root pom and needs to set measures on modules.
(The SonarJ xml report is written on the level of the root pom) I can¹t get
any modules by calling sensorContext.getResource(³groupId:artifactId²), it
always returns null.

But I can find the module over the project:

   private Project findModule(Project mod, String name)
  {
       Project result = null;
       if (mod.getArtifactId().equalsIgnoreCase(name))
       {
           result = mod;
       }
       else
       {
           for (Project child : mod.getModules())
           {
               result = findModule(child, name);
               if (result != null)
               {
                   break;
               }
           }
       }
       return result;
   }

   @SuppressWarnings("unchecked")
   private Resource<Project> findModule(String name)
   {
       Resource result = findModule(project, name);
       if (result != null)
       {
           LOG.info("Key: "+result.getKey());
           //result = sensorContext.getResource(result.getKey());
->null
        }

        return result;
   }

But saving measures with the returned resource has no effect. How do I set
measures on modules correctly?

Regards

Alexander von Zitzewitz



www.hello2morrow.com

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327





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

   http://xircles.codehaus.org/manage_email



Alexander von Zitzewitz () Re: Setting measures on Modules
Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Re: [sonar-dev] Setting measures on Modules Hi Simon !

My problem is, that I have a report with module details only at the root pom level. So now I need my sensor to pass the data to the decorator in some magic way, so that the decorator can save the architecture relevant measurements. Is there an official way to pass data structures between sensors and decorators?

Best regards

Alexander


On 10/29/09 9:49 AM, "Simon Brandhof" <simon.brandhof@...> wrote:

Hi Alexander,
Sensors have only visibility on the module, not the whole multi-modules project. For example a sensor is executed 3 times in a project with 2 modules.

On the other hand decorators parse the whole tree of resources bottom-up (from classes to packages, modules, root project).

Generally sensors are used to inject core data, consolidated afterwards by decorators. For example a sensor saves the number of lines of java files, then a decorator calculates the sum on packages and modules.

Hope it helps,
Simon


On Thu, Oct 29, 2009 at 12:47 AM, Alexander von Zitzewitz <a.zitzewitz@...> wrote:
Hi !

My sensor is working on the root pom and needs to set measures on modules.
(The SonarJ xml report is written on the level of the root pom) I can¹t get
any modules by calling sensorContext.getResource(³groupId:artifactId²), it
always returns null.

But I can find the module over the project:

 ? ?private Project findModule(Project mod, String name)
 ? {
 ? ? ? ?Project result = null;
 ? ? ? ?if (mod.getArtifactId().equalsIgnoreCase(name))
 ? ? ? ?{
 ? ? ? ? ? ?result = mod;
 ? ? ? ?}
 ? ? ? ?else
 ? ? ? ?{
 ? ? ? ? ? ?for (Project child : mod.getModules())
 ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ?result = findModule(child, name);
 ? ? ? ? ? ? ? ?if (result != null)
 ? ? ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ? ? ?break;
 ? ? ? ? ? ? ? ?}
 ? ? ? ? ? ?}
 ? ? ? ?}
 ? ? ? ?return result;
 ? ?}

 ? ?@SuppressWarnings("unchecked")
 ? ?private Resource<Project> findModule(String name)
 ? ?{
 ? ? ? ?Resource result = findModule(project, name);
 ? ? ? ?if (result != null)
 ? ? ? ?{
 ? ? ? ? ? ?LOG.info("Key: "+result.getKey());
 ? ? ? ? ? ?//result = sensorContext.getResource(result.getKey());
->null
 ? ? ? ? }

 ? ? ? ? return result;
 ? ?}

But saving measures with the returned resource has no effect. How do I set
measures on modules correctly?

Regards

Alexander von Zitzewitz



www.hello2morrow.com <http://www.hello2morrow.com>

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327





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

 ? ?http://xircles.codehaus.org/manage_email





Alexander von Zitzewitz



www.hello2morrow.com

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327



Alexander von Zitzewitz () Re: Setting measures on Modules
Reply Threaded More More options
Print post
Permalink
In reply to this post by Simon Brandhof
Some javascript/style in this post has been disabled (why?)
Re: [sonar-dev] Setting measures on Modules Simon,

just found out, that it is not possible to store violations with a decorator context, so the strategy to pass information from the sensor of the root pom to the decorator of the root pom would only work for measures, but not for violations.

It is really a problem, because in a multi-module project it makes sense to look at the architecture from the perspective of the root project t get the whole picture. But unfortunately the report for the root pm is the last one created, so it is not available when the sensors for the modules are running. I am very close to finishing the plugin – but now I am stuck with that problem.

Any idea?

Regards

Alexander



On 10/29/09 9:49 AM, "Simon Brandhof" <simon.brandhof@...> wrote:

Hi Alexander,
Sensors have only visibility on the module, not the whole multi-modules project. For example a sensor is executed 3 times in a project with 2 modules.

On the other hand decorators parse the whole tree of resources bottom-up (from classes to packages, modules, root project).

Generally sensors are used to inject core data, consolidated afterwards by decorators. For example a sensor saves the number of lines of java files, then a decorator calculates the sum on packages and modules.

Hope it helps,
Simon


On Thu, Oct 29, 2009 at 12:47 AM, Alexander von Zitzewitz <a.zitzewitz@...> wrote:
Hi !

My sensor is working on the root pom and needs to set measures on modules.
(The SonarJ xml report is written on the level of the root pom) I can¹t get
any modules by calling sensorContext.getResource(³groupId:artifactId²), it
always returns null.

But I can find the module over the project:

 ? ?private Project findModule(Project mod, String name)
 ? {
 ? ? ? ?Project result = null;
 ? ? ? ?if (mod.getArtifactId().equalsIgnoreCase(name))
 ? ? ? ?{
 ? ? ? ? ? ?result = mod;
 ? ? ? ?}
 ? ? ? ?else
 ? ? ? ?{
 ? ? ? ? ? ?for (Project child : mod.getModules())
 ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ?result = findModule(child, name);
 ? ? ? ? ? ? ? ?if (result != null)
 ? ? ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ? ? ?break;
 ? ? ? ? ? ? ? ?}
 ? ? ? ? ? ?}
 ? ? ? ?}
 ? ? ? ?return result;
 ? ?}

 ? ?@SuppressWarnings("unchecked")
 ? ?private Resource<Project> findModule(String name)
 ? ?{
 ? ? ? ?Resource result = findModule(project, name);
 ? ? ? ?if (result != null)
 ? ? ? ?{
 ? ? ? ? ? ?LOG.info("Key: "+result.getKey());
 ? ? ? ? ? ?//result = sensorContext.getResource(result.getKey());
->null
 ? ? ? ? }

 ? ? ? ? return result;
 ? ?}

But saving measures with the returned resource has no effect. How do I set
measures on modules correctly?

Regards

Alexander von Zitzewitz



www.hello2morrow.com <http://www.hello2morrow.com>

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327





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

 ? ?http://xircles.codehaus.org/manage_email





Alexander von Zitzewitz



www.hello2morrow.com

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327



Alexander von Zitzewitz () Re: Setting measures on Modules
Reply Threaded More More options
Print post
Permalink
In reply to this post by Simon Brandhof
Some javascript/style in this post has been disabled (why?)
Re: [sonar-dev] Setting measures on Modules By reading the code of DefaultDecoratorContext I figured, that it would be quite easy to add saveViolation to the DecoratorContext interface. The DefaultDecoratorContext has access to a sensor context, that supports saving violations.

Then I could pass the data read from the root report to the decorator and save violations and measures associated with the modules.

I don’’t want to do cruel hacks like having to call the root report creation from one of the modules – if this would be even possible...

Or do you have a better idea?

Regards

Alexander

On 10/29/09 9:49 AM, "Simon Brandhof" <simon.brandhof@...> wrote:

Hi Alexander,
Sensors have only visibility on the module, not the whole multi-modules project. For example a sensor is executed 3 times in a project with 2 modules.

On the other hand decorators parse the whole tree of resources bottom-up (from classes to packages, modules, root project).

Generally sensors are used to inject core data, consolidated afterwards by decorators. For example a sensor saves the number of lines of java files, then a decorator calculates the sum on packages and modules.

Hope it helps,
Simon


On Thu, Oct 29, 2009 at 12:47 AM, Alexander von Zitzewitz <a.zitzewitz@...> wrote:
Hi !

My sensor is working on the root pom and needs to set measures on modules.
(The SonarJ xml report is written on the level of the root pom) I can¹t get
any modules by calling sensorContext.getResource(³groupId:artifactId²), it
always returns null.

But I can find the module over the project:

 ? ?private Project findModule(Project mod, String name)
 ? {
 ? ? ? ?Project result = null;
 ? ? ? ?if (mod.getArtifactId().equalsIgnoreCase(name))
 ? ? ? ?{
 ? ? ? ? ? ?result = mod;
 ? ? ? ?}
 ? ? ? ?else
 ? ? ? ?{
 ? ? ? ? ? ?for (Project child : mod.getModules())
 ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ?result = findModule(child, name);
 ? ? ? ? ? ? ? ?if (result != null)
 ? ? ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ? ? ?break;
 ? ? ? ? ? ? ? ?}
 ? ? ? ? ? ?}
 ? ? ? ?}
 ? ? ? ?return result;
 ? ?}

 ? ?@SuppressWarnings("unchecked")
 ? ?private Resource<Project> findModule(String name)
 ? ?{
 ? ? ? ?Resource result = findModule(project, name);
 ? ? ? ?if (result != null)
 ? ? ? ?{
 ? ? ? ? ? ?LOG.info("Key: "+result.getKey());
 ? ? ? ? ? ?//result = sensorContext.getResource(result.getKey());
->null
 ? ? ? ? }

 ? ? ? ? return result;
 ? ?}

But saving measures with the returned resource has no effect. How do I set
measures on modules correctly?

Regards

Alexander von Zitzewitz



www.hello2morrow.com <http://www.hello2morrow.com>

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327





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

 ? ?http://xircles.codehaus.org/manage_email





Alexander von Zitzewitz



www.hello2morrow.com

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327



Olivier Gaudin () Re: Setting measures on Modules
Reply Threaded More More options
Print post
Permalink
Hello Alexander,

I have created SONAR-1247 and associated to 1.12.

Olivier


2009/10/29 Alexander von Zitzewitz <[hidden email]>
By reading the code of DefaultDecoratorContext I figured, that it would be quite easy to add saveViolation to the DecoratorContext interface. The DefaultDecoratorContext has access to a sensor context, that supports saving violations.

Then I could pass the data read from the root report to the decorator and save violations and measures associated with the modules.

I don’’t want to do cruel hacks like having to call the root report creation from one of the modules – if this would be even possible...

Or do you have a better idea?

Regards

Alexander

On 10/29/09 9:49 AM, "Simon Brandhof" <simon.brandhof@...> wrote:

Hi Alexander,
Sensors have only visibility on the module, not the whole multi-modules project. For example a sensor is executed 3 times in a project with 2 modules.

On the other hand decorators parse the whole tree of resources bottom-up (from classes to packages, modules, root project).

Generally sensors are used to inject core data, consolidated afterwards by decorators. For example a sensor saves the number of lines of java files, then a decorator calculates the sum on packages and modules.

Hope it helps,
Simon


On Thu, Oct 29, 2009 at 12:47 AM, Alexander von Zitzewitz <a.zitzewitz@...> wrote:
Hi !

My sensor is working on the root pom and needs to set measures on modules.
(The SonarJ xml report is written on the level of the root pom) I can¹t get
any modules by calling sensorContext.getResource(³groupId:artifactId²), it
always returns null.

But I can find the module over the project:

 ? ?private Project findModule(Project mod, String name)
 ? {
 ? ? ? ?Project result = null;
 ? ? ? ?if (mod.getArtifactId().equalsIgnoreCase(name))
 ? ? ? ?{
 ? ? ? ? ? ?result = mod;
 ? ? ? ?}
 ? ? ? ?else
 ? ? ? ?{
 ? ? ? ? ? ?for (Project child : mod.getModules())
 ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ?result = findModule(child, name);
 ? ? ? ? ? ? ? ?if (result != null)
 ? ? ? ? ? ? ? ?{
 ? ? ? ? ? ? ? ? ? ?break;
 ? ? ? ? ? ? ? ?}
 ? ? ? ? ? ?}
 ? ? ? ?}
 ? ? ? ?return result;
 ? ?}

 ? ?@SuppressWarnings("unchecked")
 ? ?private Resource<Project> findModule(String name)
 ? ?{
 ? ? ? ?Resource result = findModule(project, name);
 ? ? ? ?if (result != null)
 ? ? ? ?{
 ? ? ? ? ? ?LOG.info("Key: "+result.getKey());
 ? ? ? ? ? ?//result = sensorContext.getResource(result.getKey());
->null
 ? ? ? ? }

 ? ? ? ? return result;
 ? ?}

But saving measures with the returned resource has no effect. How do I set
measures on modules correctly?

Regards

Alexander von Zitzewitz



www.hello2morrow.com <http://www.hello2morrow.com>

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327





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

 ? ?http://xircles.codehaus.org/manage_email





Alexander von Zitzewitz



www.hello2morrow.com

SonarJ Elevator Pitch: http://www.hello2morrow.com/videos/benefits

+1 (877) 294-6327