forked from tabulapdf/tabula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
237 lines (188 loc) · 7.14 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
require 'fileutils'
require 'warbler'
########## java jar compilation ##########
Warbler::Task.new("war",
Warbler::Config.new { |config|
config.features = %w(executable)
config.jar_name = 'build/tabula'
config.jar_extension = 'jar'
config.webserver = "jetty"
config.webxml.jruby.compat.version = "1.9"
config.webxml.jruby.rack.logging = "stderr"
config.dirs = ['lib', 'webapp']
config.override_gem_home = false
}
)
# version we're building
def build_version
ENV['TABULA_VERSION'] || "rev#{`git rev-list --max-count=1 HEAD`.strip}"
end
def invoke_ant(*args)
IO.popen("ant #{args.join(' ')}") { |f|
yield f
}
end
########## distribution bundles ##########
task :create_version_file do |t|
puts "Creating version file (#{build_version})..."
tabula_dir = File.expand_path(File.dirname(__FILE__))
rb_file = <<-eos
$TABULA_VERSION = "#{build_version}"
eos
File.open(File.join(tabula_dir, 'webapp', 'tabula_version.rb'), 'wb') do |f|
f.write rb_file
end
end
task :delete_version_file do |t|
tabula_dir = File.expand_path(File.dirname(__FILE__))
FileUtils.rm(File.join(tabula_dir, 'webapp', 'tabula_version.rb'))
end
task :jardist => [:create_version_file, :war] do |t|
tabula_dir = File.expand_path(File.dirname(__FILE__))
build_dir = File.join(tabula_dir, "build")
dist_dir = File.join(build_dir, "jardist", "tabula")
if File.exist?(File.join(build_dir, "jardist"))
FileUtils.rm_rf(File.join(build_dir, "jardist"))
end
puts "\n======================================================"
puts "Building jar zip file bundle..."
puts "======================================================\n\n"
Dir.mkdir(File.join(build_dir, "jardist"))
Dir.mkdir(File.join(build_dir, "jardist", "tabula"))
jar_src = File.join(build_dir, "tabula.jar")
jar_dst = File.join(dist_dir, "tabula.jar")
FileUtils.cp(jar_src, jar_dst)
readme_src = File.join(build_dir, "dist-README.txt")
readme_dst = File.join(dist_dir, "README.txt")
FileUtils.cp(readme_src, readme_dst)
lic_src = File.join(build_dir, "dist-LICENSE.txt")
lic_dst = File.join(dist_dir, "LICENSE.txt")
FileUtils.cp(lic_src, lic_dst)
authors_src = File.join(tabula_dir, "AUTHORS.md")
authors_dst = File.join(dist_dir, "AUTHORS.txt")
FileUtils.cp(authors_src, authors_dst)
cd File.join(build_dir, "jardist")
output = File.join(build_dir, "tabula-jar-#{build_version}.zip")
if File.exists?(output)
File.delete(output)
end
IO.popen("7z -r9 #{output} tabula") { |f|
f.each { |line| puts line }
}
FileUtils.rm_rf(dist_dir)
puts "\n======================================================"
puts "Zip file saved to #{output}"
puts "======================================================\n\n"
end
task :macosx => [:create_version_file, :war] do |t|
tabula_dir = File.expand_path(File.dirname(__FILE__))
build_dir = File.join(tabula_dir, "build")
dist_dir = File.join(build_dir, "mac", "tabula")
cd File.join(tabula_dir)
if File.exist?(File.join(build_dir, "mac"))
FileUtils.rm_rf(File.join(build_dir, "mac"))
end
puts "\n======================================================"
puts "Building Mac OS X app..."
puts "======================================================\n\n"
invoke_ant("-Dfull_version=#{build_version}", "-v", "macbundle") { |f|
f.each { |line| puts line }
}
puts "\n======================================================"
puts "Creating zip file bundle..."
puts "======================================================\n\n"
Dir.mkdir(dist_dir)
app_src = File.join(build_dir, "mac", "Tabula.app")
app_dst = File.join(dist_dir, "Tabula.app")
FileUtils.mv(app_src, app_dst)
readme_src = File.join(build_dir, "dist-README.txt")
readme_dst = File.join(dist_dir, "README.txt")
FileUtils.cp(readme_src, readme_dst)
lic_src = File.join(build_dir, "dist-LICENSE.txt")
lic_dst = File.join(dist_dir, "LICENSE.txt")
FileUtils.cp(lic_src, lic_dst)
authors_src = File.join(tabula_dir, "AUTHORS.md")
authors_dst = File.join(dist_dir, "AUTHORS.txt")
FileUtils.cp(authors_src, authors_dst)
cd File.join(build_dir, "mac")
output = File.join(build_dir, "tabula-mac-#{build_version}.zip")
if File.exists?(output)
File.delete(output)
end
IO.popen("7z -r9 #{output} tabula") { |f|
f.each { |line| puts line }
}
FileUtils.rm_rf(dist_dir)
puts "\n======================================================"
puts "Zip file saved to #{output}"
puts "======================================================\n\n"
end
task :windows => [:create_version_file, :war] do |t|
tabula_dir = File.expand_path(File.dirname(__FILE__))
build_dir = File.join(tabula_dir, "build")
dist_dir = File.join(build_dir, "windows", "tabula")
if File.exist?(File.join(build_dir, "windows"))
FileUtils.rm_rf(File.join(build_dir, "windows"))
end
cd File.join(tabula_dir)
puts "\n======================================================"
puts "Building Windows executable..."
puts "======================================================\n\n"
# exe files REALLY need x.x.x.x otherwise the compile fails.
if build_version.start_with?('rev')
win_build_version = '0.0.0.0'
else
win_build_version = build_version
while win_build_version.split('.').length < 4
win_build_version = "#{win_build_version}.0"
end
end
cd File.join(File.expand_path(File.dirname(__FILE__)), "launch4j")
invoke_ant("-Dfull_version=#{win_build_version}", "-f", "../build.xml", "windows") { |f|
f.each { |line| puts line }
}
puts "\n======================================================"
puts "Creating zip file bundle..."
puts "======================================================\n\n"
Dir.mkdir(dist_dir)
app_src = File.join(build_dir, "windows", "tabula.exe")
app_dst = File.join(dist_dir, "tabula.exe")
FileUtils.mv(app_src, app_dst)
jar_src = File.join(build_dir, "tabula.jar")
jar_dst = File.join(dist_dir, "tabula.jar")
FileUtils.cp(jar_src, jar_dst)
readme_src = File.join(build_dir, "dist-README.txt")
readme_dst = File.join(dist_dir, "README.txt")
FileUtils.cp(readme_src, readme_dst)
lic_src = File.join(build_dir, "dist-LICENSE.txt")
lic_dst = File.join(dist_dir, "LICENSE.txt")
FileUtils.cp(lic_src, lic_dst)
authors_src = File.join(tabula_dir, "AUTHORS.md")
authors_dst = File.join(dist_dir, "AUTHORS.txt")
FileUtils.cp(authors_src, authors_dst)
cd File.join(build_dir, "windows")
output = File.join(build_dir, "tabula-win-#{build_version}.zip")
if File.exists?(output)
File.delete(output)
end
IO.popen("7z -r9 #{output} tabula") { |f|
f.each { |line| puts line }
}
FileUtils.rm_rf(dist_dir)
puts "\n======================================================"
puts "Zip file saved to #{output}"
puts "======================================================\n\n"
end
task :build_all_platforms => [:create_version_file, :war] do |t|
['jardist', 'macosx', 'windows'].each do |platform|
Rake::Task[platform].execute
puts
end
end
# delete version file after build
['jardist', 'macosx', 'windows'].each do |t|
puts "Deleting version file."
Rake::Task[t.intern].enhance {
Rake::Task['delete_version_file'.intern].invoke
}
end