Thomas Vachuska | 615361e | 2015-05-01 11:00:34 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Tool to create an application from scratch using ONOS Maven archetypes. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
Thomas Vachuska | 7f2a356 | 2018-02-28 10:02:16 -0800 | [diff] [blame] | 6 | # If ONOS_HOME is set, respect its value. |
| 7 | # If ONOS_HOME is not set (e.g. in the init or service environment), |
| 8 | # set it based on this script's path. |
| 9 | ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)} |
Thomas Vachuska | 615361e | 2015-05-01 11:00:34 -0700 | [diff] [blame] | 10 | |
| 11 | type=${1:-bundle} |
| 12 | |
Thomas Vachuska | 4bfccd54 | 2015-05-30 00:35:25 -0700 | [diff] [blame] | 13 | [ $type = app ] && archetype=bundle || archetype=$type |
| 14 | |
Thomas Vachuska | 615361e | 2015-05-01 11:00:34 -0700 | [diff] [blame] | 15 | if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then |
Sean Condon | a36f65c | 2019-05-20 08:21:41 +0100 | [diff] [blame] | 16 | echo "usage: $(basename $0) {app|bundle|ui|ui2|uitab|uitopo|cli|api} groupId artifactId version package mvn-options" |
Thomas Vachuska | 615361e | 2015-05-01 11:00:34 -0700 | [diff] [blame] | 17 | echo " All arguments are optional" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | otherOptions="" |
| 22 | [ -n "$1" ] && shift |
| 23 | [ -n "$1" ] && otherOptions="$otherOptions -DgroupId=$1" && shift |
Thomas Vachuska | 4bfccd54 | 2015-05-30 00:35:25 -0700 | [diff] [blame] | 24 | [ -n "$1" ] && otherOptions="$otherOptions -DartifactId=$1" && dir=$1 && shift |
Thomas Vachuska | 615361e | 2015-05-01 11:00:34 -0700 | [diff] [blame] | 25 | [ -n "$1" ] && otherOptions="$otherOptions -Dversion=$1" && shift |
| 26 | [ -n "$1" ] && otherOptions="$otherOptions -Dpackage=$1" && shift |
| 27 | |
Thomas Vachuska | 525651f | 2016-10-04 11:50:29 -0700 | [diff] [blame] | 28 | set -e |
| 29 | |
Thomas Vachuska | 830b8a1 | 2016-08-05 09:50:15 -0700 | [diff] [blame] | 30 | mvn archetype:generate -DarchetypeCatalog=local,remote \ |
| 31 | -DarchetypeGroupId=org.onosproject \ |
Thomas Vachuska | 4bfccd54 | 2015-05-30 00:35:25 -0700 | [diff] [blame] | 32 | -DarchetypeArtifactId=onos-$archetype-archetype \ |
| 33 | -DarchetypeVersion=$ONOS_POM_VERSION $otherOptions "$@" |
| 34 | |
| 35 | # Patch the pom.xml file to make this an app. |
Brian O'Connor | 7a9aeab | 2015-06-22 13:36:26 -0400 | [diff] [blame] | 36 | if [ $type = app ]; then |
| 37 | # We need to add a few lines to the pom.xml to make this an app |
| 38 | if [ -n "$dir" ] && [ -d $dir ]; then |
| 39 | egrep -v " (<!--|-->)" $dir/pom.xml > $dir/pom.app.xml |
| 40 | mv $dir/pom.app.xml $dir/pom.xml |
| 41 | else |
| 42 | echo |
| 43 | echo "IMPORTANT:" |
| 44 | echo "To build the application, you need to uncomment the 'onos.app.name' and 'onos.app.origin' properties in the pom.xml" |
| 45 | echo |
| 46 | fi |
| 47 | fi |