Class: Embulk::JavaPlugin

Inherits:
Object
  • Object
show all
Defined in:
embulk-core/src/main/ruby/embulk/java_plugin.rb

Class Method Summary collapse

Class Method Details

.classloader(dir) ⇒ Object



6
7
8
9
10
11
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 6

def self.classloader(dir)
  jars = Dir["#{dir}/**/*.jar"]
  urls = jars.map {|jar| java.io.File.new(File.expand_path(jar)).toURI.toURL }
  factory = Java.injector.getInstance(Java::PluginClassLoaderFactory.java_class)
  factory.create(urls, JRuby.runtime.getJRubyClassLoader())
end

.register_decoder(name, class_fqdn, jar_dir) ⇒ Object



38
39
40
41
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 38

def self.register_decoder(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_decoder(name, java_class)
end

.register_encoder(name, class_fqdn, jar_dir) ⇒ Object



43
44
45
46
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 43

def self.register_encoder(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_encoder(name, java_class)
end

.register_executor(name, class_fqdn, jar_dir) ⇒ Object



53
54
55
56
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 53

def self.register_executor(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_executor(name, java_class)
end

.register_filter(name, class_fqdn, jar_dir) ⇒ Object



23
24
25
26
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 23

def self.register_filter(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_filter(name, java_class)
end

.register_formatter(name, class_fqdn, jar_dir) ⇒ Object



33
34
35
36
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 33

def self.register_formatter(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_formatter(name, java_class)
end

.register_guess(name, class_fqdn, jar_dir) ⇒ Object



48
49
50
51
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 48

def self.register_guess(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_guess(name, java_class)
end

.register_input(name, class_fqdn, jar_dir) ⇒ Object



13
14
15
16
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 13

def self.register_input(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)  # TODO handle class not found error
  Plugin.register_java_input(name, java_class)
end

.register_output(name, class_fqdn, jar_dir) ⇒ Object



18
19
20
21
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 18

def self.register_output(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_output(name, java_class)
end

.register_parser(name, class_fqdn, jar_dir) ⇒ Object



28
29
30
31
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 28

def self.register_parser(name, class_fqdn, jar_dir)
  java_class = classloader(jar_dir).loadClass(class_fqdn)
  Plugin.register_java_parser(name, java_class)
end

.ruby_adapter_class(java_class, ruby_base_class, ruby_module) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'embulk-core/src/main/ruby/embulk/java_plugin.rb', line 58

def self.ruby_adapter_class(java_class, ruby_base_class, ruby_module)
  Class.new(ruby_base_class) do
    const_set(:PLUGIN_JAVA_CLASS, java_class)

    include ruby_module
    extend ruby_module::ClassMethods

    unless method_defined?(:plugin_java_object)
      def plugin_java_object
        @plugin_java_object ||= self.class.new_java
      end
    end

    unless (class<<self;self;end).method_defined?(:plugin_java_class)
      def self.plugin_java_class
        self::PLUGIN_JAVA_CLASS
      end
    end

    # TODO ruby_base_class already implements new_java. So
    #      this line returns always true:
    #unless (class<<self;self;end).method_defined?(:new_java)
    #      but this line could return false unexpectedly if
    #      ruby_module::ClassMethods includes other modules.
    unless ruby_module::ClassMethods.method_defined?(:new_java)
      def self.new_java
        Java.injector.getInstance(plugin_java_class)
      end
    end
  end
end