Add a new rule 'InvalidDependencyType' to pom rulesets

This commit is contained in:
Romain PELISSE
2015-05-09 00:44:40 +02:00
parent a2526cc87a
commit 8057a5c0df
2 changed files with 94 additions and 1 deletions

View File

@@ -42,4 +42,46 @@ ${project.version} in a BOM or parent POM.
]]>
</example>
</rule>
</ruleset>
<rule name="InvalidDependencyTypes"
language="xml"
since="5.4"
message="By default, Maven only recognized the following types: $validTypes."
class="net.sourceforge.pmd.lang.rule.XPathRule"
externalInfoUrl="${pmd.website.baseurl}/rules/pom/basic.html#InvalidDependencyTypes">
<description><![CDATA[
While Maven will not failed if you use an invalid type for a dependency in the dependency management section, it will not also uses the dependency. ]]>
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value>
<![CDATA[
//dependencyManagement/dependency/type/text[not(contains('pom, jar, maven-plugin, ejb, war, ear, rar, par',@Image))]
]]>
</value>
</property>
<!-- FIXME: property injection seems to be failing with XML.... -->
<!-- property name="validTypes" value="pom, jar, maven-plugin, ejb, war, ear, rar, par" description="Set of valid types."-->
</properties>
<example>
<![CDATA[
<project...>
...
<dependencyManagement>
...
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<type>bom</type> <!-- not a valid type ! 'pom' is ! -->
<scope>import</scope>
</dependency>
...
</dependencyManagement>
</project>
]]>
</example>
</rule>
</ruleset>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<test-data>
<test-code>
<description>Simple POM file - no violation</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>xml-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencyManagement>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
</project>
]]></code>
<source-type>xml</source-type>
</test-code>
<test-code>
<description>Simple POM file with violation</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>xml-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<dependencyManagement>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<type>bom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
</project>
]]></code>
<source-type>xml</source-type>
</test-code>
</test-data>