From 2a25d7391bb6bdfe145179804ab3fcf4c81f49c6 Mon Sep 17 00:00:00 2001 From: Joe DiPol Date: Fri, 24 May 2024 13:52:44 -0700 Subject: [PATCH] Add Spotbugs (#5) * Add support for running spotbugs * Add spotbugs check to validate workflow --- .github/workflows/validate.yml | 14 +++++++++- etc/scripts/spotbugs.sh | 47 ++++++++++++++++++++++++++++++++++ etc/spotbugs/exclude.xml | 26 +++++++++++++++++++ pom.xml | 44 ++++++++++++++++++++++++++++++- 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100755 etc/scripts/spotbugs.sh create mode 100644 etc/spotbugs/exclude.xml diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 45530a2..27d95bd 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -58,4 +58,16 @@ jobs: - name: Maven build run: | mvn -B -e $MAVEN_HTTP_ARGS clean install - + spotbugs: + timeout-minutes: 10 + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4.1.0 + with: + distribution: ${{ env.JAVA_DISTRO }} + java-version: ${{ env.JAVA_VERSION }} + cache: maven + - name: Spotbugs + run: etc/scripts/spotbugs.sh diff --git a/etc/scripts/spotbugs.sh b/etc/scripts/spotbugs.sh new file mode 100755 index 0000000..14d55dc --- /dev/null +++ b/etc/scripts/spotbugs.sh @@ -0,0 +1,47 @@ +#!/bin/bash -e +# +# Copyright (c) 2024 Oracle and/or its affiliates. +# +# Licensed 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. +# + +set -o pipefail || true # trace ERR through pipes +set -o errtrace || true # trace ERR through commands and functions +set -o errexit || true # exit the script if any statement returns a non-true return value + +on_error(){ + CODE="${?}" && \ + set +x && \ + printf "[ERROR] Error(code=%s) occurred at %s:%s command: %s\n" \ + "${CODE}" "${BASH_SOURCE[0]}" "${LINENO}" "${BASH_COMMAND}" +} +trap on_error ERR + +# Path to this script +if [ -h "${0}" ] ; then + SCRIPT_PATH="$(readlink "${0}")" +else + SCRIPT_PATH="${0}" +fi +readonly SCRIPT_PATH + +# Path to the root of the workspace +# shellcheck disable=SC2046 +WS_DIR=$(cd $(dirname -- "${SCRIPT_PATH}") ; cd ../.. ; pwd -P) +readonly WS_DIR + +mvn ${MAVEN_ARGS} -f ${WS_DIR}/pom.xml \ + install -e \ + -DskipTests \ + -Dmaven.test.skip=true \ + -Pspotbugs diff --git a/etc/spotbugs/exclude.xml b/etc/spotbugs/exclude.xml new file mode 100644 index 0000000..1e06a72 --- /dev/null +++ b/etc/spotbugs/exclude.xml @@ -0,0 +1,26 @@ + + + + + + + diff --git a/pom.xml b/pom.xml index a0cb60e..e701f5b 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,9 @@ false false + false + Medium + etc/spotbugs/exclude.xml 10.13.0 2.7.2 @@ -50,7 +53,8 @@ 4.0.6 3.1.7 6.2.1 - + 4.8.5.0 + 1.13.0 @@ -389,6 +393,26 @@ + + com.github.spotbugs + spotbugs-maven-plugin + ${version.plugin.spotbugs} + + FindReturnRef + ${spotbugs.skip} + ${spotbugs.threshold} + + ${spotbugs.exclude} + true + + + com.h3xstream.findsecbugs + findsecbugs-plugin + ${version.plugin.findsecbugs} + + + + org.apache.maven.plugins maven-checkstyle-plugin @@ -436,5 +460,23 @@ + + spotbugs + + + + com.github.spotbugs + spotbugs-maven-plugin + + + + check + + + + + + +