changeset 284:b7ec1ed8117b

Setup maven-pmd-plugin for automated static code analysis Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025332.html
author Miloslav Zezulka <mzezulka@redhat.com>
date Mon, 09 Oct 2017 12:29:22 +0200
parents 52ee8129e08b
children 701a5b3037dd
files build-tools/pom.xml build-tools/src/main/resources/rulesets/pmdRulesets.xml common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/ThermostatMongoStorage.java pom.xml
diffstat 4 files changed, 152 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build-tools/pom.xml	Mon Oct 09 12:29:22 2017 +0200
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2012-2017 Red Hat, Inc.
+
+ This file is part of Thermostat.
+
+ Thermostat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Thermostat is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Thermostat; see the file COPYING.  If not see
+ <http://www.gnu.org/licenses/>.
+
+ Linking this code with other modules is making a combined work
+ based on this code.  Thus, the terms and conditions of the GNU
+ General Public License cover the whole combination.
+
+ As a special exception, the copyright holders of this code give
+ you permission to link this code with independent modules to
+ produce an executable, regardless of the license terms of these
+ independent modules, and to copy and distribute the resulting
+ executable under terms of your choice, provided that you also
+ meet, for each linked independent module, the terms and conditions
+ of the license of that module.  An independent module is a module
+ which is not derived from or based on this code.  If you modify
+ this code, you may extend this exception to your version of the
+ library, but you are not obligated to do so.  If you do not wish
+ to do so, delete this exception statement from your version.
+
+-->
+<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>com.redhat.thermostat</groupId>
+  <version>1.0</version>
+  <artifactId>build-tools</artifactId>
+  <name>Thermostat Build Tools</name>
+</project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build-tools/src/main/resources/rulesets/pmdRulesets.xml	Mon Oct 09 12:29:22 2017 +0200
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright 2012-2017 Red Hat, Inc.
+
+ This file is part of Thermostat.
+
+ Thermostat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ Thermostat is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Thermostat; see the file COPYING.  If not see
+ <http://www.gnu.org/licenses/>.
+
+ Linking this code with other modules is making a combined work
+ based on this code.  Thus, the terms and conditions of the GNU
+ General Public License cover the whole combination.
+
+ As a special exception, the copyright holders of this code give
+ you permission to link this code with independent modules to
+ produce an executable, regardless of the license terms of these
+ independent modules, and to copy and distribute the resulting
+ executable under terms of your choice, provided that you also
+ meet, for each linked independent module, the terms and conditions
+ of the license of that module.  An independent module is a module
+ which is not derived from or based on this code.  If you modify
+ this code, you may extend this exception to your version of the
+ library, but you are not obligated to do so.  If you do not wish
+ to do so, delete this exception statement from your version.
+
+-->
+<ruleset name="Web-gateway PMD ruleset"
+    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>
+        Ruleset definition for Thermostat-ng web-gateway module.
+    </description>
+
+    <rule ref="rulesets/java/basic.xml"/>
+</ruleset>
\ No newline at end of file
--- a/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/ThermostatMongoStorage.java	Mon Oct 09 15:05:27 2017 +0200
+++ b/common/mongodb/src/main/java/com/redhat/thermostat/gateway/common/mongodb/ThermostatMongoStorage.java	Mon Oct 09 12:29:22 2017 +0200
@@ -33,6 +33,7 @@
  * library, but you are not obligated to do so.  If you do not wish
  * to do so, delete this exception statement from your version.
  */
+
 package com.redhat.thermostat.gateway.common.mongodb;
 
 import java.net.URI;
--- a/pom.xml	Mon Oct 09 15:05:27 2017 +0200
+++ b/pom.xml	Mon Oct 09 12:29:22 2017 +0200
@@ -56,6 +56,7 @@
         <module>services</module>
         <module>ide-launcher</module>
         <module>tests</module>
+        <module>build-tools</module>
     </modules>
 
     <properties>
@@ -85,6 +86,10 @@
         <maven.ktest.skip>true</maven.ktest.skip>
         <!-- Intentionally empty. See java-7 profile -->
         <surefire.argline></surefire.argline>
+
+        <pmd.plugin.version>3.8</pmd.plugin.version>
+        <pmd.rules.path>rulesets/pmdRulesets.xml</pmd.rules.path>
+        <jxr.version>2.3</jxr.version>
     </properties>
 
     <profiles>
@@ -139,6 +144,37 @@
         </pluginManagement>
         <plugins>
             <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-pmd-plugin</artifactId>
+                <version>${pmd.plugin.version}</version>
+                <configuration>
+                    <skip>${maven.test.skip}</skip>
+                    <rulesets>
+                        <ruleset>${pmd.rules.path}</ruleset>
+                    </rulesets>
+                    <format>xml</format>
+                    <includeTests>false</includeTests>
+                    <aggregate>true</aggregate>
+                    <printFailingErrors>true</printFailingErrors>
+                    <failOnViolation>true</failOnViolation>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>check</goal>
+                        </goals>
+                        <phase>integration-test</phase>
+                    </execution>
+                </executions>
+                <dependencies>
+                    <dependency>
+                        <groupId>com.redhat.thermostat</groupId>
+                        <artifactId>build-tools</artifactId>
+                        <version>1.0</version>
+                    </dependency>
+                </dependencies>
+            </plugin>
+            <plugin>
                 <groupId>com.mycila</groupId>
                 <artifactId>license-maven-plugin</artifactId>
                 <version>2.6</version>
@@ -180,4 +216,25 @@
             </plugin>
         </plugins>
     </build>
+    <reporting>
+        <plugins>
+            <!--add maven-jxr-plugin - this is maven-pmd-plugin dependency  -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jxr-plugin</artifactId>
+                <version>${jxr.version}</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-pmd-plugin</artifactId>
+                <version>${pmd.plugin.version}</version>
+                <configuration>
+                    <skipEmptyReport>true</skipEmptyReport>
+                    <rulesets>
+                        <ruleset>${pmd.rules.path}</ruleset>
+                    </rulesets>
+                </configuration>
+            </plugin>
+        </plugins>
+    </reporting>
 </project>