Skip to content

Commit

Permalink
Support Mac OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
rjaros87 committed Jun 30, 2016
1 parent b3ad4a1 commit 03394fd
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Berksfile.lock
.ruby-gemset
.rubocop_todo.yml
.rspec

.idea
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
site :opscode
source 'https://supermarket.chef.io'

metadata

Expand Down
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
68 changes: 46 additions & 22 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand All @@ -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}
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions recipes/maven_rescue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

#
Expand All @@ -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'],
Expand Down

0 comments on commit 03394fd

Please sign in to comment.