2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::ziplist
;
23 use File
::Spec
::Functions
qw(rel2abs);
25 use installer
::converter
;
26 use installer
::exiter
;
28 use installer
::globals
;
29 use installer
::logger
;
30 use installer
::remover
;
31 use installer
::systemactions
;
33 our @EXPORT_OK = qw(read_ziplist);
36 my $ziplistname = shift;
38 installer
::logger
::globallog
("zip list file: $ziplistname");
40 my $ziplistref = installer
::files
::read_file
($ziplistname);
42 installer
::logger
::print_message
( "... analyzing $ziplistname ... \n" );
44 my ($productblockref, $parent) = getproductblock
($ziplistref, $installer::globals
::product
, 1); # product block from zip.lst
46 my ($settingsblockref, undef) = getproductblock
($productblockref, "Settings", 0); # settings block from zip.lst
47 $settingsblockref = analyze_settings_block
($settingsblockref); # select data from settings block in zip.lst
49 my $allsettingsarrayref = get_settings_from_ziplist
($settingsblockref);
50 my $allvariablesarrayref = get_variables_from_ziplist
($settingsblockref);
52 my ($globalproductblockref, undef) = getproductblock
($ziplistref, $installer::globals
::globalblock
, 0); # global product block from zip.lst
54 while (defined $parent) {
55 my $parentproductblockref;
56 ($parentproductblockref, $parent) = getproductblock
($ziplistref, $parent, 1);
57 my ($parentsettingsblockref, undef) = getproductblock
($parentproductblockref, "Settings", 0);
58 $parentsettingsblockref = analyze_settings_block
($parentsettingsblockref);
59 my $allparentsettingsarrayref = get_settings_from_ziplist
($parentsettingsblockref);
60 my $allparentvariablesarrayref = get_variables_from_ziplist
($parentsettingsblockref);
61 $allsettingsarrayref =
62 installer
::converter
::combine_arrays_from_references_first_win
(
63 $allsettingsarrayref, $allparentsettingsarrayref)
64 if $#{$allparentsettingsarrayref} > -1;
65 $allvariablesarrayref =
66 installer
::converter
::combine_arrays_from_references_first_win
(
67 $allvariablesarrayref, $allparentvariablesarrayref)
68 if $#{$allparentvariablesarrayref} > -1;
71 if ( @
{$globalproductblockref} ) {
72 my ($globalsettingsblockref, undef) = getproductblock
($globalproductblockref, "Settings", 0); # settings block from zip.lst
74 $globalsettingsblockref = analyze_settings_block
($globalsettingsblockref); # select data from settings block in zip.lst
76 my $allglobalsettingsarrayref = get_settings_from_ziplist
($globalsettingsblockref);
78 my $allglobalvariablesarrayref = get_variables_from_ziplist
($globalsettingsblockref);
80 if ( @
{$allglobalsettingsarrayref} ) {
81 $allsettingsarrayref = installer
::converter
::combine_arrays_from_references_first_win
($allsettingsarrayref, $allglobalsettingsarrayref);
83 if ( @
{$allglobalvariablesarrayref} ) {
84 $allvariablesarrayref = installer
::converter
::combine_arrays_from_references_first_win
($allvariablesarrayref, $allglobalvariablesarrayref);
88 $allsettingsarrayref = remove_multiples_from_ziplist
($allsettingsarrayref);
89 $allvariablesarrayref = remove_multiples_from_ziplist
($allvariablesarrayref);
91 replace_variables_in_ziplist_variables
($allvariablesarrayref);
93 my $allvariableshashref = installer
::converter
::convert_array_to_hash
($allvariablesarrayref);
95 set_default_productversion_if_required
($allvariableshashref);
96 add_variables_to_allvariableshashref
($allvariableshashref);
97 overwrite_branding
( $allvariableshashref );
99 return $allsettingsarrayref, $allvariableshashref;
102 #################################################
103 # Getting data from path file and zip list file
104 #################################################
108 my ($fileref, $search, $inheritance) = @_;
110 my @searchblock = ();
111 my $searchexists = 0;
115 my $inh = $inheritance ?
'(?::\s*(\S+)\s*)?' : "";
118 for ( my $i = 0; $i <= $#{$fileref}; $i++ )
120 $line = ${$fileref}[$i];
122 if ( $line =~ /^\s*\Q$search\E\s*$inh$/i ) # case insensitive
126 $parent = $1 if $inheritance;
131 push(@searchblock, $line);
134 if ( ($record) && ($line =~ /\{/) )
139 if ( ($record) && ($line =~ /\}/) )
144 if ( ($record) && ($line =~ /\}/) && ( $count == 0 ) )
150 if (( ! $searchexists ) && ( $search ne $installer::globals
::globalblock
))
152 if ($search eq $installer::globals
::product
)
154 installer
::exiter
::exit_program
("ERROR: Product $installer::globals::product not defined in $installer::globals::ziplistname", "getproductblock");
156 else # this is not possible
158 installer
::exiter
::exit_program
("ERROR: Unknown value for $search in getproductblock()", "getproductblock");
162 return (\
@searchblock, $parent);
165 ###############################################
166 # Analyzing the settings in the zip list file
167 ###############################################
169 sub analyze_settings_block
173 my @newsettingsblock = ();
177 # Allowed values in settings block:
178 # "Settings", "Variables", "unix" (for destination path and logfile)
180 # Comment line in settings block begin with "#" or ";"
182 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
184 my $line = ${$blockref}[$i];
187 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
189 # removing comment lines
191 if (($line =~ /^\s*\#/) || ($line =~ /^\s*\;/))
196 # complete blocks of unknown strings are not recorded
198 if ((!($line =~ /^\s*\Q$installer::globals::build\E\s*$/i)) &&
199 (!($line =~ /^\s*\bSettings\b\s*$/i)) &&
200 (!($line =~ /^\s*\bVariables\b\s*$/i)) &&
201 (!($line =~ /^\s*\bunix\b\s*$/i)) &&
202 ($nextline =~ /^\s*\{\s*$/i))
205 next; # continue with next $i
210 if ($line =~ /^\s*\{\s*$/i)
215 if ($line =~ /^\s*\}\s*$/i)
223 next; # continue with next $i
229 push(@newsettingsblock, $line);
233 return \
@newsettingsblock;
236 ########################################
237 # Settings in zip list file
238 ########################################
240 sub get_settings_from_ziplist
244 my @allsettings = ();
247 my $variablescounter = 0;
249 # Take all settings from the settings block
250 # Do not take the variables from the settings block
251 # If a setting is defined more than once, take the
252 # setting with the largest counter (open brackets)
254 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
256 my $line = ${$blockref}[$i];
259 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
261 if (($line =~ /^\s*\S+\s*$/i) &&
262 ($nextline =~ /^\s*\{\s*$/i) &&
263 (!($line =~ /^\s*Variables\s*$/i)))
268 if ($line =~ /^\s*Variables\s*$/i)
270 # This is a block of variables
276 if ($line =~ /^\s*\{\s*$/i)
290 if ($line =~ /^\s*\}\s*$/i)
296 if ($variablescounter == 0)
314 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
316 $line .= "\t##$counter##\n";
318 push(@allsettings, $line);
321 return \
@allsettings;
324 #######################################
325 # Variables from zip list file
326 #######################################
328 sub get_variables_from_ziplist
332 my @allvariables = ();
335 my $variablescounter = 0;
338 # Take all variables from the settings block
339 # Do not take the other settings from the settings block
340 # If a variable is defined more than once, take the
341 # variable with the largest counter (open brackets)
343 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
345 my $line = ${$blockref}[$i];
346 my $nextline = ${$blockref}[$i+1];
348 if ($line =~ /^\s*Variables\s*$/i)
350 # This is a block of variables
356 if ($line =~ /^\s*\{\s*$/i)
370 if ($line =~ /^\s*\}\s*$/i)
376 if ($variablescounter == 0)
394 $countersum = $counter + $variablescounter;
396 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
398 $line .= "\t##$countersum##\n";
400 push(@allvariables, $line);
403 return \
@allvariables;
406 #######################################################################
407 # Removing multiple variables and settings, defined in zip list file
408 #######################################################################
410 sub remove_multiples_from_ziplist
414 # remove all definitions of settings and variables
415 # that occur more than once in the zip list file.
416 # Take the one with the most open brackets. This
417 # number is stored at the end of the string.
421 my ($line, $itemname, $itemnumber);
423 # first collecting all variables and settings names
425 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
427 $line = ${$blockref}[$i];
429 if ($line =~ /^\s*\b(\S*)\b\s+.*\#\#\d+\#\#\s*$/i)
434 if (! grep {$_ eq $itemname} @itemarray)
436 push(@itemarray, $itemname);
440 # and now all $items can be selected with the highest number
442 for ( my $i = 0; $i <= $#itemarray; $i++ )
444 $itemname = $itemarray[$i];
446 my $itemnumbermax = 0;
449 for ( my $j = 0; $j <= $#{$blockref}; $j++ )
451 $line = ${$blockref}[$j];
453 if ($line =~ /^\s*\Q$itemname\E\s+.*\#\#(\d+)\#\#\s*$/)
457 if ($itemnumber >= $itemnumbermax)
460 $itemnumbermax = $itemnumber;
465 # removing the ending number from the printline
466 # and putting it into the array
468 $printline =~ s/\#\#\d+\#\#//;
469 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
470 push(@newarray, $printline);
476 #########################################################
477 # Reading one variable defined in the zip list file
478 #########################################################
480 sub getinfofromziplist
482 my ($blockref, $variable) = @_;
484 my $searchstring = "";
487 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
489 $line = ${$blockref}[$i];
491 if ( $line =~ /^\s*\Q$variable\E\s+(.+?)\s*$/ ) # "?" for minimal matching
498 return \
$searchstring;
501 ####################################################
502 # Replacing variables in include path
503 ####################################################
505 sub replace_all_variables_in_paths
507 my ( $patharrayref, $variableshashref ) = @_;
509 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
511 my $line = ${$patharrayref}[$i];
515 foreach $key (sort { length ($b) <=> length ($a) } keys %{$variableshashref})
517 my $value = $variableshashref->{$key};
519 if (( $line =~ /\{$key\}/ ) && ( $value eq "" )) { $line = ".\n"; }
521 $line =~ s/\{\Q$key\E\}/$value/g;
524 ${$patharrayref}[$i] = $line;
528 ####################################################
529 # Replacing minor in include path
530 ####################################################
532 sub replace_minor_in_paths
534 my ( $patharrayref ) = @_;
536 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
538 my $line = ${$patharrayref}[$i];
540 $line =~ s/\.\{minor\}//g;
541 $line =~ s/\.\{minornonpre\}//g;
543 ${$patharrayref}[$i] = $line;
547 ####################################################
548 # Replacing packagetype in include path
549 ####################################################
551 sub replace_packagetype_in_paths
553 my ( $patharrayref ) = @_;
555 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
557 my $line = ${$patharrayref}[$i];
559 if (( $installer::globals
::installertypedir
) && ( $line =~ /\{pkgtype\}/ ))
561 $line =~ s/\{pkgtype\}/$installer::globals::installertypedir/g;
564 ${$patharrayref}[$i] = $line;
568 ####################################################
569 # Removing ending separators in paths
570 ####################################################
572 sub remove_ending_separator
574 my ( $patharrayref ) = @_;
576 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
578 my $line = ${$patharrayref}[$i];
580 installer
::remover
::remove_ending_pathseparator
(\
$line);
583 $line = $line . "\n";
585 ${$patharrayref}[$i] = $line;
589 ####################################################
590 # Replacing languages in include path
591 ####################################################
593 sub replace_languages_in_paths
595 my ( $patharrayref, $languagesref ) = @_;
597 installer
::logger
::include_header_into_logfile
("Replacing languages in include paths:");
602 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
604 my $line = ${$patharrayref}[$i];
606 if ( $line =~ /\$\(LANG\)/ )
608 my $originalline = $line;
611 for ( my $j = 0; $j <= $#{$languagesref}; $j++ )
613 my $language = ${$languagesref}[$j];
614 $line =~ s/\$\(LANG\)/$language/g;
615 push(@patharray ,$line);
617 $line = $originalline;
619 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$newline);
621 # Is it necessary to refresh the global array, containing all files of all include paths?
624 # Checking if $newdir is empty
625 if ( ! installer
::systemactions
::is_empty_dir
($newdir) )
627 $installer::globals
::refresh_includepaths
= 1;
628 $infoline = "Directory $newdir exists and is not empty. Refreshing global file array is required.\n";
629 push( @installer::globals
::logfileinfo
, $infoline);
633 $infoline = "Directory $newdir is empty. No refresh of global file array required.\n";
634 push( @installer::globals
::logfileinfo
, $infoline);
639 $infoline = "Directory $newdir does not exist. No refresh of global file array required.\n";
640 push( @installer::globals
::logfileinfo
, $infoline);
644 else # not language dependent include path
646 push(@patharray ,$line);
653 #####################################################
654 # Collecting all files from all include paths
655 #####################################################
657 sub list_all_files_from_include_path
659 my ( $patharrayref) = @_;
661 installer
::logger
::include_header_into_logfile
("Include paths:");
663 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
665 my $path = ${$patharrayref}[$i];
666 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$path);
667 my $infoline = "$path\n";
668 push( @installer::globals
::logfileinfo
, $infoline);
671 push( @installer::globals
::logfileinfo
, "\n");
676 #####################################################
677 # Collecting all files from all include paths
678 #####################################################
682 my ($allvariables) = @_;
685 if( defined $ENV{'OOO_VENDOR'} && $ENV{'OOO_VENDOR'} ne "" )
687 $manufacturer = $ENV{'OOO_VENDOR'};
689 elsif( defined $ENV{'USERNAME'} && $ENV{'USERNAME'} ne "" )
691 $manufacturer = $ENV{'USERNAME'};
693 elsif( defined $ENV{'USER'} && $ENV{'USER'} ne "" )
695 $manufacturer = $ENV{'USER'};
699 $manufacturer = "default";
702 $installer::globals
::manufacturer
= $manufacturer;
703 $installer::globals
::longmanufacturer
= $manufacturer;
705 $allvariables->{'MANUFACTURER'} = $installer::globals
::manufacturer
;
708 ##############################################################
709 # A ProductVersion has to be defined. If it is not set in
710 # zip.lst, it is set now to "1"
711 ##############################################################
713 sub set_default_productversion_if_required
715 my ($allvariables) = @_;
717 if (!($allvariables->{'PRODUCTVERSION'}))
719 $allvariables->{'PRODUCTVERSION'} = 1; # FAKE
723 ####################################################
724 # Removing .. in paths
725 ####################################################
729 my ( $pathref ) = @_;
731 my $oldpath = $$pathref;
735 while ( $oldpath =~ /(^.*)(\Q$installer::globals::separator\E.*\w+?)(\Q$installer::globals::separator\E\.\.)(\Q$installer::globals::separator\E.*$)/ )
739 $oldpath = $part1 . $part2;
743 if ( $change ) { $$pathref = $oldpath . "\n"; }
746 ####################################################
747 # Removing ending separators in paths
748 ####################################################
750 sub resolve_relative_paths
752 my ( $patharrayref ) = @_;
754 for my $path ( @
{$patharrayref} )
756 $path = rel2abs
($path);
757 simplify_path
(\
$path);
761 ####################################################
762 # Replacing variables inside zip list variables
763 # Example: {milestone} to be replaced by
764 # $installer::globals::lastminor
765 ####################################################
767 sub replace_variables_in_ziplist_variables
771 my $milestonevariable = $installer::globals
::lastminor
;
772 $milestonevariable =~ s/m//;
773 $milestonevariable =~ s/s/\./;
775 my $localminor = $installer::globals
::lastminor
;
776 if ( $installer::globals
::minor
) { $localminor = $installer::globals
::minor
; }
778 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
780 if ($installer::globals
::lastminor
) { ${$blockref}[$i] =~ s/\{milestone\}/$milestonevariable/; }
781 else { ${$blockref}[$i] =~ s/\{milestone\}//; }
782 if ( $localminor ) { ${$blockref}[$i] =~ s/\{minor\}/$localminor/; }
783 else { ${$blockref}[$i] =~ s/\{minor\}//; }
784 if ( $installer::globals
::buildid
) { ${$blockref}[$i] =~ s/\{buildid\}/$installer::globals::buildid/; }
785 else { ${$blockref}[$i] =~ s/\{buildid\}//; }
786 if ( $installer::globals
::build
) { ${$blockref}[$i] =~ s/\{buildsource\}/$installer::globals::build/; }
787 else { ${$blockref}[$i] =~ s/\{build\}//; }
791 ###########################################################
792 # Overwrite branding data in openoffice.lst that is defined in configure
793 ###########################################################
795 sub overwrite_branding
797 my ($variableshashref) = @_;
798 $variableshashref->{'OOOVENDOR'} = $ENV{'OOO_VENDOR'} , if( defined $ENV{'OOO_VENDOR'} && $ENV{'OOO_VENDOR'} ne "" );
799 $variableshashref->{'PROGRESSBARCOLOR'} = $ENV{'PROGRESSBARCOLOR'} , if( defined $ENV{'PROGRESSBARCOLOR'} && $ENV{'PROGRESSBARCOLOR'} ne "" );
800 $variableshashref->{'PROGRESSSIZE'} = $ENV{'PROGRESSSIZE'} , if( defined $ENV{'PROGRESSSIZE'} && $ENV{'PROGRESSSIZE'} ne "" );
801 $variableshashref->{'PROGRESSPOSITION'} = $ENV{'PROGRESSPOSITION'} , if( defined $ENV{'PROGRESSPOSITION'} && $ENV{'PROGRESSPOSITION'} ne "" );
802 $variableshashref->{'PROGRESSFRAMECOLOR'} = $ENV{'PROGRESSFRAMECOLOR'} , if( defined $ENV{'PROGRESSFRAMECOLOR'} && $ENV{'PROGRESSFRAMECOLOR'} ne "" );
803 $variableshashref->{'PROGRESSTEXTCOLOR'} = $ENV{'PROGRESSTEXTCOLOR'} , if( defined $ENV{'PROGRESSTEXTCOLOR'} && $ENV{'PROGRESSTEXTCOLOR'} ne "" );
804 $variableshashref->{'PROGRESSTEXTBASELINE'} = $ENV{'PROGRESSTEXTBASELINE'} , if( defined $ENV{'PROGRESSTEXTBASELINE'} && $ENV{'PROGRESSTEXTBASELINE'} ne "" );
807 ###########################################################
808 # Adding the lowercase variables into the variableshashref
809 ###########################################################
811 sub add_variables_to_allvariableshashref
813 my ($variableshashref) = @_;
815 my $lcvariable = lc($variableshashref->{'PRODUCTNAME'});
816 $variableshashref->{'LCPRODUCTNAME'} = $lcvariable;
818 if ($variableshashref->{'PRODUCTEXTENSION'})
820 $variableshashref->{'LCPRODUCTEXTENSION'} = "\-" . lc($variableshashref->{'PRODUCTEXTENSION'}); # including the "-" !
824 $variableshashref->{'LCPRODUCTEXTENSION'} = "";
827 if ( $installer::globals
::languagepack
) { $variableshashref->{'PRODUCTADDON'} = $installer::globals
::languagepackaddon
; }
828 elsif ( $installer::globals
::helppack
) { $variableshashref->{'PRODUCTADDON'} = $installer::globals
::helppackaddon
; }
829 else { $variableshashref->{'PRODUCTADDON'} = ""; }
831 my $localbuild = $installer::globals
::build
;
832 if ( $localbuild =~ /^\s*(\w+?)(\d+)\s*$/ ) { $localbuild = $2; } # using "680" instead of "src680"
833 $variableshashref->{'PRODUCTMAJOR'} = $localbuild;
836 if ( $installer::globals
::minor
ne "" ) { $localminor = $installer::globals
::minor
; }
837 else { $localminor = $installer::globals
::lastminor
; }
838 if ( $localminor =~ /^\s*\w(\d+)\w*\s*$/ ) { $localminor = $1; }
839 $variableshashref->{'PRODUCTMINOR'} = $localminor;
841 $variableshashref->{'PRODUCTBUILDID'} = $installer::globals
::buildid
;
842 $variableshashref->{'SYSTEM_LIBEXTTEXTCAT_DATA'} = $ENV{'SYSTEM_LIBEXTTEXTCAT_DATA'} , if( defined $ENV{'SYSTEM_LIBEXTTEXTCAT_DATA'} && $ENV{'SYSTEM_LIBEXTTEXTCAT_DATA'} ne "" );