Re-factor deploy maven file to remove dup code 87/5887/3
authorAnil Belur <abelur@linuxfoundation.org>
Mon, 14 Aug 2017 10:13:06 +0000 (20:13 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 15 Aug 2017 01:39:57 +0000 (11:39 +1000)
Change-Id: I2a4ddd37eff6da11eb04b91ceb96810e39d218aa
Jira: releng-360
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
shell/deploy

index 3a7c042..0c65633 100755 (executable)
@@ -269,6 +269,29 @@ deploy_maven_file_usage () {
     echo "    -v <version>"
 }
 
+
+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"
                 ;;
 
             * )