1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22 23 24package installer::ziplist; 25 26use installer::existence; 27use installer::exiter; 28use installer::globals; 29use installer::logger; 30use installer::parameter; 31use installer::remover; 32use installer::systemactions; 33 34################################################# 35# Getting data from path file and zip list file 36################################################# 37 38sub getproductblock 39{ 40 my ($fileref, $search, $inheritance) = @_; 41 42 my @searchblock = (); 43 my $searchexists = 0; 44 my $record = 0; 45 my $count = 0; 46 my $line; 47 my $inh = $inheritance ? '(?::\s*(\S+)\s*)?' : ""; 48 my $parent; 49 50 for ( my $i = 0; $i <= $#{$fileref}; $i++ ) 51 { 52 $line = ${$fileref}[$i]; 53 54 if ( $line =~ /^\s*\Q$search\E\s*$inh$/i ) # case insensitive 55 { 56 $record = 1; 57 $searchexists = 1; 58 $parent = $1 if $inheritance; 59 } 60 61 if ($record) 62 { 63 push(@searchblock, $line); 64 } 65 66 if ( ($record) && ($line =~ /\{/) ) 67 { 68 $count++; 69 } 70 71 if ( ($record) && ($line =~ /\}/) ) 72 { 73 $count--; 74 } 75 76 if ( ($record) && ($line =~ /\}/) && ( $count == 0 ) ) 77 { 78 $record = 0; 79 } 80 } 81 82 if (( ! $searchexists ) && ( $search ne $installer::globals::globalblock )) 83 { 84 if ($search eq $installer::globals::product ) 85 { 86 installer::exiter::exit_program("ERROR: Product $installer::globals::product not defined in $installer::globals::ziplistname", "getproductblock"); 87 } 88 elsif ($search eq $installer::globals::compiler ) 89 { 90 installer::exiter::exit_program("ERROR: Compiler $installer::globals::compiler not defined in $installer::globals::pathfilename", "getproductblock"); 91 } 92 else # this is not possible 93 { 94 installer::exiter::exit_program("ERROR: Unknown value for $search in getproductblock()", "getproductblock"); 95 } 96 } 97 98 return (\@searchblock, $parent); 99} 100 101############################################### 102# Analyzing the settings in the zip list file 103############################################### 104 105sub analyze_settings_block 106{ 107 my ($blockref) = @_; 108 109 my @newsettingsblock = (); 110 my $compilerstring = ""; 111 my $record = 1; 112 my $counter = 0; 113 114 # Allowed values in settings block: 115 # "Settings", "Variables", "unix" (for destination path and logfile) 116 # Furthermore allowed values are $installer::globals::build (srx645) and $installer::globals::compiler (pro and nonpro (unxsols4.pro)) 117 118 # Comment line in settings block begin with "#" or ";" 119 120 if ( $installer::globals::pro ) 121 { 122 $compilerstring = $installer::globals::compiler . ".pro"; 123 } 124 else 125 { 126 $compilerstring = $installer::globals::compiler; 127 } 128 129 for ( my $i = 0; $i <= $#{$blockref}; $i++ ) 130 { 131 my $line = ${$blockref}[$i]; 132 my $nextline = ""; 133 134 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; } 135 136 # removing comment lines 137 138 if (($line =~ /^\s*\#/) || ($line =~ /^\s*\;/)) 139 { 140 next; 141 } 142 143 # complete blocks of unknows strings are not recorded 144 145 if ((!($line =~ /^\s*\Q$compilerstring\E\s*$/i)) && 146 (!($line =~ /^\s*\Q$installer::globals::build\E\s*$/i)) && 147 (!($line =~ /^\s*\bSettings\b\s*$/i)) && 148 (!($line =~ /^\s*\bVariables\b\s*$/i)) && 149 (!($line =~ /^\s*\bunix\b\s*$/i)) && 150 ($nextline =~ /^\s*\{\s*$/i)) 151 { 152 $record = 0; 153 next; # continue with next $i 154 } 155 156 if (!( $record )) 157 { 158 if ($line =~ /^\s*\{\s*$/i) 159 { 160 $counter++; 161 } 162 163 if ($line =~ /^\s*\}\s*$/i) 164 { 165 $counter--; 166 } 167 168 if ($counter == 0) 169 { 170 $record = 1; 171 next; # continue with next $i 172 } 173 } 174 175 if ($record) 176 { 177 push(@newsettingsblock, $line); 178 } 179 } 180 181 return \@newsettingsblock; 182} 183 184######################################## 185# Settings in zip list file 186######################################## 187 188sub get_settings_from_ziplist 189{ 190 my ($blockref) = @_; 191 192 my @allsettings = (); 193 my $isvariables = 0; 194 my $counter = 0; 195 my $variablescounter = 0; 196 197 # Take all settings from the settings block 198 # Do not take the variables from the settings block 199 # If a setting is defined more than once, take the 200 # setting with the largest counter (open brackets) 201 202 for ( my $i = 0; $i <= $#{$blockref}; $i++ ) 203 { 204 my $line = ${$blockref}[$i]; 205 my $nextline = ""; 206 207 if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; } 208 209 if (($line =~ /^\s*\S+\s*$/i) && 210 ($nextline =~ /^\s*\{\s*$/i) && 211 (!($line =~ /^\s*Variables\s*$/i))) 212 { 213 next; 214 } 215 216 if ($line =~ /^\s*Variables\s*$/i) 217 { 218 # This is a block of variables 219 220 $isvariables = 1; 221 next; 222 } 223 224 if ($line =~ /^\s*\{\s*$/i) 225 { 226 if ($isvariables) 227 { 228 $variablescounter++; 229 } 230 else 231 { 232 $counter++; 233 } 234 235 next; 236 } 237 238 if ($line =~ /^\s*\}\s*$/i) 239 { 240 if ($isvariables) 241 { 242 $variablescounter--; 243 244 if ($variablescounter == 0) 245 { 246 $isvariables = 0; 247 } 248 } 249 else 250 { 251 $counter--; 252 } 253 254 next; 255 } 256 257 if ($isvariables) 258 { 259 next; 260 } 261 262 installer::remover::remove_leading_and_ending_whitespaces(\$line); 263 264 $line .= "\t##$counter##\n"; 265 266 push(@allsettings, $line); 267 } 268 269 return \@allsettings; 270} 271 272####################################### 273# Variables from zip list file 274####################################### 275 276sub get_variables_from_ziplist 277{ 278 my ($blockref) = @_; 279 280 my @allvariables = (); 281 my $isvariables = 0; 282 my $counter = 0; 283 my $variablescounter = 0; 284 my $countersum = 0; 285 286 # Take all variables from the settings block 287 # Do not take the other settings from the settings block 288 # If a variable is defined more than once, take the 289 # variable with the largest counter (open brackets) 290 291 for ( my $i = 0; $i <= $#{$blockref}; $i++ ) 292 { 293 my $line = ${$blockref}[$i]; 294 my $nextline = ${$blockref}[$i+1]; 295 296 if ($line =~ /^\s*Variables\s*$/i) 297 { 298 # This is a block of variables 299 300 $isvariables = 1; 301 next; 302 } 303 304 if ($line =~ /^\s*\{\s*$/i) 305 { 306 if ($isvariables) 307 { 308 $variablescounter++; 309 } 310 else 311 { 312 $counter++; 313 } 314 315 next; 316 } 317 318 if ($line =~ /^\s*\}\s*$/i) 319 { 320 if ($isvariables) 321 { 322 $variablescounter--; 323 324 if ($variablescounter == 0) 325 { 326 $isvariables = 0; 327 } 328 } 329 else 330 { 331 $counter--; 332 } 333 334 next; 335 } 336 337 if (!($isvariables)) 338 { 339 next; 340 } 341 342 $countersum = $counter + $variablescounter; 343 344 installer::remover::remove_leading_and_ending_whitespaces(\$line); 345 346 $line .= "\t##$countersum##\n"; 347 348 push(@allvariables, $line); 349 } 350 351 return \@allvariables; 352} 353 354####################################################################### 355# Removing multiple variables and settings, defined in zip list file 356####################################################################### 357 358sub remove_multiples_from_ziplist 359{ 360 my ($blockref) = @_; 361 362 # remove all definitions of settings and variables 363 # that occur more than once in the zip list file. 364 # Take the one with the most open brackets. This 365 # number is stored at the end of the string. 366 367 my @newarray = (); 368 my @itemarray = (); 369 my ($line, $itemname, $itemnumber); 370 371 # first collecting all variables and settings names 372 373 for ( my $i = 0; $i <= $#{$blockref}; $i++ ) 374 { 375 $line = ${$blockref}[$i]; 376 377 if ($line =~ /^\s*\b(\S*)\b\s+.*\#\#\d+\#\#\s*$/i) 378 { 379 $itemname = $1; 380 } 381 382 if (! installer::existence::exists_in_array($itemname, \@itemarray)) 383 { 384 push(@itemarray, $itemname); 385 } 386 } 387 388 # and now all $items can be selected with the highest number 389 390 for ( my $i = 0; $i <= $#itemarray; $i++ ) 391 { 392 $itemname = $itemarray[$i]; 393 394 my $itemnumbermax = 0; 395 my $printline = ""; 396 397 for ( my $j = 0; $j <= $#{$blockref}; $j++ ) 398 { 399 $line = ${$blockref}[$j]; 400 401 if ($line =~ /^\s*\Q$itemname\E\s+.*\#\#(\d+)\#\#\s*$/) 402 { 403 $itemnumber = $1; 404 405 if ($itemnumber >= $itemnumbermax) 406 { 407 $printline = $line; 408 $itemnumbermax = $itemnumber; 409 } 410 } 411 } 412 413 # removing the ending number from the printline 414 # and putting it into the array 415 416 $printline =~ s/\#\#\d+\#\#//; 417 installer::remover::remove_leading_and_ending_whitespaces(\$line); 418 push(@newarray, $printline); 419 } 420 421 return \@newarray; 422} 423 424######################################################### 425# Reading one variable defined in the zip list file 426######################################################### 427 428sub getinfofromziplist 429{ 430 my ($blockref, $variable) = @_; 431 432 my $searchstring = ""; 433 my $line; 434 435 for ( my $i = 0; $i <= $#{$blockref}; $i++ ) 436 { 437 $line = ${$blockref}[$i]; 438 439 if ( $line =~ /^\s*\Q$variable\E\s+(.+?)\s*$/ ) # "?" for minimal matching 440 { 441 $searchstring = $1; 442 last; 443 } 444 } 445 446 return \$searchstring; 447} 448 449#################################################### 450# Replacing variables in include path 451#################################################### 452 453sub replace_all_variables_in_pathes 454{ 455 my ( $patharrayref, $variableshashref ) = @_; 456 457 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 458 { 459 my $line = ${$patharrayref}[$i]; 460 461 my $key; 462 463 foreach $key (keys %{$variableshashref}) 464 { 465 my $value = $variableshashref->{$key}; 466 467 if (( $line =~ /\{$key\}/ ) && ( $value eq "" )) { $line = ".\n"; } 468 469 $line =~ s/\{\Q$key\E\}/$value/g; 470 } 471 472 ${$patharrayref}[$i] = $line; 473 } 474} 475 476#################################################### 477# Replacing minor in include path 478#################################################### 479 480sub replace_minor_in_pathes 481{ 482 my ( $patharrayref ) = @_; 483 484 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 485 { 486 my $line = ${$patharrayref}[$i]; 487 488 if ( ! defined $ENV{CWS_WORK_STAMP} and defined $ENV{UPDMINOR} ) 489# if ( $installer::globals::minor ) 490 { 491 $line =~ s/\{minor\}/$installer::globals::minor/g; 492 # no difference for minor and minornonpre (ToDo ?) 493 $line =~ s/\{minornonpre\}/$installer::globals::minor/g; 494 } 495 else # building without a minor 496 { 497 $line =~ s/\.\{minor\}//g; 498 $line =~ s/\.\{minornonpre\}//g; 499 } 500 501 ${$patharrayref}[$i] = $line; 502 } 503} 504 505#################################################### 506# Replacing packagetype in include path 507#################################################### 508 509sub replace_packagetype_in_pathes 510{ 511 my ( $patharrayref ) = @_; 512 513 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 514 { 515 my $line = ${$patharrayref}[$i]; 516 517 if (( $installer::globals::installertypedir ) && ( $line =~ /\{pkgtype\}/ )) 518 { 519 $line =~ s/\{pkgtype\}/$installer::globals::installertypedir/g; 520 } 521 522 ${$patharrayref}[$i] = $line; 523 } 524} 525 526#################################################### 527# Removing ending separators in pathes 528#################################################### 529 530sub remove_ending_separator 531{ 532 my ( $patharrayref ) = @_; 533 534 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 535 { 536 my $line = ${$patharrayref}[$i]; 537 538 installer::remover::remove_ending_pathseparator(\$line); 539 540 $line =~ s/\s*$//; 541 $line = $line . "\n"; 542 543 ${$patharrayref}[$i] = $line; 544 } 545} 546 547#################################################### 548# Replacing languages in include path 549#################################################### 550 551sub replace_languages_in_pathes 552{ 553 my ( $patharrayref, $languagesref ) = @_; 554 555 installer::logger::include_header_into_logfile("Replacing languages in include pathes:"); 556 557 my @patharray = (); 558 my $infoline = ""; 559 560 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 561 { 562 my $line = ${$patharrayref}[$i]; 563 564 if ( $line =~ /\$\(LANG\)/ ) 565 { 566 my $originalline = $line; 567 my $newline = ""; 568 569 for ( my $j = 0; $j <= $#{$languagesref}; $j++ ) 570 { 571 my $language = ${$languagesref}[$j]; 572 $line =~ s/\$\(LANG\)/$language/g; 573 push(@patharray ,$line); 574 $newdir = $line; 575 $line = $originalline; 576 577 installer::remover::remove_leading_and_ending_whitespaces(\$newline); 578 579 # Is it necessary to refresh the global array, containing all files of all include pathes? 580 if ( -d $newdir ) 581 { 582 # Checking if $newdir is empty 583 if ( ! installer::systemactions::is_empty_dir($newdir) ) 584 { 585 $installer::globals::refresh_includepathes = 1; 586 $infoline = "Directory $newdir exists and is not empty. Refreshing global file array is required.\n"; 587 push( @installer::globals::logfileinfo, $infoline); 588 } 589 else 590 { 591 $infoline = "Directory $newdir is empty. No refresh of global file array required.\n"; 592 push( @installer::globals::logfileinfo, $infoline); 593 } 594 } 595 else 596 { 597 $infoline = "Directory $newdir does not exist. No refresh of global file array required.\n"; 598 push( @installer::globals::logfileinfo, $infoline); 599 } 600 } 601 } 602 else # not language dependent include path 603 { 604 push(@patharray ,$line); 605 } 606 } 607 608 return \@patharray; 609} 610 611##################################################### 612# Collecting all files from all include paths 613##################################################### 614 615sub list_all_files_from_include_path 616{ 617 my ( $patharrayref) = @_; 618 619 installer::logger::include_header_into_logfile("Include pathes:"); 620 621 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 622 { 623 my $path = ${$patharrayref}[$i]; 624 installer::remover::remove_leading_and_ending_whitespaces(\$path); 625 my $infoline = "$path\n"; 626 push( @installer::globals::logfileinfo, $infoline); 627 } 628 629 push( @installer::globals::logfileinfo, "\n"); 630 631 return \@filesarray; 632} 633 634##################################################### 635# Collecting all files from all include paths 636##################################################### 637 638sub set_manufacturer 639{ 640 my ($allvariables) = @_; 641 642 my $openofficeproductname = "OpenOffice"; 643 my $sunname = ""; 644 645 646 if ( $allvariables->{'OPENSOURCE'} && $allvariables->{'OPENSOURCE'} == 1 ) 647 { 648 $installer::globals::isopensourceproduct = 1; 649 $installer::globals::manufacturer = $openofficeproductname; 650 $installer::globals::longmanufacturer = $openofficeproductname; 651 } 652 else 653 { 654 $installer::globals::isopensourceproduct = 0; 655 if (( $allvariables->{'DEFINEDMANUFACTURER'} ) && ( $allvariables->{'DEFINEDMANUFACTURER'} ne "" )) { $sunname = $allvariables->{'DEFINEDMANUFACTURER'}; } 656 else { installer::exiter::exit_program("ERROR: Property DEFINEDMANUFACTURER has to be set for this product!", "set_manufacturer"); } 657 $installer::globals::manufacturer = $sunname; 658 $installer::globals::longmanufacturer = $sunname; 659 } 660 661 $allvariables->{'MANUFACTURER'} = $installer::globals::manufacturer; 662} 663 664############################################################## 665# A ProductVersion has to be defined. If it is not set in 666# zip.lst, it is set now to "1" 667############################################################## 668 669sub set_default_productversion_if_required 670{ 671 my ($allvariables) = @_; 672 673 if (!($allvariables->{'PRODUCTVERSION'})) 674 { 675 $allvariables->{'PRODUCTVERSION'} = 1; # FAKE 676 } 677} 678 679#################################################### 680# Removing .. in pathes 681#################################################### 682 683sub simplify_path 684{ 685 my ( $pathref ) = @_; 686 687 my $oldpath = $$pathref; 688 689 my $change = 0; 690 691 while ( $oldpath =~ /(^.*)(\Q$installer::globals::separator\E.*\w+?)(\Q$installer::globals::separator\E\.\.)(\Q$installer::globals::separator\E.*$)/ ) 692 { 693 my $part1 = $1; 694 my $part2 = $4; 695 $oldpath = $part1 . $part2; 696 $change = 1; 697 } 698 699 if ( $change ) { $$pathref = $oldpath . "\n"; } 700} 701 702#################################################### 703# Removing ending separators in pathes 704#################################################### 705 706sub resolve_relative_pathes 707{ 708 my ( $patharrayref ) = @_; 709 710 for ( my $i = 0; $i <= $#{$patharrayref}; $i++ ) 711 { 712 installer::parameter::make_path_absolute(\${$patharrayref}[$i]); 713 simplify_path(\${$patharrayref}[$i]); 714 } 715} 716 717#################################################### 718# Replacing variables inside zip list variables 719# Example: {milestone} to be replaced by 720# $installer::globals::lastminor 721#################################################### 722 723sub replace_variables_in_ziplist_variables 724{ 725 my ($blockref) = @_; 726 727 my $milestonevariable = $installer::globals::lastminor; 728 $milestonevariable =~ s/m//; 729 $milestonevariable =~ s/s/\./; 730 731 my $localminor = $installer::globals::lastminor; 732 if ( $installer::globals::minor ) { $localminor = $installer::globals::minor; } 733 734 my $buildidstringcws = $installer::globals::build . $localminor . "(Build:" . $installer::globals::buildid . ")"; 735 736 # the environment variable CWS_WORK_STAMP is set only in CWS 737 if ( $ENV{'CWS_WORK_STAMP'} ) { $buildidstringcws = $buildidstringcws . "\[CWS\:" . $ENV{'CWS_WORK_STAMP'} . "\]"; } 738 739 for ( my $i = 0; $i <= $#{$blockref}; $i++ ) 740 { 741 if ($installer::globals::lastminor) { ${$blockref}[$i] =~ s/\{milestone\}/$milestonevariable/; } 742 else { ${$blockref}[$i] =~ s/\{milestone\}//; } 743 if ( $localminor ) { ${$blockref}[$i] =~ s/\{minor\}/$localminor/; } 744 else { ${$blockref}[$i] =~ s/\{minor\}//; } 745 if ( $installer::globals::buildid ) { ${$blockref}[$i] =~ s/\{buildid\}/$installer::globals::buildid/; } 746 else { ${$blockref}[$i] =~ s/\{buildid\}//; } 747 if ( $installer::globals::build ) { ${$blockref}[$i] =~ s/\{buildsource\}/$installer::globals::build/; } 748 else { ${$blockref}[$i] =~ s/\{build\}//; } 749 ${$blockref}[$i] =~ s/\{buildidcws\}/$buildidstringcws/; 750 } 751} 752 753########################################################### 754# Overwrite the vendor string in openoffice.lst that is defined in configure 755########################################################### 756 757sub overwrite_ooovendor 758{ 759 my ($variableshashref) = @_; 760 $variableshashref->{'OOOVENDOR'} = $ENV{'OOO_VENDOR'} , if( defined $ENV{'OOO_VENDOR'} && $ENV{'OOO_VENDOR'} ne "" ); 761} 762 763########################################################### 764# Adding the lowercase variables into the variableshashref 765########################################################### 766 767sub add_variables_to_allvariableshashref 768{ 769 my ($variableshashref) = @_; 770 771 my $lcvariable = lc($variableshashref->{'PRODUCTNAME'}); 772 $variableshashref->{'LCPRODUCTNAME'} = $lcvariable; 773 774 if ($variableshashref->{'SHORT_PRODUCTEXTENSION'}) 775 { 776 $variableshashref->{'LCPRODUCTEXTENSION'} = "\-" . lc($variableshashref->{'SHORT_PRODUCTEXTENSION'}); # including the "-" ! 777 } 778 else 779 { 780 $variableshashref->{'LCPRODUCTEXTENSION'} = ""; 781 } 782 783 if ( $installer::globals::patch ) { $variableshashref->{'PRODUCTADDON'} = $installer::globals::patchaddon; } 784 elsif ( $installer::globals::languagepack ) { $variableshashref->{'PRODUCTADDON'} = $installer::globals::languagepackaddon; } 785 else { $variableshashref->{'PRODUCTADDON'} = ""; } 786 787 my $localbuild = $installer::globals::build; 788 if ( $localbuild =~ /^\s*(\w+?)(\d+)\s*$/ ) { $localbuild = $2; } # using "680" instead of "src680" 789 $variableshashref->{'PRODUCTMAJOR'} = $localbuild; 790 791 my $localminor = ""; 792 if ( $installer::globals::minor ne "" ) { $localminor = $installer::globals::minor; } 793 else { $localminor = $installer::globals::lastminor; } 794 if ( $localminor =~ /^\s*\w(\d+)\w*\s*$/ ) { $localminor = $1; } 795 $variableshashref->{'PRODUCTMINOR'} = $localminor; 796 797 $variableshashref->{'PRODUCTBUILDID'} = $installer::globals::buildid; 798 $variableshashref->{'SYSTEM_LIBTEXTCAT_DATA'} = $ENV{'SYSTEM_LIBTEXTCAT_DATA'} , if( defined $ENV{'SYSTEM_LIBTEXTCAT_DATA'} && $ENV{'SYSTEM_LIBTEXTCAT_DATA'} ne "" ); 799} 800 8011; 802