forked from ageweke/fortitude
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
78 lines (65 loc) · 2.56 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "fileutils"
# RSpec::Core::RakeTask.new(:spec)
default_prerequisites = [ :spec ]
if defined?(RUBY_ENGINE) && RUBY_ENGINE.to_s.strip.downcase == 'jruby'
default_prerequisites = [ 'jruby:clean', 'jruby:compile' ] + default_prerequisites
else
default_prerequisites = [ :clobber, :compile ] + default_prerequisites
end
task :default => default_prerequisites
require 'rake/extensiontask'
spec = Gem::Specification.load('fortitude.gemspec')
Rake::ExtensionTask.new('fortitude_native_ext', spec)
namespace :jruby do
base_directory = File.expand_path(File.dirname(__FILE__))
jar_path = File.join(base_directory, 'lib', 'fortitude_jruby_native_ext.jar')
source_path = File.join(base_directory, 'ext')
classes_output_path = File.join(base_directory, 'tmp', 'classes')
jruby_jar_path = File.join(RbConfig::CONFIG['libdir'], 'jruby.jar')
def safe_system(cmd)
output = `#{cmd} 2>&1`
unless $?.success?
raise "Command failed:\n #{cmd}\nreturned #{$?.inspect}, and produced output:\n#{output}"
end
end
task :ensure_jruby do
unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
raise "You must run this task using JRuby, not #{RUBY_ENGINE}"
end
end
desc "Cleans all temporary files and the JAR from the JRuby extension"
task :clean => [ :ensure_jruby ] do
to_remove = [ classes_output_path, jar_path ]
to_remove.each { |r| FileUtils.rm_rf(r) }
puts "Cleaned: #{to_remove.join(", ")}"
end
desc "Compiles the JRuby extension"
task :compile => [ :ensure_jruby ] do
require 'find'
files = [ ]
Find.find(source_path) do |f|
files << "'#{f}'" if f =~ /\.java$/i
end
FileUtils.mkdir_p(classes_output_path)
FileUtils.mkdir_p(File.dirname(jruby_jar_path))
puts "Compiling #{files.length} Java source files."
safe_system("javac -cp '#{jruby_jar_path}' -g -sourcepath '#{source_path}' -d '#{classes_output_path}' #{files.join(" ")}")
FileUtils.rm_rf(jar_path)
puts "Building JAR."
Dir.chdir(classes_output_path) do
safe_system("jar cf '#{jar_path}' .")
end
end
end
#---------------------------------------------------------------------------------------------------
# Monkey patch Bundler gem_helper so we release to our gem server instead of rubygems.org
module Bundler
class GemHelper
def rubygem_push(path)
sh("gem push --verbose --host https://artifactory.elstc.co/artifactory/api/gems/swiftype-gems --key elastic '#{path}'")
Bundler.ui.confirm "Pushed #{name} #{version} to artifactory"
end
end
end