-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
184 lines (152 loc) · 5.04 KB
/
Rakefile
File metadata and controls
184 lines (152 loc) · 5.04 KB
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
require 'net/http'
require 'rubygems'
require 'rubygems/gem_runner' # install and uninstall
require 'rubygems/package_task'
require 'rake'
require 'rake/clean' # for clean/clobber
require 'rake/testtask'
require 'rake/packagetask'
require File.dirname(__FILE__) + '/dev/example_task'
# Test, package and publish functions.
# Author:: Peter Kofler
# See:: http://rake.rubyforge.org/files/doc/rakefile_rdoc.html
# Acknowledgement:: Building this Rake file was supported as System One Research Day. Thank you System One for funding Open Source :-)
RDOC_DIR = 'html'
RDOC_REPO = 'hosting/4_bitbucket.org/api'
gemspec = eval(IO.readlines('javaclass.gemspec').join)
full_gem_name = "#{gemspec.name}-#{gemspec.version}"
desc 'Validates the gemspec'
task :validate_gem do
gemspec.validate
end
desc 'Displays the current version'
task :version do
puts gemspec.version
end
# :test
Rake::TestTask.new do |t|
t.test_files = gemspec.test_files
t.warning = true
# t.verbose = false is default
end
begin
require 'rcov/rcovtask'
# :rcov
Rcov::RcovTask.new do |t|
t.test_files = gemspec.test_files
t.warning = true
t.rcov_opts << "--sort=coverage"
t.rcov_opts << "--only-uncovered"
end
rescue LoadError
# skip if not installed
# warn("rcov not installed. coverage not available. #{$!}")
end
desc 'Find missing test methods with ZenTest'
task :zentest do
files = gemspec.files.find_all { |f| f =~ /^#{gemspec.require_path}.*\.rb$/ } + gemspec.test_files
output = `ruby -I#{gemspec.require_path} -e "require 'rubygems'; load(Gem.bin_path('ZenTest', 'zentest'))" #{files.join(' ')}`
puts output.gsub(/^#.*\n/, '') # skip all ZenTest comments
end
# :gem
Gem::PackageTask.new(gemspec) do |pkg|
pkg.need_zip = true
end
# :package, :clobber_package, :repackage
Rake::PackageTask.new(gemspec.name, gemspec.version) do |pkg|
#pkg.need_tar = true - no compress in tar on unxutils in Windows
#pkg.need_tar_gz = true - no compress in tar on unxutils in Windows
pkg.need_zip = true
pkg.package_files.include gemspec.files
end
desc 'Install the gem locally'
task :install_gem => :package do
Gem::GemRunner.new.run ['install', "pkg/#{full_gem_name}"]
end
desc 'Uninstall the gem'
task :uninstall_gem do
Gem::GemRunner.new.run ['uninstall', gemspec.name]
end
# Helper method to execute Git with the _params_ array.
# The +git+ executable must be in the path.
def git(params)
puts `git #{params.join(' ')}`
end
desc 'Tag current version in Git'
task :tag do
git ['tag', "#{full_gem_name}"]
# git ['push']
puts 'Tag created. Don\'t forget to push'
end
# internal - desc 'Release the gem to Rubygems'
task :release_rubygems => :package do
puts "Releasing #{full_gem_name} to Rubygems"
Gem::GemRunner.new.run ['push', "pkg/#{full_gem_name}.gem"]
end
desc 'Package and upload gem to Rubygems'
task :publish_gem => [:clobber_package, :example, :package, :release_rubygems]
# :example, :clobber_example, :reexample
example_task_lib = Rake::ExampleTask.new do |example|
example.example_files.include 'examples/**/*.rb'
end
task :clobber_rdoc => [:clobber_example]
task :rdoc => [:example]
task :package => [:example]
begin
require 'rdoc/task'
SomeRDocTask = RDoc::Task
rescue LoadError
require 'rake/rdoctask'
SomeRDocTask = Rake::RDocTask
end
# :rdoc, :clobber_rdoc, :rerdoc
SomeRDocTask.new do |rdoc|
rdoc.rdoc_dir = RDOC_DIR # 'html' is default anyway
rdoc.title = "#{full_gem_name} Documentation"
rdoc.main = 'Readme.txt'
# examples are generated later and not necessarily available at definition time
examples = example_task_lib.conversion_pairs.map { |a| a[1] }
rdoc.rdoc_files.include(*examples)
rdoc.rdoc_files.include('lib/**/*.rb', *gemspec.extra_rdoc_files)
end
# Helper method to add target="_parent" to all external links in _file_ html.
def add_href_parent(file)
lines = IO.readlines(file).collect do |line|
if line =~ /(href=(?:'|")https?:\/\/)/
"#{$`}target=\"_parent\" #{$1}#{$'}"
else
line
end
end
File.open(file, 'w') { |f| f.print lines.join }
end
desc 'Fix the RDoc hrefs in framesets'
task :fix_rdoc => [:rdoc] do
Dir["#{RDOC_DIR}/**/*.html"].each { |file| add_href_parent(file) }
end
# Helper method to add the gem version _dir_ into index _file_ to frameset links.
def add_frameset_version(file, dir)
lines = IO.readlines(file).collect do |line|
if line =~ /(frame src=")/
"#{$`}#{$1}#{dir}/#{$'}"
else
line
end
end
File.open(file, 'w') { |f| f.print lines.join }
end
desc 'Publish the RDoc files to repository'
task :publish_rdoc => [:clobber_rdoc, :fix_rdoc] do
puts "Releasing #{full_gem_name} API"
version_dir = "#{gemspec.version}"
FileUtils.rm_r "#{RDOC_REPO}/#{version_dir}" rescue nil
FileUtils.cp_r RDOC_DIR, "#{RDOC_REPO}/#{version_dir}"
# modify index, update redirect in frameset
file = "#{RDOC_REPO}/index.html"
FileUtils.cp "#{RDOC_REPO}/#{version_dir}/index.html", file
add_frameset_version(file, version_dir)
puts 'API created. Don\'t forget to upload'
end
# :clean :clobber
CLOBBER.include('ClassLists', 'fullClassList*.txt')
task :default => :test