forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
executable file
·325 lines (268 loc) · 10.5 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
require "tempfile"
require "ftools" # fails in 1.9.2
require File.join(File.dirname(__FILE__), "VERSION") # For LOGSTASH_VERSION
# Compile config grammar (ragel -> ruby)
file "lib/logstash/config/grammar.rb" => ["lib/logstash/config/grammar.rl"] do
sh "make -C lib/logstash/config grammar.rb"
end
# Taken from 'jrubyc'
# Currently this code is commented out because jruby emits this:
# Failure during compilation of file logstash/web/helpers/require_param.rb:
# java.lang.RuntimeException: java.io.FileNotFoundException: File path
# /home/jls/projects/logstash/logstash/web/helpers/require_param.rb
# does not start with parent path /home/jls/projects/logstash/lib
#
# org/jruby/util/JavaNameMangler.java:105:in `mangleFilenameForClasspath'
# org/jruby/util/JavaNameMangler.java:32:in `mangleFilenameForClasspath'
#require 'jruby/jrubyc'
##args = [ "-p", "net.logstash" ]
#args = ["-d", "build"]
#args += Dir.glob("**/*.rb")
#status = JRuby::Compiler::compile_argv(args)
#if (status != 0)
#puts "Compilation FAILED: #{status} error(s) encountered"
#exit status
#end
task :clean do
sh "rm -rf .bundle || true"
#sh "rm -rf build-jar-thin"
#sh "rm -rf build-jar"
sh "rm -rf build"
sh "rm -rf vendor"
end
task :compile => "lib/logstash/config/grammar.rb" do |t|
target = "build/ruby"
mkdir_p target if !File.directory?(target)
#sh "rm -rf lib/net"
Dir.chdir("lib") do
rel_target = File.join("..", target)
sh "jrubyc", "-t", rel_target, "logstash/runner.rb"
files = Dir.glob("**/*.rb")
files.each do |file|
d = File.join(rel_target, File.dirname(file))
mkdir_p d if !File.directory?(d)
cp file, File.join(d, File.basename(file))
end
end
Dir.chdir("test") do
rel_target = File.join("..", target)
files = Dir.glob("**/*.rb")
files.each do |file|
d = File.join(rel_target, File.dirname(file))
mkdir_p d if !File.directory?(d)
cp file, File.join(d, File.basename(file))
end
end
end
task :jar => [ "package:monolith:jar" ] do |t|
# Nothing
end
VERSIONS = {
:jruby => "1.6.3", # Any of CPL1.0/GPL2.0/LGPL2.1 ? Confusing, but OK.
:elasticsearch => "0.17.0", # Apache 2.0 license
# TODO(sissel): We may not need joda since JRuby ships with it.
#:joda => "1.6.2", # Apache 2.0 license
}
namespace :vendor do
file "vendor/jar" do |t|
mkdir_p t.name if !File.directory?(t.name)
end
# Download jruby.jar
file "vendor/jar/jruby-complete-#{VERSIONS[:jruby]}.jar" => "vendor/jar" do |t|
baseurl = "http://repository.codehaus.org/org/jruby/jruby-complete"
if !File.exists?(t.name)
sh "wget -O #{t.name} #{baseurl}/#{VERSIONS[:jruby]}/#{File.basename(t.name)}"
end
end # jruby
task :jruby => "vendor/jar/jruby-complete-#{VERSIONS[:jruby]}.jar" do
# nothing to do, the dep does it.
end
# Download elasticsearch + deps (for outputs/elasticsearch)
task :elasticsearch => "vendor/jar" do
version = VERSIONS[:elasticsearch]
tarball = "elasticsearch-#{version}.tar.gz"
url = "http://github.com/downloads/elasticsearch/elasticsearch/#{tarball}"
if !File.exists?(tarball)
# --no-check-certificate is for github and wget not supporting wildcard
# certs sanely.
sh "wget -O #{tarball} --no-check-certificate #{url}"
end
sh "tar -zxf #{tarball} -C vendor/jar/ elasticsearch-#{version}/lib"
end # elasticsearch
task :joda => "vendor/jar" do
version = VERSIONS[:joda]
baseurl = "http://sourceforge.net/projects/joda-time/files/joda-time"
tarball = "joda-time-#{version}-bin.tar.gz"
url = "#{baseurl}/#{version}/#{tarball}/download"
if !File.exists?(tarball)
sh "wget -O #{tarball} #{url}"
end
sh "tar -zxf #{tarball} -C vendor/jar/ joda-time-#{version}/joda-time-#{version}.jar"
end # joda
task :gems => "vendor/jar" do
puts "=> Installing gems to vendor/bundle/..."
sh "bundle install --path #{File.join("vendor", "bundle")}"
end
end # vendor namespace
namespace :package do
task :gem do
sh "gem build logstash.gemspec"
end
monolith_deps = [ "vendor:jruby", "vendor:gems", "vendor:elasticsearch", "compile" ]
namespace :monolith do
task :tar => monolith_deps do
paths = %w{ bin CHANGELOG CONTRIBUTORS etc examples Gemfile Gemfile.lock
INSTALL lib LICENSE patterns Rakefile README.md STYLE.md test
TODO USAGE vendor/bundle vendor/jar }
sh "tar -zcf logstash-monolithic-someversion.tar.gz #{paths.join(" ")}"
end # package:monolith:tar
task :jar => monolith_deps do
builddir = "build/monolith-jar"
mkdir_p builddir if !File.directory?(builddir)
# Unpack all the 3rdparty jars and any jars in gems
Dir.glob("vendor/{bundle,jar}/**/*.jar").each do |jar|
if jar =~ /sigar.*\.jar$/
puts "=> Skipping #{jar} (sigar not needed)"
next
end
puts "=> Unpacking #{jar} into #{builddir}/"
relative_path = File.join(builddir.split(File::SEPARATOR).collect { |a| ".." })
Dir.chdir(builddir) do
sh "jar xf #{relative_path}/#{jar}"
end
end
# We compile stuff to build/...
# TODO(sissel): Could probably just use 'jar uf' for this?
Dir.glob("build/ruby/**/*.class").each do |file|
target = File.join(builddir, file.gsub("build/ruby/", ""))
mkdir_p File.dirname(target)
puts "=> Copying #{file} => #{target}"
File.copy(file, target)
end
# Purge any extra files we don't need in META-INF (like manifests and
# jar signatures)
["INDEX.LIST", "MANIFEST.MF", "ECLIPSEF.RSA", "ECLIPSEF.SF"].each do |file|
File.delete(File.join(builddir, "META-INF", file)) rescue nil
end
output = "logstash-#{LOGSTASH_VERSION}-monolithic.jar"
sh "jar cfe #{output} logstash.runner -C #{builddir} ."
jar_update_args = []
# Learned how to do this mostly from here:
# http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar
#
# Add bundled gems to the jar
# Skip the 'cache' dir which is just the original .gem files
gem_dirs = %w{bin doc gems specifications}
gem_root = File.join(%w{vendor bundle jruby 1.8})
# for each dir, build args: -C vendor/bundle/jruby/1.8 bin, etc
gem_jar_args = gem_dirs.collect { |d| ["-C", gem_root, d ] }.flatten
jar_update_args += gem_jar_args
# Add compiled our compiled ruby code
jar_update_args += %w{ -C build/ruby . }
# Add web stuff
jar_update_args += %w{ -C lib logstash/web/public }
jar_update_args += %w{ -C lib logstash/web/views }
# Add test code
#jar_update_args += %w{ -C test logstsah }
# Add grok patterns
jar_update_args << "patterns"
# Update with other files and also build an index.
sh "jar uf #{output} #{jar_update_args.join(" ")}"
sh "jar i #{output}"
end # task package:monolith:jar
end # namespace monolith
task :jar => [ "vendor:jruby", "vendor:gems", "compile" ] do
builddir = "build/thin-jar"
mkdir_p builddir if !File.directory?(builddir)
# Unpack jruby
relative_path = File.join(builddir.split(File::SEPARATOR).collect { |a| ".." })
Dir.glob("vendor/jar/jruby-complete-1.6.3.jar").each do |jar|
puts "=> Unpacking #{jar} into #{builddir}/"
Dir.chdir(builddir) do
sh "jar xf #{relative_path}/#{jar}"
end
end
["INDEX.LIST", "MANIFEST.MF", "ECLIPSEF.RSA", "ECLIPSEF.SF"].each do |file|
File.delete(File.join(builddir, "META-INF", file)) rescue nil
end
output = "logstash-#{LOGSTASH_VERSION}.jar"
sh "jar cfe #{output} logstash.runner -C #{builddir} ."
jar_update_args = []
# Learned how to do this mostly from here:
# http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar
#
# Add bundled gems to the jar
# Skip the 'cache' dir which is just the original .gem files
gem_dirs = %w{bin doc gems specifications}
gem_root = File.join(%w{vendor bundle jruby 1.8})
# for each dir, build args: -C vendor/bundle/jruby/1.8 bin, etc
gem_jar_args = gem_dirs.collect { |dir| ["-C", gem_root, dir ] }.flatten
jar_update_args += gem_jar_args
# Add compiled our compiled ruby code
jar_update_args += %w{ -C build . }
# Add web stuff
jar_update_args += %w{ -C lib logstash/web/public }
jar_update_args += %w{ -C lib logstash/web/views }
# Add test code
#jar_update_args += %w{ -C test logstsah }
# Add grok patterns
jar_update_args << "patterns"
# Update with other files and also build an index.
sh "jar uf #{output} #{jar_update_args.join(" ")}"
sh "jar i #{output}"
end # task package:jar
end # namespace package
task :test do
sh "cd test; ruby logstash_test_runner.rb"
end
task :docs => [:docgen, :doccopy, :docindex ] do
end
task :require_output_env do
if ENV["output"].nil?
raise "No output variable set. Run like: 'rake docs output=path/to/output'"
end
end
task :doccopy => [:require_output_env] do
if ENV["output"].nil?
raise "No output variable set. Run like: 'rake docs output=path/to/output'"
end
output = ENV["output"].gsub("VERSION", LOGSTASH_VERSION)
Dir.glob("docs/**/*").each do |doc|
dir = File.join(output, File.dirname(doc).gsub(/docs\/?/, ""))
mkdir_p dir if !File.directory?(dir)
if File.directory?(doc)
mkdir_p doc
else
puts "Copy #{doc} => #{dir}"
cp(doc, dir)
end
end
end
task :docindex => [:require_output_env] do
output = ENV["output"].gsub("VERSION", LOGSTASH_VERSION)
sh "ruby docs/generate_index.rb #{output} > #{output}/index.html"
end
task :docgen => [:require_output_env] do
if ENV["output"].nil?
raise "No output variable set. Run like: 'rake docgen output=path/to/output'"
end
output = ENV["output"].gsub("VERSION", LOGSTASH_VERSION)
sh "find lib/logstash/inputs lib/logstash/filters lib/logstash/outputs -type f -not -name 'base.rb' -a -name '*.rb'| xargs ruby docs/docgen.rb -o #{output}"
end
task :publish do
latest_gem = %x{ls -t logstash-[0-9]*.gem}.split("\n").first
sh "gem push #{latest_gem}"
end
task :release do
docs_dir = File.join(File.dirname(__FILE__), "..", "logstash.github.com",
"docs", LOGSTASH_VERSION)
ENV["output"] = docs_dir
sh "sed -i -Re 's/1.0.[0-9]/#{LOGSTASH_VERSION}/'"
sh "git tag v#{LOGSTASH_VERSION}"
#Rake::Task["docs"].invoke
Rake::Task["package:gem"].invoke
Rake::Task["package:monolith:jar"].invoke
puts "Packaging complete."
puts "Run the following under ruby 1.8.7 (require bluecloth)"
puts "> rake docs output=#{docs_dir}"
end