launchy 2.0.3-java → 2.0.4-java

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,6 @@
4
4
  doc/
5
5
  coverage/
6
6
  pkg/
7
+ *.gemspec
8
+ Gemfile*
9
+ .rvmrc
data/HISTORY CHANGED
@@ -1,4 +1,11 @@
1
1
  = Launchy Changlog
2
+ == Version 2.0.4 - 2011-07-23
3
+
4
+ * Fix windows 'start' commandline (copiousfreetime/launchy#5)
5
+ * Add capability to open local files with no file: scheme present (copiousfreetime/launchy#29)
6
+ * Added 'rake how_to_contribute' task (copiousfreetime/launchy#30)
7
+ * Make better decisions on when to do shell escaping (copiousfreetime/launchy#31)
8
+ * Switch to Addressable::URI so UTF-8 urls may be parsed. (copiousfreetime/launchy#32)
2
9
 
3
10
  == Version 2.0.3 - 2011-07-17
4
11
 
data/README CHANGED
@@ -47,6 +47,38 @@ An example of using the public API:
47
47
 
48
48
  Launchy.open( "http://www.ruby-lang.org" )
49
49
 
50
+ == UPGRADING
51
+
52
+ The previously published version of Launchy was 0.4.0. There have been so many
53
+ changes, and a mistaken tag at 1.0.0, that I have decided to bump all the way
54
+ to 2.0.x.
55
+
56
+ I have attempted to keep backward compatibility with the previous examples. The
57
+ previous API examples of:
58
+
59
+ Launchy::Browser.run("http://www.ruby-lang.org/")
60
+
61
+ and
62
+
63
+ Launchy::Browser.new.visit("http://www.ruby-lang.org/")
64
+
65
+ will still work, and you will get a deprecation notice, along with the line
66
+ of code you should probably update. For example, this is what would print out
67
+ in the github gem if it was updated to use 2.0.x but not use the supported API.
68
+
69
+ % gh home
70
+ WARNING: You made a call to a deprecated Launchy API. This call should be changed to 'Launchy.open( uri )'
71
+ WARNING: I think I was able to find the location that needs to be fixed. Please go look at:
72
+ WARNING:
73
+ WARNING: /Users/jeremy/.rvm/gems/ruby-1.8.7-p334/gems/github-0.6.2/lib/commands/helpers.rb:275:in `open'
74
+ WARNING: helper :open do |url|
75
+ WARNING: has_launchy? proc {
76
+ WARNING: Launchy::Browser.new.visit url
77
+ WARNING: }
78
+ WARNING: end
79
+ WARNING:
80
+ WARNING: If this is not the case, please file a bug. Please file a bug at https://github.com/copiousfreetime/launchy/issues/new
81
+
50
82
  == ISC LICENSE
51
83
 
52
84
  http://opensource.org/licenses/isc-license.txt
data/Rakefile CHANGED
@@ -4,9 +4,11 @@
4
4
  #++
5
5
 
6
6
  begin
7
+ USING_BONES_VERSION = '3.7.0'
7
8
  require 'bones'
8
9
  rescue LoadError
9
- abort '### Please install the "bones" gem ###'
10
+ load 'tasks/contribute.rake'
11
+ Rake.application.invoke_task( :help )
10
12
  end
11
13
 
12
14
  task :default => 'test:run'
@@ -42,18 +44,27 @@ _
42
44
 
43
45
  if RUBY_PLATFORM == "java" then
44
46
  depend_on "spoon" , "~> 0.0.1"
47
+ depend_on 'ffi' , "~> 1.0.9"
45
48
  gem.extras = { :platform => Gem::Platform.new( "java" ) }
46
49
  end
47
50
 
51
+ depend_on "addressable", "~> 2.2.6"
52
+
48
53
  depend_on "rake" , "~> 0.9.2", :development => true
49
54
  depend_on "minitest" , "~> 2.3.1", :development => true
50
- depend_on 'bones' , "~> 3.7.0", :development => true
55
+ depend_on 'bones' , "~> #{USING_BONES_VERSION}", :development => true
51
56
  depend_on 'bones-rcov', "~> 1.0.1", :development => true
52
57
  depend_on 'rcov' , "~> 0.9.9", :development => true
53
58
  depend_on "spoon" , "~> 0.0.1", :development => true
59
+ depend_on 'ffi' , "~> 1.0.9", :development => true
54
60
 
55
61
  test.files = FileList["spec/**/*_spec.rb"]
56
62
  test.opts << "-w -Ilib:spec"
57
63
 
58
64
  rcov.opts << "--exclude gems"
59
65
  }
66
+
67
+ # Sorry Tim, I need to manage my own bones version
68
+ ::Bones.config.gem._spec.dependencies.delete_if do |d|
69
+ d.name == 'bones' and d.requirement.to_s =~ /^>=/
70
+ end
data/lib/launchy.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'uri'
1
+ require 'addressable/uri'
2
2
 
3
3
  #
4
4
  # The entry point into Launchy. This is the sole supported public API.
@@ -25,8 +25,8 @@ module Launchy
25
25
  def open(uri, options = {} )
26
26
  begin
27
27
  extract_global_options( options )
28
- uri = URI.parse( uri )
29
- app = Launchy::Application.for_scheme( uri )
28
+ uri = Addressable::URI.parse( uri )
29
+ app = Launchy::Application.handling( uri )
30
30
  app.new.open( uri, options )
31
31
  rescue Exception => e
32
32
  msg = "Failure in opening #{uri} with options #{options.inspect}: #{e}"
@@ -9,39 +9,19 @@ module Launchy
9
9
  # 1. A constructor taking no parameters
10
10
  # 2. An instance method 'open' taking a string or URI as the first parameter and a
11
11
  # hash as the second
12
- # 3. A class method 'schemes' that returns an array of Strings containing the
13
- # schemes that the Application will handle
12
+ # 3. A class method 'handles?' that takes a String and returns true if that
13
+ # class can handle the input.
14
14
  class Application
15
15
  extend DescendantTracker
16
16
 
17
17
  class << self
18
+ # Find the application that handles the given uri.
18
19
  #
19
- # The list of all the schemes all the applications know
20
- #
21
- def scheme_list
22
- children.collect { |a| a.schemes }.flatten.sort
23
- end
24
-
25
- #
26
- # if this application handles the given scheme
27
- #
28
- def handles?( scheme )
29
- schemes.include?( scheme )
30
- end
31
-
32
- #
33
- # Find the application that handles the given scheme. May take either a
34
- # String or something that responds_to?( :scheme )
35
- #
36
- def for_scheme( scheme )
37
- if scheme.respond_to?( :scheme ) then
38
- scheme = scheme.scheme
39
- end
40
-
41
- klass = find_child( :handles?, scheme )
20
+ # returns the Class that can handle the uri
21
+ def handling( uri )
22
+ klass = find_child( :handles?, uri )
42
23
  return klass if klass
43
-
44
- raise SchemeNotFoundError, "No application found to handle scheme '#{scheme}'. Known schemes: #{scheme_list.join(", ")}"
24
+ raise ApplicationNotFoundError, "No application found to handle '#{uri}'"
45
25
  end
46
26
 
47
27
  #
@@ -7,12 +7,17 @@ class Launchy::Application
7
7
  %w[ http https ftp file ]
8
8
  end
9
9
 
10
+ def self.handles?( uri )
11
+ return true if schemes.include?( uri.scheme )
12
+ return true if File.exist?( uri.path )
13
+ end
14
+
10
15
  def windows_app_list
11
- [ 'start "Launchy" /d']
16
+ [ 'start /b' ]
12
17
  end
13
18
 
14
19
  def cygwin_app_list
15
- [ 'cmd /C start "Launchy" /d' ]
20
+ [ 'cmd /C start /b' ]
16
21
  end
17
22
 
18
23
  def darwin_app_list
@@ -34,18 +34,19 @@ module Launchy::Detect
34
34
  #
35
35
  # cut it down to just the shell commands that will be passed to exec or
36
36
  # posix_spawn. The cmd argument is split according to shell rules and the
37
- # args are escaped according to shell rules.
37
+ # args are not escaped because they whole set is passed to system as *args
38
+ # and in that case system shell escaping rules are not done.
38
39
  #
39
40
  def shell_commands( cmd, args )
40
41
  cmdline = [ cmd.shellsplit ]
41
- cmdline << args.flatten.collect{ |a| a.to_s.shellescape }
42
+ cmdline << args.flatten.collect{ |a| a.to_s }
42
43
  return commandline_normalize( cmdline )
43
44
  end
44
45
 
45
46
  def commandline_normalize( cmdline )
46
47
  c = cmdline.flatten!
47
48
  c = c.find_all { |a| (not a.nil?) and ( a.size > 0 ) }
48
- Launchy.log "ARGV => #{c.inspect}"
49
+ Launchy.log "commandline_normalized => #{c.join(' ')}"
49
50
  return c
50
51
  end
51
52
 
@@ -69,16 +70,20 @@ module Launchy::Detect
69
70
  class Windows < Runner
70
71
 
71
72
  def all_args( cmd, *args )
72
- [ 'cmd', '/c', *shell_commands( cmd, *args ) ]
73
+ args = [ 'cmd', '/c', *shell_commands( cmd, *args ) ]
74
+ Launchy.log "Windows: all_args => #{args.inspect}"
75
+ return args
73
76
  end
74
77
 
75
78
  def dry_run( cmd, *args )
76
79
  all_args( cmd, *args ).join(" ")
77
80
  end
78
81
 
82
+ # escape the reserved shell characters in windows command shell
83
+ # http://technet.microsoft.com/en-us/library/cc723564.aspx
79
84
  def shell_commands( cmd, *args )
80
- cmdline = [ cmd ]
81
- cmdline << args.flatten.collect { |a| a.to_s.gsub("&", "^&") }
85
+ cmdline = [ cmd.shellsplit ]
86
+ cmdline << args.flatten.collect { |a| a.to_s.gsub(/([&|()<>^])/, "^\\1") }
82
87
  return commandline_normalize( cmdline )
83
88
  end
84
89
 
data/lib/launchy/error.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Launchy
2
2
  class Error < ::StandardError; end
3
- class SchemeNotFoundError < Error; end
3
+ class ApplicationNotFoundError < Error; end
4
4
  end
@@ -1,5 +1,5 @@
1
1
  module Launchy
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
 
4
4
  module Version
5
5
 
@@ -1,17 +1,17 @@
1
1
  require 'spec_helper'
2
- require 'mock_scheme'
2
+ require 'mock_application'
3
3
 
4
4
  class JunkApp < Launchy::Application
5
- def self.schemes
6
- %w[ junk ]
5
+ def self.handles?( uri )
6
+ uri.scheme == "junk"
7
7
  end
8
8
  end
9
9
 
10
10
  describe Launchy::Application do
11
11
  it 'registers inherited classes' do
12
12
  class Junk2App < Launchy::Application
13
- def self.schemes
14
- %w[ junk2 ]
13
+ def self.handles?( uri )
14
+ uri.scheme == "junk2"
15
15
  end
16
16
  end
17
17
  Launchy::Application.children.must_include( Junk2App )
@@ -20,12 +20,14 @@ describe Launchy::Application do
20
20
 
21
21
  it "can find an app" do
22
22
  Launchy::Application.children.must_include( JunkApp )
23
- Launchy::Application.scheme_list.size.must_equal 7
24
- Launchy::Application.for_scheme( "junk" ).must_equal( JunkApp )
23
+ Launchy::Application.children.size.must_equal 3
24
+ uri = Addressable::URI.parse( "junk:///foo" )
25
+ Launchy::Application.handling( uri ).must_equal( JunkApp )
25
26
  end
26
27
 
27
28
  it "raises an error if an application cannot be found for the given scheme" do
28
- lambda { Launchy::Application.for_scheme( "foo" ) }.must_raise( Launchy::SchemeNotFoundError )
29
+ uri = Addressable::URI.parse( "foo:///bar" )
30
+ lambda { Launchy::Application.handling( uri ) }.must_raise( Launchy::ApplicationNotFoundError )
29
31
  end
30
32
 
31
33
  it "can find open or curl" do
@@ -12,9 +12,9 @@ describe Launchy::Application::Browser do
12
12
  ENV.delete( 'KDE_FULL_SESSION' )
13
13
  end
14
14
 
15
- { 'windows' => 'start "Launchy" /d' ,
15
+ { 'windows' => 'start /b' ,
16
16
  'darwin' => '/usr/bin/open',
17
- 'cygwin' => 'cmd /C start "Launchy" /d',
17
+ 'cygwin' => 'cmd /C start /b',
18
18
 
19
19
  # when running these tests on a linux box, this test will fail
20
20
  'linux' => nil }.each do |host_os, cmdline|
@@ -35,5 +35,10 @@ describe Launchy::Application::Browser do
35
35
  args.must_equal []
36
36
  end
37
37
  end
38
+
39
+ it "handles a file on the file system when there is no file:// scheme" do
40
+ uri = Addressable::URI.parse( __FILE__ )
41
+ Launchy::Application::Browser.handles?( uri ).must_equal true
42
+ end
38
43
  end
39
44
 
@@ -62,18 +62,37 @@ describe Launchy::Detect::Runner do
62
62
  cmd.must_equal 'cmd /c not-really http://example.com'
63
63
  end
64
64
 
65
- it "Windows escapes '&' in urls" do
66
- win = Launchy::Detect::Runner::Windows.new
67
- win.all_args( "not-really", [ @test_url ] ).must_equal [ 'cmd', '/c', 'not-really', 'http://example.com/?foo=bar^&baz=wibble' ]
65
+ %w[ & | ( ) < > ^ ].each do |reserved_char|
66
+ it "Windows escapes '#{reserved_char}' in urls" do
67
+ win = Launchy::Detect::Runner::Windows.new
68
+ parts = [ 'http://example.com/?foo=bar', 'baz=wibble' ]
69
+ url = parts.join( reserved_char )
70
+ output_url = parts.join( "^#{reserved_char}" )
71
+
72
+ win.all_args( "not-really", [ url ] ).must_equal [ 'cmd', '/c', 'not-really', output_url ]
68
73
 
69
- cmd = win.dry_run( "not-really", [ @test_url ] )
70
- cmd.must_equal 'cmd /c not-really http://example.com/?foo=bar^&baz=wibble'
74
+ cmd = win.dry_run( "not-really", [ url ] )
75
+ cmd.must_equal "cmd /c not-really #{output_url}"
76
+ end
71
77
  end
72
78
 
73
- it "Jruby escapes '&' in urls" do
79
+ it "Jruby doesnot escapes '&' in urls" do
74
80
  jruby = Launchy::Detect::Runner::Jruby.new
75
81
  cmd = jruby.dry_run( "not-really", [ @test_url ])
76
- cmd.must_equal 'not-really http://example.com/\\?foo\\=bar\\&baz\\=wibble'
82
+ cmd.must_equal 'not-really http://example.com/?foo=bar&baz=wibble'
83
+ end
84
+
85
+ it "does not escape %38 items in urls" do
86
+ l = Launchy::Detect::Runner::Forkable.new
87
+ cmd = l.dry_run( "not-really", [ "http://ja.wikipedia.org/wiki/%E3%81%82" ] )
88
+ cmd.must_equal( 'not-really http://ja.wikipedia.org/wiki/%E3%81%82' )
89
+ end
90
+
91
+ it "can launch a utf8 url" do
92
+ url = "http://ja.wikipedia.org/wiki/あ"
93
+ l = Launchy::Detect::Runner::Forkable.new
94
+ cmd = l.dry_run( "not-really", [ url ] )
95
+ cmd.must_equal( "not-really #{url}" )
77
96
  end
78
97
 
79
98
  end
@@ -0,0 +1,9 @@
1
+ class MockApplication < Launchy::Application
2
+ def self.schemes
3
+ %w[ mock mockother ]
4
+ end
5
+
6
+ def self.handles?( uri )
7
+ schemes.include?( uri.scheme )
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ namespace :bundle do
2
+
3
+ file 'Gemfile' => [ 'gem:spec' ] do
4
+ File.open( 'Gemfile', 'w+' ) do |f|
5
+ f.puts 'source "http://rubygems.org"'
6
+ f.puts 'gemspec'
7
+ end
8
+ end
9
+
10
+ desc "Create a bundler Gemfile"
11
+ task :gemfile => 'Gemfile'
12
+
13
+ end
@@ -0,0 +1,36 @@
1
+ desc "Instructions on how to contribute to launchy"
2
+ task :help do
3
+ abort <<-_banner
4
+ -----------------------------------------------------------------------
5
+ I see you are wanting to do some development on launchy. You will
6
+ need to install the 'bones' gem first.
7
+
8
+ % gem install bones -v #{USING_BONES_VERSION}
9
+
10
+ The easiest way to start after that is with the
11
+ 'install:dependencies' task:
12
+
13
+ % rake gem:install_dependencies
14
+
15
+ If you use bundler, then you will need to first create the Gemfile
16
+ and then run 'bundle install':
17
+
18
+ % rake bundle:gemfile
19
+ % bundle install
20
+
21
+ Now you are ready to work on launchy. Please submit bugs and pull
22
+ requests to:
23
+
24
+ https://github.com/copiousfreetime/launchy
25
+
26
+ Thanks!
27
+
28
+ -jeremy
29
+ -----------------------------------------------------------------------
30
+ _banner
31
+ end
32
+
33
+ desc "(Alias for 'help') Instructions on how to contribute to launchy"
34
+ task 'how_to_contribute' => :help
35
+ desc "(Alias for 'help') Instructions on how to contribute to launchy"
36
+ task '==> I WANT TO CONTRIBUTE <==' => :help
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: launchy
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.3
5
+ version: 2.0.4
6
6
  platform: java
7
7
  authors:
8
8
  - Jeremy Hinegardner
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-17 00:00:00 -06:00
13
+ date: 2011-07-23 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -25,82 +25,104 @@ dependencies:
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: ffi
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: 0.9.2
36
- type: :development
35
+ version: 1.0.9
36
+ type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: minitest
39
+ name: addressable
40
40
  prerelease: false
41
41
  requirement: &id003 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: 2.3.1
47
- type: :development
46
+ version: 2.2.6
47
+ type: :runtime
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: bones
50
+ name: rake
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ~>
56
56
  - !ruby/object:Gem::Version
57
- version: 3.7.0
57
+ version: 0.9.2
58
58
  type: :development
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: bones-rcov
61
+ name: minitest
62
62
  prerelease: false
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 1.0.1
68
+ version: 2.3.1
69
69
  type: :development
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: rcov
72
+ name: bones
73
73
  prerelease: false
74
74
  requirement: &id006 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
78
78
  - !ruby/object:Gem::Version
79
- version: 0.9.9
79
+ version: 3.7.0
80
80
  type: :development
81
81
  version_requirements: *id006
82
82
  - !ruby/object:Gem::Dependency
83
- name: spoon
83
+ name: bones-rcov
84
84
  prerelease: false
85
85
  requirement: &id007 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
89
89
  - !ruby/object:Gem::Version
90
- version: 0.0.1
90
+ version: 1.0.1
91
91
  type: :development
92
92
  version_requirements: *id007
93
93
  - !ruby/object:Gem::Dependency
94
- name: bones
94
+ name: rcov
95
95
  prerelease: false
96
96
  requirement: &id008 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ">="
99
+ - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 3.7.0
101
+ version: 0.9.9
102
102
  type: :development
103
103
  version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: spoon
106
+ prerelease: false
107
+ requirement: &id009 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: 0.0.1
113
+ type: :development
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: ffi
117
+ prerelease: false
118
+ requirement: &id010 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ~>
122
+ - !ruby/object:Gem::Version
123
+ version: 1.0.9
124
+ type: :development
125
+ version_requirements: *id010
104
126
  description: |
105
127
  Launchy is helper class for launching cross-platform applications in a
106
128
  fire and forget manner.
@@ -152,10 +174,12 @@ files:
152
174
  - spec/detect/ruby_engine_spec.rb
153
175
  - spec/detect/runner_spec.rb
154
176
  - spec/launchy_spec.rb
155
- - spec/mock_scheme.rb
177
+ - spec/mock_application.rb
156
178
  - spec/spec_helper.rb
157
179
  - spec/tattle-host-os.yaml
158
180
  - spec/version_spec.rb
181
+ - tasks/bundler.rake
182
+ - tasks/contribute.rake
159
183
  has_rdoc: true
160
184
  homepage: http://www.copiousfreetime.org/projects/launchy
161
185
  licenses: []
data/spec/mock_scheme.rb DELETED
@@ -1,5 +0,0 @@
1
- class MockScheme < Launchy::Application
2
- def self.schemes
3
- %w[ mock mockother ]
4
- end
5
- end