From 746b90ad64e65b70bc902ed1bcd2c33ec7adf008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trygve=20Laugst=C3=B8l?= Date: Thu, 31 Oct 2013 16:27:09 +0100 Subject: [PATCH 3/5] app-resolver-maven: Adding support for artifacts with classifier. --- libexec/app-resolver-maven | 43 +++++++++++++++++++++++++++++++++---------- test/app-resolver-maven.bats | 27 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-) create mode 100755 test/app-resolver-maven.bats diff --git a/libexec/app-resolver-maven b/libexec/app-resolver-maven index ec1ad6b..4e21c4b 100755 --- a/libexec/app-resolver-maven +++ b/libexec/app-resolver-maven @@ -12,6 +12,8 @@ usage_text() { echo "usage: $usage_app init -r " echo "usage: $usage_app resolve-version" echo "usage: $usage_app download-version -v -f " + echo "Maven url can be one of: :: and" + echo ":::" } slash() { @@ -122,6 +124,7 @@ xmlstarlet() { resolve_version() { local group_id=`app-conf get maven.group_id` local artifact_id=`app-conf get maven.artifact_id` + local classifier=`app-conf get app.classifier` local version=`app-conf get app.version` repo=`app-conf get maven.repo` @@ -199,15 +202,17 @@ download_version() { repo=`app-conf get maven.repo` group_id=`app-conf get maven.group_id` artifact_id=`app-conf get maven.artifact_id` + classifier=`app-conf get maven.classifier` version=`app-conf get app.version` group_id_slash=`slash $group_id` base_path=$group_id_slash/$artifact_id/$version + file_name=$artifact_id-$resolved_version${classifier:+-}$classifier.zip mkdir -p .app/cache/$base_path - l=.app/cache/$base_path/$artifact_id-$resolved_version.zip - r=$repo/$base_path/$artifact_id-$resolved_version.zip + l=.app/cache/$base_path/$file_name + r=$repo/$base_path/$file_name echo "Downloading $group_id:$artifact_id:$resolved_version..." get $r $l @@ -236,17 +241,35 @@ init() { x=${x//:/ } set -- $x - if [[ $# != 3 || $1 == "" || $2 == "" || $3 == "" ]] - then - usage "Invalid Maven coordinates: $coordinates" - fi - - group_id=$1 - artifact_id=$2 - version=$3 + case $# in + 3) + if [[ $1 == "" || $2 == "" || $3 == "" ]] + then + usage "Invalid Maven coordinates: $coordinates" + fi + group_id=$1; shift + artifact_id=$1; shift + classifier= + version=$1; shift + ;; + 4) + if [[ $1 == "" || $2 == "" || $3 == "" || $4 == "" ]] + then + usage "Invalid Maven coordinates: $coordinates" + fi + group_id=$1; shift + artifact_id=$1; shift + classifier=$1; shift + version=$1; shift + ;; + *) + usage "Invalid Maven coordinates: $coordinates" + ;; + esac app-conf set maven.group_id "$group_id" app-conf set maven.artifact_id "$artifact_id" + [[ ! -z $classifier ]] && app-conf set maven.classifier "$classifier" app-conf set app.version "$version" } diff --git a/test/app-resolver-maven.bats b/test/app-resolver-maven.bats new file mode 100755 index 0000000..e5a5474 --- /dev/null +++ b/test/app-resolver-maven.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats +# vim: set filetype=sh: + +load utils + +@test "plain init" { + mkdir .app + app resolver-maven init my-group:my-artifact:1.0-SNAPSHOT + app cat-conf + eq '${lines[0]}' "app.version=1.0-SNAPSHOT" + eq '${lines[1]}' "maven.artifact_id=my-artifact" + eq '${lines[2]}' "maven.group_id=my-group" + eq '${lines[3]}' "maven.repo=http://repo1.maven.org" + eq '${#lines[*]}' 4 +} + +@test "init with classifier" { + mkdir .app + app resolver-maven init my-group:my-artifact:app:1.0-SNAPSHOT + app cat-conf + eq '${lines[0]}' "app.version=1.0-SNAPSHOT" + eq '${lines[1]}' "maven.artifact_id=my-artifact" + eq '${lines[2]}' "maven.classifier=app" + eq '${lines[3]}' "maven.group_id=my-group" + eq '${lines[4]}' "maven.repo=http://repo1.maven.org" + eq '${#lines[*]}' 5 +} -- 1.8.4.rc3