Skip to content

Commit

Permalink
Item12952: finish tools/configure script; move common functionality o…
Browse files Browse the repository at this point in the history
…ut of the ConfigurePlugin and into the core.
  • Loading branch information
crawford committed Oct 29, 2014
1 parent a2559f9 commit 652aec2
Show file tree
Hide file tree
Showing 13 changed files with 1,086 additions and 888 deletions.
514 changes: 22 additions & 492 deletions ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# and do nothing.
# **STRING FEEDBACK="label='Test one';wizard='Test';method='test1';auth=1" \
# FEEDBACK="label='Test two';wizard='Test';method='test1'" \
# CHECK="min:3 max:20" **
# CHECK="min:3 max:20"**
# When you press either of the test buttons, expect the value to change
# to "ROPE" and there to be one each of the different levels of report.
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{STRING} = 'STRING';
Expand All @@ -15,7 +15,7 @@ $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{BOOLEAN} = 1;
# **COMMAND**
# Should be COMMAND
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{COMMAND} = 'COMMAND';
# **DATE**
# **DATE CHECK="nullok"**
# Should be 12 Feb 2012
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{DATE} = '12 Feb 2012';
# **EMAILADDRESS**
Expand Down
4 changes: 1 addition & 3 deletions UnitTestContrib/test/unit/ConfigureSaveTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# Tests for the core 'Save' wizard.

use strict;
use warnings;

package ConfigureSaveTests;

use FoswikiTestCase;
Expand Down Expand Up @@ -92,6 +89,7 @@ sub test_changecfg {
my $ms = $reporter->messages();
$this->assert_matches( qr/^Previous/, $ms->[0]->{text} );
$this->assert_matches( qr/^New/, $ms->[1]->{text} );
die Data::Dumper->Dump( [$ms] );
$this->assert_matches(
qr/AccessibleCFG.*\[.+ \[\]/,
$ms->[3]->{text},
Expand Down
31 changes: 0 additions & 31 deletions core/lib/Foswiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -140,35 +140,6 @@ sub _getLibDir {
return $foswikiLibDir;
}

sub _workOutOS {
unless ( ( $Foswiki::cfg{DetailedOS} = $^O ) ) {
require Config;
$Foswiki::cfg{DetailedOS} = $Config::Config{'osname'};
}
$Foswiki::cfg{OS} = 'UNIX';
if ( $Foswiki::cfg{DetailedOS} =~ /darwin/i ) { # MacOS X
$Foswiki::cfg{OS} = 'UNIX';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /Win/i ) {
$Foswiki::cfg{OS} = 'WINDOWS';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /vms/i ) {
$Foswiki::cfg{OS} = 'VMS';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /bsdos/i ) {
$Foswiki::cfg{OS} = 'UNIX';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /dos/i ) {
$Foswiki::cfg{OS} = 'DOS';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /^MacOS$/i ) { # MacOS 9 or earlier
$Foswiki::cfg{OS} = 'MACINTOSH';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /os2/i ) {
$Foswiki::cfg{OS} = 'OS2';
}
}

BEGIN {

#Monitor::MARK("Start of BEGIN block in Foswiki.pm");
Expand Down Expand Up @@ -345,8 +316,6 @@ BEGIN {
);
$contextFreeSyntax{IF} = 1;

_workOutOS();

# Load LocalSite.cfg
if ( Foswiki::Configure::Load::readConfig( 0, 0, 0 ) ) {
$Foswiki::cfg{isVALID} = 1;
Expand Down
5 changes: 5 additions & 0 deletions core/lib/Foswiki/Configure/Checkers/ConfigureFilter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ our @ISA = ('Foswiki::Configure::Checker');
sub check_current_value {
my ( $this, $reporter ) = @_;

# Checkers may be called in a script context, in which case
# Foswiki::Func is not available. However in a script context
# this option isn't interesting anyway.
return unless eval "require Foswiki::Func";

my $it = Foswiki::Func::eachGroupMember( $Foswiki::cfg{SuperAdminGroup} );
my @admins;

Expand Down
82 changes: 81 additions & 1 deletion core/lib/Foswiki/Configure/Load.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ our %remap = (
'{RCS}{WorkAreaDir}' => '{Store}{WorkAreaDir}'
);

sub _workOutOS {
unless ( ( $Foswiki::cfg{DetailedOS} = $^O ) ) {
require Config;
$Foswiki::cfg{DetailedOS} = $Config::Config{'osname'};
}
$Foswiki::cfg{OS} = 'UNIX';
if ( $Foswiki::cfg{DetailedOS} =~ /darwin/i ) { # MacOS X
$Foswiki::cfg{OS} = 'UNIX';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /Win/i ) {
$Foswiki::cfg{OS} = 'WINDOWS';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /vms/i ) {
$Foswiki::cfg{OS} = 'VMS';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /bsdos/i ) {
$Foswiki::cfg{OS} = 'UNIX';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /dos/i ) {
$Foswiki::cfg{OS} = 'DOS';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /^MacOS$/i ) { # MacOS 9 or earlier
$Foswiki::cfg{OS} = 'MACINTOSH';
}
elsif ( $Foswiki::cfg{DetailedOS} =~ /os2/i ) {
$Foswiki::cfg{OS} = 'OS2';
}
}

=begin TML
---++ StaticMethod readConfig([$noexpand][,$nospec][,$config_spec])
Expand Down Expand Up @@ -91,6 +120,8 @@ sub readConfig {
# Read Foswiki.spec and LocalSite.cfg
# (Suppress Foswiki.spec if already read)

_workOutOS();

my @files = qw( Foswiki.spec LocalSite.cfg );
if ($nospec) {
shift @files;
Expand Down Expand Up @@ -284,6 +315,7 @@ settings for operation when a LocalSite.cfg could not be found.

sub bootstrapConfig {
my $noload = shift;
Carp::confess "WTF";

# Failed to read LocalSite.cfg
# Clear out $Foswiki::cfg to allow variable expansion to work
Expand Down Expand Up @@ -471,7 +503,7 @@ EPITAPH
# JQueryPlugin. Without the Config.spec, no plugins get registered)
Foswiki::Configure::Load::readConfig( 0, 0, 1 ) unless ($noload);

Foswiki::_workOutOS();
_workOutOS();

$Foswiki::cfg{isVALID} = 1;
$Foswiki::cfg{isBOOTSTRAPPING} = 1;
Expand Down Expand Up @@ -501,6 +533,54 @@ BOOTS

}

=begin TML
---++ StaticMethod findDependencies(\%cfg) -> \%deps
* =\%cfg= configuration hash to scan; defaults to %Foswiki::cfg
Recursively locate references to other keys in the values of keys.
Returns a hash containing two keys:
* =forward= => a hash mapping keys to a list of the keys that depend
on their value
* =reverse= => a hash mapping keys to a list of keys whose value they
depend on.
=cut

sub findDependencies {
my ( $fwcfg, $deps, $extend_keypath, $keypath ) = @_;

unless ( defined $fwcfg ) {
( $fwcfg, $extend_keypath, $keypath ) = ( \%Foswiki::cfg, 1, '' );
}

$deps ||= { forward => {}, reverse => {} };

if ( ref($fwcfg) eq 'HASH' ) {
while ( my ( $k, $v ) = each %$fwcfg ) {
if ( defined $v ) {
my $subkey = $extend_keypath ? "$keypath\{$k\}" : $keypath;
findDependencies( $v, $deps, $extend_keypath, $subkey );
}
}
}
elsif ( ref($fwcfg) eq 'ARRAY' ) {
foreach my $v (@$fwcfg) {
if ( defined $v ) {
findDependencies( $v, $deps, 0, $keypath );
}
}
}
else {
while ( $fwcfg =~ /\$Foswiki::cfg(({[^}]*})+)/g ) {
push( @{ $deps->{forward}->{$1} }, $keypath );
push( @{ $deps->{reverse}->{$keypath} }, $1 );
}
}
return $deps;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down
Loading

0 comments on commit 652aec2

Please sign in to comment.