From 459d82689edd58f387de224711e1cdb7550327e3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 23 May 2012 15:57:43 -0700 Subject: [PATCH] Get rid of autoload use in Guests I don't use `activated` here because I'd really like to optimize performance as much as possible, and loading files from disk is generally slow. So instead of using `activated` I load the file at the last possible moment which is when the exact class is being requested. I don't think many people will do this outside of the core, and I'm not too concerned. --- plugins/guests/arch/guest.rb | 3 +++ plugins/guests/arch/plugin.rb | 7 ++++--- plugins/guests/debian/guest.rb | 3 +++ plugins/guests/debian/plugin.rb | 7 ++++--- plugins/guests/fedora/guest.rb | 3 +++ plugins/guests/fedora/plugin.rb | 10 +++++++--- plugins/guests/freebsd/plugin.rb | 14 +++++++++----- plugins/guests/gentoo/guest.rb | 3 +++ plugins/guests/gentoo/plugin.rb | 7 ++++--- plugins/guests/linux/guest.rb | 2 ++ plugins/guests/linux/plugin.rb | 14 +++++++++----- plugins/guests/openbsd/guest.rb | 4 ++++ plugins/guests/openbsd/plugin.rb | 7 ++++--- plugins/guests/redhat/guest.rb | 3 +++ plugins/guests/redhat/plugin.rb | 7 ++++--- plugins/guests/solaris/guest.rb | 2 ++ plugins/guests/solaris/plugin.rb | 14 +++++++++----- plugins/guests/suse/guest.rb | 4 ++++ plugins/guests/suse/plugin.rb | 7 ++++--- plugins/guests/ubuntu/guest.rb | 4 ++++ plugins/guests/ubuntu/plugin.rb | 7 ++++--- 21 files changed, 93 insertions(+), 39 deletions(-) diff --git a/plugins/guests/arch/guest.rb b/plugins/guests/arch/guest.rb index a45efb369..dfea86541 100644 --- a/plugins/guests/arch/guest.rb +++ b/plugins/guests/arch/guest.rb @@ -1,8 +1,11 @@ require 'set' require 'tempfile' +require "vagrant" require 'vagrant/util/template_renderer' +require Vagrant.source_root.join("plugins/guests/linux/guest") + module VagrantPlugins module GuestArch class Guest < VagrantPlugins::GuestLinux::Guest diff --git a/plugins/guests/arch/plugin.rb b/plugins/guests/arch/plugin.rb index 864463f65..7ae62c0c2 100644 --- a/plugins/guests/arch/plugin.rb +++ b/plugins/guests/arch/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestArch - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Arch guest" description "Arch guest support." - guest("arch") { Guest } + guest("arch") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/debian/guest.rb b/plugins/guests/debian/guest.rb index d43e50c25..411e0f329 100644 --- a/plugins/guests/debian/guest.rb +++ b/plugins/guests/debian/guest.rb @@ -1,8 +1,11 @@ require 'set' require 'tempfile' +require "vagrant" require 'vagrant/util/template_renderer' +require Vagrant.source_root.join("plugins/guests/linux/guest") + module VagrantPlugins module GuestDebian class Guest < VagrantPlugins::GuestLinux::Guest diff --git a/plugins/guests/debian/plugin.rb b/plugins/guests/debian/plugin.rb index c4124e00e..4508064ec 100644 --- a/plugins/guests/debian/plugin.rb +++ b/plugins/guests/debian/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestDebian - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Debian guest" description "Debian guest support." - guest("debian") { Guest } + guest("debian") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/fedora/guest.rb b/plugins/guests/fedora/guest.rb index adbaa5a3e..ca7414723 100644 --- a/plugins/guests/fedora/guest.rb +++ b/plugins/guests/fedora/guest.rb @@ -1,8 +1,11 @@ require 'set' require 'tempfile' +require "vagrant" require 'vagrant/util/template_renderer' +require Vagrant.source_root.join("plugins/guests/linux/guest") + module VagrantPlugins module GuestFedora class Guest < VagrantPlugins::GuestLinux::Guest diff --git a/plugins/guests/fedora/plugin.rb b/plugins/guests/fedora/plugin.rb index 1d55b2db5..19be0ab72 100644 --- a/plugins/guests/fedora/plugin.rb +++ b/plugins/guests/fedora/plugin.rb @@ -2,13 +2,17 @@ require "vagrant" module VagrantPlugins module GuestFedora - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Fedora guest" description "Fedora guest support." - guest("fedora") { Guest } + activated do + end + + guest("fedora") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/freebsd/plugin.rb b/plugins/guests/freebsd/plugin.rb index 00f9f4555..8fe7f8529 100644 --- a/plugins/guests/freebsd/plugin.rb +++ b/plugins/guests/freebsd/plugin.rb @@ -2,15 +2,19 @@ require "vagrant" module VagrantPlugins module GuestFreeBSD - autoload :Config, File.expand_path("../config", __FILE__) - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "FreeBSD guest" description "FreeBSD guest support." - config("freebsd") { Config } - guest("freebsd") { Guest } + config("freebsd") do + require File.expand_path("../config", __FILE__) + Config + end + + guest("freebsd") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/gentoo/guest.rb b/plugins/guests/gentoo/guest.rb index 4dc19817d..48e9cd1e3 100644 --- a/plugins/guests/gentoo/guest.rb +++ b/plugins/guests/gentoo/guest.rb @@ -1,7 +1,10 @@ require 'tempfile' +require "vagrant" require 'vagrant/util/template_renderer' +require Vagrant.source_root.join("plugins/guests/linux/guest") + module VagrantPlugins module GuestGentoo class Guest < VagrantPlugins::GuestLinux::Guest diff --git a/plugins/guests/gentoo/plugin.rb b/plugins/guests/gentoo/plugin.rb index 2796b1d71..ab9b618e9 100644 --- a/plugins/guests/gentoo/plugin.rb +++ b/plugins/guests/gentoo/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestGentoo - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Gentoo guest" description "Gentoo guest support." - guest("gentoo") { Guest } + guest("gentoo") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/linux/guest.rb b/plugins/guests/linux/guest.rb index 23ab0f746..69ccd6890 100644 --- a/plugins/guests/linux/guest.rb +++ b/plugins/guests/linux/guest.rb @@ -1,5 +1,7 @@ require 'log4r' +require "vagrant" + module VagrantPlugins module GuestLinux class Guest < Vagrant::Guest::Base diff --git a/plugins/guests/linux/plugin.rb b/plugins/guests/linux/plugin.rb index ed5149797..c095e8059 100644 --- a/plugins/guests/linux/plugin.rb +++ b/plugins/guests/linux/plugin.rb @@ -2,15 +2,19 @@ require "vagrant" module VagrantPlugins module GuestLinux - autoload :Config, File.expand_path("../config", __FILE__) - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Linux guest." description "Linux guest support." - config("linux") { Config } - guest("linux") { Guest } + config("linux") do + require File.expand_path("../config", __FILE__) + Config + end + + guest("linux") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/openbsd/guest.rb b/plugins/guests/openbsd/guest.rb index 42de5d6d1..5fb8af200 100644 --- a/plugins/guests/openbsd/guest.rb +++ b/plugins/guests/openbsd/guest.rb @@ -1,3 +1,7 @@ +require "vagrant" + +require Vagrant.source_root.join("plugins/guests/linux/guest") + module VagrantPlugins module GuestOpenBSD class Guest < VagrantPlugins::GuestLinux::Guest diff --git a/plugins/guests/openbsd/plugin.rb b/plugins/guests/openbsd/plugin.rb index 7f9f1f430..bce655ba4 100644 --- a/plugins/guests/openbsd/plugin.rb +++ b/plugins/guests/openbsd/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestOpenBSD - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "OpenBSD guest" description "OpenBSD guest support." - guest("openbsd") { Guest } + guest("openbsd") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/redhat/guest.rb b/plugins/guests/redhat/guest.rb index 681fe4f47..269900182 100644 --- a/plugins/guests/redhat/guest.rb +++ b/plugins/guests/redhat/guest.rb @@ -1,8 +1,11 @@ require 'set' require 'tempfile' +require "vagrant" require 'vagrant/util/template_renderer' +require Vagrant.source_root.join("plugins/guests/linux/guest") + module VagrantPlugins module GuestRedHat class Guest < VagrantPlugins::GuestLinux::Guest diff --git a/plugins/guests/redhat/plugin.rb b/plugins/guests/redhat/plugin.rb index fd88a2504..4b88e6766 100644 --- a/plugins/guests/redhat/plugin.rb +++ b/plugins/guests/redhat/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestRedHat - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "RedHat guest" description "RedHat guest support." - guest("redhat") { Guest } + guest("redhat") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/solaris/guest.rb b/plugins/guests/solaris/guest.rb index 9baa11bbb..031013311 100644 --- a/plugins/guests/solaris/guest.rb +++ b/plugins/guests/solaris/guest.rb @@ -1,3 +1,5 @@ +require "vagrant" + module VagrantPlugins module GuestSolaris # A general Vagrant system implementation for "solaris". diff --git a/plugins/guests/solaris/plugin.rb b/plugins/guests/solaris/plugin.rb index 03eb181ac..1cdecdff2 100644 --- a/plugins/guests/solaris/plugin.rb +++ b/plugins/guests/solaris/plugin.rb @@ -2,15 +2,19 @@ require "vagrant" module VagrantPlugins module GuestSolaris - autoload :Config, File.expand_path("../config", __FILE__) - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Solaris guest." description "Solaris guest support." - config("solaris") { Config } - guest("solaris") { Guest } + config("solaris") do + require File.expand_path("../config", __FILE__) + Config + end + + guest("solaris") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/suse/guest.rb b/plugins/guests/suse/guest.rb index bba0c7ec0..cc8045c6c 100644 --- a/plugins/guests/suse/guest.rb +++ b/plugins/guests/suse/guest.rb @@ -1,3 +1,7 @@ +require "vagrant" + +require Vagrant.source_root.join("plugins/guests/redhat/guest") + module VagrantPlugins module GuestSuse class Guest < VagrantPlugins::GuestRedHat::Guest diff --git a/plugins/guests/suse/plugin.rb b/plugins/guests/suse/plugin.rb index e692b0e29..5cef846c8 100644 --- a/plugins/guests/suse/plugin.rb +++ b/plugins/guests/suse/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestSuse - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "SUSE guest" description "SUSE guest support." - guest("suse") { Guest } + guest("suse") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end diff --git a/plugins/guests/ubuntu/guest.rb b/plugins/guests/ubuntu/guest.rb index 8e30ba8b4..818c83550 100644 --- a/plugins/guests/ubuntu/guest.rb +++ b/plugins/guests/ubuntu/guest.rb @@ -1,3 +1,7 @@ +require "vagrant" + +require Vagrant.source_root.join("plugins/guests/debian/guest") + module VagrantPlugins module GuestUbuntu class Guest < VagrantPlugins::GuestDebian::Guest diff --git a/plugins/guests/ubuntu/plugin.rb b/plugins/guests/ubuntu/plugin.rb index 2cd361b90..dc6998c6b 100644 --- a/plugins/guests/ubuntu/plugin.rb +++ b/plugins/guests/ubuntu/plugin.rb @@ -2,13 +2,14 @@ require "vagrant" module VagrantPlugins module GuestUbuntu - autoload :Guest, File.expand_path("../guest", __FILE__) - class Plugin < Vagrant.plugin("1") name "Ubuntu guest" description "Ubuntu guest support." - guest("ubuntu") { Guest } + guest("ubuntu") do + require File.expand_path("../guest", __FILE__) + Guest + end end end end