This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new b7a2ce0ecf HDDS-12339. Add CI check for PMD (#7896)
b7a2ce0ecf is described below

commit b7a2ce0ecfa5fe406927e6f7577267609d48ddbb
Author: Ivan Zlenko <[email protected]>
AuthorDate: Mon Feb 17 16:59:44 2025 +0500

    HDDS-12339. Add CI check for PMD (#7896)
---
 .github/ci.md                                |  1 +
 CONTRIBUTING.md                              |  1 +
 dev-support/ci/selective_ci_checks.bats      | 28 +++++++++----------
 dev-support/ci/selective_ci_checks.sh        | 21 ++++++++++++++
 dev-support/pmd/pmd-ruleset.xml              | 30 ++++++++++++++++++++
 hadoop-ozone/dev-support/checks/pmd.sh       | 41 ++++++++++++++++++++++++++++
 hadoop-ozone/httpfsgateway/src/site/site.xml |  2 +-
 pom.xml                                      | 12 ++++++++
 8 files changed, 121 insertions(+), 15 deletions(-)

diff --git a/.github/ci.md b/.github/ci.md
index 46abf29d21..fda4983d10 100644
--- a/.github/ci.md
+++ b/.github/ci.md
@@ -44,6 +44,7 @@ Runs a subset of the following subjobs depending on what was 
selected by build-i
 - checkstyle: [Runs](../hadoop-ozone/dev-support/checks/checkstyle.sh) 'mvn 
checkstyle' plugin to confirm Java source abides by Ozone coding conventions
 - docs: [Builds](../hadoop-ozone/dev-support/checks/docs.sh) website with 
[Hugo](https://gohugo.io/)
 - findbugs: [Runs](../hadoop-ozone/dev-support/checks/findbugs.sh) spotbugs 
static analysis on bytecode
+- pmd: [Runs](../hadoop-ozone/dev-support/checks/pmd.sh) PMD static analysis 
on project's source code
 - rat (release audit tool): 
[Confirms](../hadoop-ozone/dev-support/checks/rat.sh) source files include 
licenses
 
 
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e633b159d2..8a1eeda8cf 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -145,6 +145,7 @@ The [`hadoop-ozone/dev-support/checks` 
directory](https://github.com/apache/ozon
     * `docs.sh`: sanity checks for [Ozone 
documentation](https://github.com/apache/ozone/tree/master/hadoop-hdds/docs)
     * `dependency.sh`: compares list of jars in build output with known list
     * `checkstyle.sh`: Checkstyle
+    * `pmd.sh`: PMD
  3. moderate (around 10 minutes)
     * `findbugs.sh`: SpotBugs
     * `kubernetes.sh`: very limited set of tests run in Kubernetes environment
diff --git a/dev-support/ci/selective_ci_checks.bats 
b/dev-support/ci/selective_ci_checks.bats
index e1a9f90807..99085c942e 100644
--- a/dev-support/ci/selective_ci_checks.bats
+++ b/dev-support/ci/selective_ci_checks.bats
@@ -102,7 +102,7 @@ load bats-assert/load.bash
 @test "integration and unit: java change" {
   run dev-support/ci/selective_ci_checks.sh 9aebf6e25
 
-  assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=false
@@ -135,7 +135,7 @@ load bats-assert/load.bash
 @test "unit only" {
   run dev-support/ci/selective_ci_checks.sh 1dd1d0ba3
 
-  assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=false
@@ -146,7 +146,7 @@ load bats-assert/load.bash
 @test "unit helper" {
   run dev-support/ci/selective_ci_checks.sh 88383d1d5
 
-  assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=false
@@ -157,7 +157,7 @@ load bats-assert/load.bash
 @test "integration only" {
   run dev-support/ci/selective_ci_checks.sh 61396ba9f
 
-  assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=false
@@ -168,7 +168,7 @@ load bats-assert/load.bash
 @test "native only" {
   run dev-support/ci/selective_ci_checks.sh 5b1319a8c2
 
-  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","native"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd","native"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=false
@@ -179,7 +179,7 @@ load bats-assert/load.bash
 @test "native test in other module" {
   run dev-support/ci/selective_ci_checks.sh 822c0dee1a
 
-  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","native"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd","native"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=false
@@ -212,7 +212,7 @@ load bats-assert/load.bash
 @test "main/java change" {
   run dev-support/ci/selective_ci_checks.sh 86a771dfe
 
-  assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -223,7 +223,7 @@ load bats-assert/load.bash
 @test "..../java change" {
   run dev-support/ci/selective_ci_checks.sh 01c616536
 
-  assert_output -p 'basic-checks=["rat","author","checkstyle","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -234,7 +234,7 @@ load bats-assert/load.bash
 @test "java and compose change" {
   run dev-support/ci/selective_ci_checks.sh d0f0f806e
 
-  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","native"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","findbugs","pmd","native"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -245,7 +245,7 @@ load bats-assert/load.bash
 @test "java and docs change" {
   run dev-support/ci/selective_ci_checks.sh 2c0adac26
 
-  assert_output -p 
'basic-checks=["rat","author","checkstyle","docs","findbugs"]'
+  assert_output -p 
'basic-checks=["rat","author","checkstyle","docs","findbugs","pmd"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -256,7 +256,7 @@ load bats-assert/load.bash
 @test "pom change" {
   run dev-support/ci/selective_ci_checks.sh 9129424a9
 
-  assert_output -p 'basic-checks=["rat","checkstyle","findbugs","native"]'
+  assert_output -p 
'basic-checks=["rat","checkstyle","findbugs","pmd","native"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -267,7 +267,7 @@ load bats-assert/load.bash
 @test "CI lib change" {
   run dev-support/ci/selective_ci_checks.sh ceb79acaa
 
-  assert_output -p 
'basic-checks=["author","bats","checkstyle","docs","findbugs","native","rat"]'
+  assert_output -p 
'basic-checks=["author","bats","checkstyle","docs","findbugs","native","pmd","rat"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -278,7 +278,7 @@ load bats-assert/load.bash
 @test "CI workflow change" {
   run dev-support/ci/selective_ci_checks.sh 90a8d7c01
 
-  assert_output -p 
'basic-checks=["author","bats","checkstyle","docs","findbugs","native","rat"]'
+  assert_output -p 
'basic-checks=["author","bats","checkstyle","docs","findbugs","native","pmd","rat"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
@@ -301,7 +301,7 @@ load bats-assert/load.bash
 @test "CI workflow change (ci.yaml)" {
   run dev-support/ci/selective_ci_checks.sh 90fd5f2adc
 
-  assert_output -p 
'basic-checks=["author","bats","checkstyle","docs","findbugs","native","rat"]'
+  assert_output -p 
'basic-checks=["author","bats","checkstyle","docs","findbugs","native","pmd","rat"]'
   assert_output -p needs-build=true
   assert_output -p needs-compile=true
   assert_output -p needs-compose-tests=true
diff --git a/dev-support/ci/selective_ci_checks.sh 
b/dev-support/ci/selective_ci_checks.sh
index a20d3cc307..213d071b91 100755
--- a/dev-support/ci/selective_ci_checks.sh
+++ b/dev-support/ci/selective_ci_checks.sh
@@ -418,6 +418,26 @@ function check_needs_findbugs() {
     start_end::group_end
 }
 
+function check_needs_pmd() {
+    start_end::group_start "Check if pmd is needed"
+    local pattern_array=(
+        "^hadoop-ozone/dev-support/checks/pmd.sh"
+        "pom.xml"
+        "src/..../java"
+        "pmd-ruleset.xml"
+    )
+    local ignore_array=(
+        "^hadoop-ozone/dist"
+    )
+    filter_changed_files
+
+    if [[ ${match_count} != "0" ]]; then
+        add_basic_check pmd
+    fi
+
+    start_end::group_end
+}
+
 function check_needs_native() {
     start_end::group_start "Check if native is needed"
     local pattern_array=(
@@ -584,6 +604,7 @@ check_needs_bats
 check_needs_checkstyle
 check_needs_docs
 check_needs_findbugs
+check_needs_pmd
 check_needs_native
 calculate_test_types_to_run
 set_outputs
diff --git a/dev-support/pmd/pmd-ruleset.xml b/dev-support/pmd/pmd-ruleset.xml
new file mode 100644
index 0000000000..3b251b79b7
--- /dev/null
+++ b/dev-support/pmd/pmd-ruleset.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<ruleset name="Default Maven PMD Plugin 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.io/ruleset_2_0_0.xsd";>
+
+    <description>
+        PMD Ruleset for Apache Ozone
+    </description>
+
+    <exclude-pattern>.*/generated-sources/.*</exclude-pattern>
+</ruleset>
diff --git a/hadoop-ozone/dev-support/checks/pmd.sh 
b/hadoop-ozone/dev-support/checks/pmd.sh
new file mode 100755
index 0000000000..1a9c9487f3
--- /dev/null
+++ b/hadoop-ozone/dev-support/checks/pmd.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#checks:basic
+
+set -u -o pipefail
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+cd "$DIR/../../.." || exit 1
+
+REPORT_DIR=${OUTPUT_DIR:-"$DIR/../../../target/pmd"}
+mkdir -p "$REPORT_DIR"
+
+REPORT_FILE="$REPORT_DIR/summary.txt"
+
+MAVEN_OPTIONS='-B -fae --no-transfer-progress -Dpmd.failOnViolation=false 
-Dpmd.printFailingErrors -DskipRecon'
+
+declare -i rc
+
+#shellcheck disable=SC2086
+mvn $MAVEN_OPTIONS test-compile pmd:check "$@" | tee "${REPORT_DIR}/output.log"
+rc=$?
+
+grep -o "PMD Failure.*" "${REPORT_DIR}/output.log" > "$REPORT_FILE"
+
+ERROR_PATTERN="\[ERROR\]"
+
+source "${DIR}/_post_process.sh"
diff --git a/hadoop-ozone/httpfsgateway/src/site/site.xml 
b/hadoop-ozone/httpfsgateway/src/site/site.xml
index 98b6b5a418..cabc85022f 100644
--- a/hadoop-ozone/httpfsgateway/src/site/site.xml
+++ b/hadoop-ozone/httpfsgateway/src/site/site.xml
@@ -17,7 +17,7 @@
     <skin>
       <groupId>org.apache.maven.skins</groupId>
       <artifactId>maven-stylus-skin</artifactId>
-      <version>${maven-stylus-skin.version}</version>
+      <version>1.5</version>
     </skin>
 
     <body>
diff --git a/pom.xml b/pom.xml
index 5c904ed6dd..fe1cbeb3f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,6 +187,7 @@
     <ozone.version>2.0.0-SNAPSHOT</ozone.version>
     <picocli.version>4.7.5</picocli.version>
     <plexus-archiver.version>4.2.2</plexus-archiver.version>
+    <pmd.version>3.26.0</pmd.version>
     <!-- Enable Reproducible Builds mode -->
     
<project.build.outputTimestamp>2023-01-01T00:00:00Z</project.build.outputTimestamp>
     <!-- platform encoding override -->
@@ -1754,6 +1755,17 @@
           <artifactId>cyclonedx-maven-plugin</artifactId>
           <version>${cyclonedx.version}</version>
         </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-pmd-plugin</artifactId>
+          <version>${pmd.version}</version>
+          <configuration>
+            <rulesets>
+              <ruleset>dev-support/pmd/pmd-ruleset.xml</ruleset>
+            </rulesets>
+            <printFailingErrors>true</printFailingErrors>
+          </configuration>
+        </plugin>
       </plugins>
     </pluginManagement>
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to