Skip to content

Commit

Permalink
Item12952: fixes for extension installation and handling of perl values
Browse files Browse the repository at this point in the history
  • Loading branch information
crawford committed Oct 16, 2014
1 parent a5ddb65 commit e80d705
Show file tree
Hide file tree
Showing 48 changed files with 832 additions and 546 deletions.
57 changes: 57 additions & 0 deletions ConfigurePlugin/lib/Foswiki/Configure/Wizards/Test.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# See bottom of file for license and copyright information
package Foswiki::Configure::Wizards::Test;

=begin TML
---++ package Foswiki::Configure::Wizards::Test
Wizard to test configure parameter passing
=cut

use strict;
use warnings;

use Assert;

use Foswiki::Configure::Wizard ();
our @ISA = ('Foswiki::Configure::Wizard');

sub test1 {
my ( $this, $reporter ) = @_;

die "No username" unless $this->param('cfgusername');
die "No password" unless $this->param('cfgpassword');
$reporter->ERROR("This is an error");
$reporter->WARN("This is a warning");
$reporter->NOTE("This is a note");
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{STRING} = 'ROPE';
$reporter->CHANGED('{Plugins}{ConfigurePlugin}{Test}{STRING}');
return undef;
}

sub format {
my ( $this, $reporter ) = @_;
$reporter->CHANGED('{Plugins}{ConfigurePlugin}{Test}{PERL}');
return undef;
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2014 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.
23 changes: 19 additions & 4 deletions ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ hash with fields =keys= and =reports=. =reports= is an array of reports,
each being a hash with keys =level= (e.g. =warnings=, =errors=), and
=message=.
Any errors will be reported using exceptions.
=cut

sub _getSetParams {
Expand All @@ -426,7 +428,8 @@ sub _getSetParams {
my $spec = $root->getValueObject($k);
my $value = $v;
if ($spec) {
$value = $spec->decodeValue($value);
eval { $value = $spec->decodeValue( $value, 1 ); };
die "The value of $k was unreadable: $@" if $@;
}
if ( defined $value ) {
eval "\$Foswiki::cfg$k=\$value";
Expand All @@ -438,7 +441,7 @@ sub _getSetParams {
else {
eval "undef \$Foswiki::cfg$k";
}
die $@ if $@;
die $@ if ($@);
}

# Expand imported values
Expand Down Expand Up @@ -498,7 +501,14 @@ sub check_current_value {
my %deps;

# Apply "set" values to $Foswiki::cfg
_getSetParams( $params, $root );
eval { _getSetParams( $params, $root ); };

if ($@) {
$reporter->ERROR( '<verbatim>'
. Foswiki::Configure::Reporter::stripStacktrace($@)
. '</verbatim>' );
return [ { reports => $reporter->messages() } ];
}

if ( $params->{check_dependencies} ) {

Expand Down Expand Up @@ -594,7 +604,12 @@ sub wizard {
$method = $1; # untaint
my $reporter = Foswiki::Configure::Reporter->new();

_getSetParams( $params, $root );
eval { _getSetParams( $params, $root ); };

if ($@) {
$reporter->ERROR( Foswiki::Configure::Reporter::stripStacktrace($@) );
return undef;
}

my $response = $target->$method($reporter);

Expand Down
21 changes: 11 additions & 10 deletions ConfigurePlugin/lib/Foswiki/Plugins/ConfigurePlugin/Config.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# ---+++ Testing
# The following key specs are only used in testing the ConfigurePlugin
# and do nothing.
# **STRING FEEDBACK="label='Test one';wizard='Test';method='test';auth=1" \
# FEEDBACK="label='Test two';wizard='Gandalf';method='wand'" \
# **STRING FEEDBACK="label='Test one';wizard='Test';method='test1';auth=1" \
# FEEDBACK="label='Test two';wizard='Test';method='test1'" \
# CHECK="min:3 max:20" **
# When you press the Test button, expect the value to change to "ROPE" and
# there to be one each of the different levels of report.
# 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';
# **BOOLEAN**
# Should be 1
Expand All @@ -33,14 +33,15 @@ $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{PASSWORD} = 'PASSWORD';
# **PATH**
# Should be PATH
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{PATH} = 'PATH';
# **PERL**
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{PERL} = '\'PERL\';';
# **PERL FEEDBACK="label='Format';wizard='Test';method='format'" **
# The test button should come back with a prettified version of your value.
#$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{PERL} = '\'PERL\';';
# **REGEX**
# Should be '^regex$'
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{REGEX} = '^regex$';
# **SELECTCLASS none,Foswiki::Confi* **
# Should be Foswiki::Configure
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{SELECTCLASS} = 'Foswiki::Configure';
# **SELECTCLASS none,Foswiki::Configure::P* **
# Should be Package; should offer Pluggables,Package
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{SELECTCLASS} = 'Foswiki::Configure::Package';
# **SELECT choose,life**
# Should be life
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{SELECT} = 'life';
Expand All @@ -54,7 +55,7 @@ $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{H} = 'H';
# **STRING EXPERT**
# Should be EXPERT
$Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{EXPERT} = 'EXPERT';
# **PATH**
# **PATH CHECK='nullok'**
# Should be 'empty'
# $Foswiki::cfg{Plugins}{ConfigurePlugin}{Test}{empty} = 'empty';
# **STRING**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
!noci
bin/configure
data/System/ConfigurePlugin.txt 0644 Documentation page
lib/Foswiki/Configure/Wizards/Test.pm 0444 Perl module
lib/Foswiki/Plugins/ConfigurePlugin.pm 0444 Perl module
lib/Foswiki/Plugins/ConfigurePlugin/Config.spec 0444 Configuration
lib/Foswiki/Plugins/ConfigurePlugin/JQuery.pm 0444 Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ function _id_ify(id) {
$('body').css('cursor','auto');
}
});
return;
}
var id = _id_ify(r.keys),
has, $reports, $whine;
Expand Down Expand Up @@ -1000,6 +1001,7 @@ function _id_ify(id) {
var handler = $(this).data('value_handler');
handler.commitVal();
update_modified_default($(this));
$(this).removeClass('value_modified');
});
$('#saveButton').button('disable');
}
Expand Down
2 changes: 0 additions & 2 deletions ConfigurePlugin/test/unit/ConfigurePlugin/SaveTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ sub test_changecfg {
my $reporter = Foswiki::Configure::Reporter->new();
$wizard->save($reporter);

#print STDERR Data::Dumper->Dump([$reporter]);

# Check report
my $ms = $reporter->messages();
$this->assert_matches( qr/^Previous/, $ms->[0]->{text} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $Foswiki::cfg{UnitTestContrib}{SeleniumRc}{Username} = '';
# **PASSWORD 30**
# The password for the Selenium RC user
$Foswiki::cfg{UnitTestContrib}{SeleniumRc}{Password} = '';
# **PERL 40x10 UNDEFINEDOK**
# **PERL 40x10 CHECK='nullok'**
# List the browsers accessible via Selenium RC.
# It is keyed by browser identifier - you choose the identifiers as seems sensible. Browser identifiers may only consist of alphanumeric characters.
# Examples: <code>FF3 FF2dot1OnWindows IE6_1_345 w3m</code>
Expand Down
13 changes: 6 additions & 7 deletions core/lib/Foswiki.spec
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ $Foswiki::cfg{PermittedRedirectHostUrls} = '';
# You may need to set this if your webserver requires an extension.
# $Foswiki::cfg{ScriptSuffix} = '';

# **URLPATH CHECK='expand nullok notrail' FEEDBACK="label='Verify';wizard='ScriptHash';method='verify';auth=1" UNDEFINEDOK MANDATORY**
# **URLPATH CHECK='expand nullok notrail' FEEDBACK="label='Verify';wizard='ScriptHash';method='verify';auth=1" MANDATORY**
#! n.b. options should match Pluggables/SCRIPTHASH.pm for dynamic path items
# This is the complete path used to access the Foswiki view script,
# including any suffix.
Expand Down Expand Up @@ -182,14 +182,14 @@ $Foswiki::cfg{PermittedRedirectHostUrls} = '';
# are pending verification.
# $Foswiki::cfg{WorkingDir} = '/home/httpd/foswiki/working';

# **PATH UNDEFINEDOK EXPERT**
# **PATH CHECK="nullok" EXPERT**
# This is used to override the default system temporary file location.
# Set this if you wish to have control over where working tmp files are
# created. It substitutes for the environment variable =TempfileDir= which
# is not used by Foswiki for security reasons.
#$Foswiki::cfg{TempfileDir} = '';

# **PATH EXPERT UNDEFINEDOK MANDATORY**
# **PATH EXPERT CHECK='nullok' MANDATORY**
# You can override the default PATH setting to control
# where Foswiki looks for external programs, such as grep.
# By restricting this path to just a few key
Expand All @@ -205,7 +205,7 @@ $Foswiki::cfg{PermittedRedirectHostUrls} = '';
# Typical setting is =/cygdrive/c/windows/system32=
#$Foswiki::cfg{SafeEnvPath} = '';

# **STRING 20 UNDEFINEDOK EXPERT**
# **STRING 20 CHECK='nullok' EXPERT**
# {OS} and {DetailedOS} are calculated in the Foswiki code. *You
# should only need to override if there is something badly wrong with
# those calculations*
Expand Down Expand Up @@ -1058,11 +1058,10 @@ $Foswiki::cfg{AccessibleENV} =
# Some environments require outbound HTTP traffic to go through a proxy
# server (for example http://proxy.your.company).
# **URL 30 CHECK='parts:scheme,authority,path,user,pass \
# **URL 30 CHECK='nullok parts:scheme,authority,path,user,pass \
# partsreq:scheme,authority \
# schemes:http,https \
# authtype:hostip \
# nullok' **
# authtype:hostip' **
# Hostname or address of the proxy server.
# If your proxy requires authentication, simply put it in the URL, as in:
# http://username:password@proxy.your.company.
Expand Down
97 changes: 33 additions & 64 deletions core/lib/Foswiki/Configure/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -165,29 +165,28 @@ sub check_current_value {
}
}

=begin TML
---++ ObjectMethod getCfg([$keys]) -> $expanded_value
Get the value of the named configuration var.
* =$keys= - optional keys to retrieve e.g
=getCfg("{Validation}{ExpireKeyOnUse}")=. Defaults to the
keys of the item associated with the checker.
Any embedded references to other Foswiki::cfg vars will be expanded.
Note that any embedded references to undefined variables will be
expanded as the string 'undef'. Use =getCfgUndefOk= if you want a
real undef for undefined values rather than the string.
Synonymous with:
<verbatim>
my $x = '$Foswiki::cfg{Keys}';
Foswiki::Configure::Load::expandValue($x, 0);
</verbatim>
Thus it returns the value as Foswiki will see it (i.e. with undef
expanded as the string 'undef')
=cut
###################################################################
# Compatibility methods
# Note that ASSERT($this->{reporter} if DEBUG is used to confirm that
# the call has come from an implementation of check()

# Get the value of the named configuration var.
# * =$keys= - optional keys to retrieve e.g
# =getCfg("{Validation}{ExpireKeyOnUse}")=. Defaults to the
# keys of the item associated with the checker.
#
# Any embedded references to other Foswiki::cfg vars will be expanded.
# Note that any embedded references to undefined variables will be
# expanded as the string 'undef'. Use =getCfgUndefOk= if you want a
# real undef for undefined values rather than the string.
#
# Synonymous with:
# <verbatim>
# my $x = '$Foswiki::cfg{Keys}';
# Foswiki::Configure::Load::expandValue($x, 0);
# </verbatim>
# Thus it returns the value as Foswiki will see it (i.e. with undef
# expanded as the string 'undef')
sub getCfg {
my ( $this, $name ) = @_;
$name ||= $this->{item}->{keys};
Expand All @@ -197,19 +196,11 @@ sub getCfg {
return $item;
}

=begin TML
---++ ObjectMethod getCfgUndefOk([$keys]) -> $expanded_value
As =getCfg=, except that =undef= will not be expanded to the string 'undef'.
Note that recursive expansion of embedded =$Foswiki::cfg= will also return
undef, and will result in a program error.
=cut

# As =getCfg=, except that =undef= will not be expanded to the string 'undef'.
# Note that recursive expansion of embedded =$Foswiki::cfg= will also return
# undef, and will result in a program error.
sub getCfgUndefOk {

# $undef provided for check() compatibility; new callers must not use it
my ( $this, $name, $undef ) = @_;
$name ||= $this->{item}->{keys};

Expand All @@ -218,11 +209,6 @@ sub getCfgUndefOk {
return $item;
}

###################################################################
# Compatibility methods
# Note that ASSERT($this->{reporter} if DEBUG is used to confirm that
# the call has come from an implementation of check()

# Provided for compatibility; if a checker tries to call SUPER::check and
# the superclass only has check_current_value, it will fold back to here.
sub check {
Expand Down Expand Up @@ -375,16 +361,13 @@ Return the expanded value of a parameter as a note for display.
sub showExpandedValue {
my ( $this, $reporter ) = @_;

my $field = eval "\$Foswiki::cfg$this->{item}->{keys}";
my $field = $this->{item}->getExpandedValue();
if ( defined $field ) {
Foswiki::Configure::Load::expandValue($field);
if ( ref($field) ) {
local $Data::Dumper::Indent = 2;
$field = Data::Dumper->Dump( [$field] );
$field =~ s/\$.*?= //;
$field = Foswiki::Configure::Reporter::uneval( $field, 2 );
$reporter->NOTE( 'Expands to: <verbatim>', $field, '</verbatim>' );
}
elsif ($field) {
elsif ( $field ne '' ) {
if ( $field =~ /\n/ ) {
$reporter->NOTE( 'Expands to: <verbatim>',
$field, '</verbatim>' );
Expand All @@ -393,32 +376,18 @@ sub showExpandedValue {
$reporter->NOTE("Expands to: =$field=");
}
}
elsif ( defined $field ) {
$reporter->NOTE("Expands to ''");
}
else {
$reporter->NOTE("Is undefined after expansion");
$reporter->NOTE("Expands to ''");
}
}
elsif ( !$this->{item}->{UNDEFINEDOK} ) {
$reporter->NOTE("$this->{item}->{keys} is undefined");
else {
my $check = $this->{item}->{CHECK}->[0];
unless ( $check && $check->{nullok}[0] ) {
$reporter->NOTE("$this->{item}->{keys} is undefined");
}
}
}

# Strip traceback from die and carp for a user message

sub stripTraceback {
my ( $this, $message ) = @_;

return '' unless ( length $message );

return $message if ( $Foswiki::cfg::{DebugTracebacks} );

$message = ( split( /\n/, $message ) )[0];
$message =~ s/ at .*? line \d+\.$//;
return $message;
}

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

0 comments on commit e80d705

Please sign in to comment.