This is a bit complicated, but here is a bash script that will analyze the property element from pom.xml, check to see if each property is used in pom, and, if necessary, check all the project files (deep search).
#!/bin/bash cmd=$(basename $0) read_dom () { local IFS=\> read -d \< entity content local retval=$? tag=${entity%% *} attr=${entity#* } return $retval } parse_dom () { # uncomment this line to access element attributes as variables #eval local $attr if [[ $tag = "!--" ]]; then # !-- is a comment return elif [[ $tag = "properties" ]]; then in=true elif [[ $tag = "/properties" ]]; then in= elif [[ "$in" && $tag != echo $tag fi } unused_terms () { file=$1 while read p; do grep -m 1 -qe "\${$p}" $file if [[ $? == 1 ]]; then echo $p; fi done } unused_terms_dir () { dir=$1 while read p; do unused_term_find $dir $p done } unused_term_find () { dir=$1 p=$2 echo -n "$p..." find $dir -type f | xargs grep -m 1 -qe "\${$p}" 2> /dev/null if [[ $? == 0 ]]; then echo -ne "\r$(tput el)" else echo -e "\b\b\b " fi } if [[ -z $1 ]]; then echo "Usage: $cmd [-d] <pom-file>" exit fi if [[ $1 == "-d" ]]; then deep=true shift fi file=$1 dir=$(dirname $1) if [ $deep ]; then while read_dom; do parse_dom done < $file | unused_terms $file | unused_terms_dir $dir else while read_dom; do parse_dom done < $file | unused_terms $file fi
The script uses the parsing XML from this stream .
No properties that are directly used by maven or maven plugins will be found in this script. It just looks for the $ {property} template in the project files.
It works on my mac; Your movement may vary.
source share