Skip to content

Commit 648230d

Browse files
committed
Add all the parameters and generalize usage
1 parent 11e1418 commit 648230d

2 files changed

Lines changed: 91 additions & 22 deletions

File tree

action.yml

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,47 @@ inputs:
88
description: 'SpotBugs version to use.'
99
default: 'latest'
1010
required: false
11+
packages:
12+
description: >
13+
Comma separated list of packages to scan. It will fill the
14+
-onlyAnalyze parameter in spotbugs. It can contain the wildcards '*' and
15+
'-': com.example.* for single package or com.example.- for all
16+
subpackages.
17+
18+
If not specified, it will scan all packages.
19+
See more: https://spotbugs.readthedocs.io/en/stable/running.html#text-ui-options
20+
required: false
1121
arguments:
12-
description: 'Command arguments to be sent to SpotBugs'
13-
required: true
14-
default: ''
22+
description: >
23+
A string with any additional command arguments to be sent to spotbugs.
24+
See more: https://spotbugs.readthedocs.io/en/stable/running.html#text-ui-options
25+
required: false
1526
output:
16-
description: 'Output file name'
17-
required: true
27+
description: >
28+
The output filename. If not specified, it will use the default name
29+
'results.EXTENSION'
1830
target:
19-
description: 'Target of what you want to analyze'
20-
required: true
31+
description: >
32+
Target of what you want to analyze. It can be a file or a directory, it
33+
is usually the ./target folder where you compiled your project.
34+
required: false
35+
outputType:
36+
description: >
37+
Output type for the report. It can be 'xml', 'html', 'sarif', 'emacs'
38+
or 'xdocs'. Default value is 'sarif' as it is the used by GitHub Advanced
39+
Security.
40+
default: 'sarif'
41+
required: true
42+
dependenciesPath:
43+
description: >
44+
Path to the dependencies folder. For Maven it is usually stored in the
45+
'~/.m2' folder.
46+
required: false
47+
basePath:
48+
description: >
49+
The basePath is used as a prefix in the sarif file to help GitHub find the
50+
right file of the issue. It is tipically something like 'src/main/java'.
51+
required: false
2152
runs:
2253
using: "composite"
2354
steps:
@@ -26,6 +57,10 @@ runs:
2657
shell: bash
2758
env:
2859
SPOTBUGS_VERSION: ${{ inputs.spotbugs-version }}
60+
PACKAGES: ${{ inputs.packages }}
2961
OUTPUT: ${{ inputs.output }}
62+
OUTPUT_TYPE: ${{ inputs.outputType }}
3063
ARGUMENTS: ${{ inputs.arguments }}
31-
TARGET: ${{ inputs.target }}
64+
TARGET: ${{ inputs.target }}
65+
DEPENDENCIES_PATH: ${{ inputs.dependenciesPath }}
66+
BASE_PATH: ${{ inputs.basePath }}

analyze.sh

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# PACKAGES="com.example.demo.-"
55
# source path to prepend to the class path
66
# BASEPATH="src/main/java"
7-
# DEPENDENCYPATH="~/.m2"
8-
7+
# DEPENDENCIES_PATH="~/.m2"
8+
# OUTPUT_TYPE="sarif"
99

1010
# Check whether to use latest version of PMD
1111
if [ "$SPOTBUGS_VERSION" == 'latest' ] || [ "$SPOTBUGS_VERSION" == "" ]; then
@@ -34,20 +34,54 @@ fi
3434

3535
CMD="$CMD -quiet -effort:max -low -noClassOk"
3636

37-
if [ "$SARIF" == "true" ]; then
38-
CMD="$CMD -sarif:withMessages=./resultspre.sarif"
39-
fi
40-
41-
if [ "$DEPENDENCYPATH" != "" ]; then
42-
find "$DEPENDENCYPATH" -name "*.jar" -type f > /tmp/jardependencies.txt
37+
case $OUTPUT_TYPE in
38+
"xml")
39+
if [ "$OUTPUT" == "" ]; then
40+
OUTPUT="results.xml"
41+
fi
42+
CMD="$CMD -xml:withMessages=./$OUTPUT"
43+
;;
44+
"html")
45+
if [ "$OUTPUT" == "" ]; then
46+
OUTPUT="results.html"
47+
fi
48+
CMD="$CMD -html:withMessages=./$OUTPUT"
49+
;;
50+
"emacs")
51+
if [ "$OUTPUT" == "" ]; then
52+
OUTPUT="results.emacs"
53+
fi
54+
CMD="$CMD -emacs:withMessages=./$OUTPUT"
55+
;;
56+
"xdocs")
57+
if [ "$OUTPUT" == "" ]; then
58+
OUTPUT="results.xdocs"
59+
fi
60+
CMD="$CMD -xdoc:withMessages=./$OUTPUT"
61+
;;
62+
*)
63+
OUTPUT_TYPE="sarif"
64+
if [ "$OUTPUT" == "" ]; then
65+
OUTPUT="results.sarif"
66+
fi
67+
CMD="$CMD -sarif:withMessages=./resultspre.sarif"
68+
;;
69+
esac
70+
71+
if [ "$DEPENDENCIES_PATH" != "" ]; then
72+
find "$DEPENDENCIES_PATH" -name "*.jar" -type f > /tmp/jardependencies.txt
4373
CMD="$CMD -auxclasspathFromFile /tmp/jardependencies.txt"
4474
fi
4575

46-
if [ "$BASEPATH" != "" ]; then
47-
if [[ "$BASEPATH" != */ ]]; then
48-
BASEPATH="$BASEPATH/"
76+
if [ "$BASE_PATH" != "" ]; then
77+
if [[ "$BASE_PATH" != */ ]]; then
78+
BASEPATH="$BASE_PATH/"
4979
fi
50-
CMD="$CMD -sourcepath ${BASEPATH}"
80+
CMD="$CMD -sourcepath ${BASE_PATH}"
81+
fi
82+
83+
if [ "$ARGUMENTS" != ""]; then
84+
CMD="$CMD ${ARGUMENTS}"
5185
fi
5286

5387
if [ "$TARGET" != "" ]; then
@@ -60,8 +94,8 @@ echo "Running SpotBugs with command: $CMD"
6094

6195
eval ${CMD}
6296

63-
if [ "$SARIF" == "true" ] && [ "$BASEPATH" != "" ]; then
97+
if [ "$OUTPUT_TYPE" == "sarif" ] && [ "$BASE_PATH" != "" ]; then
6498
# prepend the pyhsical path
65-
jq -c "(.runs[].results[].locations[].physicalLocation.artifactLocation.uri) |=\"$BASEPATH\"+." resultspre.sarif > results.sarif
99+
jq -c "(.runs[].results[].locations[].physicalLocation.artifactLocation.uri) |=\"$BASEPATH\"+." resultspre.sarif > "$OUTPUT"
66100
fi
67101

0 commit comments

Comments
 (0)