Fixed exception with ajp-rails-0.0.0
[g-gem.git] / ebuild.rb
blobd50254006d7bfa255aa9aef9a5c3c719b753a032
1 require 'portage'
2 require 'depatom'
3 require 'rubygems'
5 class Ebuild
7   EXTENSION = ".ebuild"
9   require 'forwardable'
10   extend Forwardable
12   def_delegators :@spec, :name, :version, :date, :summary, :email,
13                  :rubyforge_project, :description, :local?, :remote?
15   attr_reader :spec
17   def initialize(spec)
18     @spec = spec
19   end
21   def file_path
22     File.expand_path(File.join(Portage.rubydev_overlay, spec.name, "#{spec.full_name}#{EXTENSION}"))
23   end
25   def dirname
26     File.dirname(file_path)
27   end
29   def basename(include_extension=true)
30     File.basename(file_path, (EXTENSION unless include_extension) )
31   end
33   def exists?
34     File.exists? file_path
35   end
37   def write
38     require 'fileutils'
39     dir = File.dirname(file_path)
40     FileUtils.mkdir_p(dir) unless File.directory?(dir)
41     File.open(file_path, 'w') { |f| f.write(content) }
42   end
44   def src_uri
45     uri = spec.fetched_from if spec.respond_to? :fetched_from
46     spec.local? ? "#{uri}/${P}.gem" : "#{uri}/gems/${P}.gem"
47   end
49   def license
50     "Unknown"
51   end
53   def keywords
54     Portage.env('ARCH')
55   end
57   def homepage
58     @spec.homepage || "http://rubyforge.org/projects/#{@spec.rubyforge_project or @spec.name}"
59   end
61   def iuse
62     "#{'doc' if spec.has_rdoc}"
63   end
65   def depend
66     category = Portage.category
67     required_ruby = DependencyAtom.from_required_ruby_version(spec)
68     spec.dependencies.inject(required_ruby) do |s,d|
69       s + "\n" + DependencyAtom.from_gem_dependency(d, category).to_s
70     end
71   end
73   def content
74     require 'date'
75     <<-EBUILD
76 # Copyright 1999-#{Date.today.year} Gentoo Foundation
77 # Distributed under the terms of the GNU General Public License v2
78 # $Header: $
80 inherit ruby gems
82 USE_RUBY="ruby18"
83 DESCRIPTION=#{(summary.capitalize.chomp('.')+'.').inspect}
84 HOMEPAGE=#{homepage.inspect}
85 SRC_URI=#{src_uri.inspect}
87 LICENSE=#{license.inspect}
88 SLOT="0"
89 KEYWORDS=#{keywords.inspect}
91 IUSE=#{iuse.inspect}
92 DEPEND=#{depend.inspect.gsub('\n', "\n\t")}
93     EBUILD
94   end
96   def execute(*commands)
97     callcc do |c|
98       if spec.local?
99         ENV.with(:GENTOO_MIRRORS => local_gentoo_mirror) do
100           c.call
101         end
102       end
103     end
104     generate if commands.delete('generate')
105     raise "Missing #{file_path}" unless exists?
106     system("ebuild #{file_path} #{commands.join(' ')}") unless commands.empty?
107   end