[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.9.7-923-g60a7ba2
Chia-liang Kao
clkao at bestpractical.com
Fri Dec 17 10:37:34 EST 2010
The branch, 3.9-trunk has been updated
via 60a7ba2782d3d0779c4c4137c19678ae89233b55 (commit)
via a7dee13e7e4a083b1a989cb2e61da88f385882eb (commit)
from 811af6f29d87fd28d304d93a4905465006d9761f (commit)
Summary of changes:
lib/RT.pm | 71 +++++++++++++++++-----------------
lib/RT/Plugin.pm | 9 ++--
lib/RT/Test.pm | 2 +-
sbin/rt-server.in | 2 +-
share/html/Admin/Global/Plugins.html | 2 +-
t/plugins/api.t | 5 ++-
6 files changed, 47 insertions(+), 44 deletions(-)
- Log -----------------------------------------------------------------
commit a7dee13e7e4a083b1a989cb2e61da88f385882eb
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Dec 17 23:31:32 2010 +0800
Make sure RT::Interface::Web::Handler is loaded early enough.
diff --git a/sbin/rt-server.in b/sbin/rt-server.in
index 97ad46a..6ca2b1c 100755
--- a/sbin/rt-server.in
+++ b/sbin/rt-server.in
@@ -84,6 +84,7 @@ if (grep { m/help/ } @ARGV) {
}
require RT;
+require RT::Interface::Web::Handler;
RT->LoadConfig();
require RT::Handle;
@@ -134,7 +135,6 @@ if ($RT::Handle) {
undef $RT::Handle;
}
-require RT::Interface::Web::Handler;
my $app = RT::Interface::Web::Handler->PSGIApp;
if ($ENV{RT_TESTING}) {
commit 60a7ba2782d3d0779c4c4137c19678ae89233b55
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Dec 17 23:32:47 2010 +0800
Bring back the separate stage for actually loading plugins during init.
The original change made the plugins loaded when RT->Plugins is called
the first time, which is when LoadConfig needs to get all the etc
directories of plugins. However that was too early for plugins
overriding core functions.
diff --git a/lib/RT.pm b/lib/RT.pm
index b32972c..8706e05 100755
--- a/lib/RT.pm
+++ b/lib/RT.pm
@@ -144,7 +144,7 @@ sub Init {
InitSystemObjects();
InitClasses();
InitLogging();
- RT->Plugins();
+ RT->InitPlugins();
RT::I18N->Init;
RT->Config->PostLoadCheck;
@@ -549,6 +549,7 @@ also L</InitSystemObjects>.
sub Nobody { return $Nobody }
my $PLUGINS;
+my $ENABLED_PLUGINS;
my $LOADED_PLUGINS;
=head2 ProbePlugins($reprobe)
@@ -562,6 +563,23 @@ sub ProbePlugins {
my $reprobe = shift;
undef $PLUGINS if $reprobe;
$PLUGINS ||= RT::Plugin->AvailablePlugins;
+
+ @$ENABLED_PLUGINS = ();
+ for (grep $_, RT->Config->Get('Plugins')) {
+ s/::/-/g;
+ my $plugin = $PLUGINS->{$_};
+ $plugin->ConfigEnabled(1);
+ $plugin->Enabled(1);
+ push @$ENABLED_PLUGINS, $plugin;
+ }
+
+ for (keys %$PLUGINS) {
+ my $plugin = $PLUGINS->{$_};
+ next unless -e $plugin->Path(".enabled");
+
+ $plugin->Enabled(1);
+ push @$ENABLED_PLUGINS, $plugin;
+ }
}
=head2 Plugins
@@ -575,10 +593,7 @@ sub Plugins {
my $self = shift;
$self->ProbePlugins;
- unless ($LOADED_PLUGINS) {
- $self->InitPlugins;
- }
- return $LOADED_PLUGINS;
+ return $ENABLED_PLUGINS;
}
=head2 PluginDirs
@@ -627,42 +642,28 @@ Initialze all Plugins found in the RT configuration file, setting up their lib a
=cut
-sub _try_enable_plugin {
- my ($self, $plugin_name, $explicit) = @_;
-
- my $plugin = $PLUGINS->{$plugin_name};
- unless ($plugin) {
- # XXX: this is mostly for testing for rt plugin dists.
- $PLUGINS->{$plugin_name} = $plugin = RT::Plugin->new(Name => $plugin_name);
- }
- return if $plugin->Enabled;
-
- if ( $explicit || -e $plugin->Path(".enabled")) {
- eval { $plugin->Enable($explicit); 1 }
- or do {
- # XXX: the rt bootstrapping sequence loads RT_Config
- # first, which requires scanning plugin directories,
- # so the very first initplugins calls is actually
- # before initlogging.
- warn "Unable to load plugin: $plugin_name: $@";
- return;
- };
- push @$LOADED_PLUGINS, $plugin;
- }
+sub _try_load_plugin {
+ my ($self, $plugin) = @_;
+
+ eval { $plugin->Load; 1 }
+ or do {
+ # XXX: the rt bootstrapping sequence loads RT_Config
+ # first, which requires scanning plugin directories,
+ # so the very first initplugins calls is actually
+ # before initlogging.
+ warn "Unable to load plugin: @{[ $plugin->Name ]}: $@";
+ return;
+ };
+ push @$LOADED_PLUGINS, $plugin;
}
sub InitPlugins {
my $self = shift;
- $LOADED_PLUGINS ||= [];
require RT::Plugin;
- for (grep $_, RT->Config->Get('Plugins')) {
- s/::/-/g;
- $self->_try_enable_plugin($_, 1);
- }
-
- for (keys %$PLUGINS) {
- $self->_try_enable_plugin($_);
+ for (@$ENABLED_PLUGINS) {
+ $self->_try_load_plugin($_)
+ unless $_->Loaded;
}
return @$LOADED_PLUGINS;
diff --git a/lib/RT/Plugin.pm b/lib/RT/Plugin.pm
index d8771a9..7638c8b 100644
--- a/lib/RT/Plugin.pm
+++ b/lib/RT/Plugin.pm
@@ -72,6 +72,7 @@ use List::MoreUtils qw(first_index);
has _added_inc_path => (is => "rw", isa => "Str");
has Name => (is => "rw", isa => "Str");
+has Loaded => (is => "rw", isa => "Bool");
has Enabled => (is => "rw", isa => "Bool");
has ConfigEnabled => (is => "rw", isa => "Bool");
has Description => (is => "rw", isa => "Str");
@@ -88,11 +89,9 @@ sub new {
# the @INC entry that plugins lib dirs should be pushed splice into.
# it should be the one after local lib
my $inc_anchor;
-sub Enable {
- my ($self, $global) = @_;
+sub Load {
+ my ($self) = @_;
my $add = $self->Path("lib");
- $self->ConfigEnabled(1)
- if $global;
unless (defined $inc_anchor) {
my $anchor = first_index { Cwd::realpath($_) eq Cwd::realpath($RT::LocalLibPath) } @INC;
$inc_anchor = ($anchor == -1 || $anchor == $#INC) # not found or last
@@ -109,7 +108,7 @@ sub Enable {
$module =~ s/-/::/g;
$module->require;
die $UNIVERSAL::require::ERROR if ($UNIVERSAL::require::ERROR);
- $self->Enabled(1);
+ $self->Loaded(1);
$self->_added_inc_path( $add );
}
diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index c8cdfc2..cb6c023 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -487,7 +487,7 @@ sub bootstrap_plugins {
$RT::Handle->Connect; # XXX: strange but mysql can loose connection
}
$dba_dbh->disconnect if $dba_dbh;
- return RT->Plugins;
+ return RT->InitPlugins;
}
sub _get_dbh {
diff --git a/share/html/Admin/Global/Plugins.html b/share/html/Admin/Global/Plugins.html
index 2767f6e..ef55177 100644
--- a/share/html/Admin/Global/Plugins.html
+++ b/share/html/Admin/Global/Plugins.html
@@ -95,7 +95,7 @@ if ($PluginName) {
if ($Enable) {
if ( eval { die loc("You need to make the directory [_1] writable first.\n", $plugin->Path)
unless -w $plugin->Path;
- $plugin->Enable;
+ $plugin->Load;
open my $fh, '>', $plugin_enable
or die $!;
close $fh;
diff --git a/t/plugins/api.t b/t/plugins/api.t
index 876b92d..a7a44d4 100644
--- a/t/plugins/api.t
+++ b/t/plugins/api.t
@@ -19,7 +19,6 @@ BEGIN {
use RT::Test nodb => 1, tests => 9;
-is_deeply([RT->PluginDirs('lib')], []);
ok(!grep { $_ eq "$RT::LocalPluginPath/Hello/lib" } @INC);;
RT->Config->Set('Plugins',qw(Hello));
@@ -27,6 +26,9 @@ RT->ProbePlugins(1);
RT->UnloadPlugins;
RT->Plugins;
+ok(!grep { $_ eq "$RT::LocalPluginPath/Hello/lib" } @INC);;
+
+RT->InitPlugins;
ok(grep { $_ eq "$RT::LocalPluginPath/Hello/lib" } @INC);;
is_deeply([RT->PluginDirs('lib')], ["$RT::LocalPluginPath/Hello/lib"], 'plugin lib dir found');
@@ -55,6 +57,7 @@ RT->Config->Set('Plugins',qw(Hello World));
RT->ProbePlugins(1);
RT->UnloadPlugins;
RT->Plugins;
+RT->InitPlugins;
is_deeply([@INC[0..2]],
[map { abs_path($_) }
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list