#!/bin/sh
# ----------------------------------------------------------------------------
#  Copyright 2001-2006 The Apache Software Foundation.
#
#  Licensed 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.
# ----------------------------------------------------------------------------
#
#   Copyright (c) 2001-2006 The Apache Software Foundation.  All rights
#   reserved.


# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`
BASEDIR=`cd "$PRGDIR/.." >/dev/null; pwd`



# OS specific support.  $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
case "`uname`" in
  CYGWIN*) cygwin=true ;;
  Darwin*) darwin=true
           if [ -z "$JAVA_VERSION" ] ; then
             JAVA_VERSION="CurrentJDK"
           else
             echo "Using Java version: $JAVA_VERSION"
           fi
           if [ -z "$JAVA_HOME" ] ; then
             JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Home
           fi
           ;;
esac

if [ -z "$JAVA_HOME" ] ; then
  if [ -r /etc/gentoo-release ] ; then
    JAVA_HOME=`java-config --jre-home`
  fi
fi

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi

# If a specific java binary isn't specified search for the standard 'java' binary
if [ -z "$JAVACMD" ] ; then
  if [ -n "$JAVA_HOME"  ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
      # IBM's JDK on AIX uses strange locations for the executables
      JAVACMD="$JAVA_HOME/jre/sh/java"
    else
      JAVACMD="$JAVA_HOME/bin/java"
    fi
  else
    JAVACMD=`which java`
  fi
fi

if [ ! -x "$JAVACMD" ] ; then
  echo "Error: JAVA_HOME is not defined correctly." 1>&2
  echo "  We cannot execute $JAVACMD" 1>&2
  exit 1
fi

if [ -z "$REPO" ]
then
  REPO="$BASEDIR"/repo
fi

CLASSPATH=$CLASSPATH_PREFIX:"$BASEDIR"/etc:"$REPO"/org/apache/maven/maven-plugin-api/3.0.4/maven-plugin-api-3.0.4.jar:"$REPO"/org/apache/maven/maven-model/3.0.4/maven-model-3.0.4.jar:"$REPO"/org/apache/maven/maven-artifact/3.0.4/maven-artifact-3.0.4.jar:"$REPO"/org/sonatype/sisu/sisu-inject-plexus/2.3.0/sisu-inject-plexus-2.3.0.jar:"$REPO"/org/sonatype/sisu/sisu-inject-bean/2.3.0/sisu-inject-bean-2.3.0.jar:"$REPO"/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar:"$REPO"/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar:"$REPO"/com/github/kevinsawicki/http-request/5.4/http-request-5.4.jar:"$REPO"/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar:"$REPO"/org/apache/maven/maven-core/3.0.4/maven-core-3.0.4.jar:"$REPO"/org/apache/maven/maven-settings/3.0.4/maven-settings-3.0.4.jar:"$REPO"/org/apache/maven/maven-settings-builder/3.0.4/maven-settings-builder-3.0.4.jar:"$REPO"/org/apache/maven/maven-repository-metadata/3.0.4/maven-repository-metadata-3.0.4.jar:"$REPO"/org/apache/maven/maven-model-builder/3.0.4/maven-model-builder-3.0.4.jar:"$REPO"/org/apache/maven/maven-aether-provider/3.0.4/maven-aether-provider-3.0.4.jar:"$REPO"/org/sonatype/aether/aether-spi/1.13.1/aether-spi-1.13.1.jar:"$REPO"/org/sonatype/aether/aether-impl/1.13.1/aether-impl-1.13.1.jar:"$REPO"/org/sonatype/aether/aether-api/1.13.1/aether-api-1.13.1.jar:"$REPO"/org/sonatype/aether/aether-util/1.13.1/aether-util-1.13.1.jar:"$REPO"/org/codehaus/plexus/plexus-interpolation/1.14/plexus-interpolation-1.14.jar:"$REPO"/org/codehaus/plexus/plexus-classworlds/2.4/plexus-classworlds-2.4.jar:"$REPO"/org/codehaus/plexus/plexus-component-annotations/1.5.5/plexus-component-annotations-1.5.5.jar:"$REPO"/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar:"$REPO"/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar:"$REPO"/org/sonatype/sisu/sisu-guava/0.11.1/sisu-guava-0.11.1.jar:"$REPO"/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar:"$REPO"/org/apache/commons/commons-exec/1.1/commons-exec-1.1.jar:"$REPO"/org/webjars/webjars-maven-plugin/0.2.0/webjars-maven-plugin-0.2.0.jar

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  [ -n "$CLASSPATH" ] && CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
  [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
  [ -n "$HOME" ] && HOME=`cygpath --path --windows "$HOME"`
  [ -n "$BASEDIR" ] && BASEDIR=`cygpath --path --windows "$BASEDIR"`
  [ -n "$REPO" ] && REPO=`cygpath --path --windows "$REPO"`
fi

exec "$JAVACMD" $JAVA_OPTS  \
  -classpath "$CLASSPATH" \
  -Dapp.name="webjars" \
  -Dapp.pid="$$" \
  -Dapp.repo="$REPO" \
  -Dapp.home="$BASEDIR" \
  -Dbasedir="$BASEDIR" \
  org.webjars.WebJarsCommandLine \
  "$@"
