You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Chris Adams <ch...@edatasource.com> on 2012/04/10 05:38:18 UTC

Buildr + Checkstyle

Hi,

I am trying to integrate checkstyle with builder. Thus far, this is what I have come up with:
    task :checkstyle do
        begin
            ant('checkstyle') do |ant|
                rm_rf 'reports/checkstyle_report.xml'
                mkdir_p 'reports'
                
                ant.taskdef :resource=>"checkstyletask.properties", :classpath=>Buildr.artifacts(CHECKSTYLE).each(&:invoke).map(&:name).join(File::PATH_SEPARATOR)
                ant.checkstyle :config=>"buildconf/checkstyle.xml" do
                    ant.formatter :type=>'plain'
                    ant.formatter :type=>'xml', :toFile=>"reports/checkstyle_report.xml"
                    
                    ant.property :key=>'javadoc.method.scope', :value=>'public'
                    ant.property :key=>'javadoc.type.scope', :value=>'package'
                    ant.property :key=>'javadoc.var.scope', :value=>'package'
                    ant.property :key=>'javadoc.lazy', :value=>'false'
                    
                    ant.fileset :dir=>path_to(:src,:main,:java), :includes=>'**/*.java'
                end
            end
        end
    end   

However, the problem I'm having is that path_to(:src, :main, :java) is at the top-level parent directory (where my buildfile is located)… How would I make the ":dir" relative to the current sub-project that the user is within or if they are building from the root, all the sub-projects?

Thanks for any help/info you can provide.

Chris Adams





Re: Buildr + Checkstyle

Posted by "Jesus M. Rodriguez" <jm...@gmail.com>.
We put our checkstyle task in a separate file: buildr/checkstyle.rb

http://bit.ly/HVG1G2

And it's a simple call in our buildfile

http://bit.ly/Hx7kcT

As you can see we just specified the directory directly.


Sincerely,
jesus rodriguez


On Mon, Apr 9, 2012 at 11:38 PM, Chris Adams <ch...@edatasource.com> wrote:
> Hi,
>
> I am trying to integrate checkstyle with builder. Thus far, this is what I have come up with:
>    task :checkstyle do
>        begin
>            ant('checkstyle') do |ant|
>                rm_rf 'reports/checkstyle_report.xml'
>                mkdir_p 'reports'
>
>                ant.taskdef :resource=>"checkstyletask.properties", :classpath=>Buildr.artifacts(CHECKSTYLE).each(&:invoke).map(&:name).join(File::PATH_SEPARATOR)
>                ant.checkstyle :config=>"buildconf/checkstyle.xml" do
>                    ant.formatter :type=>'plain'
>                    ant.formatter :type=>'xml', :toFile=>"reports/checkstyle_report.xml"
>
>                    ant.property :key=>'javadoc.method.scope', :value=>'public'
>                    ant.property :key=>'javadoc.type.scope', :value=>'package'
>                    ant.property :key=>'javadoc.var.scope', :value=>'package'
>                    ant.property :key=>'javadoc.lazy', :value=>'false'
>
>                    ant.fileset :dir=>path_to(:src,:main,:java), :includes=>'**/*.java'
>                end
>            end
>        end
>    end
>
> However, the problem I'm having is that path_to(:src, :main, :java) is at the top-level parent directory (where my buildfile is located)… How would I make the ":dir" relative to the current sub-project that the user is within or if they are building from the root, all the sub-projects?
>
> Thanks for any help/info you can provide.
>
> Chris Adams
>
>
>
>

Re: Buildr + Addon

Posted by Peter Donald <pe...@realityforge.org>.
On Wed, Apr 11, 2012 at 3:19 AM, Chris Adams <ch...@edatasource.com> wrote:
> Thanks Peter,
>
> So, I'm trying to do it slightly different, but what I've done is the following:
>
> 1. Downloaded the findbugs.rb add-on
> 2. Put the add-on into a subfolder within my project ('buildconf/modules/findbugs.rb')
> 3. Updated my buildfile.rb to include 'require 'buildconf/modules/findbugs'
>
> However, when I execute 'builder findbugs:html' I get the error 'Don't know how to build task 'findbugs:html'.  I have also tried executing 'builder findbugs' same result.
>
> Sorry for my ignorance in this matter.

No problem - it is actually my fault for not documenting it properly.
You need to explicitly enable the plugin and you (may?) need to
configure some paths etc. Heres an example from one of my top level
projects. HTHs

project X do
...
  findbugs.enabled = true
  findbugs.config_directory = _('planner/etc/findbugs')
  findbugs.source_paths << project('planner:shared')._(:source, :main, :java)
  findbugs.source_paths << project('planner:client')._(:source, :main, :java)
  findbugs.source_paths << project('planner:server')._(:source, :main, :java)
  findbugs.analyze_paths << project('planner:shared').compile.target
  findbugs.analyze_paths << project('planner:client').compile.target
  findbugs.analyze_paths << project('planner:server').compile.target
  findbugs.extra_dependencies << project('planner:shared').compile.dependencies
  findbugs.extra_dependencies << project('planner:client').compile.dependencies
  findbugs.extra_dependencies << project('planner:server').compile.dependencies
end

-- 
Cheers,

Peter Donald

Re: Buildr + Addon

Posted by Chris Adams <ch...@edatasource.com>.
Thanks Peter,

So, I'm trying to do it slightly different, but what I've done is the following:

1. Downloaded the findbugs.rb add-on
2. Put the add-on into a subfolder within my project ('buildconf/modules/findbugs.rb')
3. Updated my buildfile.rb to include 'require 'buildconf/modules/findbugs'

However, when I execute 'builder findbugs:html' I get the error 'Don't know how to build task 'findbugs:html'.  I have also tried executing 'builder findbugs' same result.

Sorry for my ignorance in this matter.

- Chris


On Apr 9, 2012, at 10:52 PM, Peter Donald wrote:

> Hi,
> 
> In the next release of buildr (not sure when that is happening?)
> there will be checkstyle support baked in (as well as findbugs,
> jdepend, pmd etc). You can see the next set of addons in [1] and the
> checkstyle one in particular is [2]. You can rename [2] to end with
> .rake and drop it in a tasks directory and start using it straight
> away. In one of our projects we have something like
> 
> 
> project ... do
> 
>  checkstyle.config_directory = _('planner/etc/checkstyle')
>  checkstyle.source_paths << project('planner:shared')._(:source, :main, :java)
>  checkstyle.source_paths << project('planner:client')._(:source, :main, :java)
>  checkstyle.source_paths << project('planner:client')._(:test, :main, :java)
>  checkstyle.source_paths << project('planner:server')._(:source, :main, :java)
>  checkstyle.source_paths << project('planner:server')._(:test, :main, :java)
> end
> 
> 
> [1] https://github.com/apache/buildr/tree/trunk/addon/buildr
> [2] https://github.com/apache/buildr/blob/trunk/addon/buildr/checkstyle.rb
> 
> On Tue, Apr 10, 2012 at 1:38 PM, Chris Adams <ch...@edatasource.com> wrote:
>> Hi,
>> 
>> I am trying to integrate checkstyle with builder. Thus far, this is what I have come up with:
>>    task :checkstyle do
>>        begin
>>            ant('checkstyle') do |ant|
>>                rm_rf 'reports/checkstyle_report.xml'
>>                mkdir_p 'reports'
>> 
>>                ant.taskdef :resource=>"checkstyletask.properties", :classpath=>Buildr.artifacts(CHECKSTYLE).each(&:invoke).map(&:name).join(File::PATH_SEPARATOR)
>>                ant.checkstyle :config=>"buildconf/checkstyle.xml" do
>>                    ant.formatter :type=>'plain'
>>                    ant.formatter :type=>'xml', :toFile=>"reports/checkstyle_report.xml"
>> 
>>                    ant.property :key=>'javadoc.method.scope', :value=>'public'
>>                    ant.property :key=>'javadoc.type.scope', :value=>'package'
>>                    ant.property :key=>'javadoc.var.scope', :value=>'package'
>>                    ant.property :key=>'javadoc.lazy', :value=>'false'
>> 
>>                    ant.fileset :dir=>path_to(:src,:main,:java), :includes=>'**/*.java'
>>                end
>>            end
>>        end
>>    end
>> 
>> However, the problem I'm having is that path_to(:src, :main, :java) is at the top-level parent directory (where my buildfile is located)… How would I make the ":dir" relative to the current sub-project that the user is within or if they are building from the root, all the sub-projects?
>> 
>> Thanks for any help/info you can provide.
>> 
>> Chris Adams
>> 
>> 
>> 
>> 
> 
> 
> 
> -- 
> Cheers,
> 
> Peter Donald


Re: Buildr + Checkstyle

Posted by Peter Donald <pe...@realityforge.org>.
Hi,

In the next release of buildr (not sure when that is happening?)
there will be checkstyle support baked in (as well as findbugs,
jdepend, pmd etc). You can see the next set of addons in [1] and the
checkstyle one in particular is [2]. You can rename [2] to end with
.rake and drop it in a tasks directory and start using it straight
away. In one of our projects we have something like


project ... do

  checkstyle.config_directory = _('planner/etc/checkstyle')
  checkstyle.source_paths << project('planner:shared')._(:source, :main, :java)
  checkstyle.source_paths << project('planner:client')._(:source, :main, :java)
  checkstyle.source_paths << project('planner:client')._(:test, :main, :java)
  checkstyle.source_paths << project('planner:server')._(:source, :main, :java)
  checkstyle.source_paths << project('planner:server')._(:test, :main, :java)
end


[1] https://github.com/apache/buildr/tree/trunk/addon/buildr
[2] https://github.com/apache/buildr/blob/trunk/addon/buildr/checkstyle.rb

On Tue, Apr 10, 2012 at 1:38 PM, Chris Adams <ch...@edatasource.com> wrote:
> Hi,
>
> I am trying to integrate checkstyle with builder. Thus far, this is what I have come up with:
>    task :checkstyle do
>        begin
>            ant('checkstyle') do |ant|
>                rm_rf 'reports/checkstyle_report.xml'
>                mkdir_p 'reports'
>
>                ant.taskdef :resource=>"checkstyletask.properties", :classpath=>Buildr.artifacts(CHECKSTYLE).each(&:invoke).map(&:name).join(File::PATH_SEPARATOR)
>                ant.checkstyle :config=>"buildconf/checkstyle.xml" do
>                    ant.formatter :type=>'plain'
>                    ant.formatter :type=>'xml', :toFile=>"reports/checkstyle_report.xml"
>
>                    ant.property :key=>'javadoc.method.scope', :value=>'public'
>                    ant.property :key=>'javadoc.type.scope', :value=>'package'
>                    ant.property :key=>'javadoc.var.scope', :value=>'package'
>                    ant.property :key=>'javadoc.lazy', :value=>'false'
>
>                    ant.fileset :dir=>path_to(:src,:main,:java), :includes=>'**/*.java'
>                end
>            end
>        end
>    end
>
> However, the problem I'm having is that path_to(:src, :main, :java) is at the top-level parent directory (where my buildfile is located)… How would I make the ":dir" relative to the current sub-project that the user is within or if they are building from the root, all the sub-projects?
>
> Thanks for any help/info you can provide.
>
> Chris Adams
>
>
>
>



-- 
Cheers,

Peter Donald