aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2005-11-06 01:39:32 +0000
committerSam Stephenson <sam@37signals.com>2005-11-06 01:39:32 +0000
commitd3275cadaa410fc00365db41d0155e4fa463e128 (patch)
tree0c187feec0fe62486a1039540a37d1f42a7d6d04
parent55fab64391593641b7722d35fc8099da205ffc1a (diff)
downloadrails-d3275cadaa410fc00365db41d0155e4fa463e128.tar.gz
rails-d3275cadaa410fc00365db41d0155e4fa463e128.tar.bz2
rails-d3275cadaa410fc00365db41d0155e4fa463e128.zip
Enable HTTP installation of plugins when svn isn't avaialable. Closes #2661. [Chad Fowler]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2885 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/lib/commands/plugin.rb80
2 files changed, 74 insertions, 8 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 58b90a8aaa..2363bb805c 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Enable HTTP installation of plugins when svn isn't avaialable. Closes #2661. [Chad Fowler]
+
* Load Rails::Info after initialization [Sam Stephenson]
* Added script/about to display formatted Rails::Info output [Sam Stephenson]
diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb
index f666d6a2b9..36fe914f24 100644
--- a/railties/lib/commands/plugin.rb
+++ b/railties/lib/commands/plugin.rb
@@ -44,13 +44,9 @@
# and is licensed MIT: (http://www.opensource.org/licenses/mit-license.php)
$verbose = false
-`svn --version`
-unless $?.success?
- $stderr.puts "ERROR: Must have subversion (svn) available in the PATH to use plugin manager"
- exit 1
-end
+require 'open-uri'
require 'fileutils'
require 'tempfile'
@@ -95,7 +91,12 @@ class RailsEnvironment
puts "plugin not found: #{name_uri_or_plugin}"
end
end
-
+
+ def use_svn?
+ `svn --version`
+ $?.success?
+ end
+
def use_externals?
File.directory?("#{root}/vendor/plugins/.svn")
end
@@ -108,6 +109,7 @@ class RailsEnvironment
end
def best_install_method
+ return :http unless use_svn?
case
when use_externals? then :externals
when use_checkout? then :checkout
@@ -181,7 +183,14 @@ class Plugin
rails_env.externals = externals
install_using_checkout
end
-
+
+ def install_using_http
+ root = rails_env.root
+ mkdir_p "#{root}/vendor/plugins"
+ Dir.chdir "#{root}/vendor/plugins"
+ RecursiveHTTPFetcher.new(uri).fetch
+ end
+
def guess_name(url)
@name = File.basename(url)
if @name == 'trunk' || @name.empty?
@@ -662,9 +671,14 @@ module Commands
requested = case
when @export then method = :export
when @checkout then method = :checkout
- else method = :externals
+ when @http then method = :http
+ else method = @base_command.environment.best_install_method
end
best = @base_command.environment.best_install_method
+ if best == :http and requested != :http
+ puts "Cannot install using subversion because `svn' cannot be found in your PATH"
+ exit 1
+ end
if best == :export and requested != :export
puts "Cannot install using #{requested} because this project is not under subversion."
exit 1
@@ -761,5 +775,55 @@ module Commands
end
end
+
+class RecursiveHTTPFetcher
+ def initialize(urls_to_fetch, cwd = ".")
+ @cwd = cwd
+ @urls_to_fetch = urls_to_fetch.to_a
+ end
+
+ def push_d(dir)
+ @cwd = File.join(@cwd, dir)
+ FileUtils.mkdir_p(@cwd)
+ end
+
+ def pop_d
+ @cwd = File.dirname(@cwd)
+ end
+
+ def links(base_url, contents)
+ links = []
+ contents.scan(/href\s*=\s*\"*[^\">]*/i) do |link|
+ link = link.sub(/href="/i, "")
+ next if link =~ /^http/i || link =~ /^\./
+ links << File.join(base_url, link)
+ end
+ links
+ end
+
+ def download(link)
+ puts "+ #{File.join(@cwd, File.basename(link))}"
+ open(link) do |stream|
+ File.open(File.join(@cwd, File.basename(link)), "wb") do |file|
+ file.write(stream.read)
+ end
+ end
+ end
+
+ def fetch(links = @urls_to_fetch)
+ links.each do |l|
+ (l =~ /\/$/ || links == @urls_to_fetch) ? fetch_dir(l) : download(l)
+ end
+ end
+
+ def fetch_dir(url)
+ push_d(File.basename(url))
+ open(url) do |stream|
+ contents = stream.read
+ fetch(links(url, contents))
+ end
+ pop_d
+ end
+end
Commands::Plugin.parse!