blob: 55216b05fa12f5962f75dde1cb04afbbd7e2a59e [file] [log] [blame]
Thomas Vachuska615361e2015-05-01 11:00:34 -07001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Tool to create an application from scratch using ONOS Maven archetypes.
4# -----------------------------------------------------------------------------
5
Thomas Vachuska7f2a3562018-02-28 10:02:16 -08006# 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.
9ONOS_HOME=${ONOS_HOME:-$(cd $(dirname $0)/.. >/dev/null 2>&1 && pwd)}
Thomas Vachuska615361e2015-05-01 11:00:34 -070010
11type=${1:-bundle}
12
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070013[ $type = app ] && archetype=bundle || archetype=$type
14
Thomas Vachuska615361e2015-05-01 11:00:34 -070015if [ "$1" = "-?" -o "$1" = "-h" -o "$1" = "--help" ]; then
Sean Condona36f65c2019-05-20 08:21:41 +010016 echo "usage: $(basename $0) {app|bundle|ui|ui2|uitab|uitopo|cli|api} groupId artifactId version package mvn-options"
Thomas Vachuska615361e2015-05-01 11:00:34 -070017 echo " All arguments are optional"
18 exit 1
19fi
20
21otherOptions=""
22[ -n "$1" ] && shift
23[ -n "$1" ] && otherOptions="$otherOptions -DgroupId=$1" && shift
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070024[ -n "$1" ] && otherOptions="$otherOptions -DartifactId=$1" && dir=$1 && shift
Thomas Vachuska615361e2015-05-01 11:00:34 -070025[ -n "$1" ] && otherOptions="$otherOptions -Dversion=$1" && shift
26[ -n "$1" ] && otherOptions="$otherOptions -Dpackage=$1" && shift
27
Thomas Vachuska525651f2016-10-04 11:50:29 -070028set -e
29
Thomas Vachuska830b8a12016-08-05 09:50:15 -070030mvn archetype:generate -DarchetypeCatalog=local,remote \
31 -DarchetypeGroupId=org.onosproject \
Thomas Vachuska4bfccd542015-05-30 00:35:25 -070032 -DarchetypeArtifactId=onos-$archetype-archetype \
33 -DarchetypeVersion=$ONOS_POM_VERSION $otherOptions "$@"
34
35# Patch the pom.xml file to make this an app.
Brian O'Connor7a9aeab2015-06-22 13:36:26 -040036if [ $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
47fi