From 6dc2bb84499830d1ed2a1590143bd686ac69b644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 10 Jan 2014 20:10:20 +0100 Subject: [PATCH] Move gradle script to separate file, install it properly --- .../cookbooks/gradle/recipes/default.rb | 79 ++----------------- buildserver/cookbooks/gradle/recipes/gradle | 68 ++++++++++++++++ 2 files changed, 76 insertions(+), 71 deletions(-) create mode 100755 buildserver/cookbooks/gradle/recipes/gradle diff --git a/buildserver/cookbooks/gradle/recipes/default.rb b/buildserver/cookbooks/gradle/recipes/default.rb index 89f5144c..b13e397e 100644 --- a/buildserver/cookbooks/gradle/recipes/default.rb +++ b/buildserver/cookbooks/gradle/recipes/default.rb @@ -1,6 +1,9 @@ user = node[:settings][:user] +gradle_script = IO.read(File.join( + File.expand_path(File.dirname(__FILE__)), "gradle")) + script "add-gradle-bindir" do cwd "/tmp" interpreter "bash" @@ -30,78 +33,12 @@ end script "add-gradle-wrapper" do cwd "/tmp" interpreter "bash" - code %{cat << EOF > /opt/gradle/bin/gradle -#!/bin/bash - -bindir=$(dirname $0) -basedir=$(dirname $bindir) -verdir="${basedir}/versions" -args=("$@") -pushd "${verdir}" &>/dev/null - -v_all=(*/) -v_all=(${v_all[@]%/}) - -v_def=${v_all[-1]} -echo "Available gradle versions: ${v_all[@]}" - -popd &>/dev/null - -run_gradle() { - ${verdir}/${v_found}/bin/gradle "${args[@]}" - exit $? -} - -# key-value pairs of what gradle version each gradle plugin version -# should accept -d_plugin_k=(0.7 0.6 0.5 0.4 0.3 0.2) -d_plugin_v=(1.9 1.8 1.6 1.6 1.4 1.4) - -# Latest takes priority -files=(build.gradle) - -for f in ${files[@]}; do - [[ -f $f ]] || continue - while read l; do - if [[ "$l" == *'com.android.tools.build:gradle:'* ]]; then - plugin_pver=$(echo -n "$l" | sed "s/.*com.android.tools.build:gradle:\\([0-9\\.\\+]\\+\\).*/\\1/") - elif [[ "$l" == *'gradleVersion'* ]]; then - wrapper_ver=$(echo -n "$l" | sed "s/.*gradleVersion[ ]*=[ ]*[\"']\\([0-9\\.]\\+\\)[\"'].*/\\1/") - fi - done < $f -done - -if [[ -n $wrapper_ver ]]; then - v_found=$wrapper_ver - echo "Found $v_found via gradleVersion" - run_gradle -fi - -if [[ -n $plugin_pver ]]; then - i=0 - match=false - for k in ${d_plugin_k[@]}; do - if [[ $plugin_pver == ${k}* ]]; then - plugin_ver=${d_plugin_v[$i]} - match=true - break - fi - let i++ - done - if $match; then - v_found=$plugin_ver - echo "Found $v_found via gradle plugin version ${k}*" - fi -fi - -[[ -n $v_found ]] && run_gradle - -echo "No suitable gradle version found - defaulting to $v_def" -v_found=$v_def -run_gradle - + code " + cat << \"EOF\" > /opt/gradle/bin/gradle +#{gradle_script} EOF - } + chmod a+x /opt/gradle/bin/gradle + " end execute "add-android-ndk-path" do diff --git a/buildserver/cookbooks/gradle/recipes/gradle b/buildserver/cookbooks/gradle/recipes/gradle new file mode 100755 index 00000000..652de586 --- /dev/null +++ b/buildserver/cookbooks/gradle/recipes/gradle @@ -0,0 +1,68 @@ +#!/bin/bash + +bindir="$(dirname $0)" +basedir="$(dirname $bindir)" +verdir="${basedir}/versions" +args=("$@") +pushd "${verdir}" &>/dev/null + +v_all=(*/) +v_all=(${v_all[@]%/}) + +v_def=${v_all[-1]} +echo "Available gradle versions: ${v_all[@]}" + +popd &>/dev/null + +run_gradle() { + ${verdir}/${v_found}/bin/gradle "${args[@]}" + exit $? +} + +# key-value pairs of what gradle version each gradle plugin version +# should accept +d_plugin_k=(0.7 0.6 0.5 0.4 0.3 0.2) +d_plugin_v=(1.9 1.8 1.6 1.6 1.4 1.4) + +# Latest takes priority +files=(build.gradle) + +for f in ${files[@]}; do + [[ -f $f ]] || continue + while read l; do + if [[ $l == *'com.android.tools.build:gradle:'* ]]; then + plugin_pver=$(echo -n "$l" | sed "s/.*com.android.tools.build:gradle:\\([0-9\\.\\+]\\+\\).*/\\1/") + elif [[ $l == *'gradleVersion'* ]]; then + wrapper_ver=$(echo -n "$l" | sed "s/.*gradleVersion[ ]*=[ ]*[\"']\\([0-9\\.]\\+\\)[\"'].*/\\1/") + fi + done < $f +done + +if [[ -n $wrapper_ver ]]; then + v_found=$wrapper_ver + echo Found $v_found via gradleVersion + run_gradle +fi + +if [[ -n $plugin_pver ]]; then + i=0 + match=false + for k in ${d_plugin_k[@]}; do + if [[ $plugin_pver == ${k}* ]]; then + plugin_ver=${d_plugin_v[$i]} + match=true + break + fi + let i++ + done + if $match; then + v_found=$plugin_ver + echo Found $v_found via gradle plugin version $k + fi +fi + +[[ -n $v_found ]] && run_gradle + +echo No suitable gradle version found - defaulting to $v_def +v_found=$v_def +run_gradle