Class: EmbulkJavundler::JavaPlugin

Inherits:
Object
  • Object
show all
Defined in:
lib/embulk_javundler/java_plugin.rb

Defined Under Namespace

Classes: BuildFailure, GitError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, install_dir:, git: nil, github: nil, commit: "master", libdir: nil, classpathdir: nil) ⇒ JavaPlugin

Returns a new instance of JavaPlugin.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/embulk_javundler/java_plugin.rb', line 10

def initialize(name:, install_dir:, git: nil, github: nil, commit: "master", libdir: nil, classpathdir: nil)
  @name = name
  @install_dir = install_dir
  @git = git
  @github = github
  @repo = if git
            git
          elsif github
            "https://github.com/#{github}.git"
          else
            raise ArgumentError, "Need git or github param"
          end
  @commit = commit
  @libdir = libdir ? install_dir.join(libdir) : install_dir.join("lib")
  @classpathdir = classpathdir ? install_dir.join(classpathdir) : install_dir.join("classpath")
end

Instance Attribute Details

#classpathdirObject (readonly)

Returns the value of attribute classpathdir.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def classpathdir
  @classpathdir
end

#commitObject (readonly)

Returns the value of attribute commit.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def commit
  @commit
end

#gitObject (readonly)

Returns the value of attribute git.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def git
  @git
end

#githubObject (readonly)

Returns the value of attribute github.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def github
  @github
end

#install_dirObject (readonly)

Returns the value of attribute install_dir.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def install_dir
  @install_dir
end

#libdirObject (readonly)

Returns the value of attribute libdir.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def libdir
  @libdir
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def name
  @name
end

#repoObject (readonly)

Returns the value of attribute repo.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def repo
  @repo
end

#sha1Object (readonly)

Returns the value of attribute sha1.



8
9
10
# File 'lib/embulk_javundler/java_plugin.rb', line 8

def sha1
  @sha1
end

Instance Method Details

#build_gemObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/embulk_javundler/java_plugin.rb', line 82

def build_gem
  Bundler.with_clean_env do
    puts "Build #{name}"
    log, result_status = Open3.capture2e("./gradlew", "gem", chdir: install_dir.to_s)
    puts log
    unless result_status.success?
      raise BuildFailure
    end
  end
end

#checkoutObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/embulk_javundler/java_plugin.rb', line 55

def checkout
  log, result_status = Open3.capture2e("git", "checkout", commit, chdir: install_dir.to_s)
  unless result_status.success?
    puts log
    raise GitError
  end

  sha1 = IO.popen(["git", "rev-parse", "HEAD", {chdir: install_dir.to_s}]) do |io|
    io.read.chomp
  end
  @sha1 = sha1
end

#fetchObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/embulk_javundler/java_plugin.rb', line 39

def fetch
  if cloned?
    puts "Using #{name}"
  else
    print "Fetch #{name} from #{repo} ... "
    log, result_status = Open3.capture2e("git", "clone", repo, install_dir.to_s)
    unless result_status.success?
      puts log
      raise GitError
    end
    print "OK\n"
  end

  checkout
end

#to_hObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/embulk_javundler/java_plugin.rb', line 27

def to_h
  {
    name: name,
    install_dir: install_dir,
    git: git,
    github: github,
    commit: sha1 || commit,
    libdir: libdir,
    classpathdir: classpathdir,
  }
end

#updateObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/embulk_javundler/java_plugin.rb', line 68

def update
  return fetch unless cloned?

  print "Update #{name} from #{repo} ... "
  log, result_status = Open3.capture2e("git", "pull", "origin", "--all", "--ff-only", chdir: install_dir.to_s)
  unless result_status.success?
    puts log
    raise GitError
  end
  print "OK\n"

  checkout
end