-
Notifications
You must be signed in to change notification settings - Fork 17
/
Rakefile
243 lines (198 loc) · 6.99 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
PROJECT_NAME = 'jruby-rack-worker'
SRC_DIR = 'src'
MAIN_SRC_DIR = File.join(SRC_DIR, 'main/java')
RUBY_SRC_DIR = File.join(SRC_DIR, 'main/ruby')
TEST_SRC_DIR = File.join(SRC_DIR, 'test/java')
OUT_DIR = 'out'
MAIN_BUILD_DIR = File.join(OUT_DIR, 'classes')
TEST_BUILD_DIR = File.join(OUT_DIR, 'test-classes')
TEST_RESULTS_DIR = File.join(OUT_DIR, 'test-results')
LIB_BASE_DIR = 'lib'
unless defined?(JRUBY_VERSION)
raise "Hey, we're not running within JRuby my dear !"
end
load File.join(RUBY_SRC_DIR, "#{PROJECT_NAME.gsub('-', '/')}", 'version.rb')
def project_version
JRuby::Rack::Worker::VERSION
end
def out_jar_path
"#{OUT_DIR}/#{PROJECT_NAME}_#{project_version}.jar"
end
require 'ant'
ant.property :name => "ivy.lib.dir", :value => LIB_BASE_DIR
namespace :ivy do
ivy_version = '2.2.0'
ivy_jar_dir = File.join(LIB_BASE_DIR, 'build')
ivy_jar_file = File.join(ivy_jar_dir, 'ivy.jar')
task :download do
mkdir_p ivy_jar_dir
ant.get :src => "http://repo1.maven.org/maven2/org/apache/ivy/ivy/#{ivy_version}/ivy-#{ivy_version}.jar",
:dest => ivy_jar_file,
:usetimestamp => true
end
task :install do
Rake::Task["ivy:download"].invoke unless File.exist?(ivy_jar_file)
ant.path :id => 'ivy.lib.path' do
fileset :dir => ivy_jar_dir, :includes => '*.jar'
end
ant.taskdef :resource => "org/apache/ivy/ant/antlib.xml", :classpathref => "ivy.lib.path"
end
task :clean do
rm_rf LIB_BASE_DIR
end
end
task :retrieve => :"ivy:install" do
ant.retrieve :pattern => "${ivy.lib.dir}/[conf]/[artifact].[type]"
end
ant.path :id => "main.class.path" do
fileset :dir => LIB_BASE_DIR do
include :name => 'runtime/*.jar'
end
end
ant.path :id => "test.class.path" do
fileset :dir => LIB_BASE_DIR do
include :name => 'test/*.jar'
end
end
task :compile => :retrieve do
mkdir_p MAIN_BUILD_DIR
ant.javac :destdir => MAIN_BUILD_DIR, :source => '1.5' do
src :path => MAIN_SRC_DIR
classpath :refid => "main.class.path"
end
end
task :copy_resources do
mkdir_p ruby_dest_dir = File.join(MAIN_BUILD_DIR, '') # 'META-INF/jruby_rack_worker'
ant.copy :todir => ruby_dest_dir do
fileset :dir => RUBY_SRC_DIR do
exclude :name => 'jruby_rack_worker.rb' # exclude :name => 'jruby/**'
end
end
end
desc "build jar"
task :jar => [ :compile, :copy_resources ] do
ant.jar :destfile => out_jar_path, :basedir => MAIN_BUILD_DIR do
manifest do
attribute :name => "Built-By", :value => "${user.name}"
attribute :name => "Implementation-Title", :value => PROJECT_NAME
attribute :name => "Implementation-Version", :value => project_version
attribute :name => "Implementation-Vendor", :value => "Karol Bucek"
attribute :name => "Implementation-Vendor-Id", :value => "org.kares"
end
end
end
desc "build gem"
task :gem => [ :jar ] do
warn "building using JRuby: #{JRUBY_VERSION}" if JRUBY_VERSION > '9.0'
raise "building on Java > 7" if ENV_JAVA['java.specification.version'] > '1.7'
mkdir_p gem_out = File.join(OUT_DIR, 'gem')
mkdir_p gem_out_lib = File.join(gem_out, 'lib')
cp FileList["LICENSE", "README.md"], gem_out
cp out_jar_path, gem_out_lib
if (jars = FileList["#{gem_out_lib}/*.jar"].to_a).size > 1
abort "too many jars! #{jars.map{ |j| File.basename(j) }.inspect}\nrake clean first"
end
ant.copy :todir => gem_out_lib do
fileset :dir => RUBY_SRC_DIR do
include :name => '*.rb'
include :name => 'jruby/**/*.rb'
end
end
Dir.chdir(gem_out) do
rm_f gemspec_file = "#{PROJECT_NAME}.gemspec"
gem_spec = Gem::Specification.new do |spec|
spec.name = PROJECT_NAME
spec.version = project_version
spec.authors = ["Karol Bucek"]
spec.email = ["[email protected]"]
spec.homepage = 'https://github.com/kares/jruby-rack-worker'
spec.license = 'Apache-2.0'
spec.summary = 'Threaded Workers with JRuby-Rack'
spec.description =
"Implements a thread based worker pattern on top of JRuby-Rack. " +
"Useful if you'd like to run background workers within your (deployed) " +
"web-application, concurrently in 'native' threads, instead of using " +
"separate daemon processes. " +
"Provides (thread-safe) implementations for popular worker libraries " +
"such as Resque and Delayed::Job, but one can easily write their own " +
"'daemon' work processing loop as well."
spec.add_dependency 'jruby-rack', "~> 1.1.10"
spec.files = FileList["./**/*"].exclude("*.gem").map{ |f| f.sub(/^\.\//, '') }
spec.has_rdoc = false
spec.rubyforge_project = '[none]'
end
defined?(Gem::Builder) ? Gem::Builder.new(gem_spec).build : begin
require 'rubygems/package'; Gem::Package.build(gem_spec)
end
File.open(gemspec_file, 'w') { |f| f << gem_spec.to_ruby }
mv FileList['*.gem'], '..'
end
end
task :'test:compile' => :compile do
mkdir_p TEST_BUILD_DIR
ant.javac :destdir => TEST_BUILD_DIR, :source => '1.5' do
src :path => TEST_SRC_DIR
classpath :refid => "main.class.path"
classpath :refid => "test.class.path"
classpath { pathelement :path => MAIN_BUILD_DIR }
end
end
task :'bundler:setup' do
begin
require 'bundler/setup'
rescue LoadError
puts "Please install Bundler and run `bundle install` to ensure you have all dependencies"
end
end
namespace :test do
desc "run ruby tests"
task :ruby do # => :'bundler:setup'
Rake::Task['jar'].invoke unless File.exists?(out_jar_path)
_ruby_test('src/test/ruby/**/*_test.rb')
end
desc "run DJ (ruby) tests only"
task 'ruby:delayed' do # => :'bundler:setup'
Rake::Task['jar'].invoke unless File.exists?(out_jar_path)
_ruby_test('src/test/ruby/delayed/**/*_test.rb')
end
desc "run Resque (ruby) tests only"
task 'ruby:resque' do # => :'bundler:setup'
Rake::Task['jar'].invoke unless File.exists?(out_jar_path)
_ruby_test('src/test/ruby/resque/**/*_test.rb')
end
def _ruby_test(test_files)
test_files = ENV['TEST'] || File.join(test_files)
#test_opts = (ENV['TESTOPTS'] || '').split(' ')
test_files = FileList[test_files].map { |path| path.sub('src/test/ruby/', '') }
ruby "-Isrc/main/ruby:src/test/ruby", "-e #{test_files.inspect}.each { |test| require test }"
end
desc "run java tests"
task :java => :'test:compile' do
mkdir_p TEST_RESULTS_DIR
ant.junit :fork => true,
:haltonfailure => false,
:haltonerror => true,
:showoutput => true,
:printsummary => true do
classpath :refid => "main.class.path"
classpath :refid => "test.class.path"
classpath do
pathelement :path => MAIN_BUILD_DIR
pathelement :path => TEST_BUILD_DIR
end
formatter :type => "xml"
batchtest :fork => "yes", :todir => TEST_RESULTS_DIR do
fileset :dir => TEST_SRC_DIR do
include :name => "**/*Test.java"
end
end
end
end
end
desc "run all tests"
task :test => [ 'test:java', 'test:ruby' ]
task :default => :test
desc "clean up"
task :clean do
rm_rf OUT_DIR
end