This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Rakefile
96 lines (82 loc) · 2.33 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
def mvn(*args)
ensure_cmd("mvn")
args.unshift("-o") if ENV["OFFLINE"] == "1"
system("mvn", *args)
return $?.exitstatus == 0
end
def mvn_or_die(*args)
if !mvn(*args)
yield if block_given?
exit(-1)
end
end
def cmd?(name)
%x{which #{name}}
return $?.exitstatus == 0
end
def ensure_cmd(name)
if not cmd?(name)
$stderr.puts "Unable to find command '#{name}'! Make sure it is installed and in your PATH (#{ENV['PATH']})"
exit(-1)
end
end
task :default => [:test]
desc "Runs the tests."
task :test do
mvn_or_die("clean", "test") do
for test_file in Dir["target/surefire-reports/*.txt"]
test_results = File.read(test_file)
if test_results =~ /FAILURE/m
puts test_results
end
end
end
end
namespace :test do
desc "Generates an HTML coverage report and opens it in your default browser. NO_OPEN=1 to just generate the report."
task :coverage do
mvn_or_die("clean", "cobertura:cobertura")
system("open", "target/site/cobertura/index.html") unless ENV["NO_OPEN"] == "1"
end
desc "Generates an HTML test report and opens it in your default browser. NO_OPEN=1 to just generate the report."
task :report do
mvn_or_die("clean", "surefire-report:report")
system("open", "target/site/surefire-report.html") unless ENV["NO_OPEN"] == "1"
end
end
def run_app(level, cmd)
mvn(
"-e",
"-Djava.util.logging.config.file=src/test/resources/logging-#{level}.properties",
"-Dexec.mainClass=com.wesabe.api.accounts.Runner",
"-Dexec.args=#{cmd}",
"clean", "compile", "exec:java"
)
end
def run_server(level)
run_app(level, "server --config=development.properties --port=#{ENV['PORT'] || 8080}")
end
desc "Run brcm-accounts-api in an embedded Jetty server."
task :run do
run_server(:normal)
end
namespace :run do
desc "Run brcm-accounts-api in an embedded Jetty server with logging disabled."
task :silent do
run_server(:silent)
end
desc "Run brcm-accounts-api in an embedded Jetty server with logging turned up to 11."
task :noisy do
run_server(:noisy)
end
end
namespace :db do
desc "Generate a migration SQL DDL script."
task :migration do
run_app(:silent, "schema --config=development.properties --migration")
end
desc "Generate a SQL DDL schema."
task :schema do
run_app(:silent, "schema --config=development.properties")
end
end