#!/bin/sh
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# $Id: servicemix 979 2005-11-30 22:50:55Z bsnyder $
#

if [ "$SERVICEMIX_VERSION" = "" ] ; then
  SERVICEMIX_VERSION=3.3.1.13-fuse
fi

if [ "$DEF_GROUP_ID" = "" ] ; then
  DEF_GROUP_ID=com.mycompany
fi

if [ "$1" = "sl" ] ; then

  ARCHETYPE=servicemix-shared-library
  DEF_ARTIFACT_ID=my-sl
  shift

elif [ "$1" = "se" ] ; then

  ARCHETYPE=servicemix-service-engine
  DEF_ARTIFACT_ID=my-se
  shift

elif [ "$1" = "bc" ] ; then

  ARCHETYPE=servicemix-binding-component
  DEF_ARTIFACT_ID=my-bc
  shift

elif [ "$1" = "sa" ] ; then

  ARCHETYPE=servicemix-service-assembly
  DEF_ARTIFACT_ID=my-sa
  shift

elif [ "$1" = "su" ] ; then

  if [ "$2" = "" ] ; then
    ARCHETYPE=servicemix-service-unit
    DEF_ARTIFACT_ID=my-su
  else
    ARCHETYPE=servicemix-$2-service-unit
    DEF_ARTIFACT_ID=my-$2-su
    shift
  fi
  shift

elif [ "$1" = "top" ] ; then

  ARCHETYPE=servicemix-root-pom
  DEF_ARTIFACT_ID=my-project
  shift

else

  echo "Usage: smx-arch command [su-type] [args]"
  echo "commands:"
  echo "  top               Creates a top level project"
  echo "  sl                Creates a new Shared Library"
  echo "  se                Creates a new Service Engine"
  echo "  bc                Creates a new Binding Component"
  echo "  sa                Creates a new Service Assembly"
  echo "  su                Creates a generic Service Unit"
  echo "  su [type]         Creates a SU of the specified type"
  echo "SU types:"
  echo "                    http-consumer, http-provider,"
  echo "                    jms-consumer, jms-provider,"
  echo "                    file-poller, file-sender,"
  echo "                    ftp-poller, ftp-sender,"
  echo "                    jsr181-annotated, jsr181-wsdl-first,"
  echo "                    saxon-xquery, saxon-xslt, osworkflow,"
  echo "                    eip, lwcontainer, bean, ode, camel"
  echo "		    cxf-se, cxf-se-wsdl-first, cxf-bc"
  echo "Optional arguments:"
  echo "  -DgroupId=xxxx"
  echo "  -DartifactId=xxxx"
  exit 1

fi

mvn archetype:create \
  -DremoteRepositories=http://repo.open.iona.com/maven2 \
  -DarchetypeGroupId=org.apache.servicemix.tooling \
  -DarchetypeArtifactId=$ARCHETYPE \
  -DarchetypeVersion=$SERVICEMIX_VERSION \
  -DgroupId=$DEF_GROUP_ID \
  -DartifactId=$DEF_ARTIFACT_ID \
  "$@"

