buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject svn commit: r1190713 - in /buildr/trunk: CHANGELOG addon/buildr/pmd.rake doc/more_stuff.textile
Date Sat, 29 Oct 2011 00:28:41 GMT
Author: donaldp
Date: Sat Oct 29 00:28:41 2011
New Revision: 1190713

URL: http://svn.apache.org/viewvc?rev=1190713&view=rev
Log:
Add a PMD extension and some minimalistic documentation

Added:
    buildr/trunk/addon/buildr/pmd.rake
Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/doc/more_stuff.textile

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1190713&r1=1190712&r2=1190713&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Sat Oct 29 00:28:41 2011
@@ -1,6 +1,7 @@
 1.4.7 (Pending)
 * Added:  Add a Checkstyle extension.
 * Added:  Add a JavaNCSS extension.
+* Added:  Add a PMD extension.
 * Change: Parameterize the the directory where the top level cobertura tasks will generate
           reports. Specify using Buildr::Cobertura.report_dir = '....'
 * Fixed:  BUILDR-611 Buildr should not unnecessarily recompile Java files

Added: buildr/trunk/addon/buildr/pmd.rake
URL: http://svn.apache.org/viewvc/buildr/trunk/addon/buildr/pmd.rake?rev=1190713&view=auto
==============================================================================
--- buildr/trunk/addon/buildr/pmd.rake (added)
+++ buildr/trunk/addon/buildr/pmd.rake Sat Oct 29 00:28:41 2011
@@ -0,0 +1,166 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership.  The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+module Buildr
+  # Provides the <code>pmd:rule:xml</code>, <code>pmd:rule:html</code>,
<code>pmd:cpd:xml</code>
+  # and <code>pmd:cpd:html</code> tasks.
+  #
+  # Require explicitly using <code>require "buildr/pmd"</code>.
+  module Pmd
+
+    class << self
+
+      # The specs for requirements
+      def dependencies
+        [
+          'pmd:pmd:jar:4.2.6',
+          'jaxen:jaxen:jar:1.1.1',
+          'asm:asm:jar:3.2'
+        ]
+      end
+
+      def pmd(rule_set_files, format, output_file_prefix, source_paths, options = {})
+        dependencies = (options[:dependencies] || []) + self.dependencies
+        cp = Buildr.artifacts(dependencies).each(&:invoke).map(&:to_s)
+        (options[:rule_set_paths] || []).each {|p| cp << p}
+
+        puts "PMD: Analyzing source code..."
+        mkdir_p File.dirname(output_file_prefix)
+
+        Buildr.ant("pmd-report") do |ant|
+          ant.taskdef :name=> 'pmd', :classpath => cp.join(';'), :classname => 'net.sourceforge.pmd.ant.PMDTask'
+          ant.pmd :shortFilenames => true, :rulesetfiles => rule_set_files.join(',')
do
+            ant.formatter :type => format, :toFile => "#{output_file_prefix}.#{format}"
+            source_paths.each do |src|
+              ant.fileset :dir=> src, :includes=>'**/*.java'
+            end
+          end
+
+        end
+      end
+
+      def cpd(format, output_file_prefix, source_paths, options = {})
+        dependencies = (options[:dependencies] || []) + self.dependencies
+        cp = Buildr.artifacts(dependencies).each(&:invoke).map(&:to_s)
+
+        puts "PMD-CPD: Analyzing source code..."
+        mkdir_p File.dirname(output_file_prefix)
+
+        Buildr.ant("cpd-report") do |ant|
+          ant.taskdef :name=> 'cpd', :classpath => cp.join(';'), :classname => 'net.sourceforge.pmd.cpd.CPDTask'
+          ant.cpd :format => format, :minimumTokenCount => 100, :outputFile => "#{output_file_prefix}.#{format}"
do
+            source_paths.each do |src|
+              ant.fileset :dir=> src, :includes=>'**/*.java'
+            end
+          end
+
+        end
+      end
+    end
+
+    class Config
+
+      def enable
+        @enabled = true
+      end
+
+      def enabled?
+        !!@enabled
+      end
+
+      attr_writer :rule_set_files
+
+      def rule_set_files
+        @rule_set_files || ['basic','imports','unusedcode']
+      end
+
+      attr_writer :rule_set_paths
+
+      def rule_set_paths
+        @rule_set_paths ||= []
+      end
+
+      attr_writer :report_dir
+
+      def report_dir
+        @report_dir || project._(:reports, :pmd)
+      end
+
+      attr_writer :output_file_prefix
+
+      def output_file_prefix
+        @output_file_prefix || "#{self.report_dir}/pmd"
+      end
+
+      attr_writer :cpd_output_file_prefix
+
+      def cpd_output_file_prefix
+        @cpd_output_file_prefix || "#{self.report_dir}/cpd"
+      end
+
+      def source_paths
+        @source_paths ||= [self.project.compile.sources, self.project.test.compile.sources]
+      end
+
+      def flat_source_paths
+        source_paths.flatten.compact
+      end
+
+      protected
+
+      def initialize(project)
+        @project = project
+      end
+
+      attr_reader :project
+    end
+
+    module ProjectExtension
+      include Extension
+
+      def pmd
+        @pmd ||= Buildr::Pmd::Config.new(project)
+      end
+
+      after_define do |project|
+        if project.pmd.enabled?
+          desc "Generate pmd xml report."
+          project.task("pmd:rule:xml") do
+            Buildr::Pmd.pmd(project.pmd.rule_set_files, 'xml', project.pmd.output_file_prefix,
project.pmd.flat_source_paths, :rule_set_paths => project.pmd.rule_set_paths)
+          end
+
+          desc "Generate pmd html report."
+          project.task("pmd:rule:html") do
+            Buildr::Pmd.pmd(project.pmd.rule_set_files, 'html', project.pmd.output_file_prefix,
project.pmd.flat_source_paths, :rule_set_paths => project.pmd.rule_set_paths)
+          end
+
+          desc "Generate pmd cpd xml report."
+          project.task("pmd:cpd:xml") do
+            Buildr::Pmd.cpd('xml', project.pmd.cpd_output_file_prefix, project.pmd.flat_source_paths)
+          end
+
+          desc "Generate pmd cpd text report."
+          project.task("pmd:cpd:text") do
+            Buildr::Pmd.cpd('text', project.pmd.cpd_output_file_prefix, project.pmd.flat_source_paths)
+          end
+        end
+      end
+    end
+  end
+end
+
+class Buildr::Project
+  include Buildr::Pmd::ProjectExtension
+end

Modified: buildr/trunk/doc/more_stuff.textile
URL: http://svn.apache.org/viewvc/buildr/trunk/doc/more_stuff.textile?rev=1190713&r1=1190712&r2=1190713&view=diff
==============================================================================
--- buildr/trunk/doc/more_stuff.textile (original)
+++ buildr/trunk/doc/more_stuff.textile Sat Oct 29 00:28:41 2011
@@ -810,7 +810,7 @@ $ buildr -rbuildr/java/cobertura cobertu
 
 h2(#checkstyle). Checkstyle
 
-Checkstyle is integrated into Buildr through an extension. The extension adds the "checkstyle:xml"
task that generates an xml report listing checkstyle violations and may add a "checkstyle:html"
task if an appropriate xsl is preset. A typical project that uses the extension may look something
like;
+Checkstyle is integrated into Buildr through an extension. The extension adds the "checkstyle:xml"
task that generates an xml report listing checkstyle violations and may add a "checkstyle:html"
task if an appropriate xsl is present. A typical project that uses the extension may look
something like;
 
 {% highlight ruby %}
 require 'buildr/checkstyle'
@@ -835,7 +835,7 @@ If the xsl file named "checkstyle-report
 
 h2(#javancss). JavaNCSS
 
-JavaNCSS is integrated into Buildr through an extension. The extension adds the "javancss:xml"
task that generates an xml report and may add a "javancss:html" task if an appropriate xsl
is preset. A typical project that uses the extension may look something like;
+JavaNCSS is integrated into Buildr through an extension. The extension adds the "javancss:xml"
task that generates an xml report and may add a "javancss:html" task if an appropriate xsl
is present. A typical project that uses the extension may look something like;
 
 {% highlight ruby %}
 require 'buildr/javancss'
@@ -854,7 +854,34 @@ end
 
 The extension will include the source and test directories of the project when invoking the
javancss tool. These can be added to by the parameters "javancss.source_paths".
 
-By default checkstyle will look for all configuration files in the src/main/etc/javancss
directory but this can be overriden by the setting the "javancss.config_directory" parameter.
The "javancss:xml" task will be defined if the "javancss.enabled" property is set to true.
If the xsl file named "javancss2html.xsl" is present in the configuration directory then a
"javancss:html" task will be defined. The name of the xsl file can be overridden by the parameter
"javancss.style_file".
+By default javancss will look for all configuration files in the src/main/etc/javancss directory
but this can be overriden by the setting the "javancss.config_directory" parameter. The "javancss:xml"
task will be defined if the "javancss.enabled" property is set to true. If the xsl file named
"javancss2html.xsl" is present in the configuration directory then a "javancss:html" task
will be defined. The name of the xsl file can be overridden by the parameter "javancss.style_file".
+
+h2(#pmd). PMD
+
+PMD is integrated into Buildr through an extension. The extension adds the "pmd:rule:xml"
and "pmd:rule:html" tasks. A typical project that uses the extension may look something like;
+
+
+{% highlight ruby %}
+require 'buildr/javancss'
+
+define "foo" do
+  project.version = "1.0.0"
+
+  define "bar" do ... end
+
+  pmd.enable
+  pmd.rule_set_paths = _('etc/pmd') + "/"
+  pmd.source_paths << project('bar')._(:source, :main, :java)
+  pmd.rule_set_files = ['basic','imports','unusedcode','logging-java','finalizers']
+
+end
+{% endhighlight %}
+
+The "pmd:rule:xml" task will be defined if the "pmd.enable" method is invoked.
+
+The extension will include the source and test directories of the project when invoking the
pmd tool. These can be added to by the parameters "pmd.source_paths".
+
+By default the pmd rule files 'basic','imports' and 'unusedcode' will be evaluated but this
can be overriden by the "pmd.rule_set_files" parameter. The rule sets will be loaded from
the classpath and this can be added to by modifying the "pmd.rule_set_paths" parameter.
 
 h2(#jaxb_xjc). JAXB Xjc Compiler
 



Mime
View raw message