Skip to content

Instantly share code, notes, and snippets.

@Techcable
Last active April 12, 2017 03:58
Show Gist options
  • Select an option

  • Save Techcable/26e137d5a960b5c36ad12c963fe9aa56 to your computer and use it in GitHub Desktop.

Select an option

Save Techcable/26e137d5a960b5c36ad12c963fe9aa56 to your computer and use it in GitHub Desktop.
SonarPet development version auto-compiler
#!/bin/bash
REPOSITORY="https://github.com/TechzoneMC/SonarPet"
checkCommand() {
command=$1
command_name=${2:-$1}
if ! which $command >/dev/null 2>&1 ; then
echo "Missing required command: $command" 1>&2;
echo "Please install $command_name to compile SonarPet" 1>&2;
exit 1;
fi
}
checkCommand git
checkCommand java
checkCommand javac "the JDK"
if [ $# -lt 1 ]; then
echo "Insufficent Arguments!" 1>&2
echo "Usage: $0 [branch]" 1>&2
exit 1;
fi
BASEDIR="$(pwd)"
OUTPUT_JAR="SonarPet.jar";
if [ -f "$OUTPUT_JAR" ]; then
echo "Jar $OUTPUT_JAR already exists!" 1>&2;
exit 1;
fi
BRANCH_NAME=$1
echo "Cloning SonarPet $BRANCH_NAME from $REPOSITORY"
git clone -q -b "$BRANCH_NAME" "$REPOSITORY" "SonarPet" || { echo "Unable to clone SonarPet" 1>&2 && exit 1; }
pushd SonarPet
CURRENT_REF="$(git rev-parse HEAD 2>/dev/null)"
if [ ! $? ]; then
echo "Unable to detect current revision for SonarPet $BRANCH_NAME";
exit 1;
fi
echo "Cloned SonarPet $BRANCH_NAME at $CURRENT_REF"
echo "Compiling......"
# Spawning a daemon is stupid here, since this is one-time only
./gradlew -q --no-daemon clean build || { echo "Unable to compile SonarPet $BRANCH_NAME at $CURRENT_REF" 1>&2 && exit 1; }
echo "Successfully compiled SonarPet $BRANCH_NAME at $CURRENT_REF"
COMPILED_JAR="bootstrap/build/libs/SonarPet.jar"
if [ ! -f "$COMPILED_JAR" ]; then
echo "Couldn't find $COMPILED_JAR after compiling SonarPet $BRANCH_NAME at $CURRENT_REF" 1>&2;
exit 1;
fi
cp "$COMPILED_JAR" "$BASEDIR/$OUTPUT_JAR"
popd
rm -rf "SonarPet" || { echo "Unable to remove SonarPet" 1>&2 && exit 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment