#!/bin/bash

if [ $# -ne 4 ]; then
    echo "give"
    echo "  groupId"
    echo "  artifactId"
    echo "  version"
    echo "  snapshot or release"
    exit 1
fi

GROUP_ID=$1
ARTIFACT_ID=$2
VERSION=$3
RELEASE_TYPE=$4

JAR=`pwd`/target/${ARTIFACT_ID}-${VERSION}.jar

if [ ${RELEASE_TYPE} == "snapshot" ]; then
   URL=https://repository.jboss.org/nexus/content/repositories/snapshots/
else
   URL=https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/
fi

echo Creating $JAR
#echo Deploying to $URL

echo Adding target/classes
cd target/classes; find . |xargs jar cvf $JAR; cd ../..

echo Adding target/test-classes
cd target/test-classes; find . | xargs jar uvf $JAR; cd ../..

mvn install:install-file -Dfile=${JAR} -DgroupId=${GROUP_ID} -DartifactId=${ARTIFACT_ID} -Dpackaging=jar -Dversion=${VERSION}

mvn deploy:deploy-file -Dfile=${JAR} -DgroupId=${GROUP_ID} -DartifactId=${ARTIFACT_ID} -Dpackaging=jar -Dversion=${VERSION} \
  -DrepositoryId=jboss-${4}s-repository -Durl=${URL}
