class Rake::JavaExtensionTask

def define_java_platform_tasks

def define_java_platform_tasks
  # lib_path
  lib_path = lib_dir
  if @gem_spec && !Rake::Task.task_defined?("java:#{@gem_spec.name}")
    task "java:#{@gem_spec.name}" do |t|
      # FIXME: workaround Gem::Specification limitation around cache_file:
      # http://github.com/rubygems/rubygems/issues/78
      spec = gem_spec.dup
      spec.instance_variable_set(:"@cache_file", nil) if spec.respond_to?(:cache_file)
      # adjust to specified platform
      spec.platform = Gem::Platform.new('java')
      # clear the extensions defined in the specs
      spec.extensions.clear
      # add the binaries that this task depends on
      ext_files = []
      # go through native prerequisites and grab the real extension files from there
      t.prerequisites.each do |ext|
        ext_files << ext
      end
      # include the files in the gem specification
      spec.files += ext_files
      # expose gem specification for customization
      if @java_compiling
        @java_compiling.call(spec)
      end
      # Generate a package for this gem
      Gem::PackageTask.new(spec) do |pkg|
        pkg.need_zip = false
        pkg.need_tar = false
      end
    end
    # lib_binary_path
    lib_binary_path = "#{lib_path}/#{File.basename(binary(platform))}"
    # add binaries to the dependency chain
    task "java:#{@gem_spec.name}" => [lib_binary_path]
    # ensure the extension get copied
    unless Rake::Task.task_defined?(lib_binary_path) then
      file lib_binary_path => ["copy:#{name}:#{platform}"]
    end
    task 'java' => ["java:#{@gem_spec.name}"]
  end
  task 'java' do
    task 'compile' => 'compile:java'
  end
end