embulk_javundler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3db4d88fc585d65d42456a95ee397f93999e17f
4
+ data.tar.gz: eb1a9d547b34d49f3d5206210da88df8fcaa8686
5
+ SHA512:
6
+ metadata.gz: fc88dd1e77914f5171b7249eb2ee265b91201f2619064663bc99d55eb21008c8d8eccd1c81957fb075ac1f09ca9dc5747395dfeb034bd12956e32b4948d3e95c
7
+ data.tar.gz: 5772555a1d6df1f2991c0d296e8c753100b95b22317166ae8bcea404ddf4552c0ab83164c198a98e7d116c700b17b035f38b5f88fef6263b0690d0f7f3f24f41
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ plugins
12
+ Embulkfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in embulk_javundler.gemspec
4
+ gemspec
@@ -0,0 +1,59 @@
1
+ # EmbulkJavundler
2
+
3
+ this gem installs embulk java plugins from git repository.
4
+ And this gem run embulk command with installed java plugins.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'embulk_javundler'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install embulk_javundler
21
+
22
+ ## Usage
23
+
24
+ Write `Embulkfile`.
25
+
26
+ ex.
27
+ ```
28
+ java_plugin "embulk-input-jdbc", github: "joker1007/embulk-input-jdbc", commit: "support-json-type", libdir: "embulk-input-postgresql/lib"
29
+ java_plugin "embulk-output-bigquery", github: "embulk/embulk-output-bigquery"
30
+ ```
31
+
32
+ ```sh
33
+ # install plugins to "plugins/java" directory
34
+ $ embulk_javundler install
35
+
36
+ # install plugins to ".plugins" directory
37
+ $ embulk_javundler install --path .plugins
38
+
39
+ # embulk preview with installed java plugins
40
+ $ embulk_javundler preview config.yml
41
+
42
+ # embulk run with installed java plugins
43
+ # subcommand is "exec", not "run". this is thor restriction.
44
+ $ embulk_javundler exec config.yml
45
+ ```
46
+
47
+ After install, this gem generates `Embulkfile.lock`.
48
+ `Embulkfile.lock` is information of installed plugins.
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec embulk_javundler` to use the gem in this directory, ignoring other installed copies of this gem.
53
+
54
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joker1007/embulk_javundler.
59
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "embulk_javundler"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'embulk_javundler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "embulk_javundler"
8
+ spec.version = EmbulkJavundler::VERSION
9
+ spec.authors = ["joker1007"]
10
+ spec.email = ["kakyoin.hierophant@gmail.com"]
11
+
12
+ spec.summary = %q{Install embulk java plugin from git repository and command wrapper}
13
+ spec.description = %q{Install embulk java plugin from git repository and command wrapper}
14
+ spec.homepage = "https://github.com/joker1007/embulk_javundler"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "thor"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "embulk_javundler/cli"
4
+
5
+ EmbulkJavundler::Cli.start
@@ -0,0 +1,29 @@
1
+ require "embulk_javundler/version"
2
+
3
+ module EmbulkJavundler
4
+ class << self
5
+ def embulk_file_path
6
+ @embulk_file_path
7
+ end
8
+
9
+ def embulk_file_path=(embulk_file_path)
10
+ @embulk_file_path = embulk_file_path.absolute? ? embulk_file_path : embulk_file_path.expand_path
11
+ end
12
+
13
+ def root
14
+ embulk_file_path.dirname
15
+ end
16
+
17
+ def install_dir
18
+ @install_dir || root.join("plugins", "java")
19
+ end
20
+
21
+ def install_dir=(install_dir)
22
+ @install_dir = root.join(install_dir)
23
+ end
24
+
25
+ def lock_file_path
26
+ root.join("Embulkfile.lock")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,92 @@
1
+ require 'thor'
2
+ require 'pathname'
3
+ require 'yaml'
4
+
5
+ require 'embulk_javundler'
6
+ require 'embulk_javundler/dsl'
7
+ require 'embulk_javundler/runner'
8
+
9
+ module EmbulkJavundler
10
+ class Cli < Thor
11
+ desc "install", "install embulk java plugins"
12
+ method_option :path, type: :string
13
+ def install
14
+ lookup_embulk_plugin_file
15
+ EmbulkJavundler.install_dir = options[:path] if options[:path]
16
+
17
+ java_plugins = parse_embulk_file(need_lock: false)
18
+ java_plugins.each do |plugin|
19
+ plugin.fetch
20
+ plugin.build_gem
21
+ end
22
+
23
+ write_lock_file(java_plugins) unless EmbulkJavundler.lock_file_path.exist?
24
+ end
25
+
26
+ desc "update", "update embulk java plugins"
27
+ def update
28
+ lookup_embulk_plugin_file
29
+
30
+ java_plugins = parse_embulk_file(use_lock: false, need_lock: false)
31
+ java_plugins.each do |plugin|
32
+ plugin.update
33
+ plugin.build_gem
34
+ end
35
+
36
+ write_lock_file(java_plugins)
37
+ end
38
+
39
+ desc "exec", "execute embulk run with installed java plugins"
40
+ def exec(*run_args)
41
+ lookup_embulk_plugin_file
42
+
43
+ java_plugins = parse_embulk_file
44
+ Runner.new(java_plugins).run(*run_args)
45
+ end
46
+
47
+ desc "preview", "execute embulk preview with installed java plugins"
48
+ def preview(*preview_args)
49
+ lookup_embulk_plugin_file
50
+
51
+ java_plugins = parse_embulk_file
52
+ Runner.new(java_plugins).preview(*preview_args)
53
+ end
54
+
55
+ desc "guess", "execute embulk guess with installed java plugins"
56
+ def guess(*guess_args)
57
+ lookup_embulk_plugin_file
58
+
59
+ java_plugins = parse_embulk_file
60
+ Runner.new(java_plugins).guess(*guess_args)
61
+ end
62
+
63
+ private
64
+
65
+ def lookup_embulk_plugin_file(dir = Pathname.pwd)
66
+ embulk_file = dir.each_child.find { |path| path.basename.to_s == "Embulkfile" }
67
+ if embulk_file
68
+ EmbulkJavundler.embulk_file_path = embulk_file
69
+ return embulk_file
70
+ end
71
+
72
+ raise "Embulkfile is not found" if dir.root?
73
+
74
+ lookup_embulk_plugin_file(dir.parent)
75
+ end
76
+
77
+ def parse_embulk_file(use_lock: true, need_lock: true)
78
+ exist_lock_file = EmbulkJavundler.lock_file_path.exist?
79
+ raise "Embulkfile.lock is not found" if need_lock && !exist_lock_file
80
+
81
+ if exist_lock_file && use_lock
82
+ YAML.load_file(EmbulkJavundler.lock_file_path).map(&JavaPlugin.method(:new))
83
+ else
84
+ Dsl.new.tap { |context| context.instance_eval(File.read(EmbulkJavundler.embulk_file_path)) }.java_plugins
85
+ end
86
+ end
87
+
88
+ def write_lock_file(java_plugins)
89
+ YAML.dump(java_plugins.map(&:to_h), File.open(EmbulkJavundler.lock_file_path, "w"))
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,23 @@
1
+ require 'embulk_javundler/java_plugin'
2
+
3
+ module EmbulkJavundler
4
+ class Dsl
5
+ attr_reader :java_plugins
6
+
7
+ def initialize
8
+ @java_plugins = []
9
+ end
10
+
11
+ def java_plugin(name, git: nil, github: nil, commit: "master", libdir: nil, classpathdir: nil)
12
+ @java_plugins << JavaPlugin.new(
13
+ name: name,
14
+ install_dir: EmbulkJavundler.install_dir.join(name),
15
+ git: git,
16
+ github: github,
17
+ commit: commit,
18
+ libdir: libdir,
19
+ classpathdir: classpathdir
20
+ )
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,106 @@
1
+ require 'open3'
2
+
3
+ module EmbulkJavundler
4
+ class JavaPlugin
5
+ class GitError < StandardError; end
6
+ class BuildFailure < StandardError; end
7
+
8
+ attr_reader :name, :install_dir, :git, :github, :repo, :commit, :sha1, :libdir, :classpathdir
9
+
10
+ def initialize(name:, install_dir:, git: nil, github: nil, commit: "master", libdir: nil, classpathdir: nil)
11
+ @name = name
12
+ @install_dir = install_dir
13
+ @git = git
14
+ @github = github
15
+ @repo = if git
16
+ git
17
+ elsif github
18
+ "https://github.com/#{github}.git"
19
+ else
20
+ raise ArgumentError, "Need git or github param"
21
+ end
22
+ @commit = commit
23
+ @libdir = libdir ? install_dir.join(libdir) : install_dir.join("lib")
24
+ @classpathdir = classpathdir ? install_dir.join(classpathdir) : install_dir.join("classpath")
25
+ end
26
+
27
+ def to_h
28
+ {
29
+ name: name,
30
+ install_dir: install_dir,
31
+ git: git,
32
+ github: github,
33
+ commit: sha1 || commit,
34
+ libdir: libdir,
35
+ classpathdir: classpathdir,
36
+ }
37
+ end
38
+
39
+ def fetch
40
+ if cloned?
41
+ puts "Using #{name}"
42
+ else
43
+ print "Fetch #{name} from #{repo} ... "
44
+ log, result_status = Open3.capture2e("git", "clone", repo, install_dir.to_s)
45
+ unless result_status.success?
46
+ puts log
47
+ raise GitError
48
+ end
49
+ print "OK\n"
50
+ end
51
+
52
+ checkout
53
+ end
54
+
55
+ def checkout
56
+ log, result_status = Open3.capture2e("git", "checkout", commit, chdir: install_dir.to_s)
57
+ unless result_status.success?
58
+ puts log
59
+ raise GitError
60
+ end
61
+
62
+ sha1 = IO.popen(["git", "rev-parse", "HEAD", {chdir: install_dir.to_s}]) do |io|
63
+ io.read.chomp
64
+ end
65
+ @sha1 = sha1
66
+ end
67
+
68
+ def update
69
+ return fetch unless cloned?
70
+
71
+ print "Update #{name} from #{repo} ... "
72
+ log, result_status = Open3.capture2e("git", "pull", "origin", "--all", "--ff-only", chdir: install_dir.to_s)
73
+ unless result_status.success?
74
+ puts log
75
+ raise GitError
76
+ end
77
+ print "OK\n"
78
+
79
+ checkout
80
+ end
81
+
82
+ def build_gem
83
+ Bundler.with_clean_env do
84
+ puts "Build #{name}"
85
+ log, result_status = Open3.capture2e("./gradlew", "gem", chdir: install_dir.to_s)
86
+ puts log
87
+ unless result_status.success?
88
+ raise BuildFailure
89
+ end
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def cloned?
96
+ if install_dir.directory?
97
+ log, result_status = Open3.capture2e("git", "remote", "-v", chdir: install_dir.to_s)
98
+ if result_status.success? && log =~ /origin\s+#{Regexp.escape(repo)}/
99
+ return true
100
+ end
101
+ end
102
+
103
+ false
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,31 @@
1
+ module EmbulkJavundler
2
+ class Runner
3
+ def initialize(java_plugins)
4
+ @java_plugins = java_plugins
5
+ end
6
+
7
+ def preview(*args)
8
+ Bundler.with_clean_env do
9
+ system("embulk", "preview", *load_paths, *args)
10
+ end
11
+ end
12
+
13
+ def run(*args)
14
+ Bundler.with_clean_env do
15
+ system("embulk", "run", *load_paths, *args)
16
+ end
17
+ end
18
+
19
+ def guess(*args)
20
+ Bundler.with_clean_env do
21
+ system("embulk", "guess", *load_paths, *args)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def load_paths
28
+ @java_plugins.flat_map { |plugin| ["-I", plugin.libdir.to_s] }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module EmbulkJavundler
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk_javundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - joker1007
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Install embulk java plugin from git repository and command wrapper
56
+ email:
57
+ - kakyoin.hierophant@gmail.com
58
+ executables:
59
+ - embulk_javundler
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - embulk_javundler.gemspec
70
+ - exe/embulk_javundler
71
+ - lib/embulk_javundler.rb
72
+ - lib/embulk_javundler/cli.rb
73
+ - lib/embulk_javundler/dsl.rb
74
+ - lib/embulk_javundler/java_plugin.rb
75
+ - lib/embulk_javundler/runner.rb
76
+ - lib/embulk_javundler/version.rb
77
+ homepage: https://github.com/joker1007/embulk_javundler
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Install embulk java plugin from git repository and command wrapper
100
+ test_files: []