[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-10268?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16354499#comment-16354499
 ] 

ASF GitHub Bot commented on CLOUDSTACK-10268:
---------------------------------------------

DaanHoogland closed pull request #2433: CLOUDSTACK-10268: Fix and enhance 
package script
URL: https://github.com/apache/cloudstack/pull/2433
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/packaging/centos63/cloud.spec b/packaging/centos63/cloud.spec
index ba1798e7dac..e697be7f972 100644
--- a/packaging/centos63/cloud.spec
+++ b/packaging/centos63/cloud.spec
@@ -24,11 +24,16 @@
 Name:      cloudstack
 Summary:   CloudStack IaaS Platform
 #http://fedoraproject.org/wiki/PackageNamingGuidelines#Pre-Release_packages
+%if "%{?_brand}" != ""
+%define _brandver %{_ver}%{_brand}
+%else
+%define _brandver %{_ver}
+%endif
 %if "%{?_prerelease}" != ""
-%define _maventag %{_ver}-SNAPSHOT
+%define _maventag %{_brandver}-SNAPSHOT
 Release:   %{_rel}%{dist}
 %else
-%define _maventag %{_ver}
+%define _maventag %{_brandver}
 Release:   %{_rel}%{dist}
 %endif
 
diff --git a/packaging/centos7/cloud.spec b/packaging/centos7/cloud.spec
index 481c86c3baf..d21c9284776 100644
--- a/packaging/centos7/cloud.spec
+++ b/packaging/centos7/cloud.spec
@@ -24,11 +24,16 @@
 Name:      cloudstack
 Summary:   CloudStack IaaS Platform
 #http://fedoraproject.org/wiki/PackageNamingGuidelines#Pre-Release_packages
+%if "%{?_brand}" != ""
+%define _brandver %{_ver}%{_brand}
+%else
+%define _brandver %{_ver}
+%endif
 %if "%{?_prerelease}" != ""
-%define _maventag %{_ver}-SNAPSHOT
+%define _maventag %{_brandver}-SNAPSHOT
 Release:   %{_rel}%{dist}
 %else
-%define _maventag %{_ver}
+%define _maventag %{_brandver}
 Release:   %{_rel}%{dist}
 %endif
 
diff --git a/packaging/package.sh b/packaging/package.sh
index 8a876615123..d1f620cb505 100755
--- a/packaging/package.sh
+++ b/packaging/package.sh
@@ -17,29 +17,38 @@
 # under the License.
 
 function usage() {
-    echo ""
-    echo "usage: ./package.sh [-h|--help] -d|--distribution <name> 
[-r|--release <version>] [-p|--pack oss|OSS|noredist|NOREDIST] [-s|--simulator 
default|DEFAULT|simulator|SIMULATOR]"
-    echo ""
-    echo "The supported arguments are:"
-    echo "  To package with only redistributable libraries (default)"
-    echo "    -p|--pack oss|OSS"
-    echo "  To package with non-redistributable libraries"
-    echo "    -p|--pack noredist|NOREDIST"
-    echo "  To build a package for a distribution (mandatory)"
-    echo "    -d|--distribution centos7|centos63|fedora20|fedora21"
-    echo "  To set the package release version (optional)"
-    echo "  (default is 1 for normal and prereleases, empty for SNAPSHOT)"
-    echo "    -r|--release version(integer)"
-    echo "  To build for Simulator (optional)"
-    echo "    -s|--simulator default|DEFAULT|simulator|SIMULATOR"
-    echo "  To display this information"
-    echo "    -h|--help"
-    echo ""
-    echo "Examples: ./package.sh --pack oss"
-    echo "          ./package.sh --pack noredist"
-    echo "          ./package.sh --pack oss --distribution centos7 --release 
42"
-    echo "          ./package.sh --distribution centos7 --release 42"
-    echo "          ./package.sh --distribution centos7"
+       cat << USAGE
+Usage: ./package.sh -d DISTRO [OPTIONS]...
+Package CloudStack for specific distribution and provided options.
+
+If there's a "branding" string in the POM version (e.g. 
x.y.z.a-NAME[-SNAPSHOT]), the branding name will
+be used in the final generated pacakge like: 
cloudstack-management-x.y.z.a-NAME.NUMBER.el7.centos.x86_64
+note that you can override/provide "branding" string with "-b, --brand" flag 
as well.
+
+Mandatory arguments:
+   -d, --distribution string               Build package for specified 
distribution ("centos7"|"centos63")
+
+Optional arguments:
+   -p, --pack string                       Define which type of libraries to 
package ("oss"|"OSS"|"noredist"|"NOREDIST") (default "oss")
+                                             - oss|OSS to package with only 
redistributable libraries 
+                                             - noredist|NOREDIST to package 
with non-redistributable libraries
+   -r, --release integer                   Set the package release version 
(default is 1 for normal and prereleases, empty for SNAPSHOT)
+   -s, --simulator string                  Build package for Simulator 
("default"|"DEFAULT"|"simulator"|"SIMULATOR") (default "default")
+   -b, --brand string                      Set branding to be used in package 
name (it will override any branding string in POM version)
+   -T, --use-timestamp                     Use epoch timestamp instead of 
SNAPSHOT in the package name (if not provided, use "SNAPSHOT")
+   
+Other arguments:
+   -h, --help                              Display this help message and exit
+   
+Examples:
+   package.sh --distribution centos7
+   package.sh --distribution centos7 --pack oss
+   package.sh --distribution centos7 --pack noredist
+   package.sh --distribution centos7 --release 42
+   package.sh --distribution centos7 --pack noredist --release 42
+
+USAGE
+       exit 0    
 }
 
 # packaging
@@ -47,10 +56,12 @@ function usage() {
 #   $2 simulator flag
 #   $3 distribution name
 #   $4 package release version
+#   $5 brand string (globally provided)
 function packaging() {
     CWD=$(pwd)
     RPMDIR=$CWD/../dist/rpmbuild
     PACK_PROJECT=cloudstack
+
     if [ -n "$1" ] ; then
         DEFOSSNOSS="-D_ossnoss $1"
     fi
@@ -59,6 +70,7 @@ function packaging() {
     fi
 
     DISTRO=$3
+
     MVN=$(which mvn)
     if [ -z "$MVN" ] ; then
         MVN=$(locate bin/mvn | grep -e mvn$ | tail -1)
@@ -67,22 +79,38 @@ function packaging() {
             exit 2
         fi
     fi
+
     VERSION=$(cd ../; $MVN 
org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate 
-Dexpression=project.version | grep --color=none '^[0-9]\.')
+
+    if [ -n "$5" ]; then
+        DEFBRN="-D_brand -$5"
+        BRAND="${5}."
+    else
+        BASEVER=$(echo "$VERSION" | sed 's/-SNAPSHOT//g')
+        REALVER=$(echo "$BASEVER" | cut -d '-' -f 1)
+        BRAND=$(echo "$BASEVER" | cut -d '-' -f 2)
+
+        if [ "$REALVER" != "$BRAND" ]; then
+            DEFBRN="-D_brand -$BRAND"
+            BRAND="${BRAND}."
+        else
+            BRAND=""
+        fi
+    fi
+
     if echo "$VERSION" | grep -q SNAPSHOT ; then
-        REALVER=$(echo "$VERSION" | cut -d '-' -f 1)
         if [ -n "$4" ] ; then
             DEFPRE="-D_prerelease $4"
-            DEFREL="-D_rel SNAPSHOT$4"
+            DEFREL="-D_rel ${BRAND}${SNAPSHOT_TIMESTAMP}$4"
         else
             DEFPRE="-D_prerelease 1"
-            DEFREL="-D_rel SNAPSHOT"
+            DEFREL="-D_rel ${BRAND}${SNAPSHOT_TIMESTAMP}"
         fi
     else
-        REALVER="$VERSION"
         if [ -n "$4" ] ; then
-            DEFREL="-D_rel $4"
+            DEFREL="-D_rel ${BRAND}$4"
         else
-            DEFREL="-D_rel 1"
+            DEFREL="-D_rel ${BRAND}1"
         fi
     fi
     DEFVER="-D_ver $REALVER"
@@ -102,7 +130,7 @@ function packaging() {
     echo ". executing rpmbuild"
     cp "$DISTRO/cloud.spec" "$RPMDIR/SPECS"
 
-    (cd "$RPMDIR"; rpmbuild --define "_topdir ${RPMDIR}" "${DEFVER}" 
"${DEFREL}" ${DEFPRE+"$DEFPRE"} ${DEFOSSNOSS+"$DEFOSSNOSS"} ${DEFSIM+"$DEFSIM"} 
-bb SPECS/cloud.spec)
+    (cd "$RPMDIR"; rpmbuild --define "_topdir ${RPMDIR}" "${DEFVER}" 
"${DEFREL}" ${DEFPRE+"$DEFPRE"} ${DEFOSSNOSS+"$DEFOSSNOSS"} ${DEFSIM+"$DEFSIM"} 
${DEFBRN+"$DEFBRN"} -bb SPECS/cloud.spec)
     if [ $? -ne 0 ]; then
         echo "RPM Build Failed "
         exit 3
@@ -116,22 +144,20 @@ TARGETDISTRO=""
 SIM=""
 PACKAGEVAL=""
 RELEASE=""
+BRANDING=""
+SNAPSHOT_TIMESTAMP="SNAPSHOT"
 
-SHORTOPTS="hp:s:d:r:"
-LONGOPTS="help,pack:simulator:distribution:release:"
-ARGS=$(getopt -s bash -u -a --options "$SHORTOPTS"  --longoptions "$LONGOPTS" 
--name "$0" -- "$@")
-eval set -- "$ARGS"
-echo "$ARGS"
-while [ $# -gt 0 ] ; do
+unrecognized_flags=""
+
+while [ -n "$1" ]; do
     case "$1" in
         -h | --help)
             usage
             exit 0
             ;;
+
         -p | --pack)
-            echo "Packaging CloudStack..."
             PACKAGEVAL=$2
-            echo "$PACKAGEVAL"
             if [ "$PACKAGEVAL" == "oss" -o "$PACKAGEVAL" == "OSS" ] ; then
                 PACKAGEVAL=""
             elif [ "$PACKAGEVAL" == "noredist" -o "$PACKAGEVAL" == "NOREDIST" 
] ; then
@@ -141,11 +167,11 @@ while [ $# -gt 0 ] ; do
                 usage
                 exit 1
             fi
-            shift
+            shift 2
             ;;
+
         -s | --simulator)
             SIM=$2
-            echo "$SIM"
             if [ "$SIM" == "default" -o "$SIM" == "DEFAULT" ] ; then
                 SIM="false"
             elif [ "$SIM" == "simulator" -o "$SIM" == "SIMULATOR" ] ; then
@@ -155,8 +181,9 @@ while [ $# -gt 0 ] ; do
                 usage
                 exit 1
             fi
-            shift
+            shift 2
             ;;
+
         -d | --distribution)
             TARGETDISTRO=$2
             if [ -z "$TARGETDISTRO" ] ; then
@@ -164,22 +191,41 @@ while [ $# -gt 0 ] ; do
                 usage
                 exit 1
             fi
-            shift
+            shift 2
             ;;
+
         -r | --release)
             RELEASE=$2
-            shift
+            shift 2
             ;;
-        -)
-            echo "Error: Unrecognized option"
-            usage
-            exit 1
+
+        -b | --brand)
+            BRANDING=$2
+            shift 2
+            ;;
+
+        -T | --use-timestamp)
+            SNAPSHOT_TIMESTAMP="$(date +%s)"
+            shift 1
             ;;
+
+        -*)
+            unrecognized_flags="${unrecognized_flags}$1 "
+            shift 1
+            ;;
+
         *)
-            shift
+            shift 1
             ;;
     esac
 done
 
-packaging "$PACKAGEVAL" "$SIM" "$TARGETDISTRO" "$RELEASE"
+if [ -n "$unrecognized_flags" ]; then
+    echo "Warning: Unrecognized option(s) found \" ${unrecognized_flags}\""
+    echo "         You're advised to fix your build job scripts and prevent 
using these"
+    echo "         flags, as in the future release(s) they will break 
packaging script."
+    echo ""
+fi
 
+echo "Packaging CloudStack..."
+packaging "$PACKAGEVAL" "$SIM" "$TARGETDISTRO" "$RELEASE" "$BRANDING"


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Fix and enhance package script
> ------------------------------
>
>                 Key: CLOUDSTACK-10268
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10268
>             Project: CloudStack
>          Issue Type: Improvement
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: Packaging
>            Reporter: Khosrow Moossavi
>            Priority: Minor
>             Fix For: 4.12
>
>
> - if there's a "branding" string in the POM version (e.g. 
> `x.y.z.a-NAME[-SNAPSHOT]`),
> the branding name will be used in the final generated pacakge name such as 
> following:
> `cloudstack-management-x.y.z.a-NAME.NUMBER.el7.centos.x86_64`
> - branding string can be overriden with newly added `-b, --brand` flag
> - new flag `-T, --use-timestamp` to use `timestamp` in final package name 
> where POM
> version contains SNAPSHOT
> - fix long opts (they were broken)
> - tolerate and show a warning message for unrecognized flags
> - usage help reformat



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to