launchy 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +28 -0
- data/.gitignore +6 -0
- data/HISTORY +90 -0
- data/LICENSE +16 -0
- data/NOTES +1 -0
- data/README +53 -0
- data/Rakefile +58 -0
- data/bin/launchy +4 -0
- data/lib/launchy.rb +119 -0
- data/lib/launchy/application.rb +81 -0
- data/lib/launchy/applications/browser.rb +68 -0
- data/lib/launchy/cli.rb +70 -0
- data/lib/launchy/descendant_tracker.rb +49 -0
- data/lib/launchy/detect.rb +10 -0
- data/lib/launchy/detect/host_os.rb +31 -0
- data/lib/launchy/detect/host_os_family.rb +71 -0
- data/lib/launchy/detect/nix_desktop_environment.rb +60 -0
- data/lib/launchy/detect/ruby_engine.rb +78 -0
- data/lib/launchy/detect/runner.rb +96 -0
- data/lib/launchy/error.rb +4 -0
- data/lib/launchy/os_family.rb +8 -0
- data/lib/launchy/version.rb +18 -0
- data/spec/application_spec.rb +41 -0
- data/spec/detect/host_os_family_spec.rb +40 -0
- data/spec/detect/host_os_spec.rb +19 -0
- data/spec/detect/nix_desktop_environment_spec.rb +13 -0
- data/spec/detect/ruby_engine_spec.rb +37 -0
- data/spec/launchy_spec.rb +42 -0
- data/spec/mock_scheme.rb +5 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/tattle-host-os.yaml +427 -0
- data/spec/version_spec.rb +10 -0
- metadata +170 -0
data/.autotest
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# vim: ft=ruby
|
2
|
+
|
3
|
+
require 'autotest/growl'
|
4
|
+
|
5
|
+
Autotest.add_hook :initialize do |at|
|
6
|
+
|
7
|
+
at.libs = "lib:spec"
|
8
|
+
at.testlib = 'minitest/autorun'
|
9
|
+
|
10
|
+
at.add_exception 'coverage.info'
|
11
|
+
at.add_exception 'coverage'
|
12
|
+
at.add_exception '.git'
|
13
|
+
|
14
|
+
at.clear_mappings
|
15
|
+
|
16
|
+
at.add_mapping(%r|^spec/.*_spec\.rb$|) do |filename, _|
|
17
|
+
filename
|
18
|
+
end
|
19
|
+
|
20
|
+
at.add_mapping(%r|^lib/(.*)\.rb$|) do |_, match|
|
21
|
+
[ "test/#{match[1]}_spec.rb" ]
|
22
|
+
end
|
23
|
+
|
24
|
+
at.add_mapping(%r|^spec/spec_helper\.rb|) do
|
25
|
+
at.files_matching( %r|^spec/.*_spec\.rb| )
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/HISTORY
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
= Launchy Changlog
|
2
|
+
|
3
|
+
== Version 2.0.0 - 2011-07-16
|
4
|
+
|
5
|
+
* Almost a complete rewrite
|
6
|
+
* JRuby Support
|
7
|
+
* Organization is such that it will be easier to add additional applications
|
8
|
+
* Windows behavior possibly fixed, again
|
9
|
+
|
10
|
+
== Version 1.0.0 - 2011-03-17
|
11
|
+
|
12
|
+
* Add JRuby support (Stephen Judkins)
|
13
|
+
* Remove unused Paths module
|
14
|
+
* Switch to using bones
|
15
|
+
* Switch to use minitest
|
16
|
+
* NOTE, this version was never released.
|
17
|
+
|
18
|
+
== Version 0.4.0 - 2011-01-27
|
19
|
+
|
20
|
+
* Add support for file:/// schema (postmodern)
|
21
|
+
|
22
|
+
== Version 0.3.7 - 2010-07-19
|
23
|
+
|
24
|
+
* Fix launchy on windows (mikefarmer)
|
25
|
+
|
26
|
+
== Version 0.3.6 - 2010-02-22
|
27
|
+
|
28
|
+
* add a test:spec task to run tests without rcov support
|
29
|
+
* added 'testing' os family for running tests
|
30
|
+
|
31
|
+
== Version 0.3.5 - 2009-12-17
|
32
|
+
|
33
|
+
* clarify that launchy is under ISC license
|
34
|
+
* fix missing data file in released gem needed for running specs
|
35
|
+
|
36
|
+
== Version 0.3.3 - 2009-02-19
|
37
|
+
|
38
|
+
* pass command line as discrete items to system() to avoid string
|
39
|
+
interpretation by the system shell. (Suraj N. Kurapati)
|
40
|
+
* rework project layout and tasks
|
41
|
+
|
42
|
+
== Version 0.3.2 - 2008-05-21
|
43
|
+
|
44
|
+
* detect aix and mingw as known operating systems.
|
45
|
+
|
46
|
+
== Version 0.3.1 - 2007-09-08
|
47
|
+
|
48
|
+
* finalize the command line wrapper around the launchy library.
|
49
|
+
* added more tests
|
50
|
+
|
51
|
+
== Version 0.3.0 - 2007-08-30
|
52
|
+
|
53
|
+
* reorganize the code structure, removing Spawnable namespace
|
54
|
+
* removed 'do_magic' method, changed it to 'open'
|
55
|
+
* added override environment variable LAUNCHY_HOST_OS for testing
|
56
|
+
* fix broken cygwin support [Bug #13472]
|
57
|
+
|
58
|
+
== Version 0.2.1 - 2007-08-18
|
59
|
+
|
60
|
+
* fix inability to find windows executables [Bug #13132]
|
61
|
+
|
62
|
+
== Version 0.2.0 - 2007-08-11
|
63
|
+
|
64
|
+
* rework browser finding
|
65
|
+
* manual override with LAUNCHY_BROWSER environment variable
|
66
|
+
* on *nix use desktop application launcher with fallback to list of browsers
|
67
|
+
* On windows, switch to 'start' command and remove dependency on win32-process
|
68
|
+
* removed win32 gem
|
69
|
+
* Add debug output by setting LAUNCHY_DEBUG environment variable to 'true'
|
70
|
+
|
71
|
+
== Version 0.1.2 - 2007-08-11
|
72
|
+
|
73
|
+
* forked child exits without calling at_exit handlers
|
74
|
+
|
75
|
+
== Version 0.1.1
|
76
|
+
|
77
|
+
* fixed rubyforge task to release mswin32 gem also
|
78
|
+
|
79
|
+
== Version 0.1.0
|
80
|
+
|
81
|
+
* Initial public release
|
82
|
+
* switched to using fork to spawn process and require 'win32/process' if on windows
|
83
|
+
|
84
|
+
== Version 0.0.2
|
85
|
+
|
86
|
+
* First attempt at using systemu to spawn processes
|
87
|
+
|
88
|
+
== Version 0.0.1
|
89
|
+
|
90
|
+
* Initially working release
|
data/LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
ISC LICENSE - http://opensource.org/licenses/isc-license.txt
|
2
|
+
|
3
|
+
Copyright (c) 2007-2011 Jeremy Hinegardner
|
4
|
+
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
16
|
+
|
data/NOTES
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* Allow for new tab/ new window for opening a browser
|
data/README
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
== launchy
|
2
|
+
|
3
|
+
* Homepage[http://www.copiousfreetime.org/projects/launchy/]
|
4
|
+
* {Github Project}[http://github.com/copiousfreetime/launchy]
|
5
|
+
* email jeremy at hinegardner dot org
|
6
|
+
|
7
|
+
== DESCRIPTION
|
8
|
+
|
9
|
+
Launchy is helper class for launching cross-platform applications in a
|
10
|
+
fire and forget manner.
|
11
|
+
|
12
|
+
There are application concepts (browser, email client, etc) that are
|
13
|
+
common across all platforms, and they may be launched differently on
|
14
|
+
each platform. Launchy is here to make a common approach to launching
|
15
|
+
external application from within ruby programs.
|
16
|
+
|
17
|
+
== FEATURES
|
18
|
+
|
19
|
+
Currently only launching a browser is supported.
|
20
|
+
|
21
|
+
== SYNOPSIS
|
22
|
+
|
23
|
+
From within your ruby code you can trust launchy to do the right thing:
|
24
|
+
|
25
|
+
Launchy.open("http://www.ruby-lang.org/")
|
26
|
+
|
27
|
+
Or, if you want to launch the application yourself:
|
28
|
+
|
29
|
+
Launchy::Browser.open("http://www.ruby-lang.org/")
|
30
|
+
|
31
|
+
OR
|
32
|
+
|
33
|
+
Launchy::Browser.new.open("http://www.ruby-lang.org/")
|
34
|
+
|
35
|
+
== ISC LICENSE
|
36
|
+
|
37
|
+
http://opensource.org/licenses/isc-license.txt
|
38
|
+
|
39
|
+
Copyright (c) 2007-2011 Jeremy Hinegardner
|
40
|
+
|
41
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
42
|
+
purpose with or without fee is hereby granted, provided that the above
|
43
|
+
copyright notice
|
44
|
+
and this permission notice appear in all copies.
|
45
|
+
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
47
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
48
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
49
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
50
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
51
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
52
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2007 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'bones'
|
8
|
+
rescue LoadError
|
9
|
+
abort '### Please install the "bones" gem ###'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => 'test:run'
|
13
|
+
task 'gem:release' => 'test:run'
|
14
|
+
|
15
|
+
$:.unshift( "lib" )
|
16
|
+
require 'launchy/version'
|
17
|
+
|
18
|
+
Bones {
|
19
|
+
name "launchy"
|
20
|
+
authors "Jeremy Hinegardner"
|
21
|
+
email "jeremy@copiousfreetime.org"
|
22
|
+
url 'http://www.copiousfreetime.org/projects/launchy'
|
23
|
+
version Launchy::VERSION
|
24
|
+
|
25
|
+
ruby_opts %w[ -W0 -rubygems ]
|
26
|
+
readme_file 'README'
|
27
|
+
ignore_file '.gitignore'
|
28
|
+
history_file 'HISTORY'
|
29
|
+
|
30
|
+
rdoc.include << "README" << "HISTORY" << "LICENSE"
|
31
|
+
|
32
|
+
summary 'Launchy is helper class for launching cross-platform applications in a fire and forget manner.'
|
33
|
+
description <<_
|
34
|
+
Launchy is helper class for launching cross-platform applications in a
|
35
|
+
fire and forget manner.
|
36
|
+
|
37
|
+
There are application concepts (browser, email client, etc) that are
|
38
|
+
common across all platforms, and they may be launched differently on
|
39
|
+
each platform. Launchy is here to make a common approach to launching
|
40
|
+
external application from within ruby programs.
|
41
|
+
_
|
42
|
+
|
43
|
+
if RUBY_PLATFORM == "java" then
|
44
|
+
depend_on "spoon" , "~> 0.0.1"
|
45
|
+
gem.extras = { :platform => Gem::Platform.new( "java" ) }
|
46
|
+
end
|
47
|
+
|
48
|
+
depend_on "rake" , "~> 0.9.2", :development => true
|
49
|
+
depend_on "minitest", "~> 2.3.1", :development => true
|
50
|
+
depend_on 'bones' , "~> 3.7.0", :development => true
|
51
|
+
|
52
|
+
if defined?( RUBY_ENGINE ) and RUBY_ENGINE == "jruby" then
|
53
|
+
depend_on 'spoon' , "~> 0.0.1"
|
54
|
+
end
|
55
|
+
|
56
|
+
test.files = FileList["spec/**/*_spec.rb"]
|
57
|
+
test.opts << "-w -Ilib:spec"
|
58
|
+
}
|
data/bin/launchy
ADDED
data/lib/launchy.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Top level entry point into Launchy. Almost everyone will just use the single
|
5
|
+
# call:
|
6
|
+
#
|
7
|
+
# Launchy.open( uri, options = {} )
|
8
|
+
#
|
9
|
+
# The currently defined global options are:
|
10
|
+
#
|
11
|
+
# :debug Turn on debugging output
|
12
|
+
# :application Explicitly state what application class is going to be used
|
13
|
+
# :host_os Explicitly state what host operating system to pretend to be
|
14
|
+
# :ruby_engine Explicitly state what ruby engine to pretend to be under
|
15
|
+
#
|
16
|
+
# Other options may be used, and those will be passed directly to the
|
17
|
+
# application class
|
18
|
+
#
|
19
|
+
module Launchy
|
20
|
+
|
21
|
+
class << self
|
22
|
+
#
|
23
|
+
# Convenience method to launch an item
|
24
|
+
#
|
25
|
+
def open(uri, options = {} )
|
26
|
+
begin
|
27
|
+
extract_global_options( options )
|
28
|
+
uri = URI.parse( uri )
|
29
|
+
if app = Launchy::Application.for_scheme( uri ) then
|
30
|
+
app.new.open( uri, options )
|
31
|
+
else
|
32
|
+
msg = "Unable to launch #{uri} with options #{options.inspect}"
|
33
|
+
Launchy.log "#{self.name} : #{msg}"
|
34
|
+
$stderr.puts msg
|
35
|
+
end
|
36
|
+
rescue Exception => e
|
37
|
+
msg = "Failure in opening #{uri} with options #{options.inspect}: #{e}"
|
38
|
+
Launchy.log "#{self.name} : #{msg}"
|
39
|
+
e.backtrace.each do |bt|
|
40
|
+
Launchy.log bt
|
41
|
+
end
|
42
|
+
$stderr.puts msg
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def reset_global_options
|
47
|
+
Launchy.debug = false
|
48
|
+
Launchy.application = nil
|
49
|
+
Launchy.host_os = nil
|
50
|
+
Launchy.ruby_engine = nil
|
51
|
+
Launchy.dry_run = false
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_global_options( options )
|
55
|
+
Launchy.debug = options.delete( :debug ) || ENV['LAUNCHY_DEBUG']
|
56
|
+
Launchy.application = options.delete( :application ) || ENV['LAUNCHY_APPLICATION']
|
57
|
+
Launchy.host_os = options.delete( :host_os ) || ENV['LAUNCHY_HOST_OS']
|
58
|
+
Launchy.ruby_engine = options.delete( :ruby_engine ) || ENV['LAUNCHY_RUBY_ENGINE']
|
59
|
+
Launchy.dry_run = options.delete( :dry_run )
|
60
|
+
end
|
61
|
+
|
62
|
+
def debug=( d )
|
63
|
+
@debug = (d == "true")
|
64
|
+
end
|
65
|
+
|
66
|
+
# we may do logging before a call to 'open', hence the need to check
|
67
|
+
# LAUNCHY_DEBUG here
|
68
|
+
def debug?
|
69
|
+
@debug || (ENV['LAUNCHY_DEBUG'] == 'true')
|
70
|
+
end
|
71
|
+
|
72
|
+
def application=( app )
|
73
|
+
@application = app
|
74
|
+
end
|
75
|
+
|
76
|
+
def application
|
77
|
+
@application || ENV['LAUNCHY_APPLICATION']
|
78
|
+
end
|
79
|
+
|
80
|
+
def host_os=( host_os )
|
81
|
+
@host_os = host_os
|
82
|
+
end
|
83
|
+
|
84
|
+
def host_os
|
85
|
+
@host_os || ENV['LAUNCHY_HOST_OS']
|
86
|
+
end
|
87
|
+
|
88
|
+
def ruby_engine=( ruby_engine )
|
89
|
+
@ruby_engine = ruby_engine
|
90
|
+
end
|
91
|
+
|
92
|
+
def ruby_engine
|
93
|
+
@ruby_engine || ENV['LAUNCHY_RUBY_ENGINE']
|
94
|
+
end
|
95
|
+
|
96
|
+
def dry_run=( dry_run )
|
97
|
+
@dry_run = dry_run
|
98
|
+
end
|
99
|
+
|
100
|
+
def dry_run?
|
101
|
+
@dry_run
|
102
|
+
end
|
103
|
+
|
104
|
+
def bug_report_message
|
105
|
+
"Please file a bug at https://github.com/copiousfreetime/launchy/issues/new"
|
106
|
+
end
|
107
|
+
|
108
|
+
def log(msg)
|
109
|
+
$stderr.puts "LAUNCHY_DEBUG: #{msg}" if Launchy.debug?
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
require 'launchy/version'
|
115
|
+
require 'launchy/cli'
|
116
|
+
require 'launchy/descendant_tracker'
|
117
|
+
require 'launchy/error'
|
118
|
+
require 'launchy/application'
|
119
|
+
require 'launchy/detect'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'set'
|
2
|
+
module Launchy
|
3
|
+
#
|
4
|
+
# Application is the base class of all the application types that launchy may
|
5
|
+
# invoke. It essentially defines the public api of the launchy system.
|
6
|
+
#
|
7
|
+
# Every class that inherits from Application must define:
|
8
|
+
#
|
9
|
+
# 1. A constructor taking no parameters
|
10
|
+
# 2. An instance method 'open' taking a string or URI as the first parameter and a
|
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
|
14
|
+
class Application
|
15
|
+
extend DescendantTracker
|
16
|
+
|
17
|
+
class << self
|
18
|
+
#
|
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 )
|
42
|
+
return klass if klass
|
43
|
+
|
44
|
+
raise SchemeNotFoundError, "No application found to handle scheme '#{scheme}'. Known schemes: #{scheme_list.join(", ")}"
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Find the given executable in the available paths
|
49
|
+
def find_executable( bin, *paths )
|
50
|
+
paths = ENV['PATH'].split( File::PATH_SEPARATOR ) if paths.empty?
|
51
|
+
paths.each do |path|
|
52
|
+
file = File.join( path, bin )
|
53
|
+
if File.executable?( file ) then
|
54
|
+
Launchy.log "#{self.name} : found executable #{file}"
|
55
|
+
return file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
Launchy.log "#{self.name} : Unable to find `#{bin}' in #{paths.join(", ")}"
|
59
|
+
return nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
attr_reader :host_os_family
|
64
|
+
attr_reader :ruby_engine
|
65
|
+
attr_reader :runner
|
66
|
+
def initialize
|
67
|
+
@host_os_family = Launchy::Detect::HostOsFamily.detect
|
68
|
+
@ruby_engine = Launchy::Detect::RubyEngine.detect
|
69
|
+
@runner = Launchy::Detect::Runner.detect
|
70
|
+
end
|
71
|
+
|
72
|
+
def find_executable( bin, *paths )
|
73
|
+
Application.find_executable( bin, *paths )
|
74
|
+
end
|
75
|
+
|
76
|
+
def run( cmd, *args )
|
77
|
+
runner.run( cmd, *args )
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
require 'launchy/applications/browser'
|