-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRakefile
111 lines (96 loc) · 2.83 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require 'bundler/setup'
Bundler.require(:development)
def log_ok(message)
$stderr.write "#{message}... "
begin
yield
$stderr.puts "ok"
rescue => e
$stderr.puts "failed"
abort <<-EOF
error: #{e}
EOF
end
end
def artifact_name(path)
File.open(path) do |f|
doc = Nokogiri::XML(f)
id = doc.css("project>artifactId").text
version = doc.css("project>version").text
"#{id}-#{version}.jar"
end
end
namespace :ext do
require_relative 'lib/telekinesis/version'
desc "Cleanup all built extension"
task :clean do
FileUtils.rm(Dir.glob("lib/telekinesis/*.jar"))
Dir.chdir("ext") do
`mvn clean 2>&1`
end
end
task :have_maven? do
log_ok("Checking for maven") do
`which mvn`
raise "Maven is required to build this gem" unless $?.success?
end
end
task :have_jdk6_or_higher? do
log_ok("Checking that at least java 6 is installed") do
version_match = `java -version 2>&1`.match(/java version "1\.(\d)\.(\d+_\d+)"/)
if version_match.nil?
raise "Can't parse Java version!"
end
jdk_version, _jdk_patchlevel = version_match.captures
if jdk_version.to_i < 6
raise "Found #{version_match}"
end
end
end
task :update_pom_version do
File.open('ext/pom.xml', 'r+') do |f|
doc = Nokogiri::XML(f)
pom_version = doc.css("project>version")
if pom_version.text != Telekinesis::VERSION
log_ok("Updating pom.xml version") do
pom_version.first.content = Telekinesis::VERSION
f.truncate(0)
f.rewind
f.write(doc.to_xml)
end
end
end
end
desc "Build the Java extensions for this gem. Requires JDK6+ and Maven"
task :build => [:have_jdk6_or_higher?, :have_maven?, :update_pom_version, :clean] do
fat_jar = artifact_name('ext/pom.xml')
log_ok("Building #{fat_jar}") do
Dir.chdir("ext") do
`mkdir -p target/`
`mvn package 2>&1 > target/build_log`
raise "build failed. See ext/target/build_log for details" unless $?.success?
FileUtils.copy("target/#{fat_jar}", "../lib/telekinesis/#{fat_jar}")
end
end
end
end
namespace :gem do
desc "Build this gem"
task :build => 'ext:build' do
`gem build telekinesis.gemspec`
end
end
require 'rake/testtask'
# NOTE: Tests shouldn't be run without the extension being built, but converting
# the build task to a file task made it hard to depend on having a JDK
# and Maven installed. This is a little kludgy but better than the
# alternative.
task :check_for_ext do
fat_jar = artifact_name('ext/pom.xml')
Rake::Task["ext:build"].invoke unless File.exists?("lib/telekinesis/#{fat_jar}")
end
Rake::TestTask.new(:test) do |t|
t.test_files = FileList["test/**/test_*.rb"].exclude(/test_helper/)
t.verbose = true
end
task :test => :check_for_ext