Browse Source

added ant files

master
SeshagiriSriram 10 years ago
parent
commit
bd56a6cf7d
  1. 60
      build.properties
  2. 474
      build.xml
  3. 2
      pom.xml
  4. 275
      src/main/pmd/pmd.xsl
  5. 120
      src/main/pmd/ruleset_basics.xml
  6. 328
      src/main/pmd/ruleset_j2ee.xml
  7. 19
      src/main/pmd/ruleset_security.xml

60
build.properties

@ -0,0 +1,60 @@
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Copyright 2015, Seshagiri Sriram. All rights reserved.
#
# Created on: Feb 02, 2015, Seshagiri Sriram
# Updated: June 20,2016 fixed some property paths..
# File Name : build.properties
#
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# ****** NOTE: ALL PARAMETERS AND VALUES IN THIS FILE ARE CASE SENSITIVE ******
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Properties file
# Modify the following properties before calling the ant build
#
# This build drops all the existing directories (mentioned in this properties file) before creating them
# The JAR file structure created by this build is
# |-- ReportGenerator.jar This is defined in build.xml
# | |-- META-INF
# |-- lib Third party jars
# |-- All property files go in here.....
#
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Build Details
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# The below are general for *** ALL *** Projects and defined inside build.xml or passed via -D options. DO NOT CHANGE
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# |Property Description
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# |build.basesrcdir Location where the project is found. Passed to this script via -Dbasesrcdir=<value>
# |maven.build.finalName Final name - hardcoded into build.xml e.g. X-1.0.0-SNAPSHOT.jar
# |maven.build.dir Location relative to buildsrcdir where build will be done. usually target
# |maven.build.outputDir Usually target/classes.
# |maven.build.srcdir location of source under buid.basesrcdir
# |maven.build.resourceDir location of resources under build.basesrcdir
# |maven.build.testDir Location of test classes
# |maven.build.testResourceDir Location of test resources
# |maven.build.testOutputDir Location of test class compilation
# |maven.test.reports Where test reports (from JUNIT) will be located.
# |maven.build.pmddir Location where PMD rules and XSL will belocated.
# |maven.reporting.outputDirectory Location of reports from PMD
# |project.3rdpartylibdir lib under build.basesrcdir
# |build.type dev,qa, or prod. passed via -Dbuildtype={dev|qa|prod}
# |environment.type.default Value if build.type is not passed. defaults to dev -- DO NOT CHANGE
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Per User configuration..... Change for local environmnent
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
ant.home=c:/Apps/ant
project.build.outputDirectory=${maven.build.outputDir}
project.build.directory=${maven.build.dir}
maven.repo.local=c\:/repos
maven.settings.offline=false
project.build.sourceEncoding=UTF-8
maven.settings.interactiveMode=false
maven.build.version=V1.2
maven.test.skip=false
pmd.installpath=c:/Apps/pmd-bin-5.2.3/lib
# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

474
build.xml

@ -0,0 +1,474 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!-- Ant build file (http://ant.apache.org/) for Ant 1.7.2 or above. -->
<!-- ====================================================================== -->
<project name="addressbook" default="zip" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant" xmlns:ac="antlib:net.sf.antcontrib" xmlns:sonar="antlib:org.sonar.ant">
<tstamp><format property="MYTIME" pattern="yyyyMMddHHmmss" /></tstamp>
<!-- ====================================================================== -->
<!-- Defining classpaths & Task Defs -->
<!-- ====================================================================== -->
<property environment="env"/>
<property name="installpath.pmd" value="${env.PMD_HOME}/lib"/>
<property name="pmd.installpath" value="${env.PMD_HOME}/lib"/>
<property name="pmd.classpath" value="${env.PMD_HOME}/lib"/>
<!-- For Cobertura -->
<property name="lib.cobertura.dir" value="c:/apps/cobertura-1.9.4.1" />
<property name="cobertura.jar.file" value="${lib.cobertura.dir}/cobertura.jar" />
<path id="pmd.classpath">
<fileset dir="${pmd.installpath}"/>
</path>
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask" classpathref="pmd.classpath"/>
<path id="maven-ant-tasks.classpath" path="${ant.home}/lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
<path id="ant.contrib.classpath" path="${ant.home}/lib/ant-contrib.jar"/>
<typedef resource="net/sf/antcontrib/antlib.xml" classpathref="ant.contrib.classpath"/>
<!-- ====================================================================== -->
<!-- Build environment properties -->
<!-- ====================================================================== -->
<property name="environment.type.default" value="dev"/>
<if>
<equals arg1="${basesrcdir}" arg2="$${basesrcdir}"/>
<then>
<property name="build.basesrcdir" value="."/>
</then>
<else>
<property name="build.basesrcdir" value="${basesrcdir}"/>
</else>
</if>
<if>
<equals arg1="${buildtype}" arg2="$${buildtype}"/>
<then>
<property name="maven.build.resourceDir" value="${build.basesrcdir}/src/main/resources/${environment.type.default}"/>
<property name="actualbuildtype" value="${environment.type.default}"/>
</then>
<else>
<property name="maven.build.resourceDir" value="${build.basesrcdir}/src/main/resources/${buildtype}"/>
<property name="actualbuildtype" value="${buildtype}"/>
</else>
</if>
<echo message="resource dir: ${maven.build.resourceDir}, Source Dir: ${build.basesrcdir}/src/main/java"/>
<property file="${build.basesrcdir}/build.properties"/>
<artifact:pom id="pom" file="pom.xml" />
<property name="actualbuildname" value="${pom.artifactId}"/>
<property name="actualversion" value="${pom.version}"/>
<echo message="Artifact ID/Version: ${actualbuildname}/${actualversion}"/>
<property name="build.version" value="${version}"/>
<property name="maven.build.finalName" value="${actualbuildname}-${actualversion}"/>
<property name="maven.build.dir" value="${build.basesrcdir}/target"/>
<property name="maven.build.outputDir" value="${maven.build.dir}/classes"/>
<property name="maven.build.srcDir" value="${build.basesrcdir}/src/main/java"/>
<property name="maven.build.testDir" value="${build.basesrcdir}/src/test/java"/>
<property name="maven.build.testResourceDir" value="${build.basesrcdir}/src/test/resources"/>
<property name="maven.build.testOutputDir" value="${maven.build.dir}/test-classes"/>
<property name="maven.test.reports" value="${maven.build.dir}/test-reports"/>
<property name="maven.reporting.outputDirectory" value="reports"/>
<property name="project.3rdpartylibdir" value="${build.basesrcdir}/lib"/>
<property name="maven.build.pmddir" value="${build.basesrcdir}/src/main/pmd"/>
<property name="sonar.host.url" value="${env.SONAR_URL}" />
<property name="sonar.jdbc.url" value="jdbc:mysql://${env.SONAR_DBSERVER}:${env.SONAR_DBPORT}/${env.SONAR_DBNAME}?useUnicode=true&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true&amp;useConfigs=maxPerformance" />
<property name="sonar.jdbc.username" value="${env.SONAR_DBUSER}"/>
<property name="sonar.jdbc.password" value="${env.SONAR_DBPASSWORD}"/>
<property name="sonar.projectKey" value="${ant.project.name}"/>
<property name="sonar.projectName" value="${ant.project.name}"/>
<property name="sonar.projectVersion" value="${actualversion}"/>
<property name="sonar.sources" value="${build.basesrcdir}/src/main/java"/>
<!-- For Cobertura -->
<property name="cob.ser.file" value="cobertura.ser" />
<property name="cobertura.dir" value="./cobertura" />
<property name="cob.instrumented.dir" value="${cobertura.dir}/instrumented" />
<property name="cob.reports.dir" value="${cobertura.dir}/reports" />
<property name="cob.reports.xml.dir" value="${cob.reports.dir}/junit-xml" />
<property name="cob.reports.html.dir" value="${cob.reports.dir}/junit-html" />
<property name="cob.coverage.xml.dir" value="${cob.reports.dir}/cobertura-xml" />
<property name="cob.coverage.html.dir" value="${cob.reports.dir}/cobertura-html" />
<path id="libpath">
<fileset dir="${project.3rdpartylibdir}"/>
</path>
<path id="build.test.classpath">
<pathelement location="${project.3rdpartylibdir}/junit-4.11.jar"/>
</path>
<echo message="***************************************************************************"/>
<echo message="Start the build for: ${ant.project.name} "/>
<echo message="Base Dir: ${build.basesrcdir} ${actualbuildtype}"/>
<mkdir dir="${project.3rdpartylibdir}"/>
<echo message="PMD Libraries installed in: ${pmd.installpath}"/>
<echo message="***************************************************************************"/>
<echo message="Skip Test? ${maven.test.skip}"/>
<!-- ====================================================================== -->
<!-- Cleaning up target -->
<!-- ====================================================================== -->
<target name="clean" description="Clean the output directory">
<delete dir="${maven.build.dir}"/>
<delete dir="${project.3rdpartylibdir}"/>
<delete dir="${maven.reporting.outputDirectory}"/>
<delete dir="./.sonar"/>
<delete dir="reports"/>
<delete file="${cob.ser.file}"/>
<delete dir="${cobertura.dir}"/>
</target>
<!-- ====================================================================== -->
<!-- Copy Maven dependencies -->
<!-- ====================================================================== -->
<target name="maven_dep_copy" depends="clean" description="Copies Maven Dependencies into local Lib folder">
<artifact:dependencies filesetId="deps.fileset" scopes="provided, test, runtime, compile">
<pom file="pom.xml"/>
</artifact:dependencies>
<mkdir dir="${project.3rdpartylibdir}"/>
<copy todir="${project.3rdpartylibdir}">
<fileset refid="deps.fileset" />
<mapper type="flatten" />
</copy>
</target>
<!-- ====================================================================== -->
<!-- Compilation target -->
<!-- ====================================================================== -->
<target name="compile" depends="maven_dep_copy" description="Compiles the code. Does a validation on PMD Rules">
<mkdir dir="${maven.build.outputDir}"/>
<javac includeantruntime="false" destdir="${maven.build.outputDir}"
nowarn="false" debug="true"
optimize="false" deprecation="true"
target="1.6" verbose="false"
fork="false" source="1.6">
<src>
<pathelement location="${maven.build.srcDir}"/>
</src>
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
</classpath>
</javac>
<copy todir="${maven.build.outputDir}">
<fileset dir="${maven.build.resourceDir}"/>
</copy>
</target>
<!-- ====================================================================== -->
<!-- Test-compilation target -->
<!-- ====================================================================== -->
<target name="compile-tests"
depends="compile"
description="Compiles the test code, unless maven's skip test property is unset">
<mkdir dir="${maven.build.testOutputDir}"/>
<javac includeantruntime="false" destdir="${maven.build.testOutputDir}"
nowarn="false" debug="true"
optimize="false" deprecation="true"
target="1.8" verbose="false"
fork="false" source="1.7">
<src>
<pathelement location="${maven.build.testDir}"/>
</src>
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
<pathelement location="${maven.build.outputDir}"/>
<fileset dir="${lib.cobertura.dir}"/>
</classpath>
</javac>
<copy todir="${maven.build.testOutputDir}">
<fileset dir="${maven.build.testResourceDir}"/>
</copy>
</target>
<!-- ====================================================================== -->
<!-- Run all tests -->
<!-- ====================================================================== -->
<target name="test"
depends="compile-tests"
description="Runs the test cases">
<mkdir dir="${maven.test.reports}"/>
<junit haltonerror="no" failureproperty="test.failed" haltonfailure="no" printSummary="yes" fork="true" dir=".">
<sysproperty key="basedir" value="."/>
<formatter type="xml"/>
<formatter type="plain" usefile="false"/>
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
<pathelement location="${maven.build.outputDir}"/>
<pathelement location="${maven.build.testOutputDir}"/>
</classpath>
<batchtest skipNonTests="false" todir="${maven.test.reports}">
<fileset dir="${maven.build.testDir}">
<include name="**/Test*.java"/>
<include name="**/*Test.java"/>
<include name="**/*TestCase.java"/>
<exclude name="**/*Abstract*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${maven.test.reports}">
<fileset dir="${maven.test.reports}">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${maven.test.reports}\html\" />
</junitreport>
<fail message="Test failure detected, check test results." if="test.failed" />
</target>
<target name="test-junit-present" description="Checks if JUNIT is present">
<available classname="junit.framework.Test" property="junit.present" classpathref="build.test.classpath"/>
<echo message="${junit.present}"/>
</target>
<target name="test-junit-status"
depends="test-junit-present" description="Set condition if JUNIT tests are to be run.">
<condition property="junit.missing">
<and>
<isfalse value="${junit.present}"/>
<isfalse value="${maven.test.skip}"/>
</and>
</condition>
<condition property="junit.skipped">
<or>
<isfalse value="${junit.present}"/>
<istrue value="${maven.test.skip}"/>
</or>
</condition>
</target>
<target name="junit-missing"
depends="test-junit-status"
if="junit.missing" description="Reports if JUNIT library is missing so to avoid running JUNIT Tests">
<echo>=================================== WARNING ==========================================</echo>
<echo> JUnit is not present in the test classpath or your $ANT_HOME/lib directory. Tests not executed. </echo>
<echo>=======================================================================================</echo>
</target>
<!-- ====================================================================== -->
<!-- Javadoc target -->
<!-- ====================================================================== -->
<target name="javadoc" description="Generates the Javadoc of the application">
<javadoc sourcepath="${maven.build.srcDir}"
packagenames="*"
destdir="${maven.reporting.outputDirectory}/apidocs"
access="protected"
old="false"
verbose="false"
version="true"
use="true"
author="true"
splitindex="false"
nodeprecated="false"
nodeprecatedlist="false"
notree="false"
noindex="false"
nohelp="false"
nonavbar="false"
serialwarn="false"
charset="ISO-8859-1"
linksource="false"
breakiterator="false"
additionalparam="-Xdoclint:none" />
</target>
<!-- ====================================================================== -->
<!-- PMD Report -->
<!-- ====================================================================== -->
<target name="pmdreport" description="Generates PMD Reported issues list as a browsable HTML">
<mkdir dir="${maven.reporting.outputDirectory}"/>
<pmd shortFilenames="true" failonerror="false" failOnRuleViolation="false" minimumPriority="5" failuresPropertyName="pmderrors" rulesetfiles="${maven.build.pmddir}/ruleset_j2ee.xml,${maven.build.pmddir}/ruleset_basics.xml"> <sourceLanguage name="java" version="1.6"/>
<formatter type="xml" toFile="${maven.reporting.outputDirectory}/pmd_report.xml">
<param name="linkPrefix" value="http://pmd.sourceforge.net/xref/"/>
</formatter>
<fileset dir="${maven.build.srcDir}"/>
</pmd>
<xslt in="${maven.reporting.outputDirectory}/pmd_report.xml" style="${maven.build.pmddir}/pmd.xsl" out="${maven.reporting.outputDirectory}/pmd_report_${ant.project.name}.html" />
<delete file="${maven.reporting.outputDirectory}/pmd_report.xml"/>
<if>
<equals arg1="${pmderrors}" arg2="$${pmderrors}"/>
<then>
<property name="pmdreporterrcnt" value="0"/>
</then>
<else>
<property name="pmdreporterrcnt" value="${pmderrors}"/>
</else>
</if>
<echo message="Number of PMD Errors: ${pmdreporterrcnt}"/>
</target>
<!-- ====================================================================== -->
<!-- Package target -->
<!-- ====================================================================== -->
<target name="package" depends="compile,test" description="Package the application as a JAR/WAR whatever">
<pathconvert property="manifest.classpath" pathsep=" ">
<path refid="libpath"/>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from="*.jar" to="${project.3rdpartylibdir}/*.jar"/>
</chainedmapper>
</mapper>
</pathconvert>
<jar jarfile="${maven.build.dir}/${maven.build.finalName}.jar"
compress="true" index="false"
basedir="${maven.build.outputDir}" excludes="**/package.html">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Created-By" value="Build Tool V1"/>
<attribute name="Implementation-Title" value="${actualbuildname}.jar"/>
<attribute name="Implementation-Version" value="${maven.build.version}-${MYTIME}"/>
<attribute name="Implementation-Vendor" value="SeshagiriSriram"/>
<attribute name="Class-Path" value="${manifest.classpath}"/>
</manifest>
</jar>
</target>
<!-- ====================================================================== -->
<!-- A dummy target for the package named after the type it creates -->
<!-- ====================================================================== -->
<target name="jar" depends="package" description="Builds the jar for the application"/>
<!-- ====================================================================== -->
<!-- Zips files into a zip for deployment -->
<!-- ====================================================================== -->
<target name="zip" depends="package" description="Zips all Resources">
<if>
<equals arg1="${zipoutput}" arg2="$${zipoutput}"/>
<then>
<property name="zipoutputdir" value="${maven.build.dir}"/>
</then>
<else>
<property name="zipoutputdir" value="${zipoutput}"/>
</else>
</if>
<echo message="Copying files from ${maven.build.resourceDir} to ${maven.build.dir}/tmp"/>
<mkdir dir="${maven.build.dir}/tmp"/>
<mkdir dir="${zipoutputdir}"/>
<echo message="Resource Directory: ${maven.build.resourceDir}" />
<copy todir="${maven.build.dir}/tmp" overwrite="true">
<fileset dir="${maven.build.resourceDir}"/>
<file name="${maven.build.dir}/${maven.build.finalName}.jar"/>
</copy>
<zip destfile="${zipoutputdir}/${maven.build.finalName}.zip">
<zipfileset dir="${maven.build.dir}/tmp" includes="*.properties,*.xml,*.txt, ${maven.build.finalName}.jar"/>
<zipfileset dir="./lib" prefix="lib"/>
</zip>
<delete dir="${maven.build.dir}/tmp"/>
<delete dir="${project.3rdpartylibdir}"/>
<mkdir dir="${project.3rdpartylibdir}"/>
<delete file="${maven.build.dir}/../${maven.build.finalName}.zip"/>
</target>
<!-- ====================================================================== -->
<!-- Download dependencies target -->
<!-- ====================================================================== -->
<target name="test-offline" description="Checks if Maven has been configured to run in offline mode">
<condition property="maven.mode.offline">
<equals arg1="${maven.settings.offline}" arg2="true"/>
</condition>
</target>
<!-- ====================================================================== -->
<!-- Installs components to Artifactory -->
<!-- ====================================================================== -->
<target name="install" depends="zip" description="Installs the JAR to artifactory">
<echo message="Maven is found in: ${env.MAVEN_HOME}"/>
<artifact:deploy file="${maven.build.dir}/${maven.build.finalName}.jar">
<pom file="pom.xml"/>
<remoteRepository url="${env.BUILD_URL}"/>
</artifact:deploy>
</target>
<!-- ====================================================================== -->
<!-- Performs SonarQube Analysis on code -->
<!-- ====================================================================== -->
<target name="sonar" description="Performs SonarQube Analysis on code">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="maven-ant-tasks.classpath" />
<!-- Execute the SonarQube analysis -->
<sonar:sonar />
</target>
<!-- ====================================================================== -->
<!-- Copy files required for instrumentation -->
<!-- ====================================================================== -->
<target name="prepare" depends="clean, maven_dep_copy">
<mkdir dir="${maven.reporting.outputDirectory}" />
<!-- cobertura directories -->
<mkdir dir="${cobertura.dir}" />
<mkdir dir="${cob.instrumented.dir}" />
<mkdir dir="${cob.reports.xml.dir}" />
<mkdir dir="${cob.reports.html.dir}" />
<mkdir dir="${cob.coverage.xml.dir}" />
<mkdir dir="${cob.coverage.html.dir}" />
<!-- WE DO NOT HAVE LIBS IN OUR APPLICTION - SO WE DEFINE THE TASK AFTER GETTING THE FILE -->
<path id="cobertura.classpath">
<fileset dir="${lib.cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
<fileset dir="${project.3rdpartylibdir}"/>
</path>
<taskdef resource="tasks.properties" classpathref="cobertura.classpath"/>
</target>
<!-- ====================================================================== -->
<!-- Do Actual Instrumentation -->
<!-- ====================================================================== -->
<target name="instrument" depends="prepare,compile-tests">
<echo>Class Path: ${toString:cobertura.classpath}</echo>
<cobertura-instrument todir="${cob.instrumented.dir}">
<fileset dir="${maven.build.outputDir}">
<include name="**/*.class"/>
</fileset>
</cobertura-instrument>
</target>
<!-- ====================================================================== -->
<!-- Call Instrumentation -->
<!-- ====================================================================== -->
<target name="cover-test" depends="instrument">
<echo message="Instrumented dir:${cob.instrumented.dir}"/>
<junit printSummary="yes" haltonerror="no" haltonfailure="no" fork="yes" dir=".">
<sysproperty key="basedir" value="."/>
<sysproperty key="net.sourceforge.cobertura.datafile"
file="${cob.ser.file}" />
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath location="${cob.instrumented.dir}" />
<classpath location="${maven.build.outputDir}" />
<classpath refid="cobertura.classpath" />
<classpath>
<fileset dir="${project.3rdpartylibdir}"/>
<pathelement location="${maven.build.testOutputDir}"/>
</classpath>
<batchtest skipNonTests="false" todir="${maven.test.reports}">
<fileset dir="${maven.build.testDir}">
<include name="**/Test*.java"/>
<include name="**/*Test.java"/>
<include name="**/*TestCase.java"/>
<exclude name="**/*Abstract*Test.java"/>
</fileset>
</batchtest>
</junit>
</target>
<!-- ====================================================================== -->
<!-- Report on this.... -->
<!-- ====================================================================== -->
<!-- run this target to generate the coverage reports -->
<target name="coverage-report" depends="cover-test">
<cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}"/>
</target>
</project>

2
pom.xml

@ -117,7 +117,7 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.12</version>
<version>4.7</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

275
src/main/pmd/pmd.xsl

@ -0,0 +1,275 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<xsl:decimal-format decimal-separator="." grouping-separator="," />
<!-- keys for violations list -->
<xsl:key name="violations" match="violation" use="@rule" />
<!-- XSL for PMD report. Author : Seshagiri Sriram. -->
<!-- Inspired by Checkstyle -->
<xsl:template name="timestamp">
<!--** Timestamp processing to display date -->
<xsl:value-of select="substring-before(//pmd/@timestamp, 'T')"/> - <xsl:value-of select="substring-before(substring-after(//pmd/@timestamp, 'T'), '.')"/>
</xsl:template>
<xsl:template match="pmd">
<!--** Process root node pmd : html header, style, call templates -->
<html>
<head>
<title>PMD <xsl:value-of select="//pmd/@version"/> Report: Demo Utilities</title>
<style type="text/css">
.bannercell {
border: 0px;
padding: 0px;
}
body {
margin-left: 10px;
margin-right: 10px;
font:normal 80% arial,helvetica,sanserif;
background-color:#FFFFFF;
color:#000000;
}
.a td {
background: #efefef;
}
.b td {
background: #fff;
}
th, td {
text-align: left;
vertical-align: top;
}
th {
font-weight:bold;
background: #ccc;
color: black;
}
table, th, td {
font-size:100%;
border: none
}
table.log tr td, tr th {
}
h2 {
font-weight:bold;
font-size:140%;
margin-bottom: 5;
}
h3 {
font-size:100%;
font-weight:bold;
background: #525D76;
color: white;
text-decoration: none;
padding: 5px;
margin-right: 2px;
margin-left: 2px;
margin-bottom: 0px;
}
.p1 { background:#FF9999; }
.p2 { background:#FFCC66; }
.p3 { background:#FFFF99; }
.p4 { background:#99FF99; }
.p5 { background:#a6caf0; }
</style>
</head>
<body>
<a name="top"></a>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="bannercell" rowspan="2">
</td>
<td class="text-align:right"><h2>PMD <xsl:value-of select="//pmd/@version"/> Report: Demo Utilities. Generated on <xsl:call-template name="timestamp"/></h2></td>
</tr>
</table>
<hr size="1"/>
<!-- Summary part -->
<xsl:apply-templates select="." mode="summary"/>
<hr size="1" width="100%" align="left"/>
<!-- Rules part -->
<xsl:apply-templates select="." mode="rulelist"/>
<hr size="1" width="100%" align="left"/>
<!-- Package List part -->
<xsl:apply-templates select="." mode="filelist"/>
<hr size="1" width="100%" align="left"/>
<!-- For each file create its part -->
<xsl:apply-templates select="file" />
<hr size="1" width="100%" align="left"/>
</body>
</html>
</xsl:template>
<xsl:template match="pmd" mode="rulelist">
<!--** Process root node pmd, for mode 'rulelist' : violated rules -->
<h3>Rules</h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th style="width:84%">Rule</th>
<th style="width:8%">Violations</th>
<th style="width:8%">Severity</th>
</tr>
<xsl:for-each
select="file/violation[@rule and generate-id(.) = generate-id(key('violations', @rule))]">
<!-- Sort by number of violations -->
<xsl:sort data-type="number" order="descending"
select="count(key('violations', @rule))" />
<xsl:variable name="currentRule" select="@rule" />
<xsl:variable name="currentSeverity" select="@priority" />
<xsl:variable name="violationCount"
select="count(../../file/violation[@rule=$currentRule])" />
<tr>
<xsl:call-template name="alternated-row" />
<td>
[<xsl:value-of select="@ruleset" />] <xsl:value-of select="$currentRule" />
</td>
<td>
<xsl:value-of select="$violationCount" />
</td>
<td><div class="p{$currentSeverity}">
<xsl:text> </xsl:text>
<xsl:value-of select="$currentSeverity" /></div>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="pmd" mode="filelist">
<!--** Process root node pmd, for mode 'filelist' : number of violations for each file -->
<h3>Files</h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th>File</th>
<th style="width:40px"><div class="p5">5</div></th>
<th style="width:40px"><div class="p4">4</div></th>
<th style="width:40px"><div class="p3">3</div></th>
<th style="width:40px"><div class="p2">2</div></th>
<th style="width:40px"><div class="p1">1</div></th>
</tr>
<xsl:for-each
select="file">
<!-- Sort by number of violations -->
<xsl:sort data-type="number" order="descending"
select="count(violation)" />
<xsl:variable name="currentSource" select="@name" />
<tr>
<xsl:call-template name="alternated-row" />
<td>
<xsl:variable name="anchor" select="translate(@name, '\/', '__')"></xsl:variable>
<a href="#f-{$anchor}"><xsl:value-of select="@name" /></a>
</td>
<td><xsl:value-of select="count(violation[@priority = 5])" /></td>
<td><xsl:value-of select="count(violation[@priority = 4])" /></td>
<td><xsl:value-of select="count(violation[@priority = 3])" /></td>
<td><xsl:value-of select="count(violation[@priority = 2])" /></td>
<td><xsl:value-of select="count(violation[@priority = 1])" /></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="file">
<!--** Process node 'file' : violations details -->
<xsl:variable name="anchor" select="translate(@name, '\/', '__')"></xsl:variable>
<a name="f-{$anchor}"></a>
<h3>File <xsl:value-of select="@name" /></h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th style="width:60px;">Violation</th>
<th>Error Description</th>
<th style="width:40px;">Line</th>
</tr>
<xsl:for-each select="violation">
<xsl:variable name="currentSeverity" select="@priority" />
<tr>
<xsl:call-template name="alternated-row" />
<td><div class="p{$currentSeverity}"><xsl:value-of select="$currentSeverity"/>
</div>
</td>
<td>
[<xsl:value-of select="@ruleset" />.<xsl:value-of select="@rule" />]
-
<xsl:choose>
<xsl:when test="@externalInfoUrl">
<a href="{@externalInfoUrl}"><xsl:value-of select="." disable-output-escaping="yes" /></a>
</xsl:when>
<xsl:otherwise><xsl:value-of select="." disable-output-escaping="yes" /></xsl:otherwise>
</xsl:choose>
</td>
<td>
<xsl:value-of select="@beginline" /> - <xsl:value-of select="@endline"/>
</td>
</tr>
</xsl:for-each>
</table>
<a href="#top">Back to top</a>
</xsl:template>
<xsl:template match="pmd" mode="summary">
<!--** Process root node 'pmd', for mode 'summary' : number of files, number of violations by severity -->
<h3>Summary</h3>
<table class="log" border="0" cellpadding="5" cellspacing="2"
width="100%">
<tr>
<th style="width:25%">Files</th>
<th>Total</th>
<th><div class="p1">Priority 1: ShowStopper</div></th>
<th><div class="p2">Priority 2:Critical</div></th>
<th><div class="p3">Priority 3:Important/Urgent</div></th>
<th><div class="p4">Priority 4:Low - Change recommended</div></th>
<th><div class="p5">Priority 5:Low - Change Optional</div></th>
</tr>
<tr>
<xsl:call-template name="alternated-row" />
<td><xsl:value-of select="count(//file)"/></td>
<td><xsl:value-of select="count(//violation)"/></td>
<td><xsl:value-of select="count(//violation[@priority = 1])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 2])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 3])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 4])"/></td>
<td><xsl:value-of select="count(//violation[@priority = 5])"/></td>
</tr>
</table>
</xsl:template>
<xsl:template name="alternated-row">
<!--** Template alternated-row, for alternated rows style in tables -->
<xsl:attribute name="class">
<xsl:if test="position() mod 2 = 1">a</xsl:if>
<xsl:if test="position() mod 2 = 0">b</xsl:if>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

120
src/main/pmd/ruleset_basics.xml

@ -0,0 +1,120 @@
<?xml version="1.0"?>
<ruleset name="Rule Set - Basics of Java"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>These are the rules by which Applications will be built. </description>
<!-- Priorities
HIGH :1
MEDIUM_HIGH:2
MEDIUM:3
MEDIUM_LOW:4
LOW : 5
Rule sets used as base:
<ruleset>rulesets/java/codesize.xml</ruleset>
<ruleset>rulesets/java/imports.xml</ruleset>
<ruleset>rulesets/java/basic.xml</ruleset>
<ruleset>rulesets/java/unnecessary.xml</ruleset>
<ruleset>rulesets/java/empty.xml</ruleset>
<ruleset>rulesets/java/unusedcode.xml</ruleset>
<ruleset>rulesets/java/strings.xml </ruleset>
<ruleset>rulesets/java/design.xml</ruleset>
-->
<rule ref="rulesets/java/codesize.xml/NPathComplexity" message="The method {0}() has an NPath complexity of {1}. Recommended to have it less than 150"> <priority>3</priority></rule>
<rule ref="rulesets/java/codesize.xml/ExcessiveMethodLength"><priority>3</priority></rule>
<rule ref="rulesets/java/codesize.xml/ExcessiveParameterList"><priority>3</priority></rule>
<rule ref="rulesets/java/codesize.xml/ExcessiveClassLength"><priority>3</priority></rule>
<rule ref="rulesets/java/codesize.xml/ExcessivePublicCount"><priority>3</priority></rule>
<rule ref="rulesets/java/codesize.xml/TooManyFields"><priority>3</priority></rule>
<rule ref="rulesets/java/codesize.xml/TooManyMethods"><priority>3</priority></rule>
<rule ref="rulesets/java/imports.xml/DuplicateImports"><priority>5</priority></rule>
<rule ref="rulesets/java/imports.xml/DontImportJavaLang"><priority>5</priority></rule>
<rule ref="rulesets/java/imports.xml/UnusedImports"><priority>5</priority></rule>
<rule ref="rulesets/java/imports.xml/ImportFromSamePackage" message="Do not import objects that are in the same package"><priority>3</priority></rule>
<rule ref="rulesets/java/imports.xml/UnnecessaryFullyQualifiedName"><priority>5</priority></rule>
<rule ref="rulesets/java/basic.xml/JumbledIncrementer"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/ForLoopShouldBeWhileLoop"><priority>5</priority></rule>
<rule ref="rulesets/java/basic.xml/DoubleCheckedLocking"><priority>1</priority></rule>
<rule ref="rulesets/java/basic.xml/ReturnFromFinallyBlock"><priority>2</priority></rule>
<rule ref="rulesets/java/basic.xml/UnconditionalIfStatement"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/BooleanInstantiation"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/CollapsibleIfStatements"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/ClassCastExceptionWithToArray"><priority>2</priority></rule>
<rule ref="rulesets/java/basic.xml/AvoidDecimalLiteralsInBigDecimalConstructor"><priority>2</priority></rule>
<rule ref="rulesets/java/basic.xml/MisplacedNullCheck"><priority>2</priority></rule>
<rule ref="rulesets/java/basic.xml/BrokenNullCheck"><priority>2</priority></rule>
<rule ref="rulesets/java/basic.xml/AvoidUsingHardCodedIP"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/CheckResultSet"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/AvoidBranchingStatementAsLastInLoop"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/DontCallThreadRun"><priority>3</priority></rule>
<rule ref="rulesets/java/basic.xml/DontUseFloatTypeForLoopIndices"><priority>3</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnnecessaryConversionTemporary"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnnecessaryReturn"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnnecessaryFinalModifier"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UselessOverridingMethod"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UselessOperationOnImmutable"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UnusedNullCheckInEquals"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/unnecessary.xml/UselessParentheses"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyCatchBlock" ><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyIfStmt"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyWhileStmt"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyTryBlock" ><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyFinallyBlock"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptySwitchStatements"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptySynchronizedBlock"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyStatementNotInLoop"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyInitializer"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyStatementBlock"><priority>5</priority></rule>
<rule deprecated="true" ref="rulesets/java/empty.xml/EmptyStaticInitializer"><priority>5</priority></rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable"><priority>4</priority></rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod"><priority>4</priority></rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/AvoidDuplicateLiterals"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/StringInstantiation"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/StringToString"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/InefficientStringBuffering"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/UnnecessaryCaseChange"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/AppendCharacterWithChar"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/ConsecutiveAppendsShouldReuse"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/ConsecutiveLiteralAppends"><priority>2</priority></rule>
<rule ref="rulesets/java/strings.xml/AvoidStringBufferField"><priority>2</priority></rule>
<rule ref="rulesets/java/strings.xml/UseEqualsToCompareStrings"><priority>2</priority></rule>
<rule ref="rulesets/java/strings.xml/UselessStringValueOf"><priority>3</priority></rule>
<rule ref="rulesets/java/strings.xml/InsufficientStringBufferDeclaration"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/UseUtilityClass"><priority>4</priority></rule>
<rule ref="rulesets/java/design.xml/SimplifyBooleanReturns"><priority>4</priority></rule>
<rule ref="rulesets/java/design.xml/AvoidDeeplyNestedIfStmts"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/AvoidReassigningParameters"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/ConstructorCallsOverridableMethod"><priority>1</priority></rule>
<rule ref="rulesets/java/design.xml/CloseResource"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/OptimizableToArrayCall"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/EqualsNull"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/InstantiationToGetClass"><priority>4</priority></rule>
<rule ref="rulesets/java/design.xml/IdempotentOperations"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/SimpleDateFormatNeedsLocale"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/AssignmentToNonFinalStatic"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/AvoidSynchronizedAtMethodLevel"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/UseNotifyAllInsteadOfNotify"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/AvoidInstanceofChecksInCatchClause"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/CompareObjectsWithEquals"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/PositionLiteralsFirstInComparisons"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/NonThreadSafeSingleton"><priority>1</priority></rule>
<rule ref="rulesets/java/design.xml/AvoidConstantsInterface"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/UnsynchronizedStaticDateFormatter"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/PreserveStackTrace"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/UseCollectionIsEmpty"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/SingularField"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/ReturnEmptyArrayRatherThanNull"><priority>2</priority></rule>
<rule ref="rulesets/java/design.xml/UseVarargs"><priority>4</priority></rule>
<rule ref="rulesets/java/design.xml/FieldDeclarationsShouldBeAtStartOfClass"><priority>3</priority></rule>
<rule ref="rulesets/java/design.xml/GodClass"><priority>3</priority></rule>
<rule ref="rulesets/java/logging-java.xml/MoreThanOneLogger"><priority>3</priority></rule>
<rule ref="rulesets/java/logging-java.xml/LoggerIsNotStaticFinal"><priority>3</priority></rule>
<rule ref="rulesets/java/logging-java.xml/SystemPrintln"><priority>2</priority></rule>
<rule ref="rulesets/java/logging-java.xml/AvoidPrintStackTrace"><priority>2</priority></rule>
<rule ref="rulesets/java/comments.xml/CommentRequired"><priority>5</priority></rule>
<rule ref="rulesets/java/comments.xml/CommentSize"><priority>5</priority></rule>
</ruleset>

328
src/main/pmd/ruleset_j2ee.xml

@ -0,0 +1,328 @@
<?xml version="1.0"?>
<ruleset name="Rule Set - J2EE/Web"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>These are the rules by which J2EE/Web Applications will be built. </description>
<!-- Priorities
HIGH :1
MEDIUM_HIGH:2
MEDIUM:3
MEDIUM_LOW:4
LOW : 5
-->
<rule ref="rulesets/java/j2ee.xml/UseProperClassLoader"> <priority>3</priority></rule>
<rule ref="rulesets/java/j2ee.xml/DoNotCallSystemExit"> <priority>3</priority></rule>
<rule ref="rulesets/java/j2ee.xml/DoNotUseThreads"> <priority>3</priority></rule>
<rule name="NoLongScripts" language="jsp" since="3.6"
message="Avoid having long scripts (e.g. Javascript) inside a JSP file."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoLongScripts">
<description>
Scripts should be part of Tag Libraries, rather than part of JSP pages.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
// HtmlScript [ (@EndLine - @BeginLine > 10) ]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML>
<BODY>
<!--Java Script-->
<SCRIPT language="JavaScript" type="text/javascript">
<!--
function calcDays(){
var date1 = document.getElementById('d1').lastChild.data;
var date2 = document.getElementById('d2').lastChild.data;
date1 = date1.split("-");
date2 = date2.split("-");
var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));
document.getElementById('diffDays').lastChild.data = daysApart;
}
onload=calcDays;
//-->
</SCRIPT>
</BODY>
</HTML>
]]>
</example>
</rule>
<rule name="NoScriptlets" language="jsp" since="3.6"
message="Avoid having scriptlets inside a JSP file."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoScriptlets">
<description>
Scriptlets should be factored into Tag Libraries or JSP declarations, rather than being part of JSP pages.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//JspScriptlet
|
//Element[ upper-case(@Name)="JSP:SCRIPTLET" ]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML>
<HEAD>
<%
response.setHeader("Pragma", "No-cache");
%>
</HEAD>
<BODY>
<jsp:scriptlet>String title = "Hello world!";</jsp:scriptlet>
</BODY>
</HTML>
]]>
</example>
</rule>
<rule name="NoInlineStyleInformation" since="3.6"
message="Avoid having style information in JSP files."
class="net.sourceforge.pmd.lang.jsp.rule.basic.NoInlineStyleInformationRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoInlineStyleInformation">
<description><![CDATA[
Style information should be put in CSS files, not in JSPs. Therefore, don't use <B> or <FONT> tags, or attributes like "align='center'". ]]>
</description>
<priority>3</priority>
<example>
<![CDATA[
<html><body><p align='center'><b>text</b></p></body></html>
]]>
</example>
</rule>
<rule name="NoClassAttribute" language="jsp" since="3.6"
message="Do not use an attribute called 'class'."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoClassAttribute">
<description>
Do not use an attribute called 'class'. Use "styleclass" for CSS styles.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[ //Attribute[ upper-case(@Name)="CLASS" ] ]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML> <BODY>
<P class="MajorHeading">Some text</P>
</BODY> </HTML>
]]>
</example>
</rule>
<rule name="NoJspForward" language="jsp" since="3.6"
message="Do not do a forward from within a JSP file."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoJspForward">
<description>
Do not do a forward from within a JSP file.
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[ //Element[ @Name="jsp:forward" ] ]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<jsp:forward page='UnderConstruction.jsp'/>
]]>
</example>
</rule>
<rule name="IframeMissingSrcAttribute" language="jsp" since="3.6"
message="IFrames must have a src attribute."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#IframeMissingSrcAttribute">
<description>
IFrames which are missing a src element can cause security information popups in IE if you are accessing the page
through SSL. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q261188
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Element[upper-case(@Name)="IFRAME"][count(Attribute[upper-case(@Name)="SRC" ]) = 0]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML><title>bad example><BODY>
<iframe></iframe>
</BODY> </HTML>
<HTML><title>good example><BODY>
<iframe src="foo"></iframe>
</BODY> </HTML>
]]>
</example>
</rule>
<rule name="NoHtmlComments" language="jsp" since="3.6"
message="Use JSP comments instead of HTML comments"
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoHtmlComments">
<description>
In a production system, HTML comments increase the payload
between the application server to the client, and serve
little other purpose. Consider switching to JSP comments.
</description>
<priority>2</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//CommentTag
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
<HTML><title>bad example><BODY>
<!-- HTML comment -->
</BODY> </HTML>
<HTML><title>good example><BODY>
<%-- JSP comment --%>
</BODY> </HTML>
]]>
</example>
</rule>
<rule name="DuplicateJspImports" since="3.7"
message="Avoid duplicate imports such as ''{0}''"
class="net.sourceforge.pmd.lang.jsp.rule.basic.DuplicateJspImportsRule"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#DuplicateJspImports">
<description><![CDATA[Avoid duplicate import statements inside JSP's. ]]>
</description>
<priority>3</priority>
<example>
<![CDATA[
<%@ page import=\"com.foo.MyClass,com.foo.MyClass\"%><html><body><b><img src=\"<%=Some.get()%>/foo\">xx</img>text</b></body></html>
]]>
</example>
</rule>
<rule name="JspEncoding" language="jsp" since="4.0"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="JSP file should use UTF-8 encoding"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#JspEncoding">
<description>
<![CDATA[
A missing 'meta' tag or page directive will trigger this rule, as well as a non-UTF-8 charset.
]]>
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//Content[
not(Element[@Name="meta"][
Attribute[@Name="content"]/AttributeValue[contains(lower-case(@Image),"charset=utf-8")]
])
and
not(JspDirective[@Name='page']/JspDirectiveAttribute[@Name='contentType'][contains(lower-case(@Value),"charset=utf-8")])
]
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
Most browsers should be able to interpret the following headers:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" />
]]>
</example>
</rule>
<rule
name="NoInlineScript" language="jsp" since="4.0"
class="net.sourceforge.pmd.lang.rule.XPathRule"
message="Avoiding inlining HTML script content"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoInlineScript">
<description>
<![CDATA[
Avoid inlining HTML script content. Consider externalizing the HTML script using the 'src' attribute on the <script> element.
Externalized script could be reused between pages. Browsers can also cache the script, reducing overall download bandwidth.
]]>
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//HtmlScript[@Image != '']
]]>
</value>
</property>
</properties>
<example>
<![CDATA[
Most browsers should be able to interpret the following headers:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<meta http-equiv="Content-Type"  content="text/html; charset=UTF-8" />
]]>
</example>
</rule>
<rule
name="NoUnsanitizedJSPExpression" since="5.1.4"
class="net.sourceforge.pmd.lang.jsp.rule.basic.NoUnsanitizedJSPExpressionRule"
message="Using unsanitized JSP expression can lead to Cross Site Scripting (XSS) attacks"
externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd-jsp/rules/jsp/basic.html#NoUnsanitizedJSPExpression">
<description>
Avoid using expressions without escaping / sanitizing. This could lead to cross site scripting - as the expression
would be interpreted by the browser directly (e.g. "&lt;script&gt;alert('hello');&lt;/script&gt;").
</description>
<priority>3</priority>
<example>
<![CDATA[
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
${expression} <!-- don't use this -->
${fn:escapeXml(expression)} <!-- instead, escape it -->
<c:out value="${expression}" /> <!-- or use c:out -->
]]>
</example>
</rule>
</ruleset>

19
src/main/pmd/ruleset_security.xml

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<ruleset name="Rule Set - Security"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>These rules check the security guidelines from Sun, published at http://java.sun.com/security/seccodeguide.html#gcg</description>
<!-- Priorities
HIGH :1
MEDIUM_HIGH:2
MEDIUM:3
MEDIUM_LOW:4
LOW : 5
-->
<rule ref="rulesets/java/sunsecure.xml/MethodReturnsInternalArray"> <priority>3</priority></rule>
<rule ref="rulesets/java/sunsecure.xml/ArrayIsStoredDirectly"> <priority>3</priority></rule>
</ruleset>
Loading…
Cancel
Save