Created
September 13, 2011 08:41
-
-
Save nobeans/1213424 to your computer and use it in GitHub Desktop.
PMD/Gradle script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
GRADLE_FILE_NAME=pmd.gradle | |
RULE_FILE_NAME=pmd-rules.xml | |
if [ -f ./$GRADLE_FILE_NAME ]; then | |
echo "WARN: $GRADLE_FILE_NAME already exists" | |
exit 1 | |
fi | |
if [ -f ./$RULE_FILE_NAME ]; then | |
echo "WARN: $RULE_FILE_NAME already exists" | |
exit 1 | |
fi | |
cat > $GRADLE_FILE_NAME <<EOS_BUILD_GRADLE | |
apply plugin:'java' | |
defaultTasks 'pmd' | |
sourceCompatibility = 1.5 | |
repositories { | |
mavenCentral() | |
} | |
configurations { | |
pmdConf | |
} | |
dependencies { | |
pmdConf 'pmd:pmd:4.2.5' | |
} | |
def defaultEncoding = 'UTF-8' | |
compileJava { | |
options.encoding = defaultEncoding | |
} | |
compileTestJava { | |
options.encoding = defaultEncoding | |
} | |
task pmd << { | |
println 'Running PMD static code analysis' | |
ant { | |
taskdef(name:'pmd', classname:'net.sourceforge.pmd.ant.PMDTask', classpath: configurations.pmdConf.asPath) | |
pmd(shortFilenames:'true', failonruleviolation:'true', rulesetfiles:'pmd-rules.xml') { | |
formatter(type:'text', toConsole:'true') | |
fileset(dir: "src/main/java") { | |
include(name: '**/*.java') | |
} | |
fileset(dir: "src/test/java") { | |
include(name: '**/*.java') | |
} | |
} | |
} | |
} | |
EOS_BUILD_GRADLE | |
cat > $RULE_FILE_NAME <<EOS_PMD_RULES | |
<?xml version="1.0"?> | |
<ruleset name="Custom ruleset" | |
xmlns="http://pmd.sf.net/ruleset/1.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" | |
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> | |
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"> | |
<properties> | |
<property name="reportLevel" value="5"/> | |
</properties> | |
</rule> | |
</ruleset> | |
EOS_PMD_RULES | |
gradle -b $GRADLE_FILE_NAME | |
rm $GRADLE_FILE_NAME >/dev/null 2>&1 | |
rm $RULE_FILE_NAME >/dev/null 2>&1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment