From: Anil Belur Date: Mon, 14 Aug 2017 10:13:06 +0000 (+1000) Subject: Re-factor deploy maven file to remove dup code X-Git-Tag: v0.8.0~3 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F87%2F5887%2F3;p=releng%2Flftools.git Re-factor deploy maven file to remove dup code Change-Id: I2a4ddd37eff6da11eb04b91ceb96810e39d218aa Jira: releng-360 Signed-off-by: Anil Belur --- diff --git a/shell/deploy b/shell/deploy index 3a7c042f..0c65633f 100755 --- a/shell/deploy +++ b/shell/deploy @@ -269,6 +269,29 @@ deploy_maven_file_usage () { echo " -v " } + +get_file_info () { + # Common function to parse artifact_id, version number from file. + local basefile + + basefile=$(basename -s ".$1" "$2") + + if [ -z "$artifact_id" ] && [[ "$1" =~ rpm|deb ]]; then + artifact_id=$(echo "$basefile" | cut -f 1 -d '_') + else + # handle other file types (tar, jar, gunzip files versions) + artifact_id=$(echo "$basefile" | rev | cut -f 2- -d '-' | rev) + fi + + if [ -z "$version" ] && [[ "$1" =~ rpm|deb ]]; then + version=$(echo "$basefile" | cut -f 2- -d '_') + else + # handle other file types (tar, jar, gunzip files versions) + version=$(echo "$basefile" | rev | cut -f 1 -d '-' | rev) + fi +} + + deploy_maven_file () { # Deploy a file to a Nexus maven2 repository. # @@ -417,17 +440,7 @@ deploy_maven_file () { fi else echo "dpkg command is not available." - - 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 + get_file_info "$file_type" "$file" fi ;; @@ -452,32 +465,12 @@ deploy_maven_file () { fi else echo "rpm command is not 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=$(echo "$basefile" | rev | cut -f 3- -d '-' | rev) - fi - if [ -z "$version" ]; then - version=$(echo "$basefile" | rev | cut -f 1 -d '-' | rev) - fi + get_file_info "$file_type" "$file" fi ;; jar|tar.gz|war ) - - 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 2- -d '-' | rev) - fi - if [ -z "$version" ]; then - version=$(echo "$basefile" | rev | cut -f 1 -d '-' | rev) - fi + get_file_info "$file_type" "$file" ;; * )