Skip to content

Commit

Permalink
Item13079: More refactoring of Bootstrap
Browse files Browse the repository at this point in the history
Clean up the "noload" hack uset by TestBootstrapPlugin

Add a "noLocal" option to readConfig().  This is used during
bootstrap testing so that Spec files can be merged without loading a
LocalSite.cfg file.

Needed: addition of $reporter support instead of returning
strings.
  • Loading branch information
gac410 committed Nov 9, 2014
1 parent b7d4d43 commit 5c1484e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions core/lib/Foswiki/Configure/Load.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ sub _workOutOS {

=begin TML
---++ StaticMethod readConfig([$noexpand][,$nospec][,$config_spec])
---++ StaticMethod readConfig([$noexpand][,$nospec][,$config_spec][,$noLocal)
In normal Foswiki operations as a web server this method is called by the
=BEGIN= block of =Foswiki.pm=. However, when benchmarking/debugging it can be
replaced by custom code which sets the configuration hash. To prevent us from
overriding the custom code again, we use an "unconfigurable" key
=$cfg{ConfigurationFinished}= as an indicator.
Note that this method is called by Foswiki and configure, and *only* reads
Note that this method is called by Foswiki and configure, and normally reads
=Foswiki.spec= to get defaults. Other spec files (those for extensions) are
*not* read.
*not* read unless the $config_spec flag is set.
The assumption is that =configure= will be run when an extension is installed,
and that will add the config values to LocalSite.cfg, so no defaults are
Expand All @@ -99,12 +99,15 @@ provide defaults, and it would be silly to have them in two places anyway.
values.
* =$nospec= - can be set when the caller knows that Foswiki.spec
has already been read.
* =$config_spec - if set, will also read Config.spec files located
* =$config_spec= - if set, will also read Config.spec files located
using the standard methods (iff !$nospec). Slow.
* =$noLocal= - if set, Load will not re-read an existing LocalSite.cfg.
this is needed when testing the bootstrap. If it rereads an existing
config, it overlays all the bootstrapped settings.
=cut

sub readConfig {
my ( $noexpand, $nospec, $config_spec ) = @_;
my ( $noexpand, $nospec, $config_spec, $noLocal ) = @_;

# To prevent us from overriding the custom code in test mode
return if $Foswiki::cfg{ConfigurationFinished};
Expand All @@ -118,6 +121,9 @@ sub readConfig {
_workOutOS();

my @files = qw( Foswiki.spec LocalSite.cfg );
if ($noLocal) {
pop @files;
}
if ($nospec) {
shift @files;
}
Expand Down Expand Up @@ -325,20 +331,14 @@ sub setBootstrap {

=begin TML
---++ StaticMethod bootstrapConfig( $noload )
---++ StaticMethod bootstrapConfig()
This routine is called from Foswiki.pm BEGIN block to discover the mandatory
settings for operation when a LocalSite.cfg could not be found.
SMELL: The noload paramter is used by the TestBootstrapPlugin to suppress loading of
the complete Foswiki.spec and Config.spec files during bootstrap. It was added
so that the test plutin could report exactly what was set during the bootstrap.
This can probably be eliminated at some point.
=cut

sub bootstrapConfig {
my $noload = shift;

# Failed to read LocalSite.cfg
# Clear out $Foswiki::cfg to allow variable expansion to work
Expand Down Expand Up @@ -438,10 +438,11 @@ directories: $fatal
EPITAPH
}

# Re-read Foswiki.spec *and Config.spec*. We need the Config.spec's
# to get a true picture of our defaults (notably those from
# JQueryPlugin. Without the Config.spec, no plugins get registered)
Foswiki::Configure::Load::readConfig( 0, 0, 1 ) unless ($noload);
# Re-read Foswiki.spec *and Config.spec*. We need the Config.spec's
# to get a true picture of our defaults (notably those from
# JQueryPlugin. Without the Config.spec, no plugins get registered)
# Don't load LocalSite.cfg if it exists (should normally not exist when bootstrapping)
Foswiki::Configure::Load::readConfig( 0, 0, 1, 1 );

_workOutOS();

Expand Down

0 comments on commit 5c1484e

Please sign in to comment.