From 875716dc48cd5c485d2342c9e5bb1d461bc64b6d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 20 Apr 2013 21:26:52 +0200 Subject: o Making the resolvers use app.resolved_version instead of app.version. o Making set-version update app.version. --- bin/app-init | 12 ++++++------ bin/app-upgrade | 40 ++++++++++++++++++++++++++++++++++++++++ lib/common | 4 ++++ libexec/app-resolver-file | 2 +- libexec/app-resolver-maven | 8 ++++---- libexec/app-set-version | 2 ++ test/app-upgrade.bats | 40 ++++++++++++++++++++++++++++++++++++++++ test/utils.bash | 36 ++++++++++++++++++++++++++---------- 8 files changed, 123 insertions(+), 21 deletions(-) create mode 100755 bin/app-upgrade create mode 100755 test/app-upgrade.bats diff --git a/bin/app-init b/bin/app-init index c59ba77..8e571e8 100755 --- a/bin/app-init +++ b/bin/app-init @@ -40,7 +40,7 @@ then fatal "Already initialized: $dir" 2>&1 fi -resolver=`grep_path "/app-resolver-$resolver_name$" "$PATH" | head -n 1` +resolver=`find_resolver "$resolver_name"` if [ -z "$resolver" ] then @@ -61,18 +61,18 @@ app-conf set app.resolver "$resolver_name" "$resolver" init "$@" "$resolver" resolve-version -version=`app-conf get app.version` +resolved_version=`app-conf get app.resolved_version` -if [[ $version == "" ]] +if [[ $resolved_version == "" ]] then echo "Unable to resolve version" 2>&1 exit fi -echo "Resolved version to $version" +echo "Resolved version to $resolved_version" -"$resolver" download-version -v "$version" -f .app/latest.zip +"$resolver" download-version -v "$resolved_version" -f .app/latest.zip -app-install-file -v "$version" -f .app/latest.zip +app-install-file -v "$resolved_version" -f .app/latest.zip ok=yes diff --git a/bin/app-upgrade b/bin/app-upgrade new file mode 100755 index 0000000..2ca84e0 --- /dev/null +++ b/bin/app-upgrade @@ -0,0 +1,40 @@ +#!/bin/bash + +set -e +set -u + +APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) + +. $APPSH_HOME/lib/common +# HEADER END + +usage_text() { + echo "usage: $usage_app" +} + +if [ $# != 0 ] +then + usage +fi + +assert_is_app + +resolver_name=`app-conf get app.resolver` +resolver=`find_resolver "$resolver_name"` + +old_version=`app-conf get app.version` +echo "Resolving version $old_version" +"$resolver" resolve-version +new_version=`app-conf get app.version` + +if [[ $new_version == $old_version ]] +then + echo "No new version available" 2>&1 + exit +fi + +echo "Resolved version to $new_version" + +"$resolver" download-version -v "$new_version" -f .app/latest.zip + +app-install-file -v "$new_version" -f .app/latest.zip diff --git a/lib/common b/lib/common index 0c8cdbd..83ee746 100755 --- a/lib/common +++ b/lib/common @@ -226,6 +226,10 @@ run_app() { ) } +find_resolver() { + grep_path "/app-resolver-$resolver_name$" "$PATH" | head -n 1 +} + ##################################################################### # Common init diff --git a/libexec/app-resolver-file b/libexec/app-resolver-file index 6282b83..b41ca47 100755 --- a/libexec/app-resolver-file +++ b/libexec/app-resolver-file @@ -44,7 +44,7 @@ resolve_version() { local s=$(stat -c %Z $path) - app-conf set app.version "$s" + app-conf set app.resolved_version "$s" } download_version() { diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index deb1e7a..72aa15b 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -91,7 +91,7 @@ resolve_version() { if [[ ! $version == *-SNAPSHOT ]] then - app-conf set app.version "$version" + app-conf set app.resolved_version "$version" exit 0 fi @@ -116,7 +116,7 @@ resolve_snapshot() { local r=$repo/$base_path/maven-metadata.xml get $r $l - x=$(xmlstarlet sel -t -m '/metadata/versioning/snapshot' -v "timestamp|buildNumber" $l) + x=$(xmlstarlet sel -t -m '/metadata/versioning/snapshot' -v timestamp -o ' ' -v buildNumber $l) set -- $x if [[ $# != 2 ]] @@ -133,7 +133,7 @@ resolve_snapshot() { fi app-conf set maven.snapshotVersion "$snapshot_version" - app-conf set app.version "${version%-SNAPSHOT}-$snapshot_version" + app-conf set app.resolved_version "${version%-SNAPSHOT}-$snapshot_version" } download_version() { @@ -200,7 +200,7 @@ init() { if [[ $# != 3 || $1 == "" || $2 == "" || $3 == "" ]] then - fatal "Invalid Maven coordinates: $coordinates" + usage "Invalid Maven coordinates: $coordinates" fi group_id=$1 diff --git a/libexec/app-set-version b/libexec/app-set-version index 75d44a8..4c8e797 100755 --- a/libexec/app-set-version +++ b/libexec/app-set-version @@ -48,3 +48,5 @@ else echo "Creating current symlink for version $version" ln -s versions/$version/root current fi + +app-conf set app.version "$version" diff --git a/test/app-upgrade.bats b/test/app-upgrade.bats new file mode 100755 index 0000000..2dde851 --- /dev/null +++ b/test/app-upgrade.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "app-upgrade" { + mkzip app-a + install_artifact + + app init -d my-app maven -r "$FIXED_REPO_URL" org.example:app-a:1.0-SNAPSHOT; echo_lines + eq '$status' 0 + + cd my-app + app conf get maven.version + match '${lines[0]}' "1.0-SNAPSHOT" + maven_version="${lines[0]}" + describe maven_version=$maven_version + + app conf get app.version + match '${lines[0]}' "1.0-.*" + app_version="${lines[0]}" + describe app_version=$app_version + + app conf get app.resolved_version + match '${lines[0]}' "1.0-.*" + eq '${lines[0]}' "$app_version" + resolved_version="${lines[0]}" + describe resolved_version=$resolved_version + + install_artifact + + app upgrade; echo_lines + eq '$status' 0 + + app conf get app.resolved_version + match '${lines[0]}' "1.0-.*" + new_resolved_version="${lines[0]}" + describe new_resolved_version=$new_resolved_version + neq $new_resolved_version $resolved_version +} diff --git a/test/utils.bash b/test/utils.bash index cb2337b..ad80629 100644 --- a/test/utils.bash +++ b/test/utils.bash @@ -61,16 +61,16 @@ app_libexec() { run "$x" $@ } -fix_path=`uname -s` +fix_path_uname=`uname -s` fix_path() { - local path=$1 - - case $fix_path in + case $fix_path_uname in CYGWIN_NT*) - x=$(cygpath -wa $1) + cygpath -wa $1 + ;; + *) + echo $1 ;; esac - echo $x } describe() { @@ -100,8 +100,8 @@ can_not_read() { is_directory() { if [ ! -d "$1" ] then - echo "Not a directory: $1" 2>&1 - return 1 + echo "Not a directory: $1" 2>&1 + return 1 fi } @@ -112,7 +112,7 @@ eq() { if [[ $e == $a ]] then - return 0 + return 0 fi echo "Assertion failed: $ex" @@ -121,6 +121,22 @@ eq() { exit 1 } +neq() { + local ex="$1" + local e="$2" + local a="`eval echo $ex`" + + if [[ $e != $a ]] + then + return 0 + fi + + echo "Not-equal assertion failed: $ex" + echo "Expected: $e" + echo "Actual: $a" + exit 1 +} + match() { local ex="$1" local regex="$2" @@ -128,7 +144,7 @@ match() { if [[ $a =~ $regex ]] then - return 0 + return 0 fi echo "Assertion failed: $ex =~ $a" -- cgit v1.2.3