From f16b45da9d0186fd6e625e82db3e6b472b7d0ff1 Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Sat, 29 Jul 2017 15:34:26 +1000 Subject: [PATCH] Make maven deploy-file more generic Add support for war, jar and tar.gz files Add support for passing pom files with -f JIRA: releng-201 Change-Id: Ia5da1e5df23eddd803877f5b42bc8a594cbe58c1 Signed-off-by: Anil Belur --- shell/deploy | 160 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 88 insertions(+), 72 deletions(-) diff --git a/shell/deploy b/shell/deploy index 06ee1bd5..b8dac280 100755 --- a/shell/deploy +++ b/shell/deploy @@ -265,6 +265,7 @@ deploy_maven_file_usage () { echo " -p " echo " -a " echo " -c " + echo " -f " echo " -g " echo " -v " } @@ -322,9 +323,6 @@ deploy_maven_file () { ;; f) local pom_file="$OPTARG" - echo "pom-file: $pom_file" - echo "ERROR: pom_file is currently unimplemented." - exit 1 ;; g) local group_id="$OPTARG" @@ -352,13 +350,6 @@ deploy_maven_file () { exit 1 fi - # Until we implement the -f parameter assume that group_id must - # be passed. - if [ -z "$group_id" ]; then - echo "ERROR: group_id must be defined. Please pass -g ." - exit 1 - fi - ################ # Start script # ################ @@ -393,91 +384,116 @@ deploy_maven_file () { params+=("$mvn_params") fi - local file_type - if [[ "$file" == *.tar.gz ]]; then - file_type="tar.gz" + if [ ! -z "$pom_file" ]; then + params+=("-DpomFile=\"$pom_file\"") else - file_type="${file##*.}" - fi - params+=("-Dtype=\"$file_type\"") + # Ensure groupId is passed when -f parameter is not used + if [ -z "$group_id" ]; then + echo "ERROR: group_id must be defined. Please pass -g ." + exit 1 + fi + + local file_type + if [[ "$file" == *.tar.gz ]]; then + file_type="tar.gz" + else + file_type="${file##*.}" + fi + params+=("-Dtype=\"$file_type\"") + params+=("-Dpackaging=\"$file_type\"") + + case "$file_type" in + deb ) + if hash dpkg 2>/dev/null; then + echo "dpkg command is available." + + # If user does not provide artifact_id and / or version then parse + # information from file. + if [ -z "$artifact_id" ]; then + artifact_id=$(dpkg -I "$file" | grep ' Package: ' | sed 's/^[ \t]*Package:[ \t]*//') - case "$file_type" in - deb ) - if hash dpkg 2>/dev/null; then - echo "dpkg command is available." + fi + if [ -z "$version" ]; then + version=$(dpkg -I "$file" | grep ' Version: ' | sed 's/^[ \t]*Version:[ \t]*//') + fi + else + echo "dpkg command is not available." - # If user does not provide artifact_id and / or version then parse - # information from file. - if [ -z "$artifact_id" ]; then - artifact_id=$(dpkg -I "$file" | grep ' Package: ' | sed 's/^[ \t]*Package:[ \t]*//') + basefile=$(basename -s .deb "$file") + # If user does not provide artifact_id and / or version then parse + # information from file. + if [ -z "$artifact_id" ]; then + artifact_id=$(echo "$basefile" | cut -f 1 -d '_') + fi + if [ -z "$version" ]; then + version=$(echo "$basefile" | cut -f 2- -d '_') + fi fi - if [ -z "$version" ]; then - version=$(dpkg -I "$file" | grep ' Version: ' | sed 's/^[ \t]*Version:[ \t]*//') - fi - else - echo "dpkg command is not available." + ;; - basefile=$(basename -s .deb "$file") + rpm ) + if hash rpm 2>/dev/null; then + echo "rpm command is available." - # If user does not provide artifact_id and / or version then parse - # information from file. - if [ -z "$artifact_id" ]; then - artifact_id=$(echo "$basefile" | cut -f 1 -d '_') - fi - if [ -z "$version" ]; then - version=$(echo "$basefile" | cut -f 2- -d '_') - fi - fi - ;; + # If user does not provide artifact_id and / or version then parse + # information from file. + if [ -z "$artifact_id" ]; then + artifact_id=$(rpm -qp --queryformat="%{name}" "$file") + fi + if [ -z "$version" ]; then + if grep -qE '\.s(rc\.)?rpm' <<<"$file"; then + rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$file") + else + rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$file") + fi + + version=$(rpm -qp --queryformat="%{version}" "$file") + version+="-$rpmrelease" + fi + else + echo "rpm command is not available." - rpm ) - if hash rpm 2>/dev/null; then - echo "rpm command is available." + basefile=$(basename -s .rpm "$file") - # If user does not provide artifact_id and / or version then parse - # information from file. - if [ -z "$artifact_id" ]; then - artifact_id=$(rpm -qp --queryformat="%{name}" "$file") - fi - if [ -z "$version" ]; then - if grep -qE '\.s(rc\.)?rpm' <<<"$file"; then - rpmrelease=$(rpm -qp --queryformat="%{release}.src" "$file") - else - rpmrelease=$(rpm -qp --queryformat="%{release}.%{arch}" "$file") + # If user does not provide artifact_id and / or version then parse + # information from file. + if [ -z "$artifact_id" ]; then + artifact_id=$(echo "$basefile" | rev | cut -f 3- -d '-' | rev) + fi + if [ -z "$version" ]; then + version=$(echo "$basefile" | rev | cut -f 1 -d '-' | rev) fi - - version=$(rpm -qp --queryformat="%{version}" "$file") - version+="-$rpmrelease" fi - else - echo "rpm command is not available." + ;; + + jar|tar.gz|war ) - basefile=$(basename -s .rpm "$file") + basefile=$(basename -s ".$file_type" "$file") # If user does not provide artifact_id and / or version then parse # information from file. if [ -z "$artifact_id" ]; then - artifact_id=$(echo "$basefile" | rev | cut -f 3- -d '-' | rev) + artifact_id=$(echo "$basefile" | rev | cut -f 2- -d '-' | rev) fi if [ -z "$version" ]; then version=$(echo "$basefile" | rev | cut -f 1 -d '-' | rev) fi - fi - ;; + ;; - * ) - echo "ERROR: Unrecognized file type \"$file_type\"." 1>&2 - exit 1 - ;; - esac + * ) + echo "ERROR: Unrecognized file type \"$file_type\"." 1>&2 + exit 1 + ;; + esac - params+=("-DgroupId=\"$group_id\"") - params+=("-DartifactId=\"$artifact_id\"") - params+=("-Dversion=\"$version\"") + params+=("-DgroupId=\"$group_id\"") + params+=("-DartifactId=\"$artifact_id\"") + params+=("-Dversion=\"$version\"") - if [ ! -z "$classifier" ]; then - params+=("-Dclassifier=\"$classifier\"") + if [ ! -z "$classifier" ]; then + params+=("-Dclassifier=\"$classifier\"") + fi fi # Disable the Maven transfer output. -- 2.16.6