Ignore:
Timestamp:
2013-05-06T15:23:45+12:00 (11 years ago)
Author:
jmt12
Message:

Replacing hardcoded additions to INC and PATH environment variables with conditional ones - this allows us to use the order of values in these variables for precedence, thus allows better support for extensions that override classifiers, plugins etc. ENV and PATH functions already exists in util, but augmentINC() is a new function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugin.pm

    r26223 r27303  
    3232
    3333require util;
     34use FileUtils;
    3435use gsprintf 'gsprintf';
    3536
     
    8485    # pp_plugname shorthand for 'perllib' 'plugin' '$pluginname.pm'
    8586    my $pp_plugname
    86     = &util::filename_cat('perllib', 'plugins', "${pluginname}.pm");
     87    = &FileUtils::filenameConcatenate('perllib', 'plugins', "${pluginname}.pm");
    8788    my $collectdir = $ENV{'GSDLCOLLECTDIR'};
    8889
     
    9192    {
    9293    my $customplugname
    93         = &util::filename_cat($collectdir, "custom",$ENV{'GSDLCOLLECTION'},
     94        = &FileUtils::filenameConcatenate($collectdir, "custom",$ENV{'GSDLCOLLECTION'},
    9495                  $pp_plugname);
    9596    push(@check_list,$customplugname);
    9697    }
    9798
    98     my $colplugname = &util::filename_cat($collectdir, $pp_plugname);
     99    my $colplugname = &FileUtils::filenameConcatenate($collectdir, $pp_plugname);
    99100    push(@check_list,$colplugname);
    100101
    101102    if (defined $ENV{'GSDLEXTS'}) {
    102103
    103     my $ext_prefix = &util::filename_cat($ENV{'GSDLHOME'}, "ext");
     104    my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, "ext");
    104105
    105106    my @extensions = split(/:/,$ENV{'GSDLEXTS'});
    106107    foreach my $e (@extensions) {
    107         my $extplugname = &util::filename_cat($ext_prefix, $e, $pp_plugname);
     108        my $extplugname = &FileUtils::filenameConcatenate($ext_prefix, $e, $pp_plugname);
    108109        push(@check_list,$extplugname);
    109110
     
    112113    if (defined $ENV{'GSDL3EXTS'}) {
    113114
    114     my $ext_prefix = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "ext");
     115    my $ext_prefix = &FileUtils::filenameConcatenate($ENV{'GSDL3SRCHOME'}, "ext");
    115116
    116117    my @extensions = split(/:/,$ENV{'GSDL3EXTS'});
    117118    foreach my $e (@extensions) {
    118         my $extplugname = &util::filename_cat($ext_prefix, $e, $pp_plugname);
     119        my $extplugname = &FileUtils::filenameConcatenate($ext_prefix, $e, $pp_plugname);
    119120        push(@check_list,$extplugname);
    120121
     
    123124
    124125
    125     my $mainplugname = &util::filename_cat($ENV{'GSDLHOME'}, $pp_plugname);
     126    my $mainplugname = &FileUtils::filenameConcatenate($ENV{'GSDLHOME'}, $pp_plugname);
    126127    push(@check_list,$mainplugname);
    127128
     
    130131    if (-e $plugname) {
    131132        # lets add perllib folder to INC
     133          # check it isn't already there first [jmt12]
    132134        my ($perllibfolder) = $plugname =~ /^(.*[\/\\]perllib)[\/\\]plugins/;
    133         if (-d $perllibfolder) {
     135        if (-d $perllibfolder)
     136            {
     137              my $found_perllibfolder = 0;
     138              foreach my $path (@INC)
     139              {
     140                if ($path eq $perllibfolder)
     141                {
     142                  $found_perllibfolder = 1;
     143                  last;
     144                }
     145              }
     146              if (!$found_perllibfolder)
     147              {
    134148        unshift (@INC, $perllibfolder);
    135         }
     149              }
     150        }
    136151        require $plugname;
    137152        $success=1;
     
    171186    $failhandle = 'STDERR' unless defined $failhandle;
    172187
    173     my $colperllibdir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib");
    174     unshift (@INC, $colperllibdir); 
    175     my $colplugindir = &util::filename_cat($colperllibdir,"plugins");
    176      unshift (@INC, $colplugindir); 
     188    # before pushing collection perl and plugin directories onto INC, test that
     189    # they aren't already there [jmt12]
     190    &util::augmentINC(&FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},'perllib'));
     191    &util::augmentINC(&FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},'perllib','plugins'));
    177192
    178193    map { $_ = "\"$_\""; } @$globaloptions;
     
    270285    # the .kill file is a handy (if not very elegant) way of aborting
    271286    # an import.pl or buildcol.pl process
    272     if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
     287    if (-e &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
    273288    gsprintf($outhandle, "{plugin.kill_file}\n");
    274289    die "\n";
     
    301316    # the .kill file is a handy (if not very elegant) way of aborting
    302317    # an import.pl or buildcol.pl process
    303     if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
     318    if (-e &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
    304319    gsprintf($outhandle, "{plugin.kill_file}\n");
    305320    die "\n";
     
    352367    # the .kill file is a handy (if not very elegant) way of aborting
    353368    # an import.pl or buildcol.pl process
    354     if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
     369    if (-e &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
    355370    gsprintf($outhandle, "{plugin.kill_file}\n");
    356371    die "\n";
Note: See TracChangeset for help on using the changeset viewer.