fdietz-ruby-config 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +64 -0
- data/bin/ruby-config +6 -0
- data/lib/ruby_config/config.rb +35 -0
- data/lib/ruby_config/environment_config.rb +43 -0
- data/lib/ruby_config/file_helper.rb +28 -0
- data/lib/ruby_config/options_parser.rb +70 -0
- data/lib/ruby_config/registry.rb +109 -0
- data/lib/ruby_config/runner.rb +165 -0
- data/lib/ruby_config/runtime_base.rb +159 -0
- data/lib/ruby_config/runtimes/jruby_runtime.rb +97 -0
- data/lib/ruby_config/runtimes/leopard_runtime.rb +46 -0
- data/lib/ruby_config/runtimes/ruby186_runtime.rb +43 -0
- data/lib/ruby_config/runtimes/ruby187_runtime.rb +43 -0
- data/lib/ruby_config/runtimes/ruby19_runtime.rb +46 -0
- data/lib/ruby_config/runtimes/ruby_enterprise_edition_runtime.rb +46 -0
- data/lib/ruby_config/runtimes/ruby_from_source_helper.rb +24 -0
- data/lib/ruby_config.rb +15 -0
- data/test/unit/registry_test.rb +103 -0
- data/test/unit/runtime_base_test.rb +120 -0
- metadata +71 -0
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# ruby-config
|
2
|
+
|
3
|
+
* Website: [http://fdietz.wordpress.com/ruby-config](http://fdietz.wordpress.com/ruby-config)
|
4
|
+
* Github: [http://github.com/fdietz/ruby-config](http://github.com/fdietz/ruby-config)
|
5
|
+
* Author: fdietz@gmail.com
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
Ruby-Config lets you install and switch between various Ruby Runtimes
|
10
|
+
|
11
|
+
|
12
|
+
## Prerequisites
|
13
|
+
|
14
|
+
### Mac OS X:
|
15
|
+
You need to install [Xcode](http://developer.apple.com/technology/Xcode.html)
|
16
|
+
|
17
|
+
### Ubuntu Linux:
|
18
|
+
Use apt-get to install the essential packages:
|
19
|
+
|
20
|
+
sudo apt-get install build-essential zlib1g-dev libreadline5-dev libssl-dev
|
21
|
+
|
22
|
+
### JRuby:
|
23
|
+
|
24
|
+
You need a JDK
|
25
|
+
#### OS X:
|
26
|
+
OS X comes with an already installed Java version.
|
27
|
+
|
28
|
+
#### Ubuntu Linux:
|
29
|
+
Use apt-get to install the essential packages:
|
30
|
+
|
31
|
+
sudo apt-get install sun-java6-jre sun-java6-jdk
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
sudo gem install ruby-config
|
36
|
+
|
37
|
+
## Kudos
|
38
|
+
|
39
|
+
Thanks to [Relevance](http://thinkrelevance.com) for their work on [Ruby Switcher](http://github.com/relevance/etc/blob/3d607c8ac2f76077f27c3cbc0140b04a89f546be/bash/ruby_switcher.sh) which I used as the basis for the installation of various Ruby Runtimes.
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
(The MIT License)
|
44
|
+
|
45
|
+
Copyright (c) 2009 Frederik Dietz <fdietz@gmail.com>
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/ruby-config
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
class Config
|
3
|
+
|
4
|
+
attr_accessor :hash
|
5
|
+
|
6
|
+
DEFAULTS = {'default' => 'ruby-leopard-1.8.6'}
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@config_file = File.join(path, "config.yml")
|
10
|
+
File.exist?(@config_file) ? load : @hash = {}.merge(DEFAULTS)
|
11
|
+
|
12
|
+
#puts "config: #{@hash.inspect}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(key)
|
16
|
+
@hash[key]
|
17
|
+
end
|
18
|
+
|
19
|
+
def set(key, value)
|
20
|
+
@hash[key] = value
|
21
|
+
end
|
22
|
+
|
23
|
+
def save
|
24
|
+
RubyConfig::FileHelper.store_yml(@config_file, @hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
def load
|
28
|
+
@hash = RubyConfig::FileHelper.load_yml(@config_file)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_hash
|
32
|
+
@hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Not used currently
|
2
|
+
module RubyConfig
|
3
|
+
class EnvironmentConfig
|
4
|
+
|
5
|
+
attr_writer :set_bash_var, :prepend_bash_var, :append_bash_var, :bash_alias
|
6
|
+
|
7
|
+
def initialize(path)
|
8
|
+
@config_file = File.join(path, "current_env_config")
|
9
|
+
end
|
10
|
+
|
11
|
+
def save
|
12
|
+
configuration = create_configuration(@set_bash_var, @prepend_bash_var, @append_bash_var, @bash_alias)
|
13
|
+
RubyConfig::FileHelper.write_content_to_file(configuration, @config_file)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def create_configuration(set_bash_var = {}, prepend_bash_var = {}, append_bash_var = {}, bash_alias = {})
|
19
|
+
configuration = ""
|
20
|
+
prepend_bash_var.each { |key,value| configuration << prepend_to_bash_environment_var(key, value) + "\n" }
|
21
|
+
set_bash_var.each { |key,value| configuration << set_bash_environment_var(key, value) + "\n" }
|
22
|
+
bash_alias.each { |key, value| configuration << set_bash_alias(key, value) + "\n" }
|
23
|
+
configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def prepend_to_bash_environment_var(var, path)
|
27
|
+
"export #{var}=#{path}:$#{var}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def append_to_bash_environment_var(var, path)
|
31
|
+
"export #{var}=$#{var}:#{path}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def set_bash_environment_var(var, path)
|
35
|
+
"export #{var}=#{path}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_bash_alias(var, script)
|
39
|
+
"alias #{var}=\"#{script}\""
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
class FileHelper
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def write_content_to_file(content, path)
|
6
|
+
File.open(path, 'w') { |file| file.write content }
|
7
|
+
end
|
8
|
+
|
9
|
+
def store_yml(path, data)
|
10
|
+
File.open(path, 'w') { |out| YAML.dump( data, out ) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def load_yml(path)
|
14
|
+
File.open(path) { |yf| YAML::load( yf ) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete_file(path)
|
18
|
+
File.delete(path) if File.exist?(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_symlink(target_path, symlink_path)
|
22
|
+
FileUtils.ln_s(target_path, symlink_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
class OptionsParser
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
create_options
|
6
|
+
end
|
7
|
+
|
8
|
+
def print_help
|
9
|
+
puts @optparse
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_options
|
13
|
+
@options = OpenStruct.new
|
14
|
+
@options.verbose = false
|
15
|
+
@options.list_available = false
|
16
|
+
@options.list_installed = false
|
17
|
+
@options.use = false
|
18
|
+
@options.runtime = nil
|
19
|
+
@options.install = false
|
20
|
+
@options.help = false
|
21
|
+
|
22
|
+
@optparse = OptionParser.new do |opts|
|
23
|
+
opts.banner = "Usage: ruby-config [options]"
|
24
|
+
|
25
|
+
opts.on('-a', '--list-available', 'List available Ruby runtimes') do
|
26
|
+
@options.list_available = true
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-l', '--list-installed', 'List installed Ruby runtimes') do
|
30
|
+
@options.list_installed = true
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-u', '--use [HANDLE]', 'Use specific Ruby runtime') do |runtime|
|
34
|
+
@options.use = true
|
35
|
+
@options.runtime = runtime
|
36
|
+
abort("No Runtime specified") unless runtime
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-i', '--install [HANDLE]', 'Install specific Ruby runtime') do |runtime|
|
40
|
+
@options.install = true
|
41
|
+
@options.runtime = runtime
|
42
|
+
abort("No Runtime specified") unless runtime
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on('--uninstall [HANDLE]', 'Uninstall specific Ruby runtime') do |runtime|
|
46
|
+
@options.uninstall = true
|
47
|
+
@options.runtime = runtime
|
48
|
+
abort("No Runtime specified") unless runtime
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on('-v', '--version', 'Display version' ) do
|
52
|
+
puts "ruby-config version: #{RubyConfig.VERSION}"
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('-h', '--help', 'Display this screen' ) do
|
57
|
+
@options.help = true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse
|
64
|
+
@optparse.parse!
|
65
|
+
@options
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
|
3
|
+
class Registry
|
4
|
+
|
5
|
+
attr_reader :ruby_config_path
|
6
|
+
|
7
|
+
def initialize(ruby_config_path)
|
8
|
+
@ruby_config_path = ruby_config_path
|
9
|
+
@runtime_install_path = File.join(ruby_config_path, "runtimes")
|
10
|
+
@tmp_path = File.join(ruby_config_path, "tmp")
|
11
|
+
|
12
|
+
@config = RubyConfig::Config.new(@ruby_config_path)
|
13
|
+
@environment_config = RubyConfig::EnvironmentConfig.new(@ruby_config_path)
|
14
|
+
|
15
|
+
@list = []
|
16
|
+
ensure_config_directory_exists
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(runtime_const)
|
20
|
+
@list << runtime_const.new(@runtime_install_path, @tmp_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def default?(handle)
|
24
|
+
handle == default_handle
|
25
|
+
end
|
26
|
+
|
27
|
+
def first
|
28
|
+
@list.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def exist?(handle)
|
32
|
+
!!get(handle)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get(handle)
|
36
|
+
handle_int = handle.to_i # returns 0 if no fixnum
|
37
|
+
if handle_int > 0 && handle_int << @list.size
|
38
|
+
@list.values_at(handle_int-1).first
|
39
|
+
else
|
40
|
+
@list.find { |item| item.handle == handle }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_available
|
45
|
+
@list
|
46
|
+
end
|
47
|
+
|
48
|
+
def list_installed
|
49
|
+
@list.find_all { |item| item.already_installed?}
|
50
|
+
end
|
51
|
+
|
52
|
+
def install(runtime)
|
53
|
+
runtime.do_install unless runtime.already_installed?
|
54
|
+
|
55
|
+
use(runtime)
|
56
|
+
|
57
|
+
runtime.do_post_install
|
58
|
+
|
59
|
+
runtime
|
60
|
+
end
|
61
|
+
|
62
|
+
def use(runtime)
|
63
|
+
set_default_handle(runtime.handle)
|
64
|
+
@config.save
|
65
|
+
|
66
|
+
set_symlinks_to_runtime(runtime)
|
67
|
+
|
68
|
+
runtime
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def set_symlinks_to_runtime(runtime)
|
74
|
+
ruby_path = File.join(@ruby_config_path, "ruby")
|
75
|
+
gem_path = File.join(@ruby_config_path, "gem")
|
76
|
+
RubyConfig::FileHelper.delete_file(ruby_path)
|
77
|
+
RubyConfig::FileHelper.delete_file(gem_path)
|
78
|
+
RubyConfig::FileHelper.set_symlink(runtime.ruby_home_path, ruby_path)
|
79
|
+
RubyConfig::FileHelper.set_symlink(runtime.gem_home_path, gem_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def default_handle
|
83
|
+
@config.get("default")
|
84
|
+
end
|
85
|
+
|
86
|
+
def set_default_handle(default_handle)
|
87
|
+
@config.set("default", default_handle)
|
88
|
+
end
|
89
|
+
|
90
|
+
def ensure_config_directory_exists
|
91
|
+
FileUtils.mkdir_p(@ruby_config_path)
|
92
|
+
FileUtils.mkdir_p(@tmp_path)
|
93
|
+
FileUtils.mkdir_p(@runtime_install_path)
|
94
|
+
end
|
95
|
+
|
96
|
+
# bash_alias required by jruby nailgun
|
97
|
+
# def update_current_environment_config(ruby_home, gem_home, bash_alias = {})
|
98
|
+
# set_bash_var = {'GEM_HOME' => gem_home, 'RUBY_HOME' => ruby_home}
|
99
|
+
# prepend_bash_var = {'PATH' => "#{ruby_home}/bin" }
|
100
|
+
#
|
101
|
+
# @environment_config.set_bash_var = set_bash_var
|
102
|
+
# @environment_config.prepend_bash_var = prepend_bash_var
|
103
|
+
# @environment_config.bash_alias = bash_alias
|
104
|
+
# @environment_config.save
|
105
|
+
# end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
|
3
|
+
class Runner
|
4
|
+
|
5
|
+
RUBY_CONFIG_PATH = File.join(ENV['HOME'], ".ruby-config")
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@registry = RubyConfig::Registry.new(RUBY_CONFIG_PATH)
|
9
|
+
load_available_runtimes.each { |runtime| @registry.add(runtime) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
options_parser = RubyConfig::OptionsParser.new
|
14
|
+
|
15
|
+
begin
|
16
|
+
options = options_parser.parse
|
17
|
+
|
18
|
+
if options.list_available
|
19
|
+
list_available
|
20
|
+
elsif options.list_installed
|
21
|
+
list_installed
|
22
|
+
elsif options.install
|
23
|
+
install_runtime(options.runtime)
|
24
|
+
elsif options.uninstall
|
25
|
+
# TODO
|
26
|
+
elsif options.use
|
27
|
+
use_runtime(options.runtime)
|
28
|
+
elsif options.help
|
29
|
+
help(options_parser)
|
30
|
+
end
|
31
|
+
rescue OptionParser::ParseError => e
|
32
|
+
puts e
|
33
|
+
options_parser.print_help
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def load_available_runtimes
|
40
|
+
list = []
|
41
|
+
list << RubyConfig::Runtimes::LeopardRuntime
|
42
|
+
list << RubyConfig::Runtimes::RubyEnterpriseEditionRuntime
|
43
|
+
list << RubyConfig::Runtimes::JRubyRuntime
|
44
|
+
list << RubyConfig::Runtimes::Ruby19Runtime
|
45
|
+
list << RubyConfig::Runtimes::Ruby186Runtime
|
46
|
+
list << RubyConfig::Runtimes::Ruby187Runtime
|
47
|
+
list
|
48
|
+
end
|
49
|
+
|
50
|
+
def help(options_parser)
|
51
|
+
print_info_header
|
52
|
+
options_parser.print_help
|
53
|
+
end
|
54
|
+
|
55
|
+
def install_runtime(handle)
|
56
|
+
unless @registry.exist?(handle)
|
57
|
+
puts "Unknown ruby runtime: #{handle}"
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
runtime = @registry.get(handle)
|
62
|
+
|
63
|
+
puts "#{runtime} already installed" if runtime.already_installed?
|
64
|
+
|
65
|
+
@registry.install(runtime)
|
66
|
+
print_use_results(runtime)
|
67
|
+
end
|
68
|
+
|
69
|
+
def use_runtime(handle)
|
70
|
+
unless @registry.exist?(handle)
|
71
|
+
puts "Unknown ruby runtime: #{handle}"
|
72
|
+
return
|
73
|
+
end
|
74
|
+
|
75
|
+
runtime = @registry.get(handle)
|
76
|
+
|
77
|
+
if @registry.use(runtime)
|
78
|
+
#display_ruby_version
|
79
|
+
#print_use_results(runtime)
|
80
|
+
display_ruby_version(runtime)
|
81
|
+
else
|
82
|
+
puts "Unknown Ruby Runtime: #{handle}"
|
83
|
+
puts
|
84
|
+
list_installed
|
85
|
+
puts
|
86
|
+
puts example_use_usage
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def example_use_usage
|
91
|
+
puts "Example usage: ruby-config -u #{@registry.first.handle}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def print_info_header
|
95
|
+
puts "ruby-config (http://github/fdietz/ruby-config)"
|
96
|
+
puts "Author: Frederik Dietz <fdietz@gmail.com>"
|
97
|
+
puts "Version: #{RubyConfig::VERSION}"
|
98
|
+
puts
|
99
|
+
end
|
100
|
+
|
101
|
+
def list_available
|
102
|
+
puts "Available Ruby Versions:\n"
|
103
|
+
@registry.list_available.each_with_index do |item, index|
|
104
|
+
print_runtime(index, item)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def list_installed
|
109
|
+
puts "Installed Ruby Versions:\n"
|
110
|
+
@registry.list_installed.each_with_index do |item, index|
|
111
|
+
print_runtime(index, item)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def print_runtime(index, item)
|
116
|
+
print "#{index+1}) "
|
117
|
+
print @registry.default?(item.handle) ? "*" : " "
|
118
|
+
puts " #{item}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def print_use_results(runtime)
|
122
|
+
puts "env:"
|
123
|
+
puts " RUBY_HOME=#{runtime.ruby_home_path}"
|
124
|
+
puts " GEM_HOME=#{runtime.gem_home_path}"
|
125
|
+
|
126
|
+
unless runtime.bash_alias.empty?
|
127
|
+
puts "\nalias:"
|
128
|
+
print_alias(runtime.bash_alias)
|
129
|
+
end
|
130
|
+
|
131
|
+
puts "\nruby -v:"
|
132
|
+
display_system_ruby_version
|
133
|
+
end
|
134
|
+
|
135
|
+
def print_alias(hash)
|
136
|
+
hash.each do |key, value|
|
137
|
+
puts " alias #{key}=\"#{value}\""
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def display_ruby_version(runtime)
|
142
|
+
puts "Running: #{runtime}"
|
143
|
+
end
|
144
|
+
|
145
|
+
def display_system_ruby_version
|
146
|
+
system "ruby -v"
|
147
|
+
end
|
148
|
+
|
149
|
+
def abort(message)
|
150
|
+
puts message
|
151
|
+
exit
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
#RubyConfig::Runner.new.run
|
158
|
+
|
159
|
+
|
160
|
+
# require 'fileutils'
|
161
|
+
# if ARGV.include?('--dry-run')
|
162
|
+
# include FileUtils::DryRun
|
163
|
+
# else
|
164
|
+
# include FileUtils::Verbose
|
165
|
+
# end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
|
3
|
+
class RuntimeBase
|
4
|
+
|
5
|
+
attr_reader :install_path, :tmp_path
|
6
|
+
|
7
|
+
def initialize(install_path, tmp_path)
|
8
|
+
@install_path = File.join(install_path, handle)
|
9
|
+
@tmp_path = tmp_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def do_install
|
13
|
+
create_directory_structure
|
14
|
+
|
15
|
+
download_file_unless_exists(archive_file_name, archive_download_url)
|
16
|
+
|
17
|
+
# runtime specific installation part
|
18
|
+
install
|
19
|
+
|
20
|
+
cleanup_tmp_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
def install
|
24
|
+
raise "Not implemented yet!"
|
25
|
+
end
|
26
|
+
|
27
|
+
def do_post_install
|
28
|
+
post_install
|
29
|
+
|
30
|
+
install_rubygems unless File.exists?(gem_executable_path)
|
31
|
+
|
32
|
+
# install thyselve
|
33
|
+
#install_gem('ruby-config')
|
34
|
+
end
|
35
|
+
|
36
|
+
# called after install and runtime is enabled
|
37
|
+
def post_install
|
38
|
+
end
|
39
|
+
|
40
|
+
# name of ruby runtime archive
|
41
|
+
def archive_file_name
|
42
|
+
raise "Not implemented yet!"
|
43
|
+
end
|
44
|
+
|
45
|
+
# download url of ruby runtime
|
46
|
+
def archive_download_url
|
47
|
+
raise "Not implemented yet!"
|
48
|
+
end
|
49
|
+
|
50
|
+
# technical name used to select runtime
|
51
|
+
def handle
|
52
|
+
raise "Not implemented yet!"
|
53
|
+
end
|
54
|
+
|
55
|
+
def description
|
56
|
+
raise "Not implemented yet!"
|
57
|
+
end
|
58
|
+
|
59
|
+
# example: 1.8 or 1.9
|
60
|
+
def major_version
|
61
|
+
'1.8'
|
62
|
+
end
|
63
|
+
|
64
|
+
# hash (key: alias name, value: alias bash script)
|
65
|
+
def bash_alias;{};end
|
66
|
+
|
67
|
+
def ruby_home_path
|
68
|
+
File.join(@install_path, 'ruby')
|
69
|
+
end
|
70
|
+
|
71
|
+
def ruby_bin_path
|
72
|
+
File.join(ruby_home_path, 'bin')
|
73
|
+
end
|
74
|
+
|
75
|
+
def gem_home_path
|
76
|
+
File.join(@install_path, 'gem')
|
77
|
+
end
|
78
|
+
|
79
|
+
def ruby_executable_path
|
80
|
+
File.join(ruby_bin_path, 'ruby')
|
81
|
+
end
|
82
|
+
|
83
|
+
def gem_executable_path
|
84
|
+
File.join(ruby_bin_path, 'gem')
|
85
|
+
end
|
86
|
+
|
87
|
+
# aka site_ruby
|
88
|
+
def additional_library_path
|
89
|
+
File.join(ruby_home_path, 'lib', 'ruby', 'site_ruby', major_version)
|
90
|
+
end
|
91
|
+
|
92
|
+
def default_library_path
|
93
|
+
File.join(ruby_home_path, 'lib', 'ruby', major_version)
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_s
|
97
|
+
"#{description} [#{handle}]"
|
98
|
+
end
|
99
|
+
|
100
|
+
def already_installed?
|
101
|
+
Pathname.new(File.join(ruby_bin_path, 'ruby')).exist?
|
102
|
+
end
|
103
|
+
|
104
|
+
protected
|
105
|
+
|
106
|
+
def install_rubygems
|
107
|
+
version = "1.3.5"
|
108
|
+
archive_name = "rubygems-#{version}"
|
109
|
+
archive_file_name = "#{archive_name}.tgz"
|
110
|
+
download_url = "http://rubyforge.org/frs/download.php/60718/#{archive_file_name}"
|
111
|
+
|
112
|
+
download_file_unless_exists(archive_file_name, download_url)
|
113
|
+
|
114
|
+
extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
|
115
|
+
FileUtils.cd(File.join(@tmp_path, archive_name))
|
116
|
+
#system("ruby setup.rb --prefix=#{additional_library_path}")
|
117
|
+
system("ruby setup.rb")
|
118
|
+
end
|
119
|
+
|
120
|
+
def cleanup_tmp_dir
|
121
|
+
empty_dir(@tmp_path)
|
122
|
+
end
|
123
|
+
|
124
|
+
def create_directory_structure
|
125
|
+
FileUtils.mkdir_p(@install_path)
|
126
|
+
FileUtils.mkdir_p(@tmp_path)
|
127
|
+
FileUtils.mkdir_p(ruby_home_path)
|
128
|
+
FileUtils.mkdir_p(ruby_bin_path)
|
129
|
+
FileUtils.mkdir_p(gem_home_path)
|
130
|
+
end
|
131
|
+
|
132
|
+
def download_file_unless_exists(archive, url)
|
133
|
+
archive_path = File.join(@tmp_path, archive)
|
134
|
+
unless File.exist?(archive_path)
|
135
|
+
path = download_file_wget(url, archive_path)
|
136
|
+
puts "#{archive} downloaded successfully to #{archive_path}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def download_file_wget(url, destination_path)
|
141
|
+
system("wget #{url} --output-document=#{destination_path}")
|
142
|
+
end
|
143
|
+
|
144
|
+
def extract_tar_gz(archive_path, destination_path)
|
145
|
+
system("tar xfvz #{archive_path} -C #{destination_path}")
|
146
|
+
end
|
147
|
+
|
148
|
+
def empty_dir(path)
|
149
|
+
Dir[File.join(path, '*')].each do |file|
|
150
|
+
FileUtils.remove_entry_secure(file) if Pathname.new(file).directory?
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def gem_install(gem_technical_name)
|
155
|
+
system "gem install -q --no-ri --no-rdoc #{gem_technical_name}"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
module RubyConfig
|
3
|
+
|
4
|
+
module Runtimes
|
5
|
+
|
6
|
+
class JRubyRuntime < RubyConfig::RuntimeBase
|
7
|
+
|
8
|
+
VERSION = '1.3.1'
|
9
|
+
JRUBY_DIR = "jruby-#{VERSION}"
|
10
|
+
JRUBY_ARCHIVE = "jruby-bin-#{VERSION}.tar.gz"
|
11
|
+
JRUBY_DOWNLOAD_URL = "http://dist.codehaus.org/jruby/#{VERSION}/#{JRUBY_ARCHIVE}"
|
12
|
+
|
13
|
+
def handle
|
14
|
+
"jruby-#{VERSION}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
"JRuby #{VERSION}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def archive_file_name
|
22
|
+
JRUBY_ARCHIVE
|
23
|
+
end
|
24
|
+
|
25
|
+
def archive_download_url
|
26
|
+
JRUBY_DOWNLOAD_URL
|
27
|
+
end
|
28
|
+
|
29
|
+
# only required for nailgun support
|
30
|
+
# def bash_alias
|
31
|
+
# {'ruby_ng', 'jruby --ng',
|
32
|
+
# 'ruby_ng_server', 'jruby --ng-server'}
|
33
|
+
# end
|
34
|
+
|
35
|
+
def install
|
36
|
+
extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
|
37
|
+
|
38
|
+
copy_archive_content_to_ruby_directory
|
39
|
+
|
40
|
+
set_symlinks_for_jruby_commands
|
41
|
+
chmod_executables
|
42
|
+
end
|
43
|
+
|
44
|
+
def post_install
|
45
|
+
# install_nailgun
|
46
|
+
install_jruby_specific_gem
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def copy_archive_content_to_ruby_directory
|
52
|
+
files = Dir.glob(File.join(@tmp_path, JRUBY_DIR, '*'))
|
53
|
+
FileUtils.cp_r(files, ruby_home_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
# there is already a jgem and gem, therefore no symlink required for gem!
|
57
|
+
def set_symlinks_for_jruby_commands
|
58
|
+
jruby_commands_requiring_symlinks.each do |item|
|
59
|
+
RubyConfig::FileHelper.set_symlink(item.first, bin_path(item.last))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def jruby_commands_requiring_symlinks
|
64
|
+
[[bin_path('jruby'), 'ruby' ],
|
65
|
+
[bin_path('jirb') , 'irb' ]]
|
66
|
+
end
|
67
|
+
|
68
|
+
# CHECK: can we download an archive which preserves permissions instead?
|
69
|
+
def chmod_executables
|
70
|
+
%w(jruby jgem gem jirb).each { |command| chmod_executable_for_others(bin_path(command)) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def chmod_executable_for_others(path)
|
74
|
+
FileUtils.chmod(0755, path)
|
75
|
+
end
|
76
|
+
|
77
|
+
def bin_path(command)
|
78
|
+
File.join(ruby_bin_path, command)
|
79
|
+
end
|
80
|
+
|
81
|
+
# TODO: "make" does not work correctly
|
82
|
+
def install_nailgun
|
83
|
+
nailgun_path = File.join(ruby_home_path, 'tool', 'nailgun')
|
84
|
+
puts "nailgun_path: #{nailgun_path}"
|
85
|
+
FileUtils.cd(nailgun_path)
|
86
|
+
system "#{nailgun_path}/make"
|
87
|
+
end
|
88
|
+
|
89
|
+
def install_jruby_specific_gem
|
90
|
+
gem_install("rake")
|
91
|
+
gem_install("jruby-openssl")
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
module Runtimes
|
3
|
+
class LeopardRuntime < RubyConfig::RuntimeBase
|
4
|
+
|
5
|
+
def handle
|
6
|
+
'ruby-leopard-1.8.6'
|
7
|
+
end
|
8
|
+
|
9
|
+
def description
|
10
|
+
'Default Leopard Ruby 1.8.6'
|
11
|
+
end
|
12
|
+
|
13
|
+
def archive_file_name
|
14
|
+
""
|
15
|
+
end
|
16
|
+
|
17
|
+
def archive_download_url
|
18
|
+
""
|
19
|
+
end
|
20
|
+
|
21
|
+
def install
|
22
|
+
# intenionally left empty, since ruby is installed by default on OS X
|
23
|
+
end
|
24
|
+
|
25
|
+
def already_installed?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
# "/System/Library/Frameworks/Ruby.framework/Versions/Current/usr"
|
30
|
+
def ruby_home_path
|
31
|
+
File.join("/System", "Library", "Frameworks", "Ruby.framework", "Versions", "Current", "usr")
|
32
|
+
end
|
33
|
+
|
34
|
+
# $ ruby -r rubygems -e "p Gem.path"
|
35
|
+
# ["/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8", "/Library/Ruby/Gems/1.8"]
|
36
|
+
|
37
|
+
# /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/lib/ruby/gems/1.8
|
38
|
+
# /Library/Ruby/Gems/1.8
|
39
|
+
def gem_home_path
|
40
|
+
File.join(ruby_home_path, "lib", "ruby", "gems", "1.8")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'ruby_from_source_helper')
|
2
|
+
|
3
|
+
module RubyConfig
|
4
|
+
|
5
|
+
module Runtimes
|
6
|
+
|
7
|
+
|
8
|
+
class Ruby186Runtime < RubyConfig::RuntimeBase
|
9
|
+
MAJOR_VERSION = '1.8'
|
10
|
+
MINOR_VERSION = '6'
|
11
|
+
PATCH_LEVEL = '383'
|
12
|
+
|
13
|
+
VERSION_STRING = RubyConfig::Runtimes::RubyFromSourceHelper.ruby_version(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
14
|
+
HANDLE = "ruby-#{VERSION_STRING}"
|
15
|
+
DESCRIPTION = "Ruby #{VERSION_STRING}"
|
16
|
+
ARCHIVE_PATH = "ruby-#{VERSION_STRING}"
|
17
|
+
|
18
|
+
def handle
|
19
|
+
HANDLE
|
20
|
+
end
|
21
|
+
|
22
|
+
def description
|
23
|
+
DESCRIPTION
|
24
|
+
end
|
25
|
+
|
26
|
+
def archive_file_name
|
27
|
+
"ruby-#{VERSION_STRING}.tar.gz"
|
28
|
+
end
|
29
|
+
|
30
|
+
def archive_download_url
|
31
|
+
RubyConfig::Runtimes::RubyFromSourceHelper.download_url(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
32
|
+
end
|
33
|
+
|
34
|
+
def install
|
35
|
+
extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
|
36
|
+
|
37
|
+
RubyConfig::Runtimes::RubyFromSourceHelper.compile(File.join(@tmp_path, ARCHIVE_PATH), ruby_home_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'ruby_from_source_helper')
|
2
|
+
|
3
|
+
module RubyConfig
|
4
|
+
|
5
|
+
module Runtimes
|
6
|
+
|
7
|
+
|
8
|
+
class Ruby187Runtime < RubyConfig::RuntimeBase
|
9
|
+
MAJOR_VERSION = '1.8'
|
10
|
+
MINOR_VERSION = '7'
|
11
|
+
PATCH_LEVEL = '174'
|
12
|
+
|
13
|
+
VERSION_STRING = RubyConfig::Runtimes::RubyFromSourceHelper.ruby_version(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
14
|
+
HANDLE = "ruby-#{VERSION_STRING}"
|
15
|
+
DESCRIPTION = "Ruby #{VERSION_STRING}"
|
16
|
+
ARCHIVE_PATH = "ruby-#{VERSION_STRING}"
|
17
|
+
|
18
|
+
def handle
|
19
|
+
HANDLE
|
20
|
+
end
|
21
|
+
|
22
|
+
def description
|
23
|
+
DESCRIPTION
|
24
|
+
end
|
25
|
+
|
26
|
+
def archive_file_name
|
27
|
+
"ruby-#{VERSION_STRING}.tar.gz"
|
28
|
+
end
|
29
|
+
|
30
|
+
def archive_download_url
|
31
|
+
RubyConfig::Runtimes::RubyFromSourceHelper.download_url(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
32
|
+
end
|
33
|
+
|
34
|
+
def install
|
35
|
+
extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
|
36
|
+
|
37
|
+
RubyConfig::Runtimes::RubyFromSourceHelper.compile(File.join(@tmp_path, ARCHIVE_PATH), ruby_home_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'ruby_from_source_helper')
|
2
|
+
|
3
|
+
module RubyConfig
|
4
|
+
|
5
|
+
module Runtimes
|
6
|
+
|
7
|
+
class Ruby19Runtime < RubyConfig::RuntimeBase
|
8
|
+
MAJOR_VERSION = '1.9'
|
9
|
+
MINOR_VERSION = '1'
|
10
|
+
PATCH_LEVEL = '243'
|
11
|
+
|
12
|
+
VERSION_STRING = RubyConfig::Runtimes::RubyFromSourceHelper.ruby_version(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
13
|
+
HANDLE = "ruby-#{VERSION_STRING}"
|
14
|
+
DESCRIPTION = "Ruby #{VERSION_STRING}"
|
15
|
+
ARCHIVE_PATH = "ruby-#{VERSION_STRING}"
|
16
|
+
|
17
|
+
def handle
|
18
|
+
HANDLE
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
DESCRIPTION
|
23
|
+
end
|
24
|
+
|
25
|
+
def major_version
|
26
|
+
MAJOR_VERSION
|
27
|
+
end
|
28
|
+
|
29
|
+
def archive_file_name
|
30
|
+
"ruby-#{VERSION_STRING}.tar.gz"
|
31
|
+
end
|
32
|
+
|
33
|
+
def archive_download_url
|
34
|
+
RubyConfig::Runtimes::RubyFromSourceHelper.download_url(MAJOR_VERSION, MINOR_VERSION, PATCH_LEVEL)
|
35
|
+
end
|
36
|
+
|
37
|
+
def install
|
38
|
+
extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
|
39
|
+
|
40
|
+
RubyConfig::Runtimes::RubyFromSourceHelper.compile(File.join(@tmp_path, ARCHIVE_PATH), ruby_home_path)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
|
3
|
+
module Runtimes
|
4
|
+
|
5
|
+
class RubyEnterpriseEditionRuntime < RubyConfig::RuntimeBase
|
6
|
+
|
7
|
+
VERSION = '1.8.6'
|
8
|
+
HANDLE = "ruby-enterprise-#{VERSION}"
|
9
|
+
TIMESTAMP = '20090421'
|
10
|
+
DESCRIPTION = "Ruby Enterprise Edition #{VERSION}-#{TIMESTAMP}"
|
11
|
+
RUBY_ENTERPRISE_EDITION_DIR = "ruby-enterprise-#{VERSION}-#{TIMESTAMP}"
|
12
|
+
RUBY_ENTERPRISE_EDITION_ARCHIVE = "#{RUBY_ENTERPRISE_EDITION_DIR}.tar.gz"
|
13
|
+
RUBY_ENTERPRISE_EDITION_DOWNLOAD_URL = "http://rubyforge.org/frs/download.php/55511/#{RUBY_ENTERPRISE_EDITION_ARCHIVE}"
|
14
|
+
|
15
|
+
def handle
|
16
|
+
HANDLE
|
17
|
+
end
|
18
|
+
|
19
|
+
def description
|
20
|
+
DESCRIPTION
|
21
|
+
end
|
22
|
+
|
23
|
+
def archive_file_name
|
24
|
+
RUBY_ENTERPRISE_EDITION_ARCHIVE
|
25
|
+
end
|
26
|
+
|
27
|
+
def archive_download_url
|
28
|
+
RUBY_ENTERPRISE_EDITION_DOWNLOAD_URL
|
29
|
+
end
|
30
|
+
|
31
|
+
def install
|
32
|
+
extract_tar_gz(File.join(@tmp_path, archive_file_name), @tmp_path)
|
33
|
+
|
34
|
+
ree_installer
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def ree_installer
|
39
|
+
FileUtils.cd(File.join(@tmp_path, RUBY_ENTERPRISE_EDITION_DIR))
|
40
|
+
system("./installer -a #{@install_path}/ruby --dont-install-useful-gems")
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RubyConfig
|
2
|
+
module Runtimes
|
3
|
+
|
4
|
+
module RubyFromSourceHelper
|
5
|
+
|
6
|
+
def self.download_url(major_version, minor_version, patch_level)
|
7
|
+
version = ruby_version(major_version, minor_version, patch_level)
|
8
|
+
"ftp://ftp.ruby-lang.org/pub/ruby/#{major_version}/ruby-#{version}.tar.gz"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.ruby_version(major_version, minor_version, patch_level)
|
12
|
+
"#{major_version}.#{minor_version}-p#{patch_level}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.compile(source_path, installation_path)
|
16
|
+
FileUtils.cd(source_path)
|
17
|
+
system("./configure --prefix=#{installation_path} --enable-shared")
|
18
|
+
system("make")
|
19
|
+
system("make install")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/ruby_config.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#puts Dir.glob(File.join(File.dirname(__FILE__), 'ruby_config/**/*.rb'))
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'ruby_config/**/*.rb')).each {|f| require f }
|
3
|
+
|
4
|
+
module RubyConfig
|
5
|
+
VERSION = '1.0.0'
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'fileutils'
|
9
|
+
require 'open-uri'
|
10
|
+
require 'tempfile'
|
11
|
+
require 'pathname'
|
12
|
+
require 'ostruct'
|
13
|
+
require 'optparse'
|
14
|
+
require "yaml"
|
15
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class RegistryInitializeTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@root = File.join("/tmp", "test")
|
6
|
+
@registry = RubyConfig::Registry.new(@root)
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
FileUtils.rm_rf(@root)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "should ensure config directories exist" do
|
14
|
+
assert File.exist?(@root)
|
15
|
+
assert File.exist?(File.join(@root,"runtimes"))
|
16
|
+
assert File.exist?(File.join(@root,"tmp"))
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class RegistryInstallTest < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@root = File.join("/tmp", "test")
|
26
|
+
@registry = RubyConfig::Registry.new(@root)
|
27
|
+
@registry.add(RegistryTestHelper::RuntimeBaseStub)
|
28
|
+
@runtime = @registry.get("handle")
|
29
|
+
end
|
30
|
+
|
31
|
+
def teardown
|
32
|
+
FileUtils.rm_rf(@root)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should install using specific runtime implementation" do
|
36
|
+
@registry.install(@runtime)
|
37
|
+
|
38
|
+
assert File.exist?(@runtime.ruby_home_path)
|
39
|
+
assert File.exist?(@runtime.gem_home_path)
|
40
|
+
assert File.exist?(File.join(@runtime.ruby_bin_path, "ruby"))
|
41
|
+
assert File.exist?(File.join(@runtime.ruby_bin_path, "gem"))
|
42
|
+
assert File.exist?(File.join(@runtime.ruby_bin_path, "irb"))
|
43
|
+
end
|
44
|
+
|
45
|
+
test "should make use of installed runtime" do
|
46
|
+
@registry.expects(:use).with(@runtime)
|
47
|
+
@registry.install(@runtime)
|
48
|
+
end
|
49
|
+
|
50
|
+
test "should call post install methods" do
|
51
|
+
@runtime.expects(:post_install)
|
52
|
+
@registry.install(@runtime)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
class RegistryUseTest < Test::Unit::TestCase
|
58
|
+
|
59
|
+
def setup
|
60
|
+
@root = File.join("/tmp", "test")
|
61
|
+
@registry = RubyConfig::Registry.new(@root)
|
62
|
+
@registry.add(RegistryTestHelper::RuntimeBaseStub)
|
63
|
+
@runtime = @registry.get("handle")
|
64
|
+
@registry.install(@runtime)
|
65
|
+
end
|
66
|
+
|
67
|
+
def teardown
|
68
|
+
FileUtils.rm_rf(@root)
|
69
|
+
end
|
70
|
+
|
71
|
+
test "should set default handle in config file" do
|
72
|
+
@registry.use(@runtime)
|
73
|
+
|
74
|
+
config = File.open(File.join(@registry.ruby_config_path, "config.yml")) { |yf| YAML::load( yf ) }
|
75
|
+
assert_equal @runtime.handle, config["default"]
|
76
|
+
end
|
77
|
+
|
78
|
+
test "should create symlinks to installed runtime" do
|
79
|
+
@registry.use(@runtime)
|
80
|
+
assert Pathname.new(File.join(@registry.ruby_config_path, "ruby")).symlink?
|
81
|
+
assert Pathname.new(File.join(@registry.ruby_config_path, "gem")).symlink?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
module RegistryTestHelper
|
86
|
+
|
87
|
+
class RuntimeBaseStub < RubyConfig::RuntimeBase
|
88
|
+
# create fake ruby and gem executables
|
89
|
+
def install
|
90
|
+
FileUtils.touch(File.join(ruby_bin_path, "ruby"))
|
91
|
+
FileUtils.touch(File.join(ruby_bin_path, "gem"))
|
92
|
+
FileUtils.touch(File.join(ruby_bin_path, "irb"))
|
93
|
+
end
|
94
|
+
|
95
|
+
def archive_file_name;"archive.zip";end
|
96
|
+
def archive_download_url;"http://download.com/archive.zip";end
|
97
|
+
def handle;"handle";end
|
98
|
+
def description;"description";end
|
99
|
+
# no download for tests
|
100
|
+
def download_file_unless_exists(archive, url);end;
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class RuntimeBaseInitializeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
test "should set install path" do
|
6
|
+
r = RuntimeBaseTestHelper::RuntimeBaseStub.new("/install", "/tmp_path")
|
7
|
+
assert_equal "/install/handle", r.install_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class RuntimeBaseDoInstallTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@root = "/tmp/test"
|
15
|
+
FileUtils.mkdir(@root)
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
FileUtils.rm_rf(@root)
|
20
|
+
end
|
21
|
+
|
22
|
+
test "should create directory structure" do
|
23
|
+
r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
|
24
|
+
r.stubs(:download_file_unless_exists)
|
25
|
+
r.stubs(:already_installed?).returns(true)
|
26
|
+
r.do_install
|
27
|
+
|
28
|
+
assert File.exist?(r.install_path)
|
29
|
+
assert File.exist?(r.tmp_path)
|
30
|
+
assert File.exist?(File.join(r.install_path,"gem"))
|
31
|
+
end
|
32
|
+
|
33
|
+
test "should install runtime and cleanup tmp unless installed already" do
|
34
|
+
r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
|
35
|
+
r.stubs(:download_file_unless_exists)
|
36
|
+
r.stubs(:already_installed?).returns(false)
|
37
|
+
|
38
|
+
r.expects(:install).once
|
39
|
+
r.expects(:cleanup_tmp_dir).once
|
40
|
+
r.do_install
|
41
|
+
end
|
42
|
+
|
43
|
+
test "should NOT install runtime if installed already" do
|
44
|
+
r = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
|
45
|
+
r.stubs(:download_file_unless_exists)
|
46
|
+
r.stubs(:already_installed?).returns(true)
|
47
|
+
|
48
|
+
r.expects(:install).never
|
49
|
+
r.expects(:cleanup_tmp_dir).never
|
50
|
+
r.do_install
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
class RuntimeBaseDownloadFileUnlessExists < Test::Unit::TestCase
|
56
|
+
|
57
|
+
def setup
|
58
|
+
@root = "/tmp/test"
|
59
|
+
FileUtils.mkdir(@root)
|
60
|
+
|
61
|
+
@runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
|
62
|
+
@runtime.send(:create_directory_structure)
|
63
|
+
end
|
64
|
+
|
65
|
+
def teardown
|
66
|
+
FileUtils.rm_rf(@root)
|
67
|
+
end
|
68
|
+
|
69
|
+
test "should download file unless it exist already" do
|
70
|
+
@runtime.expects(:download_file_wget).once
|
71
|
+
@runtime.send(:download_file_unless_exists, "archive.zip", "url")
|
72
|
+
end
|
73
|
+
|
74
|
+
test "should NOT download file if it exists already" do
|
75
|
+
archive_path = File.join(@runtime.tmp_path, "archive.zip")
|
76
|
+
FileUtils.touch(archive_path)
|
77
|
+
@runtime.expects(:download_file_wget).never
|
78
|
+
|
79
|
+
@runtime.send(:download_file_unless_exists, "archive.zip", "url")
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
class RuntimeBaseIfAlreadyInstalledTest < Test::Unit::TestCase
|
85
|
+
|
86
|
+
def setup
|
87
|
+
@root = "/tmp/test"
|
88
|
+
FileUtils.mkdir(@root)
|
89
|
+
|
90
|
+
@runtime = RuntimeBaseTestHelper::RuntimeBaseStub.new(File.join(@root, "install"), File.join(@root, "tmp"))
|
91
|
+
@runtime.send(:create_directory_structure)
|
92
|
+
FileUtils.mkdir_p(@runtime.ruby_bin_path)
|
93
|
+
end
|
94
|
+
|
95
|
+
def teardown
|
96
|
+
FileUtils.rm_rf(@root)
|
97
|
+
end
|
98
|
+
|
99
|
+
test "should return true if ruby bin found" do
|
100
|
+
bin_path = File.join(@runtime.ruby_bin_path, "ruby")
|
101
|
+
FileUtils.touch(bin_path)
|
102
|
+
|
103
|
+
assert_equal true, @runtime.already_installed?
|
104
|
+
end
|
105
|
+
|
106
|
+
test "should return false if ruby bin NOT found" do
|
107
|
+
assert_equal false, @runtime.already_installed?
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
module RuntimeBaseTestHelper
|
113
|
+
class RuntimeBaseStub < RubyConfig::RuntimeBase
|
114
|
+
def install;end
|
115
|
+
def archive_file_name;"filename";end
|
116
|
+
def archive_download_url;"http://download.com";end
|
117
|
+
def handle;"handle";end
|
118
|
+
def description;"description";end
|
119
|
+
end
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fdietz-ruby-config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Frederik Dietz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-24 00:00:00 -07:00
|
13
|
+
default_executable: ruby-config
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: ruby-config lets one easily install and switch between various Ruby Runtimes
|
17
|
+
email: fdietz@gmail.com
|
18
|
+
executables:
|
19
|
+
- ruby-config
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.md
|
24
|
+
files:
|
25
|
+
- bin/ruby-config
|
26
|
+
- lib/ruby_config.rb
|
27
|
+
- lib/ruby_config/config.rb
|
28
|
+
- lib/ruby_config/environment_config.rb
|
29
|
+
- lib/ruby_config/file_helper.rb
|
30
|
+
- lib/ruby_config/options_parser.rb
|
31
|
+
- lib/ruby_config/registry.rb
|
32
|
+
- lib/ruby_config/runner.rb
|
33
|
+
- lib/ruby_config/runtime_base.rb
|
34
|
+
- lib/ruby_config/runtimes/jruby_runtime.rb
|
35
|
+
- lib/ruby_config/runtimes/leopard_runtime.rb
|
36
|
+
- lib/ruby_config/runtimes/ruby186_runtime.rb
|
37
|
+
- lib/ruby_config/runtimes/ruby187_runtime.rb
|
38
|
+
- lib/ruby_config/runtimes/ruby19_runtime.rb
|
39
|
+
- lib/ruby_config/runtimes/ruby_enterprise_edition_runtime.rb
|
40
|
+
- lib/ruby_config/runtimes/ruby_from_source_helper.rb
|
41
|
+
- README.md
|
42
|
+
has_rdoc: false
|
43
|
+
homepage: http://github.com/fdietz/ruby-config
|
44
|
+
licenses:
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Install and Switch between various Ruby Runtimes easily
|
69
|
+
test_files:
|
70
|
+
- test/unit/registry_test.rb
|
71
|
+
- test/unit/runtime_base_test.rb
|