Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 224 lines (192 sloc) 6.269 kb
3c5a729 @danlucraft Cleaned up the load path; can now run plugin specs
danlucraft authored
1
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
2 $:.push(File.expand_path(File.join(File.dirname(__FILE__))))
3 $:.push(File.expand_path(File.join(File.dirname(__FILE__), %w{.. vendor spoon lib})))
4 $:.push(File.expand_path(File.join(File.dirname(__FILE__), %w{.. vendor ffi lib})))
3c5a729 @danlucraft Cleaned up the load path; can now run plugin specs
danlucraft authored
5
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
6 require 'redcar/usage'
7
8 require 'redcar/ruby_extensions'
9 require 'redcar/instance_exec'
58640fb @danlucraft Move install command help into usage.rb
danlucraft authored
10 require 'redcar/usage'
9709645 @danlucraft Spawn a sub jruby process unless --no-sub-jruby is specified. This makes...
danlucraft authored
11 require 'regex_replace'
58640fb @danlucraft Move install command help into usage.rb
danlucraft authored
12
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
13 require 'forwardable'
14 require 'yaml'
284dcb4 @danlucraft Make sure URI is required, some users having problems
danlucraft authored
15 require 'uri'
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
16
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
17 begin
18 if Config::CONFIG["RUBY_INSTALL_NAME"] == "jruby"
19 require 'spoon'
20 module Redcar; SPOON_AVAILABLE = true; end
21 else
d491a20 @mscharley Added null device support for Windows.
mscharley authored
22 module Redcar; SPOON_AVAILABLE = false; end
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
23 end
24 rescue LoadError
25 module Redcar; SPOON_AVAILABLE = false; end
26 end
27
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
28 # ## Loading and Initialization
29 #
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
30 # Every feature in Redcar is written as a plugin. This module contains a few
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
31 # methods to bootstrap the plugins by loading the PluginManager.
32 #
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
33 # Once loaded, bin/redcar will start the gui pump, which will run
34 # Redcar.gui.start. This starts the GUI library's event loop and hands over
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
35 # control to the GUI.
36 #
37 # ## Application
38 #
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
39 # The top class of Redcar is a {Redcar::Application}, which handles the creation
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
40 # of Redcar::Windows. {Redcar::Application} is a good place to start
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
41 # to see how the Redcar models are created.
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
42 #
43 # {Redcar::ApplicationSWT} is the start point for the SWT GUI, which listens
ae36d02 @danlucraft Soft tabs should respect tab stops
danlucraft authored
44 # for events from the {Redcar::Application} model and reflects them in the GUI.
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
45 #
46 # This structure of a model and a controller that listens to it is repeated for
47 # each part of Redcar reflected in the GUI.
48 #
ae36d02 @danlucraft Soft tabs should respect tab stops
danlucraft authored
49 # * {Redcar::Window} has {Redcar::ApplicationSWT::Window}
50 # * {Redcar::Notebook} has {Redcar::ApplicationSWT::Notebook}
51 # * {Redcar::EditTab} has {Redcar::EditViewSWT::EditTab}
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
52 #
53 # and so on.
926d3dd @danlucraft Changed the install process so it requires a 'sudo redcar install' step....
danlucraft authored
54 module Redcar
558a372 @mscharley Bumped Redcar back to a dev version for those of us using git.
mscharley authored
55 VERSION = '0.5.0dev'
926d3dd @danlucraft Changed the install process so it requires a 'sudo redcar install' step....
danlucraft authored
56 VERSION_MAJOR = 0
558a372 @mscharley Bumped Redcar back to a dev version for those of us using git.
mscharley authored
57 VERSION_MINOR = 5
4d14371 @danlucraft Bump to version 0.4
danlucraft authored
58 VERSION_RELEASE = 0
f6fcfa1 @rdp attempt to startup using drb if another redcar instance is available
rdp authored
59
3f45491 @danlucraft Fix storage spec and added Redcar.environment
danlucraft authored
60 ENVIRONMENTS = [:user, :debug, :test]
11d608b @danlucraft Halve startup time (warm)
danlucraft authored
61
62 PROCESS_START_TIME = Time.now
0a03cb1 @mscharley Added a global icon directory constant to aide in the use of these icons...
mscharley authored
63
aa61ced @mscharley Fixed some bugs in my last commit.
mscharley authored
64 ICONS_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), %w{.. share icons}))
3f45491 @danlucraft Fix storage spec and added Redcar.environment
danlucraft authored
65
66 def self.environment=(env)
67 unless ENVIRONMENTS.include?(env)
68 raise "environment must be one of #{ENVIRONMENTS.inspect}"
69 end
70 @environment = env
71 end
72
73 def self.environment
07f2d74 @danlucraft Raise an error if the environment is not set
danlucraft authored
74 raise "no environment set" unless @environment
3f45491 @danlucraft Fix storage spec and added Redcar.environment
danlucraft authored
75 @environment
76 end
77
9709645 @danlucraft Spawn a sub jruby process unless --no-sub-jruby is specified. This makes...
danlucraft authored
78 def self.spin_up
59b05f6 @mscharley Added a --fork commandline option. This can only be accessed via native ...
mscharley authored
79 forking = ARGV.include?("--fork")
80 no_runner = ARGV.include?("--no-sub-jruby")
190d748 @mscharley Fixed some minor logic errors in the way the --fork command works.
mscharley authored
81 jruby = Config::CONFIG["RUBY_INSTALL_NAME"] == "jruby"
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
82 osx = (not [:linux, :windows].include?(platform))
fecb54d @mscharley Syntax error fix. Oops, should try running before commiting...
mscharley authored
83
91990f0 @mscharley Added a rescue clause around the fork code so that systems that don't su...
mscharley authored
84 begin
85 if forking and not jruby
86 # jRuby doesn't support fork() because of the runtime stuff...
87 forking = false
88 puts 'Forking failed, attempting to start anyway...' if (pid = fork) == -1
89 exit unless pid.nil? # kill the parent process
90
91 if pid.nil?
92 # reopen the standard pipes to nothingness
d491a20 @mscharley Added null device support for Windows.
mscharley authored
93 STDIN.reopen Redcar.null_device
94 STDOUT.reopen Redcar.null_device, 'a'
91990f0 @mscharley Added a rescue clause around the fork code so that systems that don't su...
mscharley authored
95 STDERR.reopen STDOUT
96 end
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
97 elsif forking and SPOON_AVAILABLE and ::Spoon.supported?
91990f0 @mscharley Added a rescue clause around the fork code so that systems that don't su...
mscharley authored
98 # so we need to try something different...
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
99
100 forking = false
101 require 'redcar/runner'
102 runner = Redcar::Runner.new
103 runner.spin_up do |command|
e4f5d98 @mscharley Changed --forked to the much more descriptive --silent
mscharley authored
104 command.push('--silent')
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
105 ::Spoon.spawnp(*command)
106 end
107 exit 0
108 elsif forking
109 raise NotImplementedError, "Something weird has happened. Please contact us."
190d748 @mscharley Fixed some minor logic errors in the way the --fork command works.
mscharley authored
110 end
d7d7b3a @danlucraft Fix syntax error in lib/redcar.rb
danlucraft authored
111 rescue NotImplementedError
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
112 puts $!.class.name + ": " + $!.message
91990f0 @mscharley Added a rescue clause around the fork code so that systems that don't su...
mscharley authored
113 puts "Forking isn't supported on this system. Sorry."
114 puts "Starting normally..."
59b05f6 @mscharley Added a --fork commandline option. This can only be accessed via native ...
mscharley authored
115 end
116
117 return if no_runner
190d748 @mscharley Fixed some minor logic errors in the way the --fork command works.
mscharley authored
118 return if jruby and not osx
ec89d40 @danlucraft Don't spin up a child process if we are on linux/windows and already in ...
danlucraft authored
119
120 require 'redcar/runner'
121 runner = Redcar::Runner.new
304ebe7 @mscharley Implemented the spoon gem into the --fork option.
mscharley authored
122 runner.spin_up do |command|
123 exec(*command)
124 end
926d3dd @danlucraft Changed the install process so it requires a 'sudo redcar install' step....
danlucraft authored
125 end
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
126
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
127 def self.root
128 File.expand_path(File.join(File.dirname(__FILE__), ".."))
129 end
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
130
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
131 def self.plugin_manager
132 @plugin_manager ||= begin
133 m = PluginManager.new
134 m.add_plugin_source(File.join(root, "plugins"))
135 m.add_plugin_source(File.join(user_dir, "plugins"))
136 m
137 end
138 end
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
139
64ea71b @danlucraft Writing documentation
danlucraft authored
140 # Tells the plugin manager to load plugins, and prints debug output.
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
141 def self.load
e5ab655 @danlucraft Load the openssl gem after we are sure we are not installing
danlucraft authored
142 $:.push File.expand_path(File.join(File.dirname(__FILE__), "plugin_manager", "lib"))
143 require 'plugin_manager'
144
547e879 @danlucraft Add json submodule
danlucraft authored
145 $:.push File.expand_path(File.join(File.dirname(__FILE__), "json", "lib"))
146 require 'json'
147
af6e4da @danlucraft Binary assets are loaded directly from ~/.redcar
danlucraft authored
148 $:.push File.expand_path(File.join(Redcar.asset_dir))
149
c5607c4 @danlucraft Move openssl require to lib/redcar.rb, as lots of stuff will need it
danlucraft authored
150 $:.push File.expand_path(File.join(File.dirname(__FILE__), "openssl", "lib"))
151 require 'openssl'
152
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
153 plugin_manager.load
154 if plugin_manager.unreadable_definitions.any?
155 puts "Couldn't read definition files: "
156 puts plugin_manager.unreadable_definitions.map {|d| " * " + d}
157 end
158 if plugin_manager.plugins_with_errors.any?
5b1be1a @rdp add some helper methods to window and document
rdp authored
159 puts "There was an error loading plugins: "
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
160 puts plugin_manager.plugins_with_errors.map {|d| " * " + d.name}
161 end
162 if ENV["PLUGIN_DEBUG"]
163 puts "Loaded plugins:"
164 puts plugin_manager.loaded_plugins.map {|d| " * " + d.name}
165 puts
166 puts "Unloaded plugins:"
167 puts plugin_manager.unloaded_plugins.map {|d| " * " + d.name}
168 end
169 end
170
64ea71b @danlucraft Writing documentation
danlucraft authored
171 # Starts the GUI.
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
172 def self.pump
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
173 Redcar.gui.start
174 end
4bf5b18 @danlucraft Speculative jmv change
danlucraft authored
175
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
176 # Platform specific ~/.redcar
177 #
178 # @return [String] expanded path
179 def self.user_dir
fbad936 @danlucraft Use a clean environment for features
danlucraft authored
180 dirname = {
181 :user => ".redcar",
182 :test => ".redcar_test",
183 :debug => ".redcar_debug"
184 }[Redcar.environment]
8a7e7b9 @danlucraft Add Redcar.home_dir method for getting the user's ~/
danlucraft authored
185 File.expand_path(File.join(home_dir, dirname))
186 end
187
fbeecd7 @danlucraft Clean up some stuff
danlucraft authored
188 # Platform specific ~/.redcar/assets
af6e4da @danlucraft Binary assets are loaded directly from ~/.redcar
danlucraft authored
189 def self.asset_dir
fbeecd7 @danlucraft Clean up some stuff
danlucraft authored
190 File.join(user_dir, "assets")
191 end
192
8a7e7b9 @danlucraft Add Redcar.home_dir method for getting the user's ~/
danlucraft authored
193 # Platform specific ~/
194 #
195 # @return [String] expanded path
196 def self.home_dir
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
197 if platform == :windows
198 if ENV['USERPROFILE'].nil?
8a7e7b9 @danlucraft Add Redcar.home_dir method for getting the user's ~/
danlucraft authored
199 userdir = "C:/My Documents/"
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
200 else
8a7e7b9 @danlucraft Add Redcar.home_dir method for getting the user's ~/
danlucraft authored
201 userdir = ENV['USERPROFILE']
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
202 end
203 else
8a7e7b9 @danlucraft Add Redcar.home_dir method for getting the user's ~/
danlucraft authored
204 userdir = ENV['HOME'] unless ENV['HOME'].nil?
1fa016d @danlucraft Bumped version number to 0.3.3dev and merged boot.rb into redcar.rb
danlucraft authored
205 end
62aa218 @danlucraft Fix specs and features for new code loading
danlucraft authored
206 end
64ea71b @danlucraft Writing documentation
danlucraft authored
207
208 class << self
209 attr_accessor :app
210 attr_reader :gui
211 end
c895419 @danlucraft Read input from STDIN and open in a tab
danlucraft authored
212
64ea71b @danlucraft Writing documentation
danlucraft authored
213 # Set the application GUI.
214 def self.gui=(gui)
215 raise "can't set gui twice" if @gui
216 @gui = gui
217 end
926d3dd @danlucraft Changed the install process so it requires a 'sudo redcar install' step....
danlucraft authored
218 end
219
58640fb @danlucraft Move install command help into usage.rb
danlucraft authored
220 usage = Redcar::Usage.new
221 usage.version_string
222 usage.version_requested
223 usage.help_requested
Something went wrong with that request. Please try again.