Class: Echoe
- Inherits:
-
Object
- Object
- Echoe
- Defined in:
- lib/echoe.rb
Overview
Echoe includes some optional accessors for more advanced gem configuration.
For example, a simple Rakefile
might look like this:
require 'echoe'
Echoe.new("uncapitalizer") do |p|
p. = "Evan Weaver"
p.summary = "A library that uncapitalizes strings. It's awesome."
p.url = "http://www.uncapitalizer.com"
p.docs_host = "uncapitalizer.com:~/www/files/doc/"
p.dependencies = ["string_tools >=1.4.0"]
end
See below for the full list.
Signing gems
Echoe supports signing gems. First, create yourself a public and private key:
gem cert --build [email protected]
Move them somewhere secret, and add the following environment variables in your .bash_profile
or similar:
export GEM_PRIVATE_KEY='/secret/path/to/gem-private_key.pem'
export GEM_CERTIFICATE_CHAIN='/secret/path/to/gem-public_cert.pem'
Make sure your environment is up-to-date:
source ~/.bash_profile
Upload your public_cert.pem
file to your website or Rubyforge project, and tell your users to add that certificate to their system via:
gem cert --add /path/to/public_cert.pem
Finally, package and release your project as normal. Now users can install your gem via:
sudo gem install gemname -P HighSecurity
Note that you can also set the key and certificate locations in the Rakefile itself. Finally, you can add p.require_signed = true
to your Rakefile
so that you don’t accidentally release an unsigned gem if your key is missing.
Metadependencies
Echoe does not force packages to depend on Echoe itself. Instead, it generates a gemspec
from your Rakefile
and includes that, along with a comment containing the original Rakefile
source. Downstream repackagers can use the gemspec
as-is to build new versions of your gem. This way no dependencies are added, but no contents are lost.
If you do want metadependencies, add 'echoe'
to the p.dependencies
array, and set p.include_rakefile = true
and p.include_gemspec = false
.
Accessor options
Descriptive options:
-
author
- Your name. -
email
- Your email address. -
description
- A more detailed description of the library. -
summary
- A shorter description of the library. -
url
- A url for the library. -
install_message
- A message to display after the gem is installed.
Versioning options:
-
version
- A string for the version number. Parsed from CHANGELOG otherwise. -
changes
- A string describing the most recent changes. Parsed from CHANGELOG otherwise.
Common packaging options:
-
dependencies
- An array of dependencies for this gem. For example,['mongrel', 'rake >=0.7.1']
. -
extension_pattern
- A filename array, glob array, or regex for extension files that need to be run at install time. Defaults to"ext/**/extconf.rb"
. -
clean_pattern
- A filename array, glob array, or regex for files that should be removed whenrake clean
is run. -
test_pattern
- A filename array, glob array, or regex for test runners. Overridden by"test/test_all.rb"
, if it exists.
Uncommon packaging options:
-
platform
- What platform this gem is for. -
manifest_name
- The name of the manifest file. Defaults toManifest
. -
need_gem
- Whether to generate a gem package. Defaults totrue
. -
need_tar_gz
- Whether to generate a.tar.gz
package. Defaults totrue
. -
need_tgz
- Whether to generate a.tgz
package. Defaults tofalse
. -
need_zip
- Whether to generate a.zip
package. Defaults tofalse
. -
include_rakefile
- Include the Rakefile directly within the package. Defaults tofalse
. -
include_gemspec
- Include the generated gemspec file within the package. Defaults totrue
. -
ruby_version
- Version string for which Ruby to require (for example,'>= 1.8.4'
. -
eval
- Accepts a proc to be evaluated in the context of the Gem::Specification object. This allows you to set more unusual gemspec options. -
ignore_pattern
- A filename array, glob array, or regex for pathnames that should be ignored when building the manifest. -
executable_pattern
- A filename array, glob array, or regex for files that should be installed as wrapped executables.
Security options:
-
private_key
- The path to your gem private key. Defaults to ENV, if available. This accessor is not published in the resulting gemspec. -
certificate_chain
- An array representing your certificate authorization chain. If no one else has signed your certificate, just set it to your own cert. Defaults to ENV, if available. This accessor is not published in the resulting gemspec. -
require_signed
- Force Echoe to refuse to package your gem if it’s not properly signed. Default false.
Publishing options:
-
project
- The name of the Rubyforge project to upload to. Defaults to the name of the gem. -
docs_host
- A host and filesystem path to publish the documentation to. Defaults to the Rubyforge project.
Documentation options:
-
rdoc_pattern
- A filename array, glob array, or regex for filenames that should be passed to RDoc. -
rdoc_template
- A path to an RDoc template. Defaults to the generic template.
Constant Summary collapse
- PREFIX =
ENV['PREFIX'] || rubyprefix
- RUBYLIB =
if PREFIX == rubyprefix then sitelibdir else File.join(PREFIX, sitelibdir[rubyprefix.size..-1]) end
- RUBY_DEBUG =
ENV['RUBY_DEBUG']
- RUBY_FLAGS =
ENV['RUBY_FLAGS'] || "-w -I#{%w(lib ext bin test).join(File::PATH_SEPARATOR)}" + (RUBY_DEBUG ? " #{RUBY_DEBUG}" : '')
- FILTER =
for tests (eg FILTER=“-n test_blah”)
ENV['FILTER']
Instance Attribute Summary collapse
-
#author ⇒ Object
user-configurable.
-
#bin_files ⇒ Object
best left alone.
-
#certificate_chain ⇒ Object
user-configurable.
-
#changelog ⇒ Object
user-configurable.
-
#changelog_patterns ⇒ Object
best left alone.
-
#changes ⇒ Object
user-configurable.
-
#clean_pattern ⇒ Object
user-configurable.
-
#dependencies ⇒ Object
user-configurable.
-
#description ⇒ Object
user-configurable.
-
#docs_host ⇒ Object
user-configurable.
-
#email ⇒ Object
user-configurable.
-
#eval ⇒ Object
best left alone.
-
#executable_pattern ⇒ Object
user-configurable.
-
#extension_pattern ⇒ Object
user-configurable.
-
#extensions ⇒ Object
legacy.
-
#extra_deps ⇒ Object
legacy.
-
#files ⇒ Object
best left alone.
-
#gemspec_name ⇒ Object
best left alone.
-
#has_rdoc ⇒ Object
best left alone.
-
#ignore_pattern ⇒ Object
user-configurable.
-
#include_gemspec ⇒ Object
best left alone.
-
#include_rakefile ⇒ Object
best left alone.
-
#install_message ⇒ Object
user-configurable.
-
#lib_files ⇒ Object
best left alone.
-
#manifest_name ⇒ Object
user-configurable.
-
#name ⇒ Object
best left alone.
-
#need_gem ⇒ Object
user-configurable.
-
#need_tar_gz ⇒ Object
user-configurable.
-
#need_tgz ⇒ Object
user-configurable.
-
#need_zip ⇒ Object
user-configurable.
-
#platform ⇒ Object
user-configurable.
-
#private_key ⇒ Object
user-configurable.
-
#project ⇒ Object
user-configurable.
-
#rdoc_files ⇒ Object
legacy.
-
#rdoc_options ⇒ Object
best left alone.
-
#rdoc_pattern ⇒ Object
user-configurable.
-
#rdoc_template ⇒ Object
user-configurable.
-
#require_signed ⇒ Object
user-configurable.
-
#ruby_version ⇒ Object
user-configurable.
-
#rubyforge_name ⇒ Object
best left alone.
-
#spec ⇒ Object
best left alone.
-
#summary ⇒ Object
user-configurable.
-
#test_files ⇒ Object
best left alone.
-
#test_pattern ⇒ Object
user-configurable.
-
#url ⇒ Object
user-configurable.
-
#version ⇒ Object
user-configurable.
Instance Method Summary collapse
- #apply_pattern(pattern, files = nil) ⇒ Object
- #define_tasks ⇒ Object
-
#initialize(name, _version = nil) {|_self| ... } ⇒ Echoe
constructor
A new instance of Echoe.
Constructor Details
#initialize(name, _version = nil) {|_self| ... } ⇒ Echoe
Returns a new instance of Echoe.
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 |
# File 'lib/echoe.rb', line 140 def initialize(name, _version = nil) # Defaults self.name = name self.project = name.downcase self.changelog = "CHANGELOG" self.url = "" self. = "" self.email = "" self.clean_pattern = ["pkg", "doc", 'build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log', "ext/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/Makefile", "ext/**/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/**/Makefile", "pkg", "lib/*.bundle", "*.gem", ".config"] self.test_pattern = ['test/**/test_*.rb'] self.changelog_patterns = { :version => [ /^\s*v([\d\.]+)(\.|\s|$)/, /\s*\*\s*([\d\.]+)\s*\*\s*$/ ], :changes => [ /^\s*v([\d\.]+\. .*)/, /\*\s*[\d\.]+\s*\*\s*(.*)\*\s*[\d\.]+\s*\*$/m ] } self.description = "" self.summary = "" self. = nil self.has_rdoc = true self.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/ self.executable_pattern = /^bin\// self. = ['--line-numbers', '--inline-source'] self.dependencies = [] self.manifest_name = "Manifest" self.extension_pattern = ["ext/**/extconf.rb", "ext/extconf.rb"] self.private_key = ENV['GEM_PRIVATE_KEY'] self.require_signed = false self.certificate_chain = ENV['GEM_CERTIFICATE_CHAIN'].to_s.split(/\,\s*/).compact self.need_gem = true self.need_tar_gz = true self.need_tgz = false self.need_zip = false self.include_rakefile = false self.include_gemspec = true self.gemspec_name = "#{name}.gemspec" yield self if block_given? # legacy compatibility self.dependencies = extra_deps if extra_deps and dependencies.empty? self.project = rubyforge_name if rubyforge_name self.rdoc_pattern = rdoc_files if rdoc_files self.extension_pattern = extensions if extensions # read manifest begin self.files = File.read(manifest_name).split + [(gemspec_name if include_gemspec)] + [("Rakefile" if include_rakefile)] self.files = files.compact.uniq rescue Errno::ENOENT unless ARGV.include? "manifest" puts "Missing manifest. You can build one with 'rake manifest'." exit end end # snag version and changeset self.version ||= _version unless version if File.exist? changelog parsed = Array(changelog_patterns[:version]).map do |pattern| open(changelog).read[pattern, 1] end.compact.first raise "Could not parse version from #{changelog}" unless parsed self.version = parsed.chomp(".").strip else raise "No #{changelog} found, and no version supplied in Rakefile." end end self.changes = if File.exist? changelog Array(changelog_patterns[:changes]).map do |pattern| open(changelog).read[pattern, 1] end.compact.first or "" else "" end # set some post-defaults self.certificate_chain = Array(certificate_chain).map {|file| File.(file)} self.private_key = File.(private_key) if private_key self.description = summary if description.empty? self.summary = description if summary.empty? self.clean_pattern = apply_pattern(clean_pattern) self.extension_pattern = apply_pattern(extension_pattern, files) self.ignore_pattern = apply_pattern(ignore_pattern) self.rdoc_pattern = apply_pattern(rdoc_pattern, files) self.executable_pattern = apply_pattern(executable_pattern, files) define_tasks end |
Instance Attribute Details
#author ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def @author end |
#bin_files ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def bin_files @bin_files end |
#certificate_chain ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def certificate_chain @certificate_chain end |
#changelog ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def changelog @changelog end |
#changelog_patterns ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def changelog_patterns @changelog_patterns end |
#changes ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def changes @changes end |
#clean_pattern ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def clean_pattern @clean_pattern end |
#dependencies ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def dependencies @dependencies end |
#description ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def description @description end |
#docs_host ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def docs_host @docs_host end |
#email ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def email @email end |
#eval ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def eval @eval end |
#executable_pattern ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def executable_pattern @executable_pattern end |
#extension_pattern ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def extension_pattern @extension_pattern end |
#extensions ⇒ Object
legacy
138 139 140 |
# File 'lib/echoe.rb', line 138 def extensions @extensions end |
#extra_deps ⇒ Object
legacy
138 139 140 |
# File 'lib/echoe.rb', line 138 def extra_deps @extra_deps end |
#files ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def files @files end |
#gemspec_name ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def gemspec_name @gemspec_name end |
#has_rdoc ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def has_rdoc @has_rdoc end |
#ignore_pattern ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def ignore_pattern @ignore_pattern end |
#include_gemspec ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def include_gemspec @include_gemspec end |
#include_rakefile ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def include_rakefile @include_rakefile end |
#install_message ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def @install_message end |
#lib_files ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def lib_files @lib_files end |
#manifest_name ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def manifest_name @manifest_name end |
#name ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def name @name end |
#need_gem ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def need_gem @need_gem end |
#need_tar_gz ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def need_tar_gz @need_tar_gz end |
#need_tgz ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def need_tgz @need_tgz end |
#need_zip ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def need_zip @need_zip end |
#platform ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def platform @platform end |
#private_key ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def private_key @private_key end |
#project ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def project @project end |
#rdoc_files ⇒ Object
legacy
138 139 140 |
# File 'lib/echoe.rb', line 138 def rdoc_files @rdoc_files end |
#rdoc_options ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def @rdoc_options end |
#rdoc_pattern ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def rdoc_pattern @rdoc_pattern end |
#rdoc_template ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def rdoc_template @rdoc_template end |
#require_signed ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def require_signed @require_signed end |
#ruby_version ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def ruby_version @ruby_version end |
#rubyforge_name ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def rubyforge_name @rubyforge_name end |
#spec ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def spec @spec end |
#summary ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def summary @summary end |
#test_files ⇒ Object
best left alone
135 136 137 |
# File 'lib/echoe.rb', line 135 def test_files @test_files end |
#test_pattern ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def test_pattern @test_pattern end |
#url ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def url @url end |
#version ⇒ Object
user-configurable
132 133 134 |
# File 'lib/echoe.rb', line 132 def version @version end |
Instance Method Details
#apply_pattern(pattern, files = nil) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/echoe.rb', line 244 def apply_pattern(pattern, files = nil) files ||= Dir['**/**'] case pattern when String, Array files & (Array(pattern).map do |p| Dir.glob(p) end.flatten) when Regexp files.select do |file| file =~ pattern end else [] end end |
#define_tasks ⇒ Object
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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/echoe.rb', line 260 def define_tasks ### Packaging and Installing self.spec = Gem::Specification.new do |s| s.name = name s.version = version s.summary = summary s. = Array().join(", ") s.email = email s.homepage = url s.rubyforge_project = project s. = if s.description = description s.required_ruby_version = ruby_version s.platform = platform if platform if private_key and File.exist? private_key s.signing_key = private_key s.cert_chain = certificate_chain end dependencies.each do |dep| dep = dep.split(" ") if dep.is_a? String s.add_dependency(*dep) end s.files = files s.bindir = if executable_pattern.any? executable_pattern[0].split("/")[0] else "bin" end s.executables = executable_pattern.map do |file| file[(s.bindir.length)..-1] end dirs = Dir['{lib,ext}'] s.extensions = extension_pattern if extension_pattern.any? s.require_paths = dirs unless dirs.empty? s.has_rdoc = has_rdoc if File.exist? "test/test_all.rb" s.test_file = "test/test_all.rb" else s.test_files = Dir[*test_pattern] end if eval s.instance_eval &eval end end self.lib_files = spec.files.grep(/^lib/) self.bin_files = spec.files.grep(/^bin/) self.test_files = spec.files.grep(/^test/) Rake::GemPackageTask.new(spec) do |pkg| pkg.need_tar = @need_tgz pkg.need_tar_gz = @need_tar_gz pkg.need_zip = @need_zip end task :build_gemspec do # Construct the gemspec file, if needed. if include_gemspec File.open(gemspec_name, 'w') do |f| f.puts "\n# Gem::Specification for #{name.capitalize}-#{version}\n# Originally generated by Echoe\n\n" spec.to_ruby.split("\n").each do |line| # Don't publish any information about the private key or certificate chain f.puts line unless line =~ /signing_key|cert_chain|\.pem/ end f.puts "\n\n# # Original Rakefile source (requires the Echoe gem):\n# \n" File.open("Rakefile").readlines.each do |line| # Ditto f.write "# #{line}" unless line =~ /private_key|certificate_chain|\.pem/ end end end end # Chain it to the gemspec task prerequisite task gemspec_name.to_sym => [:build_gemspec] task :package do # Chain some cleanup tasks to the default :package task. # Remove the gemfile if it wasn't actually requested. unless @need_gem puts " Gem file not requested. Removed." system "rm pkg/*.gem" end # Remove the generated gemspec once the packaging is done, to discourage people from modifying it by hand. if include_gemspec and File.exist? gemspec_name File.delete gemspec_name end # Test signing status if private_key and File.exist? private_key puts "Signing gem." else raise "Key required, but not found. Maybe you forget to set ENV['GEM_PRIVATE_KEY']?" if require_signed puts "Private key not found; gem will not be signed." end end desc 'Install the gem' task :install => [:clean, :package] do system "sudo gem install pkg/*.gem -P MediumSecurity" end desc 'Uninstall the gem' task :uninstall do system "sudo gem uninstall #{name} -a -i -x" end desc 'Package and upload the release to Rubyforge' task :release => [:clean, :package] do |t| say "\n" if agree "Release #{name}-#{version} to Rubyforge? " pkg = "pkg/#{name}-#{version}" pkg_gem = pkg + ".gem" pkg_tar = pkg + ".tgz" pkg_tar_gz = pkg + ".tar.gz" pkg_zip = pkg + ".zip" rf = RubyForge.new puts "Logging in" rf.login c = rf.userconfig c["release_notes"] = description if description c["release_changes"] = changes if changes c["preformatted"] = false files = [(@need_tgz ? pkg_tar : nil), (@need_tar_gz ? pkg_tar_gz : nil), (@need_zip ? pkg_zip : nil), (@need_gem ? pkg_gem : nil)].compact puts "Releasing #{name} v. #{version}" self.version = self.version.ljust(3) rf.add_release project, name, version, *files end end ### Extension building task :lib do directory "lib" end if extension_pattern.any? task :compile => [:lib] do extension_pattern.each do |extension| directory = File.dirname(extension) Dir.chdir(directory) do ruby File.basename(extension) system(PLATFORM =~ /win32/ ? 'nmake' : 'make') end Dir["#{directory}/*.#{Config::CONFIG['DLEXT']}"].each do |file| cp file, "lib" end end end task :test => [:compile] end ### Documentation Rake::RDocTask.new(:docs) do |rd| rd.main = Dir['*'].detect {|f| f =~ /^readme/i} rd. += Array() rd.rdoc_dir = 'doc' files = rdoc_pattern files -= [manifest_name] rd.rdoc_files.push(*files) if rdoc_template rd.template = rdoc_template elsif ENV['RDOC_TEMPLATE'] and File.exist? ENV['RDOC_TEMPLATE'] rd.template = ENV['RDOC_TEMPLATE'] end title = name.downcase == name ? name.capitalize : name rd. << "-t #{title}" end task :doc => [:redocs] desc "Publish documentation to #{docs_host ? "'#{docs_host}'" : "rubyforge"}" task :publish_docs => [:clean, :docs] do local_dir = 'doc' remote_dir_name = project remote_dir_name += "/#{name}" if project != name unless docs_host config = YAML.load(File.read(File.("~/.rubyforge/user-config.yml"))) pub = Rake::SshDirPublisher.new "#{config["username"]}@rubyforge.org", "/var/www/gforge-projects/#{remote_dir_name}", local_dir if project != name then def pub.upload begin super rescue # project directory probably doesn't exist, transfer as a whole cmd = "scp -qr #{local_dir} #{host}:#{remote_dir}" puts "Uploading: #{cmd}" system(cmd) end end end pub.upload else # you may need ssh keys configured for this to work host, dir = docs_host.split(":") dir.chomp!("/") # XXX too dangerous? cmd = "ssh #{host} 'rm -rf #{dir}/#{remote_dir_name}'" puts "Deleting existing docs: #{cmd}" system(cmd) cmd = "scp -qr #{local_dir} #{host}:#{dir}/#{remote_dir_name}" puts "Uploading: #{cmd}" system(cmd) end end desc 'Generate a release announcement, edit it, and post it to Rubyforge.' task :announce do filename = "/tmp/#{name}_#{version}_announcement.txt" if !File.exist?(filename) or agree "Overwrite existing announcement file? " File.open(filename, 'w') do |f| f.write "Subject: #{name.capitalize} #{version}\n\n" f.write "#{name.capitalize} has been updated to #{version}. #{name.capitalize} is #{summary.uncapitalize}\n\n" f.write "Changes in this version: #{changes.sub(/^\s*[\w\d\.]+\s+/, '').uncapitalize}\n\n" unless changes.empty? f.write "More information is available at #{url} .\n\n" unless url.empty? end end begin system("nano #{filename}") or raise "Editor returned an error" puts File.open(filename).read end while !agree "Done editing? " if agree "Publish announcement to Rubyforge? " File.open(filename).readlines.detect { |line| line =~ /Subject: (.*)/ } subject = $1 or raise "Subject line seems to have disappeared" body = File.open(filename).readlines.reject { |line| line =~ /Subject: / }.join.gsub("\n\n\n", "\n\n") rf = RubyForge.new rf.login rf.post_news(project, subject, body) puts "Published." File.delete filename end end ### Clean desc 'Clean up auto-generated files' task :clean do puts "Cleaning" clean_pattern.each do |file| if File.exist?(file) puts "- #{file}" rm_rf file end end end ### Manifest desc "Build a Manifest list" task :manifest => [:clean] do puts "Building Manifest" old_files = files files = [] Find.find '.' do |file| file = file[2..-1] next unless file next if file =~ /^(pkg|doc)|\.svn|CVS|\.bzr|\.DS|\.git/ next if file =~ ignore_pattern and ignore_pattern next if File.directory?(file) next if !include_rakefile and file == "Rakefile" files << file end files << "Rakefile" if include_rakefile files << manifest_name files.uniq! File.open(manifest_name, 'w').puts(files) puts(files.map do |file| (old_files.include?(file) ? " " : "+") + " " + file end) end task :build_manifest => [:manifest] ### Tests # XXX unreadable desc 'Run the test suite' task :test do ruby(if File.exist? 'test/test_all.rb' "#{RUBY_FLAGS} test/test_all.rb #{FILTER}" else tests = apply_pattern(test_pattern) << 'test/unit' tests.map! {|f| %Q(require "#{f}")} "#{RUBY_FLAGS} -e '#{tests.join("; ")}' #{FILTER}" end) end task :default => :test end |