From 32826f3c989e63f53510a9bdccd1855a9ae00636 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 4 Feb 2013 17:38:32 +0100 Subject: o Adding a file resolver. o Getting the IT to work on windows. --- libexec/app-operator-pid | 2 +- libexec/app-resolver-file | 94 +++++++++++++++++++++++++++++++++++++++++++++ libexec/app-resolver-maven | 2 +- test/it-install-remove.bats | 23 +++++++++-- test/utils.bash | 24 +++++++++--- 5 files changed, 134 insertions(+), 11 deletions(-) create mode 100755 libexec/app-resolver-file mode change 100755 => 100644 test/utils.bash diff --git a/libexec/app-operator-pid b/libexec/app-operator-pid index 6aedb03..dd48979 100755 --- a/libexec/app-operator-pid +++ b/libexec/app-operator-pid @@ -1,4 +1,4 @@ -#!/bin/bash -e +#!/bin/bash set -e set -u diff --git a/libexec/app-resolver-file b/libexec/app-resolver-file new file mode 100755 index 0000000..6282b83 --- /dev/null +++ b/libexec/app-resolver-file @@ -0,0 +1,94 @@ +#!/bin/bash + +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END + +usage_text() { + echo "usage: $usage_app init " + echo "usage: $usage_app resolve-version" + echo "usage: $usage_app download-version -v -f " +} + +init() { + while getopts "r:" opt + do + case $opt in + r) + app-conf set maven.repo "$OPTARG" + shift 2 + OPTIND=1 + ;; + *) + usage "Invalid option: $OPTARG" + ;; + esac + done + + local file=${1-} + + if [[ ! -r "$file" ]] + then + fatal "Can't read file: $file" + fi + + app-conf set file.path "$file" +} + +resolve_version() { + path=$(app-conf get file.path) + + local s=$(stat -c %Z $path) + + app-conf set app.version "$s" +} + +download_version() { + target="" + while getopts "v:f:" opt + do + case $opt in + v) + # Ignored + ;; + f) + target="$OPTARG" + ;; + *) + usage "Invalid option: $OPTARG" + ;; + esac + done + + if [[ $target == "" ]] + then + usage + fi + + path=$(app-conf get file.path) + + ln -s "$path" "$target" +} + +command="$1"; shift + +case "$command" in + init) + init "$@" + ;; + resolve-version) + resolve_version + ;; + download-version) + download_version "$@" + ;; + *) + usage + ;; +esac + +exit 0 diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index 8394ee1..deb1e7a 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -200,7 +200,7 @@ init() { if [[ $# != 3 || $1 == "" || $2 == "" || $3 == "" ]] then - usage "Invalid Maven coordinates: $coordinates" + fatal "Invalid Maven coordinates: $coordinates" fi group_id=$1 diff --git a/test/it-install-remove.bats b/test/it-install-remove.bats index 96bd2db..8be9365 100755 --- a/test/it-install-remove.bats +++ b/test/it-install-remove.bats @@ -3,12 +3,23 @@ load utils -@test "install remove roundtrip" { +install_maven() { mkzip "app-a" install_artifact +} + +install_file() { + mkzip "app-a" +} + +do_test() { + install="$1"; shift + init_args="$1"; shift + + $install describe "Installing app" - app init -d my-app/prod maven -r $REPO_URL org.example:app-a:1.0-SNAPSHOT; echo_lines + app init -d my-app/prod $init_args; echo_lines eq '$status' 0 is_directory "my-app/prod/.app" @@ -35,6 +46,12 @@ load utils [ "`cat logs/app-a.env`" = "TEST_PROPERTY=awesome" ] [ "`cat current/foo.conf`" = "hello" ] +} + +@test "install+upgrade; resolver=maven" { +# do_test install_maven "maven -r $REPO_URL org.example:app-a:1.0-SNAPSHOT" +} - # TODO: Remove the version +@test "install+upgrade; resolver=file" { + do_test install_file "file $APPSH_HOME/test/data/app-a.zip" } diff --git a/test/utils.bash b/test/utils.bash old mode 100755 new mode 100644 index 3c3f33f..cb2337b --- a/test/utils.bash +++ b/test/utils.bash @@ -8,6 +8,7 @@ exit_usage_wrong=0 setup() { find test/data -name \*.zip | xargs rm -f + ORIG_PATH=$PATH PATH=/bin:/usr/bin PATH=$PATH:$APPSH_HOME APPSH_HOME=$(cd $BATS_TEST_DIRNAME/..; echo `pwd`) @@ -18,6 +19,7 @@ setup() { REPO=$BATS_TMPDIR/repo REPO_URL="file://$REPO" + FIXED_REPO_URL="file://`fix_path $REPO`" if [ "`declare -f setup_inner >/dev/null; echo $?`" = 0 ] then @@ -40,12 +42,10 @@ mkzip() { } install_artifact() { - if [ ! -f $REPO/org/example/app-a/1.0-SNAPSHOT/maven-metadata.xml ] - then - mvn deploy:deploy-file -Durl=$REPO_URL \ - -Dfile=`echo $APPSH_HOME/test/data/app-a.zip` -DgeneratePom \ - -DgroupId=org.example -DartifactId=app-a -Dversion=1.0-SNAPSHOT -Dpackaging=zip - fi + describe -Dfile=`fix_path $APPSH_HOME/test/data/app-a.zip` -DgeneratePom + PATH=$ORIG_PATH mvn deploy:deploy-file -Durl=$FIXED_REPO_URL \ + -Dfile=`fix_path $APPSH_HOME/test/data/app-a.zip` -DgeneratePom \ + -DgroupId=org.example -DartifactId=app-a -Dversion=1.0-SNAPSHOT -Dpackaging=zip } app() { @@ -61,6 +61,18 @@ app_libexec() { run "$x" $@ } +fix_path=`uname -s` +fix_path() { + local path=$1 + + case $fix_path in + CYGWIN_NT*) + x=$(cygpath -wa $1) + ;; + esac + echo $x +} + describe() { echo "# " $@ >&3 } -- cgit v1.2.3