How to find unused properties in a pump

After inheriting the maven project, I want to check the unused properties and delete them.

One of the ways that I don't want to do is to remove them one at a time and see how the assembly failed. Another way would be to count the occurrence in the entire code base (so that the filter and resource properties are not mistakenly seen as unused) with a custom script. Before I do this, I would like to make sure that I am not reinventing the wheel.

There is a way to do this for the dependencies explained here .
Is there something similar for properties that I missed? Or is there a better way?

thanks

I am using maven 3.0.3

+4
source share
3 answers

Unfortunately, there is no better way instead of doing it manually ...

+1
source

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 != /* ]]; then #does not start with slash */ 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.

0
source

If you use IntelliJ, you can simply search your property’s customs. Just place the cursor in the tag and right click β†’ Find Usage (keyboard shortcut in my case: Alt + F7).

I have not found a better way.

0
source

Source: https://habr.com/ru/post/1434145/


All Articles