From 03394fdcae2d8c3ea48160304432c73dff313987 Mon Sep 17 00:00:00 2001 From: Radoslaw Jaros Date: Thu, 30 Jun 2016 19:12:40 +0200 Subject: [PATCH] Support Mac OS X --- .gitignore | 2 +- Berksfile | 2 +- Gemfile | 6 ++-- attributes/default.rb | 6 ++-- metadata.rb | 8 ++++- recipes/default.rb | 68 ++++++++++++++++++++++++++++------------- recipes/maven_rescue.rb | 8 ++--- 7 files changed, 66 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index cbb587a..54b1bec 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ Berksfile.lock .ruby-gemset .rubocop_todo.yml .rspec - +.idea diff --git a/Berksfile b/Berksfile index 8de6824..c065914 100644 --- a/Berksfile +++ b/Berksfile @@ -1,4 +1,4 @@ -site :opscode +source 'https://supermarket.chef.io' metadata diff --git a/Gemfile b/Gemfile index 84855b8..6e8372c 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'chef', '~> 12.11' gem 'rubocop' group :integration do - gem 'berkshelf', '~> 3.3.0' - gem 'test-kitchen', '~> 1.4.2' - gem 'kitchen-vagrant', '~> 0.19.0' + gem 'berkshelf', '~> 4.3' + gem 'test-kitchen', '~> 1.10' + gem 'kitchen-vagrant', '~> 0.20.0' end diff --git a/attributes/default.rb b/attributes/default.rb index 6a51bcc..9428018 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -7,8 +7,10 @@ default['android-sdk']['set_environment_variables'] = true default['android-sdk']['version'] = '24.4' -default['android-sdk']['checksum'] = 'f2bb546534d16e2004665257ee530060338c684adad14a49cd4bbde08098d8a4' -default['android-sdk']['download_url'] = "http://dl.google.com/android/android-sdk_r#{node['android-sdk']['version']}-linux.tgz" +default['android-sdk']['checksum']['linux'] = 'f2bb546534d16e2004665257ee530060338c684adad14a49cd4bbde08098d8a4' +default['android-sdk']['checksum']['mac_os_x'] = 'a1cb0c9b2036d597e18986de1bd43918b6113373ff3bf6fdb81b6cce4ec3efd7' +default['android-sdk']['download_url']['linux'] = "http://dl.google.com/android/android-sdk_r#{node['android-sdk']['version']}-linux.tgz" +default['android-sdk']['download_url']['mac_os_x'] = "https://dl.google.com/android/android-sdk_r#{node['android-sdk']['version']}-macosx.zip" # # List of Android SDK components to preinstall: diff --git a/metadata.rb b/metadata.rb index eb7a8cb..f0bb2bc 100644 --- a/metadata.rb +++ b/metadata.rb @@ -10,14 +10,20 @@ depends 'java' depends 'ark', '>= 1.1.0' +depends 'homebrew', '>= 2.1.0' +depends 'bash', '~> 0.1.2' +depends 'chef-sugar', '>= 3.3.0' # TODO: maybe put maven into depends section recommends 'maven' # Maven 3.1.1+ is required by android-sdk::maven-rescue recipe supports 'ubuntu', '>= 12.04' supports 'centos', '>= 6.6' +supports 'mac_os_x' + # Support for more platforms is on the road (e.g. Debian, CentOS,...). # Please watch or help on https://github.com/gildegoma/chef-android-sdk/issues/5 recipe 'android-sdk::default', 'Install and update Google Android SDK' -recipe 'android-sdk::maven_rescue', 'Install missing dependencies with Maven Android SDK Deployer' +recipe 'android-sdk::maven_rescue', 'Install missing dependencies with Maven '\ + 'Android SDK Deployer' diff --git a/recipes/default.rb b/recipes/default.rb index d2864a2..7404246 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -23,6 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +include_recipe 'chef-sugar::default' include_recipe 'java' unless node['android-sdk']['java_from_system'] setup_root = node['android-sdk']['setup_root'].to_s.empty? ? node['ark']['prefix_home'] : node['android-sdk']['setup_root'] @@ -53,15 +54,25 @@ # # Download and setup android-sdk tarball package # +if linux? + sdk_url = node['android-sdk']['download_url']['linux'] + sdk_checksum = node['android-sdk']['checksum']['linux'] +elsif mac_os_x? + sdk_url = node['android-sdk']['download_url']['mac_os_x'] + sdk_checksum = node['android-sdk']['checksum']['mac_os_x'] +else + Chef::Log.error('Platform not supported!') +end + ark node['android-sdk']['name'] do - url node['android-sdk']['download_url'] + url sdk_url path node['android-sdk']['setup_root'] - checksum node['android-sdk']['checksum'] + checksum sdk_checksum version node['android-sdk']['version'] prefix_root node['android-sdk']['setup_root'] prefix_home node['android-sdk']['setup_root'] owner node['android-sdk']['owner'] - group node['android-sdk']['group'] + group node['android-sdk']['group'] unless mac_os_x? backup node['android-sdk']['backup_archive'] action node['android-sdk']['with_symlink'] ? :install : :put end @@ -71,41 +82,54 @@ # %w(add-ons platforms tools).each do |subfolder| directory File.join(android_home, subfolder) do - mode 0755 + mode '0755' end end # TODO: find a way to handle 'chmod stuff' below with own chef resource (idempotence stuff...) execute 'Grant all users to read android files' do command "chmod -R a+r #{android_home}/*" user node['android-sdk']['owner'] - group node['android-sdk']['group'] + group node['android-sdk']['group'] unless mac_os_x? end execute 'Grant all users to execute android tools' do command "chmod -R a+X #{File.join(android_home, 'tools')}/*" user node['android-sdk']['owner'] - group node['android-sdk']['group'] + group node['android-sdk']['group'] unless mac_os_x? end # # Configure environment variables (ANDROID_HOME and PATH) # -template "/etc/profile.d/#{node['android-sdk']['name']}.sh" do - source 'android-sdk.sh.erb' - mode 0644 - owner node['android-sdk']['owner'] - group node['android-sdk']['group'] - variables( - android_home: android_home - ) - only_if { node['android-sdk']['set_environment_variables'] } +if linux? + template "/etc/profile.d/#{node['android-sdk']['name']}.sh" do + source 'android-sdk.sh.erb' + mode '0644' + owner node['android-sdk']['owner'] + group node['android-sdk']['group'] unless mac_os_x? + variables( + android_home: android_home + ) + only_if { node['android-sdk']['set_environment_variables'] } + end +elsif mac_os_x? + bash_profile 'profile.android_sdk' do + user node['android-sdk']['owner'] + content <<-EOH + export ANDROID_HOME=#{android_home} + export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools + EOH + end +else + Chef::Log.error('Platform not supported!') end -package 'expect' - # # Install, Update (a.k.a. re-install) Android components # +homebrew_tap 'homebrew/dupes' if mac_os_x? +package 'expect' + # KISS: use a basic idempotent guard, waiting for https://github.com/gildegoma/chef-android-sdk/issues/12 unless File.exist?("#{setup_root}/#{node['android-sdk']['name']}/temp") @@ -119,7 +143,7 @@ environment 'ANDROID_HOME' => android_home path [File.join(android_home, 'tools')] user node['android-sdk']['owner'] - group node['android-sdk']['group'] + group node['android-sdk']['group'] unless mac_os_x? # TODO: use --force or not? code <<-EOF spawn #{android_bin} update sdk --no-ui --all --filter #{sdk_component} @@ -152,16 +176,16 @@ cookbook_file File.join(node['android-sdk']['scripts']['path'], android_helper_script) do source android_helper_script owner node['android-sdk']['scripts']['owner'] - group node['android-sdk']['scripts']['group'] - mode 0755 + group node['android-sdk']['scripts']['group'] unless mac_os_x? + mode '0755' end end %w(android-update-sdk).each do |android_helper_script| template File.join(node['android-sdk']['scripts']['path'], android_helper_script) do source "#{android_helper_script}.erb" owner node['android-sdk']['scripts']['owner'] - group node['android-sdk']['scripts']['group'] - mode 0755 + group node['android-sdk']['scripts']['group'] unless mac_os_x? + mode '0755' end end diff --git a/recipes/maven_rescue.rb b/recipes/maven_rescue.rb index 3417db6..2ecc405 100644 --- a/recipes/maven_rescue.rb +++ b/recipes/maven_rescue.rb @@ -9,8 +9,8 @@ # directory maven_android_sdk_deployer_home do user node['android-sdk']['owner'] - group node['android-sdk']['group'] - mode 00755 + group node['android-sdk']['group'] unless mac_os_x? + mode '0755' action :create end git maven_android_sdk_deployer_home do @@ -19,7 +19,7 @@ checkout_branch "deploy_#{node['android-sdk']['maven-android-sdk-deployer']['version']}" action :sync user node['android-sdk']['owner'] - group node['android-sdk']['group'] + group node['android-sdk']['group'] unless mac_os_x? end # @@ -35,7 +35,7 @@ execute 'Execute maven-android-sdk-deployer' do command "mvn clean install -Dmaven.repo.local=#{node['android-sdk']['maven-local-repository']} --fail-never -B" user node['android-sdk']['owner'] - group node['android-sdk']['group'] + group node['android-sdk']['group'] unless mac_os_x? cwd maven_android_sdk_deployer_home # FIXME: setting HOME might be required (if $HOME used in node['android-sdk']['maven-local-repository'],