Bug 568879: [Build] fix warnings, add code checkers

  add pmd support for the IDE
  add pmd rules to be picked up by the maven build

Change-Id: Ib4b4cc8585b6c47d8150bd7c1523b2914d53f3c8
diff --git a/plugins/org.eclipse.skills.dependencies/.eclipse-pmd b/plugins/org.eclipse.skills.dependencies/.eclipse-pmd
new file mode 100644
index 0000000..a18e37c
--- /dev/null
+++ b/plugins/org.eclipse.skills.dependencies/.eclipse-pmd
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
+  <analysis enabled="true" />
+  <rulesets>
+    <ruleset name="Eclipse Skills PMD Rules" ref="org.eclipse.skills.releng/pmd/pmd_rules.xml" refcontext="workspace" />
+  </rulesets>
+</eclipse-pmd>
\ No newline at end of file
diff --git a/plugins/org.eclipse.skills.dependencies/.project b/plugins/org.eclipse.skills.dependencies/.project
index a082012..432f87b 100644
--- a/plugins/org.eclipse.skills.dependencies/.project
+++ b/plugins/org.eclipse.skills.dependencies/.project
@@ -20,9 +20,15 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>ch.acanda.eclipse.pmd.builder.PMDBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>ch.acanda.eclipse.pmd.builder.PMDNature</nature>
 	</natures>
 </projectDescription>
diff --git a/plugins/org.eclipse.skills.ui.questeditor/.eclipse-pmd b/plugins/org.eclipse.skills.ui.questeditor/.eclipse-pmd
new file mode 100644
index 0000000..a18e37c
--- /dev/null
+++ b/plugins/org.eclipse.skills.ui.questeditor/.eclipse-pmd
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
+  <analysis enabled="true" />
+  <rulesets>
+    <ruleset name="Eclipse Skills PMD Rules" ref="org.eclipse.skills.releng/pmd/pmd_rules.xml" refcontext="workspace" />
+  </rulesets>
+</eclipse-pmd>
\ No newline at end of file
diff --git a/plugins/org.eclipse.skills.ui.questeditor/.project b/plugins/org.eclipse.skills.ui.questeditor/.project
index 7f65681..07d642b 100644
--- a/plugins/org.eclipse.skills.ui.questeditor/.project
+++ b/plugins/org.eclipse.skills.ui.questeditor/.project
@@ -25,9 +25,15 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>ch.acanda.eclipse.pmd.builder.PMDBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>ch.acanda.eclipse.pmd.builder.PMDNature</nature>
 	</natures>
 </projectDescription>
diff --git a/plugins/org.eclipse.skills/.eclipse-pmd b/plugins/org.eclipse.skills/.eclipse-pmd
new file mode 100644
index 0000000..a18e37c
--- /dev/null
+++ b/plugins/org.eclipse.skills/.eclipse-pmd
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
+  <analysis enabled="true" />
+  <rulesets>
+    <ruleset name="Eclipse Skills PMD Rules" ref="org.eclipse.skills.releng/pmd/pmd_rules.xml" refcontext="workspace" />
+  </rulesets>
+</eclipse-pmd>
\ No newline at end of file
diff --git a/plugins/org.eclipse.skills/.project b/plugins/org.eclipse.skills/.project
index b196ed4..0fe971a 100644
--- a/plugins/org.eclipse.skills/.project
+++ b/plugins/org.eclipse.skills/.project
@@ -20,10 +20,16 @@
 			<arguments>

 			</arguments>

 		</buildCommand>

+		<buildCommand>

+			<name>ch.acanda.eclipse.pmd.builder.PMDBuilder</name>

+			<arguments>

+			</arguments>

+		</buildCommand>

 	</buildSpec>

 	<natures>

 		<nature>org.eclipse.sirius.nature.modelingproject</nature>

 		<nature>org.eclipse.jdt.core.javanature</nature>

 		<nature>org.eclipse.pde.PluginNature</nature>

+		<nature>ch.acanda.eclipse.pmd.builder.PMDNature</nature>

 	</natures>

 </projectDescription>

diff --git a/releng/org.eclipse.skills.releng/pmd/pmd_rules.xml b/releng/org.eclipse.skills.releng/pmd/pmd_rules.xml
new file mode 100644
index 0000000..b683bbe
--- /dev/null
+++ b/releng/org.eclipse.skills.releng/pmd/pmd_rules.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0"?>
+
+<ruleset name="Custom Rules"
+	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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
+
+	<description>
+        Eclipse Skills PMD rules
+    </description>
+
+	<exclude-pattern>.*/org/eclipse/skills/model/.*</exclude-pattern>
+
+	<rule ref="category/java/bestpractices.xml">
+		<!-- Skills logger takes care of guarding -->
+		<exclude name="GuardLogStatement" />
+	</rule>
+
+	<rule ref="category/java/codestyle.xml">
+		<!-- Allow non final method arguments -->
+		<exclude name="MethodArgumentCouldBeFinal" />
+
+		<!-- Fields can be defined after static methods -->
+		<exclude name="FieldDeclarationsShouldBeAtStartOfClass" />
+
+		<!-- Allow to use single line blocks without {} -->
+		<exclude name="IfStmtsMustUseBraces" />
+		<exclude name="IfElseStmtsMustUseBraces" />
+		<exclude name="ForLoopsMustUseBraces" />
+		<exclude name="WhileLoopsMustUseBraces" />
+		<exclude name="ControlStatementBraces" />
+
+		<!-- Allow additional () for readability -->
+		<exclude name="UselessParentheses" />
+
+		<!-- Allow more than one return statement in a method -->
+		<exclude name="OnlyOneReturn" />
+
+		<!-- Do not require to call super() in constructor -->
+		<exclude name="CallSuperInConstructor" />
+
+		<!-- Do not require a default constructor -->
+		<exclude name="AtLeastOneConstructor" />
+
+		<!-- Allow variable names -->
+		<exclude name="ShortVariable" />
+		<exclude name="LongVariable" />
+	</rule>
+
+	<rule ref="category/java/codestyle.xml/ClassNamingConventions">
+		<properties>
+			<property name="utilityClassPattern"
+				value="[A-Z][a-zA-Z0-9]+" />
+		</properties>
+	</rule>
+
+	<rule ref="category/java/design.xml">
+		<exclude name="LawOfDemeter" />
+
+		<!-- needs detailed configuration to work, otherwise fails in maven -->
+		<exclude name="LoosePackageCoupling" />
+	</rule>
+
+	<rule ref="category/java/documentation.xml">
+		<exclude name="CommentRequired" />
+		<exclude name="CommentSize" />
+
+		<!-- Allow empty constructors without documentation -->
+		<exclude name="UncommentedEmptyConstructor" />
+	</rule>
+
+	<rule ref="category/java/errorprone.xml">
+		<exclude name="BeanMembersShouldSerialize" />
+	
+		<!-- fails in maven build, see https://github.com/pmd/pmd/issues/873 -->
+		<exclude name="DataflowAnomalyAnalysis" />
+	</rule>
+
+	<rule ref="category/java/multithreading.xml" />
+
+	<rule ref="category/java/performance.xml" />
+
+	<rule ref="category/java/security.xml" />
+
+</ruleset>
\ No newline at end of file
diff --git a/releng/org.eclipse.skills.releng/pom.xml b/releng/org.eclipse.skills.releng/pom.xml
index ffb92e7..5599534 100644
--- a/releng/org.eclipse.skills.releng/pom.xml
+++ b/releng/org.eclipse.skills.releng/pom.xml
@@ -73,6 +73,7 @@
 					<excludeRoots>
 						<excludeRoot>src-gen</excludeRoot>
 					</excludeRoots>
+					<rulesets>../../releng/org.eclipse.skills.releng/pmd/pmd_rules.xml</rulesets>
 				</configuration>
 			</plugin>
 
diff --git a/tests/org.eclipse.skills.dependencies.test/.eclipse-pmd b/tests/org.eclipse.skills.dependencies.test/.eclipse-pmd
new file mode 100644
index 0000000..a18e37c
--- /dev/null
+++ b/tests/org.eclipse.skills.dependencies.test/.eclipse-pmd
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
+  <analysis enabled="true" />
+  <rulesets>
+    <ruleset name="Eclipse Skills PMD Rules" ref="org.eclipse.skills.releng/pmd/pmd_rules.xml" refcontext="workspace" />
+  </rulesets>
+</eclipse-pmd>
\ No newline at end of file
diff --git a/tests/org.eclipse.skills.dependencies.test/.project b/tests/org.eclipse.skills.dependencies.test/.project
index 50bbdfd..ca9457d 100644
--- a/tests/org.eclipse.skills.dependencies.test/.project
+++ b/tests/org.eclipse.skills.dependencies.test/.project
@@ -20,9 +20,15 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>ch.acanda.eclipse.pmd.builder.PMDBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>ch.acanda.eclipse.pmd.builder.PMDNature</nature>
 	</natures>
 </projectDescription>
diff --git a/tests/org.eclipse.skills.test/.eclipse-pmd b/tests/org.eclipse.skills.test/.eclipse-pmd
new file mode 100644
index 0000000..a18e37c
--- /dev/null
+++ b/tests/org.eclipse.skills.test/.eclipse-pmd
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
+  <analysis enabled="true" />
+  <rulesets>
+    <ruleset name="Eclipse Skills PMD Rules" ref="org.eclipse.skills.releng/pmd/pmd_rules.xml" refcontext="workspace" />
+  </rulesets>
+</eclipse-pmd>
\ No newline at end of file
diff --git a/tests/org.eclipse.skills.test/.project b/tests/org.eclipse.skills.test/.project
index 6827bf4..deb4e14 100644
--- a/tests/org.eclipse.skills.test/.project
+++ b/tests/org.eclipse.skills.test/.project
@@ -20,9 +20,15 @@
 			<arguments>
 			</arguments>
 		</buildCommand>
+		<buildCommand>
+			<name>ch.acanda.eclipse.pmd.builder.PMDBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
 	</buildSpec>
 	<natures>
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>ch.acanda.eclipse.pmd.builder.PMDNature</nature>
 	</natures>
 </projectDescription>