Ignore:
Timestamp:
11/20/08 13:04:58 (4 years ago)
Author:
CrawfordCurrie
Message:

Item175: BuildContrib now builds both Foswiki and TWiki targeted plugins. If you want to target both, then target TWiki. TWiki plugins require the TWikiCompatibilityContrib to be installed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/tools/extender.pl

    r809 r827  
    4040my $reuseOK = 0; 
    4141my $inactive = 0; 
    42 my $twiki; 
    43 my $twiki4OrMore; 
     42my $session; 
    4443my %available; 
    4544my $lwp; 
    4645my @archTypes = ( '.tgz', '.tar.gz', '.zip' ); 
    47 my %cfg; 
    4846my $installationRoot; 
    4947my $MODULE; 
     
    6967             -d 'bin' && 
    7068             -e 'bin/setlib.cfg' ) { 
    71         die 'This installer must be run from the root directory of a TWiki installation'; 
     69        die 'This installer must be run from the root directory of a Foswiki installation'; 
    7270    } 
    7371    # read setlib.cfg 
     
    7573    require 'setlib.cfg'; 
    7674 
    77     # See if we can make a TWiki. If we can, then we can save topic 
    78     # and attachment histories. Key off Foswiki::Merge because it was 
    79     # added in Dakar. 
    80     if( &$check_perl_module( 'Foswiki::Merge' )) { 
    81         eval { 
    82             require Foswiki; 
    83             # We have to get the admin user, as a guest user may be blocked. 
    84             # TWiki 4.2 has AdminUserLogin; for earlier releases, we need to 
    85             # do something a bit different. 
    86             my $user = $Foswiki::cfg{AdminUserLogin} || 'admin'; 
    87             $twiki = new Foswiki($user); 
    88             # Compatibility with 4.0 <= Foswiki::VERSION < 4.2 
    89             if ($twiki->{users}->can('findUser')) { 
    90                 $Foswiki::Plugins::SESSION = $twiki; 
    91                 $twiki->{user} = 
    92                   $twiki->{users}->findUser( 
    93                       $Foswiki::cfg{AdminUserWikiName}, 
    94                       $Foswiki::cfg{AdminUserWikiName}); 
    95             } 
    96             chdir($installationRoot); 
    97             $twiki4OrMore = 1; 
    98         }; # if it fails, fall back to old behaviour 
    99     } else { 
    100         # Not TWiki-4 
    101         chdir($installationRoot); 
    102         no strict; 
    103         do 'lib/TWiki.cfg'; 
    104         if( -e 'lib/LocalSite.cfg') { 
    105             do 'lib/LocalSite.cfg'; 
    106         } 
    107         use strict; 
    108         $twiki4OrMore = 0; 
    109     } 
     75    # See if we can make a Foswiki. If we can, then we can save topic 
     76    # and attachment histories. Key off Foswiki::Merge because it is 
     77    # fairly new and fairly unique. 
     78    unless( &$check_perl_module( 'Foswiki::Merge' )) { 
     79        die "Can't find Foswiki: $@"; 
     80    } 
     81 
     82    require Foswiki; 
     83    # We have to get the admin user, as a guest user may be blocked. 
     84    my $user = $Foswiki::cfg{AdminUserLogin}; 
     85    $session = new Foswiki($user); 
     86    chdir($installationRoot); 
    11087 
    11188    if( &$check_perl_module( 'LWP' )) { 
     
    11794} 
    11895 
    119 =pod 
    120  
    121 ---+ StaticMethod remap ($file ) -> $file 
    122 Given a "canonical" path, convert it using the remappings in LocalSite.cfg to a site- 
    123 specific path. For example, if a site defines: 
    124 <verbatim> 
    125 $Foswiki::cfg{UsersWebName} = 'Users'; 
    126 </verbatim> 
    127 then this function will convert =data/Main/Burble.txt= to =data/Users/Burble.txt=. 
    128  
    129 Note: remapping only works for TWiki 4 and later. Anyone who cares enough can write 
    130 and test the mappings for Cairo. 
    131  
    132 =cut 
    133  
    13496sub remap { 
    13597    my $file = shift; 
    136     if (defined $cfg{SitePrefsTopicName}) { 
    137         $file =~ s#^data/(TWiki|Main)/TWikiPreferences\.txt(.*)$#data/$1/$cfg{SitePrefsTopicName}.txt$2#; 
    138     } 
    139     if (defined $cfg{UsersTopicName}) { 
    140         $file =~ s#(Main)/WikiUsers\.txt(.*)$#$1/$cfg{UsersTopicName}.txt$2#; 
    141     } 
     98 
     99    if ($Foswiki::cfg{SystemWebName} ne 'System') { 
     100        $file =~ s#^data/System/#data/$Foswiki::cfg{SystemWebName}/#; 
     101        $file =~ s#^pub/System/#pub/$Foswiki::cfg{SystemWebName}/#; 
     102    } 
     103 
     104    if ($Foswiki::cfg{TrashWebName} ne 'Trash') { 
     105        $file =~ s#^data/Trash/#data/$Foswiki::cfg{TrashWebName}/#; 
     106        $file =~ s#^pub/Trash/#pub/$Foswiki::cfg{TrashWebName}/#; 
     107    } 
     108 
     109    if ($Foswiki::cfg{UsersWebName} ne 'Main') { 
     110        $file =~ s#^data/Main/#data/$Foswiki::cfg{UsersWebName}/#; 
     111        $file =~ s#^pub/Main/#pub/$Foswiki::cfg{UsersWebName}/#; 
     112    } 
     113 
     114    if ($Foswiki::cfg{UsersWebName} ne 'Users') { 
     115        $file =~ s#^data/Users/#data/$Foswiki::cfg{UsersWebName}/#; 
     116        $file =~ s#^pub/Users/#pub/$Foswiki::cfg{UsersWebName}/#; 
     117    } 
     118 
     119    # Canonical symbol mappings 
    142120    foreach my $w qw( SystemWebName TrashWebName UsersWebName ) { 
    143         if (defined $cfg{$w}) { 
    144             $file =~ s#^data/$w/#data/$cfg{$w}/#; 
    145             $file =~ s#^pub/$w/#pub/$cfg{$w}/#; 
    146         } 
    147     } 
    148     foreach my $t qw( NotifyTopicName HomeTopicName WebPrefsTopicName MimeTypesFileName ) { 
    149         if (defined $cfg{$t}) { 
    150             $file =~ s#^data/(.*)/$t\.txt(,v)?#data/$1/$cfg{$t}.txt$2/#; 
    151             $file =~ s#^pub/(.*)/$t/([^/]*)$#pub/$1/$cfg{$t}/$2/#; 
     121        if (defined $Foswiki::cfg{$w}) { 
     122            $file =~ s#^data/$w/#data/$Foswiki::cfg{$w}/#; 
     123            $file =~ s#^pub/$w/#pub/$Foswiki::cfg{$w}/#; 
     124        } 
     125    } 
     126    foreach my $t qw( NotifyTopicName HomeTopicName WebPrefsTopicName 
     127                      MimeTypesFileName ) { 
     128        if (defined $Foswiki::cfg{$t}) { 
     129            $file =~ s#^data/(.*)/$t\.txt(,v)?#data/$1/$Foswiki::cfg{$t}.txt$2/#; 
     130            $file =~ s#^pub/(.*)/$t/([^/]*)$#pub/$1/$Foswiki::cfg{$t}/$2/#; 
    152131        } 
    153132    } 
     
    234213DONE 
    235214 
    236     if( $dep->{name} =~ m/^Foswiki::(Contrib|Plugins)::(\w*)/ ) { 
    237         my $pack = $1; 
    238         my $packname = $2; 
     215    if( $dep->{name} =~ m/^(Foswiki|TWiki)::(Contrib|Plugins)::(\w*)/ ) { 
     216        my $type = $1; 
     217        my $pack = $2; 
     218        my $packname = $3; 
    239219        $packname .= $pack if( $pack eq 'Contrib' && $packname !~ /Contrib$/); 
    240220        if (!$noconfirm || ($noconfirm && $downloadOK)) { 
    241             my $reply = ask('Would you like me to try to download and install the latest version of '.$packname.' from twiki.org?'); 
     221            my $reply = ask('Would you like me to try to download and install the latest version of '.$packname.' from foswiki.org?'); 
    242222            if( $reply ) { 
    243223                return installPackage( $packname ); 
     
    347327    } 
    348328    return $reply; 
    349 } 
    350  
    351 # DEPRECATED - do not use - install a .spec instead 
    352 # ---++ StaticMethod getConfig( $major, $minor, $cairo ) -> $string 
    353 #    * =$major= name of major key. 
    354 #    * =$minor= if undefined, there is no minor key 
    355 #    * =$cairo= expression that when evaled will get the cairo style config var 
    356 # Get the value of a config var, trying first the Dakar option and 
    357 # then if that fails, the Cairo name (if any). 
    358 # Example: 
    359 # =getConfig("Name")= 
    360 # will get the value of =$Foswiki::cfg{Name}=. 
    361 # =getConfig("MyPlugin", "Name")= 
    362 # will get the value of =$Foswiki::cfg{Name}=. 
    363 # =getConfig("HomeTopicName", undef, '$mainTopicname')= 
    364 # will get the name of the WebHome topic on Dakar and Cairo. 
    365 # 
    366 # See setConfig for more information on major/minor keys. 
    367  
    368 sub getConfig { 
    369     my( $major, $minor, $cairo ) = @_; 
    370  
    371     if( $minor && defined $Foswiki::cfg{$major}{$minor} ) { 
    372         return getFoswikiCfg("{$major}{$minor}"); 
    373     } 
    374     if (!$minor && defined $Foswiki::cfg{$major}) { 
    375         return getFoswikiCfg("{$minor}"); 
    376     } 
    377  
    378     if( defined $cairo ) { 
    379         return eval $cairo; 
    380     } 
    381     return undef; 
    382 } 
    383  
    384 # DEPRECATED - do not use - install a .spec instead 
    385 # ---++ StaticMethod commentConfig( $comment ) 
    386 #    * $comment - comment to insert in LocalSite.cfg, usually before a setConfig 
    387 # Inserts a comment into LocalSite.cfg. The comment will usually describe a following setConfig; for example, 
    388 # <verbatim> 
    389 # commentConfig( <<HERE 
    390 # #---++ Cars Plugin 
    391 # # **STRING 30** 
    392 # # Name of manufacturer 
    393 # HERE 
    394 # ); 
    395 # setConfig( 'CarsPlugin', Manufacturer => 'Mercedes' ); 
    396 # </verbatim> 
    397  
    398 sub commentConfig { 
    399     open(F, ">>lib/LocalSite.cfg") || 
    400               die "Failed to open lib/LocalSite.cfg for write"; 
    401     print F $_[0]; 
    402     close(F); 
    403 } 
    404  
    405 # DEPRECATED - do not use - install a .spec instead 
    406 # ---++ StaticMethod setConfig( $major, ... ) 
    407 #    * =$major= if defined, name of major key. If not given, there is no major key and the minorkeys are treated as major keys 
    408 #    * =...= list of minorkey=>value pairs 
    409 # Set the given configuration variables in LocalSite.cfg. =$value= must be 
    410 # complete with all syntactic sugar, including quotes. 
    411 # The valued are written to $Foswiki::cfg{major key}{setting} if a major 
    412 # key is given (recommended, use the plugin name) or $Foswiki::cfg{setting} otherwise. Example: 
    413 # <verbatim> 
    414 # setConfig( 'CarsPlugin', Name=>"'Mercedes'" }; 
    415 # setConfig( Tools => "qw(hammer saw screwdriver)" }; 
    416 # </verbatim> 
    417 # will write 
    418 # <verbatim> 
    419 # $Foswiki::cfg{CarsPlugin}{Best} = 'Mercedes'; 
    420 # $Foswiki::cfg{Tools} = qw(hammer saw screwdriver); 
    421 # </verbatim> 
    422  
    423 sub setConfig { 
    424     my @settings = @_; 
    425     my $txt; 
    426     my $key; 
    427     if (scalar(@settings) % 2) { 
    428         # pluck the first odd parameter off to be the major key 
    429         $key = shift @settings; 
    430     } 
    431     my %keys = @settings; 
    432     if( -e "lib/LocalSite.cfg" ) { 
    433         open(F, "<lib/LocalSite.cfg") || 
    434           die "Failed to open lib/LocalSite.cfg for read"; 
    435         local $/ = undef; 
    436         $txt = <F>; 
    437         close(F); 
    438         $txt =~ s/\n+1;\s*//gs; 
    439         # kill the old settings (and previous comment) if any are there 
    440         foreach my $setting ( keys %keys ) { 
    441             if( $key ) { 
    442                 $txt =~ s/(# \*\*.*?\n(#.*?\n))?\$Foswiki::cfg{$key}{$setting}\s*=.*;\r?\n//s; 
    443             } else { 
    444                 $txt =~ s/(# \*\*.*?\n(#.*?\n))?\$Foswiki::cfg{$setting}\s*=.*;\r?\n//s; 
    445             } 
    446         } 
    447     } 
    448     $txt .= "\n" unless $txt =~ /\n$/s; 
    449     open(F, ">lib/LocalSite.cfg") || 
    450       die "Failed to open lib/LocalSite.cfg for write"; 
    451     print F $txt if $txt; 
    452     foreach my $setting ( keys %keys ) { 
    453         if( defined $key ) { 
    454             print F '$Foswiki::cfg{'.$key.'}{'.$setting.'} = '; 
    455         } else { 
    456             print F '$Foswiki::cfg{'.$setting.'} = '; 
    457         } 
    458         print F $keys{$setting}, ";\n"; 
    459     } 
    460     print F "1;\n"; 
    461     close(F); 
    462  
    463     # is this Cairo or earlier? If it is, we need to include 
    464     # LocalSite.cfg from TWiki.cfg 
    465     unless( $twiki4OrMore ) { 
    466         open(F, "<lib/TWiki.cfg"); 
    467         undef $/; 
    468         $txt = <F>; 
    469         close(F); 
    470         unless( $txt =~ /^do.*LocalSite\.cfg/m ) { 
    471             $txt =~ s/^\s*1\s*;\s*$//m; 
    472             open(F, ">lib/TWiki.cfg") || 
    473               die "Failed to open lib/TWiki.cfg for write"; 
    474             print F "$txt\ndo 'LocalSite.cfg';\n1;\n"; 
    475             close(F); 
    476         } 
    477     } 
    478329} 
    479330 
     
    727578    my $err = 1; 
    728579 
    729     if( $twiki ) { 
     580    if( $session ) { 
    730581        if( $file ) { 
    731582            my $origfile = $Foswiki::cfg{PubDir} . '/' . $web . '/' . $topic . '/' . $file; 
     
    929780    my $path = $MODULE; 
    930781 
    931     if ($path !~ /^Foswiki::/) { 
     782    if ($path !~ /^(Foswiki|TWiki)::/) { 
     783        my $source = $1; 
    932784        my $type = 'Contrib'; 
    933785        if ($path =~ /Plugin$/) { 
    934786            $type = 'Plugins'; 
    935787        } 
    936         $path = 'Foswiki::'.$type.'::'.$rootModule; 
     788        $path = $source.'::'.$type.'::'.$rootModule; 
    937789    } 
    938790 
Note: See TracChangeset for help on using the changeset viewer.