1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: ziplist.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer
::ziplist
;
34 use installer
::existence
;
35 use installer
::exiter
;
36 use installer
::globals
;
37 use installer
::logger
;
38 use installer
::parameter
;
39 use installer
::remover
;
40 use installer
::systemactions
;
42 #################################################
43 # Getting data from path file and zip list file
44 #################################################
48 my ($fileref, $search, $inheritance) = @_;
55 my $inh = $inheritance ?
'(?::\s*(\S+)\s*)?' : "";
58 for ( my $i = 0; $i <= $#{$fileref}; $i++ )
60 $line = ${$fileref}[$i];
62 if ( $line =~ /^\s*\Q$search\E\s*$inh$/i ) # case insensitive
66 $parent = $1 if $inheritance;
71 push(@searchblock, $line);
74 if ( ($record) && ($line =~ /\{/) )
79 if ( ($record) && ($line =~ /\}/) )
84 if ( ($record) && ($line =~ /\}/) && ( $count == 0 ) )
90 if (( ! $searchexists ) && ( $search ne $installer::globals
::globalblock
))
92 if ($search eq $installer::globals
::product
)
94 installer
::exiter
::exit_program
("ERROR: Product $installer::globals::product not defined in $installer::globals::ziplistname", "getproductblock");
96 elsif ($search eq $installer::globals
::compiler
)
98 installer
::exiter
::exit_program
("ERROR: Compiler $installer::globals::compiler not defined in $installer::globals::pathfilename", "getproductblock");
100 else # this is not possible
102 installer
::exiter
::exit_program
("ERROR: Unknown value for $search in getproductblock()", "getproductblock");
106 return (\
@searchblock, $parent);
109 ###############################################
110 # Analyzing the settings in the zip list file
111 ###############################################
113 sub analyze_settings_block
117 my @newsettingsblock = ();
118 my $compilerstring = "";
122 # Allowed values in settings block:
123 # "Settings", "Variables", "unix" (for destination path and logfile)
124 # Furthermore allowed values are $installer::globals::build (srx645) and $installer::globals::compiler (pro and nonpro (unxsols4.pro))
126 # Comment line in settings block begin with "#" or ";"
128 if ( $installer::globals
::pro
)
130 $compilerstring = $installer::globals
::compiler
. ".pro";
134 $compilerstring = $installer::globals
::compiler
;
137 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
139 my $line = ${$blockref}[$i];
142 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
144 # removing comment lines
146 if (($line =~ /^\s*\#/) || ($line =~ /^\s*\;/))
151 # complete blocks of unknows strings are not recorded
153 if ((!($line =~ /^\s*\Q$compilerstring\E\s*$/i)) &&
154 (!($line =~ /^\s*\Q$installer::globals::build\E\s*$/i)) &&
155 (!($line =~ /^\s*\bSettings\b\s*$/i)) &&
156 (!($line =~ /^\s*\bVariables\b\s*$/i)) &&
157 (!($line =~ /^\s*\bunix\b\s*$/i)) &&
158 ($nextline =~ /^\s*\{\s*$/i))
161 next; # continue with next $i
166 if ($line =~ /^\s*\{\s*$/i)
171 if ($line =~ /^\s*\}\s*$/i)
179 next; # continue with next $i
185 push(@newsettingsblock, $line);
189 return \
@newsettingsblock;
192 ########################################
193 # Settings in zip list file
194 ########################################
196 sub get_settings_from_ziplist
200 my @allsettings = ();
203 my $variablescounter = 0;
205 # Take all settings from the settings block
206 # Do not take the variables from the settings block
207 # If a setting is defined more than once, take the
208 # setting with the largest counter (open brackets)
210 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
212 my $line = ${$blockref}[$i];
215 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
217 if (($line =~ /^\s*\S+\s*$/i) &&
218 ($nextline =~ /^\s*\{\s*$/i) &&
219 (!($line =~ /^\s*Variables\s*$/i)))
224 if ($line =~ /^\s*Variables\s*$/i)
226 # This is a block of variables
232 if ($line =~ /^\s*\{\s*$/i)
246 if ($line =~ /^\s*\}\s*$/i)
252 if ($variablescounter == 0)
270 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
272 $line .= "\t##$counter##\n";
274 push(@allsettings, $line);
277 return \
@allsettings;
280 #######################################
281 # Variables from zip list file
282 #######################################
284 sub get_variables_from_ziplist
288 my @allvariables = ();
291 my $variablescounter = 0;
294 # Take all variables from the settings block
295 # Do not take the other settings from the settings block
296 # If a variable is defined more than once, take the
297 # variable with the largest counter (open brackets)
299 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
301 my $line = ${$blockref}[$i];
302 my $nextline = ${$blockref}[$i+1];
304 if ($line =~ /^\s*Variables\s*$/i)
306 # This is a block of variables
312 if ($line =~ /^\s*\{\s*$/i)
326 if ($line =~ /^\s*\}\s*$/i)
332 if ($variablescounter == 0)
350 $countersum = $counter + $variablescounter;
352 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
354 $line .= "\t##$countersum##\n";
356 push(@allvariables, $line);
359 return \
@allvariables;
362 #######################################################################
363 # Removing multiple variables and settings, defined in zip list file
364 #######################################################################
366 sub remove_multiples_from_ziplist
370 # remove all definitions of settings and variables
371 # that occur more than once in the zip list file.
372 # Take the one with the most open brackets. This
373 # number is stored at the end of the string.
377 my ($line, $itemname, $itemnumber);
379 # first collecting all variables and settings names
381 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
383 $line = ${$blockref}[$i];
385 if ($line =~ /^\s*\b(\S*)\b\s+.*\#\#\d+\#\#\s*$/i)
390 if (! installer
::existence
::exists_in_array
($itemname, \
@itemarray))
392 push(@itemarray, $itemname);
396 # and now all $items can be selected with the highest number
398 for ( my $i = 0; $i <= $#itemarray; $i++ )
400 $itemname = $itemarray[$i];
402 my $itemnumbermax = 0;
405 for ( my $j = 0; $j <= $#{$blockref}; $j++ )
407 $line = ${$blockref}[$j];
409 if ($line =~ /^\s*\Q$itemname\E\s+.*\#\#(\d+)\#\#\s*$/)
413 if ($itemnumber >= $itemnumbermax)
416 $itemnumbermax = $itemnumber;
421 # removing the ending number from the printline
422 # and putting it into the array
424 $printline =~ s/\#\#\d+\#\#//;
425 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
426 push(@newarray, $printline);
432 #########################################################
433 # Reading one variable defined in the zip list file
434 #########################################################
436 sub getinfofromziplist
438 my ($blockref, $variable) = @_;
440 my $searchstring = "";
443 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
445 $line = ${$blockref}[$i];
447 if ( $line =~ /^\s*\Q$variable\E\s+(.+?)\s*$/ ) # "?" for minimal matching
454 return \
$searchstring;
457 ####################################################
458 # Replacing variables in include path
459 ####################################################
461 sub replace_all_variables_in_pathes
463 my ( $patharrayref, $variableshashref ) = @_;
465 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
467 my $line = ${$patharrayref}[$i];
471 foreach $key (keys %{$variableshashref})
473 my $value = $variableshashref->{$key};
475 if (( $line =~ /\{$key\}/ ) && ( $value eq "" )) { $line = ".\n"; }
477 $line =~ s/\{\Q$key\E\}/$value/g;
480 ${$patharrayref}[$i] = $line;
484 ####################################################
485 # Replacing minor in include path
486 ####################################################
488 sub replace_minor_in_pathes
490 my ( $patharrayref ) = @_;
492 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
494 my $line = ${$patharrayref}[$i];
496 if ( $installer::globals
::minor
)
498 $line =~ s/\{minor\}/$installer::globals::minor/g;
499 # no difference for minor and minornonpre (ToDo ?)
500 $line =~ s/\{minornonpre\}/$installer::globals::minor/g;
502 else # building without a minor
504 $line =~ s/\.\{minor\}//g;
505 $line =~ s/\.\{minornonpre\}//g;
508 ${$patharrayref}[$i] = $line;
512 ####################################################
513 # Replacing packagetype in include path
514 ####################################################
516 sub replace_packagetype_in_pathes
518 my ( $patharrayref ) = @_;
520 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
522 my $line = ${$patharrayref}[$i];
524 if (( $installer::globals
::installertypedir
) && ( $line =~ /\{pkgtype\}/ ))
526 $line =~ s/\{pkgtype\}/$installer::globals::installertypedir/g;
529 ${$patharrayref}[$i] = $line;
533 ####################################################
534 # Removing ending separators in pathes
535 ####################################################
537 sub remove_ending_separator
539 my ( $patharrayref ) = @_;
541 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
543 my $line = ${$patharrayref}[$i];
545 installer
::remover
::remove_ending_pathseparator
(\
$line);
548 $line = $line . "\n";
550 ${$patharrayref}[$i] = $line;
554 ####################################################
555 # Replacing languages in include path
556 ####################################################
558 sub replace_languages_in_pathes
560 my ( $patharrayref, $languagesref ) = @_;
562 installer
::logger
::include_header_into_logfile
("Replacing languages in include pathes:");
567 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
569 my $line = ${$patharrayref}[$i];
571 if ( $line =~ /\$\(LANG\)/ )
573 my $originalline = $line;
576 for ( my $j = 0; $j <= $#{$languagesref}; $j++ )
578 my $language = ${$languagesref}[$j];
579 $line =~ s/\$\(LANG\)/$language/g;
580 push(@patharray ,$line);
582 $line = $originalline;
584 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$newline);
586 # Is it necessary to refresh the global array, containing all files of all include pathes?
589 # Checking if $newdir is empty
590 if ( ! installer
::systemactions
::is_empty_dir
($newdir) )
592 $installer::globals
::refresh_includepathes
= 1;
593 $infoline = "Directory $newdir exists and is not empty. Refreshing global file array is required.\n";
594 push( @installer::globals
::logfileinfo
, $infoline);
598 $infoline = "Directory $newdir is empty. No refresh of global file array required.\n";
599 push( @installer::globals
::logfileinfo
, $infoline);
604 $infoline = "Directory $newdir does not exist. No refresh of global file array required.\n";
605 push( @installer::globals
::logfileinfo
, $infoline);
609 else # not language dependent include path
611 push(@patharray ,$line);
618 #####################################################
619 # Collecting all files from all include paths
620 #####################################################
622 sub list_all_files_from_include_path
624 my ( $patharrayref) = @_;
626 installer
::logger
::include_header_into_logfile
("Include pathes:");
628 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
630 my $path = ${$patharrayref}[$i];
631 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$path);
632 my $infoline = "$path\n";
633 push( @installer::globals
::logfileinfo
, $infoline);
636 push( @installer::globals
::logfileinfo
, "\n");
641 #####################################################
642 # Collecting all files from all include paths
643 #####################################################
647 my ($allvariables) = @_;
649 my $openofficeproductname = "OpenOffice.org";
650 my $sunname = "Sun Microsystems";
652 if ( $allvariables->{'OPENSOURCE'} && $allvariables->{'OPENSOURCE'} == 1 )
654 $installer::globals
::isopensourceproduct
= 1;
655 $installer::globals
::manufacturer
= $openofficeproductname;
656 $installer::globals
::longmanufacturer
= $openofficeproductname;
660 $installer::globals
::isopensourceproduct
= 0;
661 $installer::globals
::manufacturer
= $sunname;
662 $installer::globals
::longmanufacturer
= $sunname . ", Inc.";
665 $allvariables->{'MANUFACTURER'} = $installer::globals
::manufacturer
;
668 ##############################################################
669 # A ProductVersion has to be defined. If it is not set in
670 # zip.lst, it is set now to "1"
671 ##############################################################
673 sub set_default_productversion_if_required
675 my ($allvariables) = @_;
677 if (!($allvariables->{'PRODUCTVERSION'}))
679 $allvariables->{'PRODUCTVERSION'} = 1; # FAKE
682 # Creating differentiators for BUILD_SPECIAL in layering
683 if ( ! $ENV{'BUILD_SPECIAL'} )
685 if ( $allvariables->{'REGISTRYLAYERNAME'} ) { $allvariables->{'REGISTRYLAYERNAME'} = $allvariables->{'REGISTRYLAYERNAME'} . "_"; }
686 if (( $installer::globals
::iswindowsbuild
) && ( $allvariables->{'BASISROOTNAME'} )) { $allvariables->{'BASISROOTNAME'} = $allvariables->{'BASISROOTNAME'} . "_"; }
690 ####################################################
691 # Removing .. in pathes
692 ####################################################
696 my ( $pathref ) = @_;
698 my $oldpath = $$pathref;
702 while ( $oldpath =~ /(^.*)(\Q$installer::globals::separator\E.*\w+?)(\Q$installer::globals::separator\E\.\.)(\Q$installer::globals::separator\E.*$)/ )
706 $oldpath = $part1 . $part2;
710 if ( $change ) { $$pathref = $oldpath . "\n"; }
713 ####################################################
714 # Removing ending separators in pathes
715 ####################################################
717 sub resolve_relative_pathes
719 my ( $patharrayref ) = @_;
721 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
723 installer
::parameter
::make_path_absolute
(\
${$patharrayref}[$i]);
724 simplify_path
(\
${$patharrayref}[$i]);
728 ####################################################
729 # Replacing variables inside zip list variables
730 # Example: {milestone} to be replaced by
731 # $installer::globals::lastminor
732 ####################################################
734 sub replace_variables_in_ziplist_variables
738 my $milestonevariable = $installer::globals
::lastminor
;
739 $milestonevariable =~ s/m//;
740 $milestonevariable =~ s/s/\./;
742 my $localminor = $installer::globals
::lastminor
;
743 if ( $installer::globals
::minor
) { $localminor = $installer::globals
::minor
; }
745 for ( my $i = 0; $i <= $#{$blockref}; $i++ )
747 if ($installer::globals
::lastminor
) { ${$blockref}[$i] =~ s/\{milestone\}/$milestonevariable/; }
748 else { ${$blockref}[$i] =~ s/\{milestone\}//; }
749 if ( $localminor ) { ${$blockref}[$i] =~ s/\{minor\}/$localminor/; }
750 else { ${$blockref}[$i] =~ s/\{minor\}//; }
751 if ( $installer::globals
::buildid
) { ${$blockref}[$i] =~ s/\{buildid\}/$installer::globals::buildid/; }
752 else { ${$blockref}[$i] =~ s/\{buildid\}//; }
753 if ( $installer::globals
::build
) { ${$blockref}[$i] =~ s/\{buildsource\}/$installer::globals::build/; }
754 else { ${$blockref}[$i] =~ s/\{build\}//; }
758 ###########################################################
759 # Adding the lowercase variables into the variableshashref
760 ###########################################################
762 sub add_variables_to_allvariableshashref
764 my ($variableshashref) = @_;
766 my $lcvariable = lc($variableshashref->{'PRODUCTNAME'});
767 $variableshashref->{'LCPRODUCTNAME'} = $lcvariable;
769 if ($variableshashref->{'SHORT_PRODUCTEXTENSION'})
771 $variableshashref->{'LCPRODUCTEXTENSION'} = "\-" . lc($variableshashref->{'SHORT_PRODUCTEXTENSION'}); # including the "-" !
775 $variableshashref->{'LCPRODUCTEXTENSION'} = "";
778 if ( $installer::globals
::patch
) { $variableshashref->{'PRODUCTADDON'} = $installer::globals
::patchaddon
; }
779 elsif ( $installer::globals
::languagepack
) { $variableshashref->{'PRODUCTADDON'} = $installer::globals
::languagepackaddon
; }
780 else { $variableshashref->{'PRODUCTADDON'} = ""; }
782 my $localbuild = $installer::globals
::build
;
783 if ( $localbuild =~ /^\s*(\w+?)(\d+)\s*$/ ) { $localbuild = $2; } # using "680" instead of "src680"
784 $variableshashref->{'PRODUCTMAJOR'} = $localbuild;
787 if ( $installer::globals
::minor
ne "" ) { $localminor = $installer::globals
::minor
; }
788 else { $localminor = $installer::globals
::lastminor
; }
789 if ( $localminor =~ /^\s*\w(\d+)\w*\s*$/ ) { $localminor = $1; }
790 $variableshashref->{'PRODUCTMINOR'} = $localminor;
792 $variableshashref->{'PRODUCTBUILDID'} = $installer::globals
::buildid
;