This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Rakefile
140 lines (116 loc) · 3.77 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
require 'rubygems'
require 'bundler'
Bundler.setup
$:.unshift(File.dirname(__FILE__) + '/lib')
require 'cuke4duke/version'
# Make sure subprocesses use our local code.
ENV['MAVEN_OPTS'] = (ENV['MAVEN_OPTS'] || '') + " -Dcuke4duke.bin=#{File.expand_path("../bin/cuke4duke", __FILE__)}"
ENV['RUBYLIB'] = File.expand_path("../lib", __FILE__)
class ReleaseHelper < Bundler::GemHelper
def install
desc "Create tag #{version_tag} and upload #{name}-#{version}.jar and #{name}-#{version}.gem"
task 'release' do
release_jar_and_gem
end
desc 'Build gem'
task 'gem' do
build_gem
end
desc 'Install gem'
task 'install' do
install_gem
end
task 'maven_release' do
maven_release
end
desc 'Remove Maven SNAPSHOT version'
task 'remove_snapshots' do
remove_snapshots
end
desc 'Add Maven SNAPSHOT version'
task 'add_snapshots' do
add_snapshots
end
end
def release_jar_and_gem
guard_clean
guard_already_tagged
built_gem_path = build_gem
tag_version {
maven_release
rubygem_push(built_gem_path)
git_push
}
end
def remove_snapshots
system(%{find . -name 'pom.xml' -exec sed -i '' 's/-SNAPSHOT//' '{}' \\;})
end
def add_snapshots
if Cuke4Duke::VERSION =~ /(\d+\.\d+\.)(\d+)$/
major_minor = $1
new_patch = $2.to_i + 1
default_snapshot = "#{major_minor}#{new_patch}-SNAPSHOT"
asked_snapshot = Bundler.ui.instance_variable_get('@shell').ask("What is the new SNAPSHOT version? (#{default_snapshot})", :green)
snapshot = asked_snapshot.strip == "" ? default_snapshot : snapshot
system(%{find . -name 'pom.xml' -exec sed -i '' 's/#{Cuke4Duke::VERSION}/#{snapshot}/' '{}' \\;})
else
raise "You're already at a -SNAPSHOT version: #{Cuke4Duke::VERSION}"
end
end
def maven_release
# We have to run this in 2 separate mvn invocations to avoid:
#
# Unable to configure Wagon: 'scp'
# Embedded error: While configuring wagon for 'cukes': Unable to apply wagon configuration.
# Cannot find setter nor field in org.apache.maven.wagon.providers.ssh.jsch.ScpWagon for 'httpHeaders'
Dir.chdir('cuke4duke') do
sh %{MAVEN_OPTS="-Xmx512m" mvn site:site}
sh %{mvn site:deploy}
end
sh %{mvn deploy}
end
end
ReleaseHelper.install_tasks
task :default => :build_all
task :build_all => :i18n_generate do
Dir['lib/*.jar'].each{|jar| FileUtils.rm(jar)}
sh('mvn -P examples clean install')
end
desc 'Generate i18n Step Definitions'
task :i18n_generate do
require 'gherkin/i18n'
require 'erb'
java = ERB.new(IO.read(File.dirname(__FILE__) + '/cuke4duke/src/main/code_generator/I18n.java.erb'), nil, '-')
File.open(File.dirname(__FILE__) + '/cuke4duke/src/main/java/cuke4duke/annotation/I18n.java', 'wb') do |io|
io.write(<<-HEADER)
package cuke4duke.annotation;
import cuke4duke.internal.java.annotation.StepDef;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public interface I18n {
HEADER
Gherkin::I18n.all.each do |i18n|
io.write(java.result(binding))
end
io.write("}")
end
scala = ERB.new(IO.read(File.dirname(__FILE__) + '/cuke4duke/src/main/code_generator/I18n.scala.erb'), nil, '-')
File.open(File.dirname(__FILE__) + '/cuke4duke/src/main/scala/cuke4duke/I18n.scala', 'wb') do |io|
io.write("package cuke4duke\n\n")
Gherkin::I18n.all.each do |i18n|
io.write(scala.result(binding))
end
end
end
desc 'Make all files use UNIX (\n) line endings'
task :fix_cr_lf do
files = FileList['**/*']
files.each do |f|
next if File.directory?(f)
s = IO.read(f)
s.gsub!(/\r?\n/, "\n")
File.open(f, "w") { |io| io.write(s) }
end
end