#
# Author:: Doug MacEachern <dougm@vmware.com>
# Cookbook Name:: ant
# Recipe:: binary
#
# Copyright 2010, VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#installs the binary release of ant from apache.org
#unlike 'package "ant"', works on all the unix

directory node[:ant][:dir] do
  action :create
  recursive true
end

dir = "apache-ant-#{node[:ant][:release]}"
tgz = "#{dir}-bin.tar.gz"
dst = "#{node[:ant][:dir]}/#{tgz}"
home = "#{node[:ant][:dir]}/#{dir}"
junit = "#{home}/lib/#{File.basename(node[:ant][:junit_jar])}"

remote_file dst do
  source "#{node[:ant][:mirror]}/#{tgz}"
  not_if { ::File.exists?(dst) }
end

execute "gunzip < #{tgz} | tar -xf -" do
  cwd node[:ant][:dir]
  not_if { ::File.exists?("#{node[:ant][:dir]}/#{dir}/bin/ant") }
end

remote_file junit do
  source node[:ant][:junit_jar]
  mode "0444"
  not_if { ::File.exists?(junit) }
end

link "/usr/bin/ant" do
  to "#{home}/bin/ant"
  only_if { node[:ant][:link] }
end
