forked from danlucraft/redcar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
359 lines (299 loc) · 10.6 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
REDCAR_VERSION = "0.3.9dev"
require 'rubygems'
require 'fileutils'
require 'spec/rake/spectask'
require 'cucumber/rake/task'
require "rake/gempackagetask"
require "rake/rdoctask"
if RUBY_PLATFORM =~ /mswin|mingw/
begin
# not available for jruby yet
require 'win32console'
rescue LoadError
ARGV << "--nocolour"
end
end
### DOCUMENTATION
begin
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.files = [
'lib/*.rb',
'lib/*/*.rb',
'plugins/*/lib/*.rb',
'plugins/*/lib/**/*.rb'
]
t.options = ['--markup', 'markdown']
end
rescue LoadError
end
### CI
task :ci => [:specs_ci, :cucumber_ci]
def find_ci_reporter(filename)
jruby_gem_path = %x[jruby -rubygems -e "p Gem.path.first"].gsub("\n", "").gsub('"', "")
result = Dir.glob("#{jruby_gem_path}/gems/ci_reporter-*/lib/ci/reporter/rake/#{filename}.rb").reverse.first
result || raise("Could not find ci_reporter gem in #{jruby_gem_path}")
end
task :specs_ci do
rspec_loader = find_ci_reporter "rspec_loader"
files = Dir['plugins/*/spec/*/*_spec.rb'] + Dir['plugins/*/spec/*/*/*_spec.rb'] + Dir['plugins/*/spec/*/*/*/*_spec.rb']
opts = "-J-XstartOnFirstThread" if Config::CONFIG["host_os"] =~ /darwin/
opts = "#{opts} -S spec --require #{rspec_loader} --format CI::Reporter::RSpec -c #{files.join(" ")}"
sh("jruby #{opts} && echo 'done'")
end
task :cucumber_ci do
cucumber_loader = find_ci_reporter "cucumber_loader"
opts = "-J-XstartOnFirstThread" if Config::CONFIG["host_os"] =~ /darwin/
opts = "#{opts} -r #{cucumber_loader} -S bin/cucumber --format CI::Reporter::Cucumber plugins/*/features"
sh("jruby #{opts} && echo 'done'")
end
### TESTS
desc "Run all specs and features"
task :default => ["specs", "cucumber"]
task :specs do
files = Dir['plugins/*/spec/*/*_spec.rb'] + Dir['plugins/*/spec/*/*/*_spec.rb'] + Dir['plugins/*/spec/*/*/*/*_spec.rb']
case Config::CONFIG["host_os"]
when "darwin"
sh("jruby -J-XstartOnFirstThread -S spec -c #{files.join(" ")} && echo 'done'")
else
sh("jruby -S spec -c #{files.join(" ")} && echo 'done'")
end
end
desc "Run features"
task :cucumber do
case Config::CONFIG["host_os"]
when "darwin"
sh("jruby -J-XstartOnFirstThread bin/cucumber -cf progress plugins/*/features && echo 'done'")
else
sh("jruby bin/cucumber -cf progress plugins/*/features && echo 'done'")
end
end
### BUILD AND RELEASE
desc "Build"
task :build do
sh "ant jar -f vendor/java-mateview/build.xml"
cp "vendor/java-mateview/lib/java-mateview.rb", "plugins/edit_view_swt/vendor/"
cp "vendor/java-mateview/release/java-mateview.jar", "plugins/edit_view_swt/vendor/"
cd "plugins/application_swt" do
sh "ant"
end
end
def remove_gitignored_files(filelist)
ignores = File.readlines(".gitignore")
ignores = ignores.select {|ignore| ignore.chomp.strip != ""}
ignores = ignores.map {|ignore| Regexp.new(ignore.chomp.gsub(".", "\\.").gsub("*", ".*"))}
r = filelist.select {|fn| not ignores.any? {|ignore| fn =~ ignore }}
r.select {|fn| fn !~ /\.git/ }
end
spec = Gem::Specification.new do |s|
s.name = "redcar"
s.version = REDCAR_VERSION
s.summary = "A JRuby text editor."
s.author = "Daniel Lucraft"
s.email = "dan@fluentradical.com"
s.homepage = "http://redcareditor.com"
s.has_rdoc = true
s.extra_rdoc_files = %w(README.md)
s.rdoc_options = %w(--main README.md)
s.files = %w(CHANGES LICENSE Rakefile README.md ROADMAP.md) +
Dir.glob("bin/redcar") +
Dir.glob("config/**/*") +
remove_gitignored_files(Dir.glob("lib/**/*")) +
remove_gitignored_files(Dir.glob("plugins/**/*")) +
Dir.glob("textmate/Bundles/*.tmbundle/Syntaxes/**/*") +
Dir.glob("textmate/Bundles/*.tmbundle/Preferences/**/*") +
Dir.glob("textmate/Bundles/*.tmbundle/Snippets/**/*") +
Dir.glob("textmate/Bundles/*.tmbundle/info.plist") +
Dir.glob("textmate/Themes/*.tmTheme")
s.executables = FileList["bin/redcar"].map { |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency("rubyzip")
s.add_development_dependency("cucumber")
s.add_development_dependency("rspec")
s.add_development_dependency("watchr")
s.post_install_message = <<TEXT
------------------------------------------------------------------------------------
Please now run:
$ redcar install
to complete the installation.
(If you installed the gem with 'sudo', you will need to run 'sudo redcar install').
NB. This will download jars that Redcar needs to run from the internet. It will put
them only into the Redcar gem directory.
------------------------------------------------------------------------------------
TEXT
end
Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end
desc "Build a MacOS X App bundle"
task :app_bundle => :build do
require 'erb'
redcar_icon = "redcar_icon_beta.png"
bundle_contents = File.join("pkg", "Redcar.app", "Contents")
FileUtils.rm_rf bundle_contents if File.exist? bundle_contents
macos_dir = File.join(bundle_contents, "MacOS")
resources_dir = File.join(bundle_contents, "Resources")
FileUtils.mkdir_p macos_dir
FileUtils.mkdir_p resources_dir
info_plist_template = ERB.new <<-PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>redcar</string>
<key>CFBundleIconFile</key>
<string><%= redcar_icon %></string>
<key>CFBundleIdentifier</key>
<string>com.redcareditor.Redcar</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string><%= spec.version %></string>
<key>LSMinimumSystemVersion</key>
<string>10.5</string>
</dict>
</plist>
PLIST
File.open(File.join(bundle_contents, "Info.plist"), "w") do |f|
f << info_plist_template.result(binding)
end
File.open(File.join(macos_dir, "redcar"), "w") do |f|
f << '#!/bin/sh
DIR=$(cd "$(dirname "$0")"; pwd)
REDCAR=$(cd "$(dirname "${DIR}/../Resources/bin/redcar")"; pwd)
$REDCAR/redcar --ignore-stdin $@'
end
File.chmod 0777, File.join(macos_dir, "redcar")
spec.files.each do |f|
FileUtils.mkdir_p File.join(resources_dir, File.dirname(f))
FileUtils.cp_r f, File.join(resources_dir, f), :remove_destination => true
end
p "Running #{File.join(resources_dir, "bin", "redcar")} install"
system "#{File.join(resources_dir, "bin", "redcar")} install"
FileUtils.cp_r File.join(resources_dir, "plugins", "application", "icons", redcar_icon),
resources_dir, :remove_destination => true
end
desc 'Clean up (sanitize) the Textmate files for packaging'
task :clean_textmate do
# rename files to be x-platform safe
Dir["textmate/Bundles/*.tmbundle/*/**/*"].each do |fn|
if File.file?(fn)
bits = fn.split("/").last.split(".")[0..-2].join("_")
new_basename = bits.gsub(" ", "_").gsub(/[^\w_]/, "__").gsub(/\\./, "__") + File.extname(fn)
new_fn = File.join(File.dirname(fn), new_basename)
# p [fn,new_fn]
next if new_fn == fn
if File.exist?(new_fn)
puts "already exists #{new_fn}"
new_fn = File.join(File.dirname(fn), "next_" + new_basename)
unless File.exist?(new_fn)
FileUtils.mv(fn, new_fn)
end
else
begin
FileUtils.mv(fn, new_fn)
rescue => e
puts e
end
end
end
end
end
desc 'Run a watchr continuous integration daemon for the specs'
task :run_ci do
require 'watchr'
script = Watchr::Script.new
script.watch(/.*\/([^\/]+).rb$/) { |filename|
if filename[0] =~ /_spec\.rb/ # a spec file
a = "jruby -S spec #{filename} --backtrace"
puts a
system a
end
spec_filename = "#{filename[1]}_spec.rb"
spec = Dir["**/#{spec_filename}"]
if spec.length > 0
a = "jruby -S spec #{spec[0]}"
puts a
system a
end
}
contrl = Watchr::Controller.new(script, Watchr.handler.new)
contrl.run
end
desc "Release gem"
task :release => :gem do
require 'aws/s3'
credentials = YAML.load(File.read("/Users/danlucraft/.s3-creds.yaml"))
AWS::S3::Base.establish_connection!(
:access_key_id => credentials['access_key_id'],
:secret_access_key => credentials["secret_access_key"]
)
redcar_bucket = AWS::S3::Bucket.find('redcar')
file = "plugins/edit_view_swt/vendor/java-mateview.jar"
AWS::S3::S3Object.store("java-mateview-#{REDCAR_VERSION}.jar", open(file), 'redcar', :access => :public_read)
file = "plugins/application_swt/lib/dist/application_swt.jar"
AWS::S3::S3Object.store("application_swt-#{REDCAR_VERSION}.jar", open(file), 'redcar', :access => :public_read)
file = "pkg/redcar-#{REDCAR_VERSION}.gem"
AWS::S3::S3Object.store("redcar-#{REDCAR_VERSION}.gem", open(file), 'redcar', :access => :public_read)
end
namespace :redcar do
def hash_with_hash_default
Hash.new {|h,k| h[k] = hash_with_hash_default }
end
require 'json'
desc "Redcar Integration: output runnable info"
task :runnables do
mkdir_p(".redcar/runnables")
puts "Creating runnables"
File.open(".redcar/runnables/sync_stdout.rb", "w") do |fout|
fout.puts <<-RUBY
$stdout.sync = true
$stderr.sync = true
RUBY
end
tasks = Rake::Task.tasks
runnables = []
ruby_bin = Config::CONFIG["bindir"] + "/ruby -r#{File.dirname(__FILE__)}/.redcar/runnables/sync_stdout.rb "
tasks.each do |task|
name = task.name.gsub(":", "/")
command = ruby_bin + $0 + " " + task.name
runnables << {
"name" => name,
"command" => command,
"description" => task.comment,
"type" => "task/ruby/rake"
}
end
File.open(".redcar/runnables/rake.json", "w") do |f|
data = {"commands" => runnables}
f.puts(JSON.pretty_generate(data))
end
File.open(".redcar/runnables/ruby.json", "w") do |f|
data = {"file_runners" =>
[
{
"regex" => ".*.rb$",
"name" => "Run as ruby",
"command" => ruby_bin + "__PATH__",
"type" => "script/ruby"
}
]
}
f.puts(JSON.pretty_generate(data))
end
end
task :sample do
5.times do |i|
puts "out#{i}"
sleep 1
$stderr.puts "err#{i}"
sleep 1
end
FileUtils.touch("finished_process")
end
end