From d3fe51a0b8203fa2ad9e5d2f6f1e347f008a523b Mon Sep 17 00:00:00 2001
From: Kenny Stridh <kenny.stridh@gmail.com>
Date: Tue, 11 Dec 2012 21:20:54 +0100
Subject: [PATCH] GRADLE-2106 - Added target jdk to PMD

---
 .../org/gradle/api/plugins/quality/Pmd.groovy      |    8 +++++++-
 .../gradle/api/plugins/quality/PmdExtension.groovy |    5 +++++
 .../gradle/api/plugins/quality/PmdPlugin.groovy    |    4 +++-
 .../dsl/org.gradle.api.plugins.quality.Pmd.xml     |    4 ++++
 ...org.gradle.api.plugins.quality.PmdExtension.xml |    4 ++++
 5 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/Pmd.groovy b/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/Pmd.groovy
index 57101d2..f079842 100644
--- a/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/Pmd.groovy
+++ b/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/Pmd.groovy
@@ -48,6 +48,12 @@ class Pmd extends SourceTask implements VerificationTask, Reporting<PmdReports>
     List<String> ruleSets
 
     /**
+     * The target jdk to use with pmd
+     */
+    @Input
+    String targetJdk
+
+    /**
      * The custom rule set files to be used. See the <a href="http://pmd.sourceforge.net/howtomakearuleset.html">official documentation</a> for
      * how to author a rule set file.
      *
@@ -78,7 +84,7 @@ class Pmd extends SourceTask implements VerificationTask, Reporting<PmdReports>
     void run() {
         antBuilder.withClasspath(getPmdClasspath()).execute {
             ant.taskdef(name: 'pmd', classname: 'net.sourceforge.pmd.ant.PMDTask')
-            ant.pmd(failOnRuleViolation: false, failuresPropertyName: "pmdFailureCount") {
+            ant.pmd(failOnRuleViolation: false, failuresPropertyName: "pmdFailureCount", targetjdk: targetJdk) {
                 getSource().addToAntBuilder(ant, 'fileset', FileCollection.AntType.FileSet)
                 getRuleSets().each {
                     ruleset(it)
diff --git a/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdExtension.groovy b/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdExtension.groovy
index d13dc6b..c4795f5 100644
--- a/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdExtension.groovy
+++ b/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdExtension.groovy
@@ -37,6 +37,11 @@ class PmdExtension extends CodeQualityExtension {
      * Example: ruleSets = ["basic", "braces"]
      */
     List<String> ruleSets
+
+    /**
+     * The target jdk to use with pmd, 1.3, 1.4, 1.5, 1.6, 1.7 or jsp
+     */
+    String targetJdk
     
     /**
      * Convenience method for adding rule sets.
diff --git a/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdPlugin.groovy b/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdPlugin.groovy
index f084a9c..3144924 100644
--- a/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdPlugin.groovy
+++ b/subprojects/code-quality/src/main/groovy/org/gradle/api/plugins/quality/PmdPlugin.groovy
@@ -15,6 +15,7 @@
  */
 package org.gradle.api.plugins.quality
 
+import org.gradle.api.JavaVersion
 import org.gradle.api.plugins.quality.internal.AbstractCodeQualityPlugin
 import org.gradle.api.tasks.SourceSet
 
@@ -51,6 +52,7 @@ class PmdPlugin extends AbstractCodeQualityPlugin<Pmd> {
             toolVersion = "4.3"
             ruleSets = ["basic"]
             ruleSetFiles = project.files()
+            targetJdk = project.sourceCompatibility
         }
         return extension
     }
@@ -70,7 +72,7 @@ class PmdPlugin extends AbstractCodeQualityPlugin<Pmd> {
             ruleSets = { extension.ruleSets }
             ruleSetFiles = { extension.ruleSetFiles }
             ignoreFailures = { extension.ignoreFailures }
-
+            targetJdk = { extension.targetJdk }
             task.reports.all { report ->
                 report.conventionMapping.with {
                     enabled = { true }
diff --git a/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.Pmd.xml b/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.Pmd.xml
index a777dba..e5ba89a 100644
--- a/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.Pmd.xml
+++ b/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.Pmd.xml
@@ -25,6 +25,10 @@
                 <td><literal>project.pmd.ignoreFailures</literal></td>
             </tr>
             <tr>
+                <td>targetJdk</td>
+                <td><literal>project.pmd.targetJdk</literal></td>
+            </tr>
+            <tr>
                 <td>source</td>
                 <td><literal><replaceable>sourceSet</replaceable>.allJava</literal></td>
             </tr>
diff --git a/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.PmdExtension.xml b/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.PmdExtension.xml
index b88bd6d..b8316e8 100644
--- a/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.PmdExtension.xml
+++ b/subprojects/docs/src/docs/dsl/org.gradle.api.plugins.quality.PmdExtension.xml
@@ -24,6 +24,10 @@
                 <td>ruleSetFiles</td>
                 <td><literal>[]</literal></td>
             </tr>
+            <tr>
+                <td>targetJdk</td>
+                <td><literal>project.sourceCompatibility</literal></td>
+            </tr>
         </table>
     </section>
     <section>
-- 
1.7.1

