Class: Rubydoop::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/rubydoop/package.rb

Overview

Utility for making a job JAR that works with Hadoop.

Examples:

Easy to use from Rake

task :package do
  Rudoop::Package.create!
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Package

A package has sane defaults that works in most situations, but almost everything can be changed.

If you have extra JAR files that you need to make available for your job you can specify them with the ‘:lib_jars` option.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :project_base_dir (String)

    The project’s base dir, defaults to the current directory (the assumption is that Package will be used from a Rake task)

  • :project_name (String)

    The name of the JAR file (minus .jar), defaults to the directory name of the ‘:project_base_dir`

  • :build_dir (String)

    The directory to put the final JAR into, defaults to ‘:project_base_dir + ’/build’‘

  • :gem_groups (Array<String>)

    All gems from these Gemfile groups will be included, defaults to ‘[:default]` (the top-level group of a Gemfile)

  • :lib_jars (Array<String>)

    Paths to extra JAR files to include in the JAR’s lib directory (where they will be on the classpath when the job is run)

  • :jruby_version (String)

    The JRuby version to package, defaults to ‘JRUBY_VERSION`

  • :jruby_jar_path (String)

    The path to a local copy of ‘jruby-complete.jar`, defaults to downloading and caching a version defined by `:jruby_version`



34
35
36
37
38
39
40
# File 'lib/rubydoop/package.rb', line 34

def initialize(options={})
  @options = default_options.merge(options)
  @options[:project_name] ||= File.basename(@options[:project_base_dir])
  @options[:build_dir] ||= File.join(@options[:project_base_dir], 'build')
  @options[:jruby_jar_path] ||= File.join(@options[:build_dir], "jruby-complete-#{@options[:jruby_version]}.jar")
  @options[:jar_path] ||= File.join(@options[:build_dir], "#{@options[:project_name]}.jar")
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



63
64
65
# File 'lib/rubydoop/package.rb', line 63

def method_missing(name, *args)
  @options[name] or super
end

Class Method Details

.create!(options = {}) ⇒ Object

A shortcut for ‘Package.new(options).create!`.



55
56
57
# File 'lib/rubydoop/package.rb', line 55

def self.create!(options={})
  new(options).create!
end

Instance Method Details

#create!Object

Create the JAR package, see #initialize for configuration options.

On the first run a complete JRuby runtime JAR will be downloaded (‘jruby-complete.jar`) and locally cached, but if you already have a copy in a local Ivy or Maven repository that will be used instead.



47
48
49
50
51
52
# File 'lib/rubydoop/package.rb', line 47

def create!
  create_directories!
  fetch_jruby!
  find_gems!
  build_jar!
end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rubydoop/package.rb', line 59

def respond_to?(name)
  @options.key?(name) or super
end