[DRE-commits] [ruby-launchy] 02/13: Imported Upstream version 2.3.0
Gioele Barabucci
gioele-guest at alioth.debian.org
Sat Oct 5 13:43:21 UTC 2013
This is an automated email from the git hooks/post-receive script.
gioele-guest pushed a commit to branch master
in repository ruby-launchy.
commit cae0b19e32b409df32f5a075f5681be52c2bf77c
Author: Gioele Barabucci <gioele at svario.it>
Date: Sat Oct 5 11:28:58 2013 +0000
Imported Upstream version 2.3.0
---
CONTRIBUTING.md | 52 +++++
HISTORY.rdoc => HISTORY.md | 69 +++---
LICENSE | 2 +-
Manifest.txt | 8 +-
NOTES | 1 -
README.rdoc => README.md | 64 +++---
Rakefile | 293 +------------------------
checksums.yaml.gz | Bin 0 -> 429 bytes
lib/launchy.rb | 59 +++--
lib/launchy/applications/browser.rb | 2 +-
lib/launchy/cli.rb | 24 +-
lib/launchy/detect/nix_desktop_environment.rb | 14 +-
lib/launchy/detect/runner.rb | 12 +-
lib/launchy/error.rb | 1 +
lib/launchy/version.rb | 2 +-
metadata.yml | 77 ++-----
spec/detect/nix_desktop_environment_spec.rb | 8 +
spec/launchy_spec.rb | 31 ++-
spec/spec_helper.rb | 6 +
Rakefile => tasks/default.rake | 237 +++++++++-----------
tasks/this.rb | 209 ++++++++++++++++++
21 files changed, 603 insertions(+), 568 deletions(-)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..ea1a2eb
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,52 @@
+# Hi there!
+
+I see you are interested in contributing. That is wonderful. I love
+contributions.
+
+I guarantee that there are bugs in this software. And I guarantee that there is
+a feature you want that is not in here yet. As such, any and all bugs reports
+are gratefully accepted, bugfixes even more so. Helping out with bugs is the
+easiest way to contribute.
+
+
+## The Quick Version
+
+* Have a [GitHub Account][].
+* Search the [GitHub Issues][] and see if your issue already present. If so
+ add your comments, :thumbsup:, etc.
+* Issue not there? Not a problem, open up a [new issue][].
+ * **Bug reports** please be as detailed as possible. Include:
+ * full ruby engine and version: `ruby -e 'puts RUBY_DESCRIPTION'`
+ * operating system and version
+ * version of launchy `ruby -rubygems -Ilib -e "require 'launchy'; puts Launchy::VERSION"`
+ * as much detail about the bug as possible so I can replicate it. Feel free
+ to link in a [gist][]
+ * **New Feature**
+ * What the new feature should do.
+ * What benefit the new feature brings to the project.
+* Fork the [repo][].
+* Create a new branch for your issue: `git checkout -b issue/my-issue`
+* Lovingly craft your contribution:
+ * `rake develop` to get started, or if you prefer bundler `rake develop:using_bundler && bundle`.
+ * `rake test` to run tests
+* Make sure that `rake test` passes. It's important, I said it twice.
+* Add yourself to the contributors section below.
+* Submit your [pull request][].
+
+# Contributors
+
+* [Jeremy Hinegardner](https://github.com/copiousfreetime)
+* [Mike Farmer](https://github.com/mikefarmer)
+* [Suraj N. Kurapati](https://github.com/sunaku)
+* [Postmodern](https://github.com/postmodern)
+* [Stephen Judkins](https://github.com/stephenjudkins)
+* [Mariusz Pietrzyk](https://github.com/wijet)
+* [Bogdan Gusiev](https://github.com/bogdan)
+* [Miquel Rodríguez Telep](https://github.com/mrtorrent)
+
+[GitHub Account]: https://github.com/signup/free "GitHub Signup"
+[GitHub Issues]: https://github.com/copiousfreetime/launchy/issues "Launchy Issues"
+[new issue]: https://github.com/copiousfreetime/launchy/issues/new "New Launchy Issue"
+[gist]: https://gist.github.com/ "New Gist"
+[repo]: https://github.com/copiousfreetime/launchy "Launchy Repo"
+[pull request]: https://help.github.com/articles/using-pull-requests "Using Pull Requests"
diff --git a/HISTORY.rdoc b/HISTORY.md
similarity index 67%
rename from HISTORY.rdoc
rename to HISTORY.md
index 30b84f6..318dfe5 100644
--- a/HISTORY.rdoc
+++ b/HISTORY.md
@@ -1,25 +1,38 @@
-= Launchy Changlog
-== Version 2.1.2 - 2012-08-06
+# Launchy Changelog
+
+## Version 2.3.0 - 2013-04-11
+
+* Add the option to call a block on error instead of raising an exception
+
+## Version 2.2.0 - 2013-02-06
+
+* Change XFCE detection to not depend on grep (copiousfreetime/launchy#52 - thanks bogdan)
+* Suppress forked process output (copiousfreetime/launchy#51)
+* Display help/usage if no url is given (copiousfreetime/launchy#54)
+* Detect the fluxbox environment (copiousfreetime/launchy#53)
+* Automatically detect `http` url's if they are missing the `http://` (copiousfreetime/launchy#55)
+* Update to latest project management rake tasks
+
+## Version 2.1.2 - 2012-08-06
* Fix where HostOS would fail to convert to string on JRuby in 1.9 mode (copiousfreetime/launchy#45)
-== Version 2.1.1 - 2012-07-28
+## Version 2.1.1 - 2012-07-28
* Update addressable runtime dependency (copiousfreetime/launchy#47)
* Bring minitest and ffi development dependencies up to date
-== Version 2.1.0 - 2012-03-18
+## Version 2.1.0 - 2012-03-18
* Fix raising exception when no browser program found (copiousfreetime/launchy#42)
* Add LAUNCHY_DRY_RUN environment variable (thanks Mariusz Pietrzyk / wijet)
* Update dependencies
-
-== Version 2.0.5 - 2011-07-24
+## Version 2.0.5 - 2011-07-24
* Fix the case where $BROWSER is set and no *nix desktop was found (copiousfreetime/launchy#33)
-== Version 2.0.4 - 2011-07-23
+## Version 2.0.4 - 2011-07-23
* Fix windows 'start' commandline (copiousfreetime/launchy#5)
* Add capability to open local files with no file: scheme present (copiousfreetime/launchy#29)
@@ -27,24 +40,24 @@
* Make better decisions on when to do shell escaping (copiousfreetime/launchy#31)
* Switch to Addressable::URI so UTF-8 urls may be parsed. (copiousfreetime/launchy#32)
-== Version 2.0.3 - 2011-07-17
+## Version 2.0.3 - 2011-07-17
* Add in Deprecated API wrappers that warn the user
-== Version 2.0.2 - 2011-07-17
+## Version 2.0.2 - 2011-07-17
* Typo fixes from @mtorrent
* Documentation updates explicitly stating the Public API
* Increase test coverage
-== Version 2.0.1 - 2011-07-16
+## Version 2.0.1 - 2011-07-16
* Almost a complete rewrite
* JRuby Support
* Organization is such that it will be easier to add additional applications
* Windows behavior possibly fixed, again
-== Version 1.0.0 - 2011-03-17
+## Version 1.0.0 - 2011-03-17
* Add JRuby support (Stephen Judkins)
* Remove unused Paths module
@@ -52,51 +65,51 @@
* Switch to use minitest
* NOTE, this version was never released.
-== Version 0.4.0 - 2011-01-27
+## Version 0.4.0 - 2011-01-27
-* Add support for file:/// schema (postmodern)
+* Add support for `file:///` schema (postmodern)
-== Version 0.3.7 - 2010-07-19
+## Version 0.3.7 - 2010-07-19
* Fix launchy on windows (mikefarmer)
-== Version 0.3.6 - 2010-02-22
+## Version 0.3.6 - 2010-02-22
* add a test:spec task to run tests without rcov support
-* added 'testing' os family for running tests
+* added `testing` os family for running tests
-== Version 0.3.5 - 2009-12-17
+## Version 0.3.5 - 2009-12-17
* clarify that launchy is under ISC license
* fix missing data file in released gem needed for running specs
-== Version 0.3.3 - 2009-02-19
+## Version 0.3.3 - 2009-02-19
* pass command line as discrete items to system() to avoid string
interpretation by the system shell. (Suraj N. Kurapati)
* rework project layout and tasks
-== Version 0.3.2 - 2008-05-21
+## Version 0.3.2 - 2008-05-21
* detect aix and mingw as known operating systems.
-== Version 0.3.1 - 2007-09-08
+## Version 0.3.1 - 2007-09-08
* finalize the command line wrapper around the launchy library.
* added more tests
-== Version 0.3.0 - 2007-08-30
+## Version 0.3.0 - 2007-08-30
* reorganize the code structure, removing Spawnable namespace
* removed 'do_magic' method, changed it to 'open'
* added override environment variable LAUNCHY_HOST_OS for testing
* fix broken cygwin support [Bug #13472]
-== Version 0.2.1 - 2007-08-18
+## Version 0.2.1 - 2007-08-18
* fix inability to find windows executables [Bug #13132]
-== Version 0.2.0 - 2007-08-11
+## Version 0.2.0 - 2007-08-11
* rework browser finding
* manual override with LAUNCHY_BROWSER environment variable
@@ -105,23 +118,23 @@
* removed win32 gem
* Add debug output by setting LAUNCHY_DEBUG environment variable to 'true'
-== Version 0.1.2 - 2007-08-11
+## Version 0.1.2 - 2007-08-11
* forked child exits without calling at_exit handlers
-== Version 0.1.1
+## Version 0.1.1
* fixed rubyforge task to release mswin32 gem also
-== Version 0.1.0
+## Version 0.1.0
* Initial public release
* switched to using fork to spawn process and require 'win32/process' if on windows
-== Version 0.0.2
+## Version 0.0.2
* First attempt at using systemu to spawn processes
-== Version 0.0.1
+## Version 0.0.1
* Initially working release
diff --git a/LICENSE b/LICENSE
index 7959700..70b1ea1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
ISC LICENSE - http://opensource.org/licenses/isc-license.txt
-Copyright (c) 2007-2011 Jeremy Hinegardner
+Copyright (c) 2007-2013 Jeremy Hinegardner
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/Manifest.txt b/Manifest.txt
index 8eb24ca..a258386 100644
--- a/Manifest.txt
+++ b/Manifest.txt
@@ -1,8 +1,8 @@
-HISTORY.rdoc
+CONTRIBUTING.md
+HISTORY.md
LICENSE
Manifest.txt
-NOTES
-README.rdoc
+README.md
Rakefile
bin/launchy
lib/launchy.rb
@@ -33,3 +33,5 @@ spec/mock_application.rb
spec/spec_helper.rb
spec/tattle-host-os.yaml
spec/version_spec.rb
+tasks/default.rake
+tasks/this.rb
diff --git a/NOTES b/NOTES
deleted file mode 100644
index b8fe0e5..0000000
--- a/NOTES
+++ /dev/null
@@ -1 +0,0 @@
-* Allow for new tab/ new window for opening a browser
diff --git a/README.rdoc b/README.md
similarity index 64%
rename from README.rdoc
rename to README.md
index b07a611..4d10017 100644
--- a/README.rdoc
+++ b/README.md
@@ -1,39 +1,39 @@
-== launchy
+# launchy
-* Homepage[http://www.copiousfreetime.org/projects/launchy/]
-* {Github Project}[http://github.com/copiousfreetime/launchy]
+* [Homepage](https://github.com/copiousfreetime/launchy)
+* [Github Project](https://github.com/copiousfreetime/launchy)
* email jeremy at hinegardner dot org
-== DESCRIPTION
+## DESCRIPTION
-Launchy is helper class for launching cross-platform applications in a
-fire and forget manner.
+Launchy is helper class for launching cross-platform applications in a fire and
+forget manner.
-There are application concepts (browser, email client, etc) that are
-common across all platforms, and they may be launched differently on
-each platform. Launchy is here to make a common approach to launching
-external application from within ruby programs.
+There are application concepts (browser, email client, etc) that are common
+across all platforms, and they may be launched differently on each platform.
+Launchy is here to make a common approach to launching external application from
+within ruby programs.
-== FEATURES
+## FEATURES
Currently only launching a browser is supported.
-== SYNOPSIS
+## SYNOPSIS
You can use launchy on the commandline, or via its API.
-=== Commandline
+### Commandline
% launchy http://www.ruby-lang.org/
-There are additional commandline options, use 'launchy --help' to see them.
+There are additional commandline options, use `launchy --help` to see them.
-=== Public API
+### Public API
-In the vein of {Semantic Versioning}[http://semver.org], starting with version 2.0.0, this is the
-sole supported public API.
+In the vein of [Semantic Versioning](http://semver.org), this is the sole
+supported public API.
- Launchy.open( uri, options = {} )
+ Launchy.open( uri, options = {} ) { |exception| }
At the moment, the only available options are:
@@ -43,15 +43,26 @@ At the moment, the only available options are:
:ruby_engine Explicitly state what ruby engine to pretend to be under
:dry_run Do nothing and print the command that would be executed on $stdout
-An example of using the public API:
+If `Launchy.open` is invoked with a block, then no exception will be thrown, and
+the block will be called with the parameters passed to `#open` along with the
+exception that was raised.
+
+### An example of using the public API:
Launchy.open( "http://www.ruby-lang.org" )
-== UPGRADING
+### An example of using the public API and using the error block:
+
+ uri = "http://www.ruby-lang.org"
+ Launchy.open( uri ) do |exception|
+ puts "Attempted to open #{uri} and failed because #{exception}"
+ end
-The previously published version of Launchy was 0.4.0. There have been so many
-changes, and a mistaken tag at 1.0.0, that I have decided to bump all the way
-to 2.0.x.
+## UPGRADING from versions before 2.0.0
+
+The previously published versino of Launchy before the 2.0.0 series was 0.4.0.
+There have been so many changes, and a mistaken tag at 1.0.0, that I have
+decided to bump all the way to 2.x.y.
I have attempted to keep backward compatibility with the previous examples. The
previous API examples of:
@@ -79,11 +90,14 @@ in the github gem if it was updated to use 2.0.x but not use the supported API.
WARNING:
WARNING: If this is not the case, please file a bug. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new
-== ISC LICENSE
+These deprecation notices will go away with version 3.0 and the only availabel
+API will be the documented one.
+
+## ISC LICENSE
http://opensource.org/licenses/isc-license.txt
-Copyright (c) 2007-2011 Jeremy Hinegardner
+Copyright (c) 2007-2013 Jeremy Hinegardner
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
diff --git a/Rakefile b/Rakefile
index d9f526d..78174e9 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,298 +1,21 @@
# vim: syntax=ruby
+load 'tasks/this.rb'
This.name = "launchy"
This.author = "Jeremy Hinegardner"
This.email = "jeremy at copiousfreetime.org"
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
-This.version = Util.version
-#------------------------------------------------------------------------------
-# If you want to Develop on this project just run 'rake develop' and you'll
-# have all you need to get going. If you want to use bundler for development,
-# then run 'rake develop:using_bundler'
-#------------------------------------------------------------------------------
-namespace :develop do
+This.ruby_gemspec do |spec|
+ spec.add_dependency( 'addressable', '~> 2.3')
- # Install all the development and runtime dependencies of this gem using the
- # gemspec.
- task :default do
- require 'rubygems/dependency_installer'
- installer = Gem::DependencyInstaller.new
-
- puts "Installing gem depedencies needed for development"
- Util.platform_gemspec.dependencies.each do |dep|
- if dep.matching_specs.empty? then
- puts "Installing : #{dep}"
- installer.install dep
- else
- puts "Skipping : #{dep} -> already installed #{dep.matching_specs.first.full_name}"
- end
- end
- puts "\n\nNow run 'rake test'"
- end
-
- # Create a Gemfile that just references the gemspec
- file 'Gemfile' => :gemspec do
- File.open( "Gemfile", "w+" ) do |f|
- f.puts 'source :rubygems'
- f.puts 'gemspec'
- end
- end
-
- desc "Create a bundler Gemfile"
- task :using_bundler => 'Gemfile' do
- puts "Now you can 'bundle'"
- end
-
- # Gemfiles are build artifacts
- CLOBBER << FileList['Gemfile*']
-end
-desc "Boostrap development"
-task :develop => "develop:default"
-
-#------------------------------------------------------------------------------
-# Minitest - standard TestTask
-#------------------------------------------------------------------------------
-begin
- require 'rake/testtask'
- Rake::TestTask.new( :test ) do |t|
- t.ruby_opts = %w[ -w -rubygems ]
- t.libs = %w[ lib spec ]
- t.pattern = "spec/**/*_spec.rb"
- end
- task :default => :test
-rescue LoadError
- Util.task_warning( 'test' )
-end
-
-#------------------------------------------------------------------------------
-# RDoc - standard rdoc rake task, although we must make sure to use a more
-# recent version of rdoc since it is the one that has 'tomdoc' markup
-#------------------------------------------------------------------------------
-begin
- gem 'rdoc' # otherwise we get the wrong task from stdlib
- require 'rdoc/task'
- RDoc::Task.new do |t|
- t.markup = 'tomdoc'
- t.rdoc_dir = 'doc'
- t.main = 'README.rdoc'
- t.title = "#{This.name} #{This.version}"
- t.rdoc_files.include( '*.rdoc', 'lib/**/*.rb' )
- end
-rescue LoadError => le
- Util.task_warning( 'rdoc' )
-end
-
-#------------------------------------------------------------------------------
-# Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
-# for the moment only rcov is listed.
-#------------------------------------------------------------------------------
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |t|
- t.libs << 'spec'
- t.pattern = 'spec/**/*_spec.rb'
- t.verbose = true
- t.rcov_opts << "-x ^/" # remove all the global files
- t.rcov_opts << "--sort coverage" # so we see the worst files at the top
- end
-rescue LoadError
- $stderr.puts "rcov task is not defined, please 'gem install rcov'"
-end
-
-#------------------------------------------------------------------------------
-# Manifest - We want an explicit list of thos files that are to be packaged in
-# the gem. Most of this is from Hoe.
-#------------------------------------------------------------------------------
-namespace 'manifest' do
- desc "Check the manifest"
- task :check => :clean do
- files = FileList["**/*", ".*"].exclude( This.exclude_from_manifest ).to_a.sort
- files = files.select{ |f| File.file?( f ) }
-
- tmp = "Manifest.tmp"
- File.open( tmp, 'w' ) do |f|
- f.puts files.join("\n")
- end
-
- begin
- sh "diff -du Manifest.txt #{tmp}"
- ensure
- rm tmp
- end
- puts "Manifest looks good"
- end
-
- desc "Generate the manifest"
- task :generate => :clean do
- files = %x[ git ls-files ].split("\n").sort
- files.reject! { |f| f =~ This.exclude_from_manifest }
- File.open( "Manifest.txt", "w" ) do |f|
- f.puts files.join("\n")
- end
- end
-end
-
-#------------------------------------------------------------------------------
-# Gem Specification
-#------------------------------------------------------------------------------
-This.gemspec = Hash.new
-This.gemspec['ruby'] = Gem::Specification.new do |spec|
- spec.name = This.name
- spec.version = This.version
- spec.author = This.author
- spec.email = This.email
- spec.homepage = This.homepage
-
- spec.summary = This.summary
- spec.description = This.description
-
- spec.files = This.manifest
- spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
- spec.test_files = spec.files.grep(/^spec/)
-
- spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc)$/)
- spec.rdoc_options = [ "--main" , 'README.rdoc', ]
-
- # The Runtime Dependencies
- spec.add_runtime_dependency( 'addressable', '~> 2.3' )
-
- # The Development Dependencies
- spec.add_development_dependency( 'rake' , '~> 0.9.2.2')
- spec.add_development_dependency( 'minitest' , '~> 3.3.0' )
+ spec.add_development_dependency( 'rake' , '~> 10.0.3')
+ spec.add_development_dependency( 'minitest' , '~> 4.5.0' )
spec.add_development_dependency( 'rdoc' , '~> 3.12' )
- spec.add_development_dependency( 'spoon' , '~> 0.0.1' )
- spec.add_development_dependency( 'ffi' , '~> 1.1.1' )
-
end
-#----------------------------------------------
-# JRuby spec has a few more runtime dependencies
-#----------------------------------------------
-jruby_gemspec = This.gemspec['ruby'].dup
-jruby_gemspec.add_runtime_dependency( 'spoon', '~> 0.0.1' )
-jruby_gemspec.add_runtime_dependency( 'ffi' , '~> 1.1.1' )
-jruby_gemspec.platform = 'java'
-This.gemspec['java'] = jruby_gemspec
-
-
-# The name of the gemspec file on disk
-This.gemspec_file = "#{This.name}.gemspec"
-
-# Really this is only here to support those who use bundler
-desc "Build the #{This.name}.gemspec file"
-task :gemspec do
- File.open( This.gemspec_file, "wb+" ) do |f|
- f.write Util.platform_gemspec.to_ruby
- end
-end
-
-# the gemspec is also a dev artifact and should not be kept around.
-CLOBBER << This.gemspec_file
-
-# The standard gem packaging task, everyone has it.
-require 'rubygems/package_task'
-Gem::PackageTask.new( Util.platform_gemspec ) do
- # nothing
+This.java_gemspec( This.ruby_gemspec ) do |spec|
+ spec.add_dependency( 'spoon', '~> 0.0.1' )
end
-#------------------------------------------------------------------------------
-# Release - the steps we go through to do a final release, this is pulled from
-# a compbination of mojombo's rakegem, hoe and hoe-git
-#
-# 1) make sure we are on the master branch
-# 2) make sure there are no uncommitted items
-# 3) check the manifest and make sure all looks good
-# 4) build the gem
-# 5) do an empty commit to have the commit message of the version
-# 6) tag that commit as the version
-# 7) push master
-# 8) push the tag
-# 7) pus the gem
-#------------------------------------------------------------------------------
-task :release_check do
- unless `git branch` =~ /^\* master$/
- abort "You must be on the master branch to release!"
- end
- unless `git status` =~ /^nothing to commit/m
- abort "Nope, sorry, you have unfinished business"
- end
-end
-
-desc "Create tag v#{This.version}, build and push #{Util.platform_gemspec.full_name} to rubygems.org"
-task :release => [ :release_check, 'manifest:check', :gem ] do
- sh "git commit --allow-empty -a -m 'Release #{This.version}'"
- sh "git tag -a -m 'v#{This.version}' v#{This.version}"
- sh "git push origin master"
- sh "git push origin v#{This.version}"
- sh "gem push pkg/#{Util.platform_gemspec.full_name}.gem"
-end
-
-#------------------------------------------------------------------------------
-# Rakefile Support - This is all the guts and utility methods that are
-# necessary to support the above tasks.
-#
-# Lots of Credit for this Rakefile goes to:
-#
-# Ara T. Howard - see the Rakefile in all of his projects -
-# https://github.com/ahoward/
-# Tom Preston Werner - his Rakegem project https://github.com/mojombo/rakegem
-# Seattle.rb - Hoe - cuz it has relly good stuff in there
-#------------------------------------------------------------------------------
-BEGIN {
-
- require 'ostruct'
- require 'rake/clean'
- require 'rubygems' unless defined? Gem
-
- module Util
- def self.version
- [ "lib/#{ This.name }.rb", "lib/#{ This.name }/version.rb" ].each do |v|
- line = File.read( v )[/^\s*VERSION\s*=\s*.*/]
- if line then
- return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
- end
- end
- end
-
- # Partition an rdoc file into sections and return the text of the section
- # as an array of paragraphs
- def self.section_of( file, section_name )
- re = /^=+ (.*)$/
- parts = File.read( file ).split( re )[1..-1]
- parts.map! { |p| p.strip }
-
- sections = Hash.new
- Hash[*parts].each do |k,v|
- sections[k] = v.split("\n\n")
- end
- return sections[section_name]
- end
-
- def self.task_warning( task )
- warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
- end
-
- def self.read_manifest
- abort "You need a Manifest.txt" unless File.readable?( "Manifest.txt" )
- File.readlines( "Manifest.txt" ).map { |l| l.strip }
- end
-
- def self.platform_gemspec
- This.gemspec[This.platform]
- end
- end
-
- # Hold all the metadata about this project
- This = OpenStruct.new
- This.platform = (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
-
- desc = Util.section_of( 'README.rdoc', 'DESCRIPTION')
- This.summary = desc.first
- This.description = desc.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
-
-
- This.exclude_from_manifest = %r/tmp$|\.(git|DS_Store)|^(doc|coverage|pkg)|\.gemspec$|\.swp$|\.jar|\.rvmrc$|~$/
- This.manifest = Util.read_manifest
-
-}
+load 'tasks/default.rake'
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
new file mode 100644
index 0000000..518ce58
Binary files /dev/null and b/checksums.yaml.gz differ
diff --git a/lib/launchy.rb b/lib/launchy.rb
index d4197d1..51b9dd4 100644
--- a/lib/launchy.rb
+++ b/lib/launchy.rb
@@ -20,24 +20,44 @@ module Launchy
class << self
#
- # Convenience method to launch an item
+ # Launch an application for the given uri string
#
- def open(uri, options = {} )
- begin
- extract_global_options( options )
- uri = Addressable::URI.parse( uri )
- app = Launchy::Application.handling( uri )
- app.new.open( uri, options )
- rescue Exception => e
- msg = "Failure in opening #{uri} with options #{options.inspect}: #{e}"
- Launchy.log "#{self.name} : #{msg}"
- e.backtrace.each do |bt|
- Launchy.log bt
- end
- $stderr.puts msg
+ def open(uri_s, options = {}, &error_block )
+ leftover = extract_global_options( options )
+ uri = string_to_uri( uri_s )
+ app = app_for_uri( uri )
+ app.new.open( uri, leftover )
+ rescue Launchy::Error => le
+ raise le
+ rescue Exception => e
+ msg = "Failure in opening uri #{uri_s.inspect} with options #{options.inspect}: #{e}"
+ raise Launchy::Error, msg
+ ensure
+ if $! and block_given? then
+ yield $!
+ return # explicitly swallow the errors
end
end
+ def app_for_uri( uri )
+ Launchy::Application.handling( uri )
+ end
+
+ def app_for_uri_string( s )
+ app_for_uri( string_to_uri( s ) )
+ end
+
+ def string_to_uri( s )
+ uri = Addressable::URI.parse( s )
+ Launchy.log "URI parsing pass 1 : #{s} -> #{uri.to_hash}"
+ if not uri.scheme then
+ uri = Addressable::URI.heuristic_parse( s )
+ Launchy.log "URI parsing pass 2 : #{s} -> #{uri.to_hash}"
+ end
+ raise Launchy::ArgumentError, "Invalid URI given: #{s.inspect}" unless uri
+ return uri
+ end
+
def reset_global_options
Launchy.debug = false
Launchy.application = nil
@@ -47,11 +67,12 @@ module Launchy
end
def extract_global_options( options )
- Launchy.debug = options.delete( :debug ) || ENV['LAUNCHY_DEBUG']
- Launchy.application = options.delete( :application ) || ENV['LAUNCHY_APPLICATION']
- Launchy.host_os = options.delete( :host_os ) || ENV['LAUNCHY_HOST_OS']
- Launchy.ruby_engine = options.delete( :ruby_engine ) || ENV['LAUNCHY_RUBY_ENGINE']
- Launchy.dry_run = options.delete( :dry_run ) || ENV['LAUNCHY_DRY_RUN']
+ leftover = options.dup
+ Launchy.debug = leftover.delete( :debug ) || ENV['LAUNCHY_DEBUG']
+ Launchy.application = leftover.delete( :application ) || ENV['LAUNCHY_APPLICATION']
+ Launchy.host_os = leftover.delete( :host_os ) || ENV['LAUNCHY_HOST_OS']
+ Launchy.ruby_engine = leftover.delete( :ruby_engine ) || ENV['LAUNCHY_RUBY_ENGINE']
+ Launchy.dry_run = leftover.delete( :dry_run ) || ENV['LAUNCHY_DRY_RUN']
end
def debug=( d )
diff --git a/lib/launchy/applications/browser.rb b/lib/launchy/applications/browser.rb
index 2332a43..e29b44c 100644
--- a/lib/launchy/applications/browser.rb
+++ b/lib/launchy/applications/browser.rb
@@ -9,7 +9,7 @@ class Launchy::Application
def self.handles?( uri )
return true if schemes.include?( uri.scheme )
- return true if File.exist?( uri.path )
+ return true if File.exist?( uri.path ) and uri.scheme.nil?
end
def windows_app_list
diff --git a/lib/launchy/cli.rb b/lib/launchy/cli.rb
index 87d0140..54b3a0f 100644
--- a/lib/launchy/cli.rb
+++ b/lib/launchy/cli.rb
@@ -57,25 +57,31 @@ module Launchy
end
def parse( argv, env )
- begin
- parser.parse!( argv )
- return true
- rescue ::OptionParser::ParseError => pe
- $stderr.puts "#{parser.program_name}: #{pe}"
- $stderr.puts "Try `#{parser.program_name} --help for more information."
- return false
- end
+ parser.parse!( argv )
+ return true
+ rescue ::OptionParser::ParseError => pe
+ error_output( pe )
end
def good_run( argv, env )
if parse( argv, env ) then
- Launchy.open( argv.shift, options )
+ Launchy.open( argv.shift, options ) { |e| error_output( e ) }
return true
else
return false
end
end
+ def error_output( error )
+ $stderr.puts "ERROR: #{error}"
+ Launchy.log "ERROR: #{error}"
+ error.backtrace.each do |bt|
+ Launchy.log bt
+ end
+ $stderr.puts "Try `#{parser.program_name} --help' for more information."
+ return false
+ end
+
def run( argv = ARGV, env = ENV )
exit 1 unless good_run( argv, env )
end
diff --git a/lib/launchy/detect/nix_desktop_environment.rb b/lib/launchy/detect/nix_desktop_environment.rb
index 1b1e690..2da08a8 100644
--- a/lib/launchy/detect/nix_desktop_environment.rb
+++ b/lib/launchy/detect/nix_desktop_environment.rb
@@ -2,7 +2,7 @@ module Launchy::Detect
#
# Detect the current desktop environment for *nix machines
# Currently this is Linux centric. The detection is based upon the detection
- # used by xdg-open from http://portland.freedesktop.org/wiki/XdgUtils
+ # used by xdg-open from http://portland.freedesktop.org/
class NixDesktopEnvironment
class NotFoundError < Launchy::Error; end
@@ -49,7 +49,7 @@ module Launchy::Detect
class Xfce < NixDesktopEnvironment
def self.is_current_desktop_environment?
if Launchy::Application.find_executable( 'xprop' ) then
- %x[ xprop -root _DT_SAVE_MODE | grep ' = \"xfce\"$' ].strip.size > 0
+ %x[ xprop -root _DT_SAVE_MODE].include?("xfce")
else
false
end
@@ -59,6 +59,16 @@ module Launchy::Detect
'exo-open'
end
end
+
+ class Fluxbox < NixDesktopEnvironment
+ def self.is_current_desktop_environment?
+ ENV['DESKTOP_SESSION'] == 'fluxbox'
+ end
+
+ def self.browser
+ 'xdg-open'
+ end
+ end
end
end
diff --git a/lib/launchy/detect/runner.rb b/lib/launchy/detect/runner.rb
index 8df6e92..0f8a868 100644
--- a/lib/launchy/detect/runner.rb
+++ b/lib/launchy/detect/runner.rb
@@ -25,7 +25,6 @@ module Launchy::Detect
return Windows.new if host_os_family.windows?
if ruby_engine.jruby? then
- require 'spoon'
return Jruby.new
end
return Forkable.new
@@ -95,6 +94,7 @@ module Launchy::Detect
class Jruby < Runner
def wet_run( cmd, *args )
+ require 'spoon'
Spoon.spawnp( *shell_commands( cmd, *args ) )
end
end
@@ -102,11 +102,21 @@ module Launchy::Detect
class Forkable < Runner
def wet_run( cmd, *args )
child_pid = fork do
+ close_file_descriptors unless Launchy.debug?
+ Launchy.log("wet_run: before exec in child process")
exec( *shell_commands( cmd, *args ))
exit!
end
Process.detach( child_pid )
end
+
+ def close_file_descriptors
+ [$stdin, $stdout, $stderr].each do |io|
+ io.reopen( "/dev/null", "r+" )
+ end
+ end
+
+ private :close_file_descriptors
end
end
end
diff --git a/lib/launchy/error.rb b/lib/launchy/error.rb
index 2c594c5..fc1dda9 100644
--- a/lib/launchy/error.rb
+++ b/lib/launchy/error.rb
@@ -2,4 +2,5 @@ module Launchy
class Error < ::StandardError; end
class ApplicationNotFoundError < Error; end
class CommandNotFoundError < Error; end
+ class ArgumentError < Error; end
end
diff --git a/lib/launchy/version.rb b/lib/launchy/version.rb
index e56cd98..d94ebdb 100644
--- a/lib/launchy/version.rb
+++ b/lib/launchy/version.rb
@@ -1,5 +1,5 @@
module Launchy
- VERSION = "2.1.2"
+ VERSION = "2.3.0"
module Version
diff --git a/metadata.yml b/metadata.yml
index 2589a38..49ee8b3 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,20 +1,18 @@
--- !ruby/object:Gem::Specification
name: launchy
version: !ruby/object:Gem::Version
- version: 2.1.2
- prerelease:
+ version: 2.3.0
platform: ruby
authors:
- Jeremy Hinegardner
autorequire:
bindir: bin
cert_chain: []
-date: 2012-08-06 00:00:00.000000000 Z
+date: 2013-04-16 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: addressable
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
@@ -30,39 +27,34 @@ dependencies:
- !ruby/object:Gem::Dependency
name: rake
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
- version: 0.9.2.2
+ version: 10.0.3
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
- version: 0.9.2.2
+ version: 10.0.3
- !ruby/object:Gem::Dependency
name: minitest
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
- version: 3.3.0
+ version: 4.5.0
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
- version: 3.3.0
+ version: 4.5.0
- !ruby/object:Gem::Dependency
name: rdoc
requirement: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
@@ -70,43 +62,10 @@ dependencies:
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ~>
- !ruby/object:Gem::Version
version: '3.12'
-- !ruby/object:Gem::Dependency
- name: spoon
- requirement: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: 0.0.1
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: 0.0.1
-- !ruby/object:Gem::Dependency
- name: ffi
- requirement: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: 1.1.1
- type: :development
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- version: 1.1.1
description: Launchy is helper class for launching cross-platform applications in
a fire and forget manner. There are application concepts (browser, email client,
etc) that are common across all platforms, and they may be launched differently
@@ -117,15 +76,16 @@ executables:
- launchy
extensions: []
extra_rdoc_files:
-- HISTORY.rdoc
+- CONTRIBUTING.md
+- HISTORY.md
- Manifest.txt
-- README.rdoc
+- README.md
files:
-- HISTORY.rdoc
+- CONTRIBUTING.md
+- HISTORY.md
- LICENSE
- Manifest.txt
-- NOTES
-- README.rdoc
+- README.md
- Rakefile
- bin/launchy
- lib/launchy.rb
@@ -156,31 +116,34 @@ files:
- spec/spec_helper.rb
- spec/tattle-host-os.yaml
- spec/version_spec.rb
+- tasks/default.rake
+- tasks/this.rb
homepage: http://github.com/copiousfreetime/launchy
licenses: []
+metadata: {}
post_install_message:
rdoc_options:
- --main
-- README.rdoc
+- README.md
+- --markup
+- tomdoc
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
- none: false
requirements:
- - ! '>='
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
-rubygems_version: 1.8.24
+rubygems_version: 2.0.3
signing_key:
-specification_version: 3
+specification_version: 4
summary: Launchy is helper class for launching cross-platform applications in a fire
and forget manner.
test_files:
diff --git a/spec/detect/nix_desktop_environment_spec.rb b/spec/detect/nix_desktop_environment_spec.rb
index a0f7a99..e5c17e7 100644
--- a/spec/detect/nix_desktop_environment_spec.rb
+++ b/spec/detect/nix_desktop_environment_spec.rb
@@ -22,6 +22,14 @@ describe Launchy::Detect::NixDesktopEnvironment do
end
end
+ it "detects the fluxbox desktop environment" do
+ ENV['DESKTOP_SESSION'] = 'fluxbox'
+ fluxbox_env = Launchy::Detect::NixDesktopEnvironment.detect
+ fluxbox_env.must_equal( Launchy::Detect::NixDesktopEnvironment::Fluxbox )
+ fluxbox_env.browser.must_equal( Launchy::Detect::NixDesktopEnvironment::Fluxbox.browser )
+ ENV.delete( 'DESKTOP_SESSION' )
+ end
+
it "returns false for XFCE if xprop is not found" do
Launchy.host_os = "linux"
Launchy::Detect::NixDesktopEnvironment::Xfce.is_current_desktop_environment?.must_equal( false )
diff --git a/spec/launchy_spec.rb b/spec/launchy_spec.rb
index 4f2e761..7ef0054 100644
--- a/spec/launchy_spec.rb
+++ b/spec/launchy_spec.rb
@@ -6,6 +6,7 @@ describe Launchy do
Launchy.reset_global_options
@stderr = $stderr
$stderr = StringIO.new
+ @invalid_url = 'blah://example.com/invalid'
end
after do
@@ -50,9 +51,33 @@ describe Launchy do
Launchy.ruby_engine.must_equal 'myruby'
end
- it "prints an error on stderr when no scheme is found for the given uri" do
- Launchy.open( "blah://something/invalid" )
- $stderr.string.must_match( /Failure in opening/ )
+ it "raises an exception if no scheme is found for the given uri" do
+ lambda { Launchy.open( @invalid_url ) }.must_raise Launchy::ApplicationNotFoundError
end
+ it "raises an exception if we have an invalid scheme and a valid path" do
+ lambda { Launchy.open( "blah://example.com/" ) }.must_raise Launchy::ApplicationNotFoundError
+ end
+
+ it "calls the block if instead of raising an exception if there is an error" do
+ Launchy.open( @invalid_url ) { $stderr.puts "oops had an error opening #{@invalid_url}" }
+ $stderr.string.strip.must_equal "oops had an error opening #{@invalid_url}"
+ end
+
+ it "calls the block with the values passed to launchy and the error" do
+ options = { :dry_run => true }
+ Launchy.open( @invalid_url, :dry_run => true ) { |e| $stderr.puts "had an error opening #{@invalid_url} with options #{options}: #{e}" }
+ $stderr.string.strip.must_equal "had an error opening #{@invalid_url} with options #{options}: No application found to handle '#{@invalid_url}'"
+ end
+
+ it "raises the error in the called block" do
+ lambda { Launchy.open( @invalid_url ) { raise StandardError, "KABOOM!" } }.must_raise StandardError
+ end
+
+ [ 'www.example.com', 'www.example.com/foo/bar' ].each do |x|
+ it "picks a Browser for #{x}" do
+ app = Launchy.app_for_uri_string( x )
+ app.must_equal( Launchy::Application::Browser )
+ end
+ end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index fe2550b..262182e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,9 @@
+if RUBY_VERSION >= '1.9.2' then
+ require 'simplecov'
+ puts "Using coverage!"
+ SimpleCov.start if ENV['COVERAGE']
+end
+
gem 'minitest'
require 'launchy'
require 'stringio'
diff --git a/Rakefile b/tasks/default.rake
similarity index 55%
copy from Rakefile
copy to tasks/default.rake
index d9f526d..35e6743 100644
--- a/Rakefile
+++ b/tasks/default.rake
@@ -1,11 +1,5 @@
# vim: syntax=ruby
-
-This.name = "launchy"
-This.author = "Jeremy Hinegardner"
-This.email = "jeremy at copiousfreetime.org"
-This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
-This.version = Util.version
-
+require 'rake/clean'
#------------------------------------------------------------------------------
# If you want to Develop on this project just run 'rake develop' and you'll
# have all you need to get going. If you want to use bundler for development,
@@ -19,8 +13,10 @@ namespace :develop do
require 'rubygems/dependency_installer'
installer = Gem::DependencyInstaller.new
+ This.set_coverage_gem
+
puts "Installing gem depedencies needed for development"
- Util.platform_gemspec.dependencies.each do |dep|
+ This.platform_gemspec.dependencies.each do |dep|
if dep.matching_specs.empty? then
puts "Installing : #{dep}"
installer.install dep
@@ -60,9 +56,12 @@ begin
t.libs = %w[ lib spec ]
t.pattern = "spec/**/*_spec.rb"
end
+
+ task :test_requirements
+ task :test => :test_requirements
task :default => :test
rescue LoadError
- Util.task_warning( 'test' )
+ This.task_warning( 'test' )
end
#------------------------------------------------------------------------------
@@ -75,29 +74,44 @@ begin
RDoc::Task.new do |t|
t.markup = 'tomdoc'
t.rdoc_dir = 'doc'
- t.main = 'README.rdoc'
+ t.main = 'README.md'
t.title = "#{This.name} #{This.version}"
- t.rdoc_files.include( '*.rdoc', 'lib/**/*.rb' )
+ t.rdoc_files.include( FileList['*.{rdoc,md,txt}'], FileList['ext/**/*.c'],
+ FileList['lib/**/*.rb'] )
end
rescue LoadError => le
- Util.task_warning( 'rdoc' )
+ This.task_warning( 'rdoc' )
end
#------------------------------------------------------------------------------
# Coverage - optional code coverage, rcov for 1.8 and simplecov for 1.9, so
# for the moment only rcov is listed.
#------------------------------------------------------------------------------
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |t|
- t.libs << 'spec'
- t.pattern = 'spec/**/*_spec.rb'
- t.verbose = true
- t.rcov_opts << "-x ^/" # remove all the global files
- t.rcov_opts << "--sort coverage" # so we see the worst files at the top
+if RUBY_VERSION < "1.9.0"
+ begin
+ require 'rcov/rcovtask'
+ Rcov::RcovTask.new( 'coverage' ) do |t|
+ t.libs << 'spec'
+ t.pattern = 'spec/**/*_spec.rb'
+ t.verbose = true
+ t.rcov_opts << "-x ^/" # remove all the global files
+ t.rcov_opts << "--sort coverage" # so we see the worst files at the top
+ end
+ rescue LoadError
+ This.task_warning( 'rcov' )
+ end
+else
+ begin
+ require 'simplecov'
+ desc 'Run tests with code coverage'
+ task :coverage do
+ ENV['COVERAGE'] = 'true'
+ Rake::Task[:test].execute
+ end
+ CLOBBER << FileList["coverage"]
+ rescue LoadError
+ This.task_warning( 'simplecov' )
end
-rescue LoadError
- $stderr.puts "rcov task is not defined, please 'gem install rcov'"
end
#------------------------------------------------------------------------------
@@ -134,65 +148,93 @@ namespace 'manifest' do
end
#------------------------------------------------------------------------------
-# Gem Specification
+# Fixme - look for fixmes and report them
#------------------------------------------------------------------------------
-This.gemspec = Hash.new
-This.gemspec['ruby'] = Gem::Specification.new do |spec|
- spec.name = This.name
- spec.version = This.version
- spec.author = This.author
- spec.email = This.email
- spec.homepage = This.homepage
-
- spec.summary = This.summary
- spec.description = This.description
-
- spec.files = This.manifest
- spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
- spec.test_files = spec.files.grep(/^spec/)
+namespace :fixme do
+ task :default => 'manifest:check' do
+ This.manifest.each do |file|
+ next if file == __FILE__
+ next unless file =~ %r/(txt|rb|md|rdoc|css|html|xml|css)\Z/
+ puts "FIXME: Rename #{file}" if file =~ /fixme/i
+ IO.readlines( file ).each_with_index do |line, idx|
+ prefix = "FIXME: #{file}:#{idx+1}".ljust(42)
+ puts "#{prefix} => #{line.strip}" if line =~ /fixme/i
+ end
+ end
+ end
- spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc)$/)
- spec.rdoc_options = [ "--main" , 'README.rdoc', ]
+ def fixme_project_root
+ This.project_path( '../fixme' )
+ end
- # The Runtime Dependencies
- spec.add_runtime_dependency( 'addressable', '~> 2.3' )
+ def fixme_project_path( subtree )
+ fixme_project_root.join( subtree )
+ end
- # The Development Dependencies
- spec.add_development_dependency( 'rake' , '~> 0.9.2.2')
- spec.add_development_dependency( 'minitest' , '~> 3.3.0' )
- spec.add_development_dependency( 'rdoc' , '~> 3.12' )
- spec.add_development_dependency( 'spoon' , '~> 0.0.1' )
- spec.add_development_dependency( 'ffi' , '~> 1.1.1' )
+ def local_fixme_files
+ This.manifest.select { |p| p =~ %r|^tasks/| }
+ end
-end
+ def outdated_fixme_files
+ local_fixme_files.reject do |local|
+ upstream = fixme_project_path( local )
+ Digest::SHA256.file( local ) == Digest::SHA256.file( upstream )
+ end
+ end
-#----------------------------------------------
-# JRuby spec has a few more runtime dependencies
-#----------------------------------------------
-jruby_gemspec = This.gemspec['ruby'].dup
-jruby_gemspec.add_runtime_dependency( 'spoon', '~> 0.0.1' )
-jruby_gemspec.add_runtime_dependency( 'ffi' , '~> 1.1.1' )
-jruby_gemspec.platform = 'java'
-This.gemspec['java'] = jruby_gemspec
+ def fixme_up_to_date?
+ outdated_fixme_files.empty?
+ end
+ desc "See if the fixme tools are outdated"
+ task :outdated => :release_check do
+ if fixme_up_to_date? then
+ puts "Fixme files are up to date."
+ else
+ outdated_fixme_files.each do |f|
+ puts "#{f} is outdated"
+ end
+ end
+ end
-# The name of the gemspec file on disk
-This.gemspec_file = "#{This.name}.gemspec"
+ desc "Update outdated fixme files"
+ task :update => :release_check do
+ if fixme_up_to_date? then
+ puts "Fixme files are already up to date."
+ else
+ puts "Updating fixme files:"
+ outdated_fixme_files.each do |local|
+ upstream = fixme_project_path( local )
+ puts " * #{local}"
+ FileUtils.cp( upstream, local )
+ end
+ puts "Use your git commands as appropriate."
+ end
+ end
+end
+desc "Look for fixmes and report them"
+task :fixme => "fixme:default"
+#------------------------------------------------------------------------------
+# Gem Specification
+#------------------------------------------------------------------------------
# Really this is only here to support those who use bundler
desc "Build the #{This.name}.gemspec file"
task :gemspec do
File.open( This.gemspec_file, "wb+" ) do |f|
- f.write Util.platform_gemspec.to_ruby
+ f.write This.platform_gemspec.to_ruby
end
end
# the gemspec is also a dev artifact and should not be kept around.
-CLOBBER << This.gemspec_file
+CLOBBER << This.gemspec_file.to_s
+
+# .rbc files from ruby 2.0
+CLOBBER << FileList["**/*.rbc"]
# The standard gem packaging task, everyone has it.
require 'rubygems/package_task'
-Gem::PackageTask.new( Util.platform_gemspec ) do
+Gem::PackageTask.new( This.platform_gemspec ) do
# nothing
end
@@ -219,80 +261,11 @@ task :release_check do
end
end
-desc "Create tag v#{This.version}, build and push #{Util.platform_gemspec.full_name} to rubygems.org"
+desc "Create tag v#{This.version}, build and push #{This.platform_gemspec.full_name} to rubygems.org"
task :release => [ :release_check, 'manifest:check', :gem ] do
sh "git commit --allow-empty -a -m 'Release #{This.version}'"
sh "git tag -a -m 'v#{This.version}' v#{This.version}"
sh "git push origin master"
sh "git push origin v#{This.version}"
- sh "gem push pkg/#{Util.platform_gemspec.full_name}.gem"
+ sh "gem push pkg/#{This.platform_gemspec.full_name}.gem"
end
-
-#------------------------------------------------------------------------------
-# Rakefile Support - This is all the guts and utility methods that are
-# necessary to support the above tasks.
-#
-# Lots of Credit for this Rakefile goes to:
-#
-# Ara T. Howard - see the Rakefile in all of his projects -
-# https://github.com/ahoward/
-# Tom Preston Werner - his Rakegem project https://github.com/mojombo/rakegem
-# Seattle.rb - Hoe - cuz it has relly good stuff in there
-#------------------------------------------------------------------------------
-BEGIN {
-
- require 'ostruct'
- require 'rake/clean'
- require 'rubygems' unless defined? Gem
-
- module Util
- def self.version
- [ "lib/#{ This.name }.rb", "lib/#{ This.name }/version.rb" ].each do |v|
- line = File.read( v )[/^\s*VERSION\s*=\s*.*/]
- if line then
- return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
- end
- end
- end
-
- # Partition an rdoc file into sections and return the text of the section
- # as an array of paragraphs
- def self.section_of( file, section_name )
- re = /^=+ (.*)$/
- parts = File.read( file ).split( re )[1..-1]
- parts.map! { |p| p.strip }
-
- sections = Hash.new
- Hash[*parts].each do |k,v|
- sections[k] = v.split("\n\n")
- end
- return sections[section_name]
- end
-
- def self.task_warning( task )
- warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
- end
-
- def self.read_manifest
- abort "You need a Manifest.txt" unless File.readable?( "Manifest.txt" )
- File.readlines( "Manifest.txt" ).map { |l| l.strip }
- end
-
- def self.platform_gemspec
- This.gemspec[This.platform]
- end
- end
-
- # Hold all the metadata about this project
- This = OpenStruct.new
- This.platform = (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
-
- desc = Util.section_of( 'README.rdoc', 'DESCRIPTION')
- This.summary = desc.first
- This.description = desc.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
-
-
- This.exclude_from_manifest = %r/tmp$|\.(git|DS_Store)|^(doc|coverage|pkg)|\.gemspec$|\.swp$|\.jar|\.rvmrc$|~$/
- This.manifest = Util.read_manifest
-
-}
diff --git a/tasks/this.rb b/tasks/this.rb
new file mode 100644
index 0000000..4b310cb
--- /dev/null
+++ b/tasks/this.rb
@@ -0,0 +1,209 @@
+require 'pathname'
+
+# Public: A Class containing all the metadata and utilities needed to manage a
+# ruby project.
+class ThisProject
+ # The name of this project
+ attr_accessor :name
+
+ # The author's name
+ attr_accessor :author
+
+ # The email address of the author(s)
+ attr_accessor :email
+
+ # The homepage of this project
+ attr_accessor :homepage
+
+ # The regex of files to exclude from the manifest
+ attr_accessor :exclude_from_manifest
+
+ # The hash of Gem::Specifications keyed' by platform
+ attr_accessor :gemspecs
+
+ # Public: Initialize ThisProject
+ #
+ # Yields self
+ def initialize(&block)
+ @exclude_from_manifest = %r/\.(git|DS_Store)|^(doc|coverage|pkg|tmp)|Gemfile*|\.(gemspec|swp|jar|bundle|so|rvmrc)$|~$/
+ @gemspecs = Hash.new
+ yield self if block_given?
+ end
+
+ # Public: return the version of ThisProject
+ #
+ # Search the ruby files in the project looking for the one that has the
+ # version string in it. This does not eval any code in the project, it parses
+ # the source code looking for the string.
+ #
+ # Returns a String version
+ def version
+ [ "lib/#{ name }.rb", "lib/#{ name }/version.rb" ].each do |v|
+ path = project_path( v )
+ line = path.read[/^\s*VERSION\s*=\s*.*/]
+ if line then
+ return line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
+ end
+ end
+ end
+
+ # Internal: Return a section of an RDoc file with the given section name
+ #
+ # path - the relative path in the project of the file to parse
+ # section_name - the section out of the file from which to parse data
+ #
+ # Retuns the text of the section as an array of paragrphs.
+ def section_of( file, section_name )
+ re = /^[=#]+ (.*)$/
+ sectional = project_path( file )
+ parts = sectional.read.split( re )[1..-1]
+ parts.map! { |p| p.strip }
+
+ sections = Hash.new
+ Hash[*parts].each do |k,v|
+ sections[k] = v.split("\n\n")
+ end
+ return sections[section_name]
+ end
+
+ # Internal: print out a warning about the give task
+ def task_warning( task )
+ warn "WARNING: '#{task}' tasks are not defined. Please run 'rake develop'"
+ end
+
+ # Internal: Return the full path to the file that is relative to the project
+ # root.
+ #
+ # path - the relative path of the file from the project root
+ #
+ # Returns the Pathname of the file
+ def project_path( *relative_path )
+ project_root.join( *relative_path )
+ end
+
+ # Internal: The absolute path of this file
+ #
+ # Returns the Pathname of this file.
+ def this_file_path
+ Pathname.new( __FILE__ ).expand_path
+ end
+
+ # Internal: The root directory of this project
+ #
+ # This is defined as being the directory that is in the path of this project
+ # that has the first Rakefile
+ #
+ # Returns the Pathname of the directory
+ def project_root
+ this_file_path.ascend do |p|
+ rakefile = p.join( 'Rakefile' )
+ return p if rakefile.exist?
+ end
+ end
+
+ # Internal: Returns the contents of the Manifest.txt file as an array
+ #
+ # Returns an Array of strings
+ def manifest
+ manifest_file = project_path( "Manifest.txt" )
+ abort "You need a Manifest.txt" unless manifest_file.readable?
+ manifest_file.readlines.map { |l| l.strip }
+ end
+
+ # Internal: Return the files that define the extensions
+ #
+ # Returns an Array
+ def extension_conf_files
+ manifest.grep( /extconf.rb\Z/ )
+ end
+
+ # Internal: Returns the gemspace associated with the current ruby platform
+ def platform_gemspec
+ gemspecs[platform]
+ end
+
+ def core_gemspec
+ Gem::Specification.new do |spec|
+ spec.name = name
+ spec.version = version
+ spec.author = author
+ spec.email = email
+ spec.homepage = homepage
+
+ spec.summary = summary
+ spec.description = description
+
+ spec.files = manifest
+ spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
+ spec.test_files = spec.files.grep(/^spec/)
+
+ spec.extra_rdoc_files += spec.files.grep(/(txt|rdoc|md)$/)
+ spec.rdoc_options = [ "--main" , 'README.md',
+ "--markup", "tomdoc" ]
+ end
+ end
+
+ # Internal: Return the gemspec for the ruby platform
+ def ruby_gemspec( core = core_gemspec, &block )
+ yielding_gemspec( 'ruby', core, &block )
+ end
+
+ # Internal: Return the gemspec for the jruby platform
+ def java_gemspec( core = core_gemspec, &block )
+ yielding_gemspec( 'java', core, &block )
+ end
+
+ # Internal: give an initial spec and a key, create a new gemspec based off of
+ # it.
+ #
+ # This will force the new gemspecs 'platform' to be that of the key, since the
+ # only reason you would have multiple gemspecs at this point is to deal with
+ # different platforms.
+ def yielding_gemspec( key, core )
+ spec = gemspecs[key] ||= core.dup
+ spec.platform = key
+ yield spec if block_given?
+ return spec
+ end
+
+ # Internal: Set the recovery gem development dependency
+ #
+ # These are dynamically set since they cannot be hard coded as there is
+ # no way to ship them correctly in the gemspec
+ #
+ # Returns nothing.
+ def set_coverage_gem
+ if RUBY_VERSION < "1.9.0"
+ platform_gemspec.add_development_dependency( 'rcov', '~> 1.0.0' )
+ else
+ platform_gemspec.add_development_dependency( 'simplecov', '~> 0.7.1' )
+ end
+ end
+
+ # Internal: Return the platform of ThisProject at the current moment in time.
+ def platform
+ (RUBY_PLATFORM == "java") ? 'java' : Gem::Platform::RUBY
+ end
+
+ # Internal: Return the DESCRIPTION section of the README.rdoc file
+ def description_section
+ section_of( 'README.md', 'DESCRIPTION')
+ end
+
+ # Internal: Return the summary text from the README
+ def summary
+ description_section.first
+ end
+
+ # Internal: Return the full description text from the READEM
+ def description
+ description_section.join(" ").tr("\n", ' ').gsub(/[{}]/,'').gsub(/\[[^\]]+\]/,'') # strip rdoc
+ end
+
+ # Internal: The path to the gemspec file
+ def gemspec_file
+ project_path( "#{ name }.gemspec" )
+ end
+end
+
+This = ThisProject.new
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-launchy.git
More information about the Pkg-ruby-extras-commits
mailing list