xref: /AOO41X/main/solenv/bin/modules/installer/packagelist.pm (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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::packagelist;
25
26use installer::converter;
27use installer::exiter;
28use installer::globals;
29use installer::remover;
30use installer::scriptitems;
31
32########################################
33# Check existence of module
34########################################
35
36sub check_module_existence
37{
38    my ($onegid, $moduleslist) = @_;
39
40    my $foundgid = 0;
41
42    for ( my $i = 0; $i <= $#{$moduleslist}; $i++ )
43    {
44        my $gid = ${$moduleslist}[$i]->{'gid'};
45
46        if ( $gid eq $onegid )
47        {
48            $foundgid = 1;
49            last;
50        }
51    }
52
53    return $foundgid;
54}
55
56###################################################
57# Analyzing the gids, defined in the packagelist
58###################################################
59
60sub analyze_list
61{
62    my ($packagelist, $moduleslist) = @_;
63
64    @allpackages = ();
65
66    my $moduleshash = get_module_hash($moduleslist);
67
68    for ( my $i = 0; $i <= $#{$packagelist}; $i++ )
69    {
70        my $onepackage = ${$packagelist}[$i];
71
72        my $onegid = $onepackage->{'module'};
73
74        installer::remover::remove_leading_and_ending_whitespaces(\$onegid);
75
76        my $moduleexists = check_module_existence($onegid, $moduleslist);
77
78        if ( ! $moduleexists ) { next; }
79
80        my @allmodules = ();
81
82        push(@allmodules, $onegid);
83
84        # get_children($moduleslist, $onegid, \@allmodules);
85        get_children_with_hash($moduleshash, $onegid, \@allmodules);
86
87        $onepackage->{'allmodules'} = \@allmodules;
88
89        push(@allpackages, $onepackage);
90    }
91
92    return \@allpackages;
93}
94
95###################################################
96# Creating a hash, that contains the module gids
97# as keys and the parentids as values
98###################################################
99
100sub get_module_hash
101{
102    my ($moduleslist) = @_;
103
104    my %modulehash = ();
105
106    for ( my $i = 0; $i <= $#{$moduleslist}; $i++ )
107    {
108        my $gid = ${$moduleslist}[$i]->{'gid'};
109        # Containing only modules with parent. Root modules can be ignored.
110        if ( ${$moduleslist}[$i]->{'ParentID'} ) { $modulehash{$gid} = ${$moduleslist}[$i]->{'ParentID'}; }
111    }
112
113    return \%modulehash;
114}
115
116########################################################
117# Recursively defined procedure to order
118# modules and directories
119########################################################
120
121sub get_children_with_hash
122{
123    my ($modulehash, $parentgid, $newitemorder) = @_;
124
125    foreach my $gid ( keys %{$modulehash} )
126    {
127        my $parent = $modulehash->{$gid};
128
129        if ( $parent eq $parentgid )
130        {
131            push(@{$newitemorder}, $gid);
132            my $parent = $gid;
133            get_children_with_hash($modulehash, $parent, $newitemorder);    # recursive!
134        }
135    }
136}
137
138########################################################
139# Recursively defined procedure to order
140# modules and directories
141########################################################
142
143sub get_children
144{
145    my ($allitems, $startparent, $newitemorder) = @_;
146
147    for ( my $i = 0; $i <= $#{$allitems}; $i++ )
148    {
149        my $gid = ${$allitems}[$i]->{'gid'};
150        my $parent = "";
151        if ( ${$allitems}[$i]->{'ParentID'} ) { $parent = ${$allitems}[$i]->{'ParentID'}; }
152
153        if ( $parent eq $startparent )
154        {
155            push(@{$newitemorder}, $gid);
156            my $parent = $gid;
157            get_children($allitems, $parent, $newitemorder);    # recursive!
158        }
159    }
160}
161
162#####################################################################
163# All modules below a defined gid_Module_A are collected now for
164# each modules defined in the packagelist. Now the modules have
165# to be removed, that are part of more than one package.
166#####################################################################
167
168sub remove_multiple_modules_packages
169{
170    my ($allpackagemodules) = @_;
171
172    # iterating over all packages
173
174    for ( my $i = 0; $i <= $#{$allpackagemodules}; $i++ )
175    {
176        my $onepackage = ${$allpackagemodules}[$i];
177        my $allmodules = $onepackage->{'allmodules'};
178
179        # print "Modules below $onepackage->{'module'}: $#{$allmodules}\n";
180
181        # Comparing each package, with all following packages. If a
182        # gid for the module is part of more than one package, it is
183        # removed if the number of modules in the package is greater
184        # in the current package than in the compare package.
185
186        # Taking all modules from package $i
187
188        my $packagecount = $#{$allmodules};
189
190        my @optimizedpackage = ();
191
192        # iterating over all modules of this package
193
194        for ( my $j = 0; $j <= $#{$allmodules}; $j++ )
195        {
196            my $onemodule = ${$allmodules}[$j]; # this is the module, that shall be removed or not
197
198            my $put_module_into_new_package = 1;
199
200            # iterating over all other packages
201
202            for ( my $k = 0; $k <= $#{$allpackagemodules}; $k++ )
203            {
204                if ( $k == $i ) { next; }   # not comparing equal module
205
206                if (! $put_module_into_new_package) { next; } # do not compare, if already found
207
208                my $comparepackage = ${$allpackagemodules}[$k];
209                my $allcomparemodules = $comparepackage->{'allmodules'};
210
211                my $comparepackagecount = $#{$allcomparemodules};
212
213                # modules will only be removed from packages, that have more modules
214                # than the compare package
215
216                if ( $packagecount <= $comparepackagecount ) { next; }  # nothing to do, take next package
217
218                # iterating over all modules of this package
219
220                for ( my $m = 0; $m <= $#{$allcomparemodules}; $m++ )
221                {
222                    my $onecomparemodule = ${$allcomparemodules}[$m];
223
224                    if ( $onemodule eq $onecomparemodule )  # this $onemodule has to be removed
225                    {
226                        $put_module_into_new_package = 0;
227                    }
228                }
229            }
230
231            if ( $put_module_into_new_package )
232            {
233                push(@optimizedpackage, $onemodule)
234            }
235        }
236
237        $onepackage->{'allmodules'} = \@optimizedpackage;
238    }
239
240    # for ( my $i = 0; $i <= $#{$allpackagemodules}; $i++ )
241    # {
242    #   my $onepackage = ${$allpackagemodules}[$i];
243    #   my $allmodules = $onepackage->{'allmodules'};
244    #   print "New: Modules below $onepackage->{'module'}: $#{$allmodules}\n";
245    # }
246
247}
248
249#####################################################################
250# Analyzing all files if they belong to a special package.
251# A package is described by a list of modules.
252#####################################################################
253
254sub find_files_for_package
255{
256    my ($filelist, $onepackage) = @_;
257
258    my @newfilelist = ();
259
260    for ( my $i = 0; $i <= $#{$filelist}; $i++ )
261    {
262        my $onefile = ${$filelist}[$i];
263        my $modulesstring = $onefile->{'modules'};   # comma separated modules list
264        my $moduleslist = installer::converter::convert_stringlist_into_array(\$modulesstring, ",");
265
266        my $includefile = 0;
267
268        # iterating over all modules of this file
269
270        for ( my $j = 0; $j <= $#{$moduleslist}; $j++ )
271        {
272            if ( $includefile ) { next; }
273            my $filemodule = ${$moduleslist}[$j];
274            installer::remover::remove_leading_and_ending_whitespaces(\$filemodule);
275
276            # iterating over all modules of the package
277
278            my $packagemodules = $onepackage->{'allmodules'};
279
280            for ( my $k = 0; $k <= $#{$packagemodules}; $k++ )
281            {
282                if ( $includefile ) { next; }
283                my $packagemodule = ${$packagemodules}[$k];
284
285                if ( $filemodule eq $packagemodule )
286                {
287                    $includefile = 1;
288                    last;
289                }
290            }
291        }
292
293        if ( $includefile )
294        {
295            push(@newfilelist, $onefile);
296        }
297    }
298
299    return \@newfilelist;
300}
301
302#####################################################################
303# Analyzing all links if they belong to a special package.
304# A package is described by a list of modules.
305# A link is inserted into the package, if the corresponding
306# file is also inserted.
307#####################################################################
308
309sub find_links_for_package
310{
311    my ($linklist, $filelist) = @_;
312
313    # First looking for all links with a FileID.
314    # Then looking for all links with a ShortcutID.
315
316    my @newlinklist = ();
317
318    for ( my $i = 0; $i <= $#{$linklist}; $i++ )
319    {
320        my $includelink = 0;
321
322        my $onelink = ${$linklist}[$i];
323
324        my $fileid = "";
325        if ( $onelink->{'FileID'} ) { $fileid = $onelink->{'FileID'}; }
326
327        if ( $fileid eq "" ) { next; }   # A link with a ShortcutID
328
329        for ( my $j = 0; $j <= $#{$filelist}; $j++ )     # iterating over file list
330        {
331            my $onefile = ${$filelist}[$j];
332            my $gid = $onefile->{'gid'};
333
334            if ( $gid eq $fileid )
335            {
336                $includelink = 1;
337                last;
338            }
339        }
340
341        if ( $includelink )
342        {
343            push(@newlinklist, $onelink);
344        }
345    }
346
347    # iterating over the new list, because of all links with a ShortcutID
348
349    for ( my $i = 0; $i <= $#{$linklist}; $i++ )
350    {
351        my $includelink = 0;
352
353        my $onelink = ${$linklist}[$i];
354
355        my $shortcutid = "";
356        if ( $onelink->{'ShortcutID'} ) { $shortcutid = $onelink->{'ShortcutID'}; }
357
358        if ( $shortcutid eq "" ) { next; }   # A link with a ShortcutID
359
360        for ( my $j = 0; $j <= $#newlinklist; $j++ )     # iterating over newly created link list
361        {
362            my $onefilelink = $newlinklist[$j];
363            my $gid = $onefilelink->{'gid'};
364
365            if ( $gid eq $shortcutid )
366            {
367                $includelink = 1;
368                last;
369            }
370        }
371
372        if ( $includelink )
373        {
374            push(@newlinklist, $onelink);
375        }
376    }
377
378    return \@newlinklist;
379}
380
381#####################################################################
382# Analyzing all directories if they belong to a special package.
383# A package is described by a list of modules.
384# Directories are included into the package, if they are needed
385# by a file or a link included into the package.
386# Attention: A directory with the flag CREATE, is only included
387# into the root module:
388# ($packagename eq $installer::globals::rootmodulegid)
389#####################################################################
390
391sub find_dirs_for_package
392{
393    my ($dirlist, $onepackage) = @_;
394
395    my @newdirlist = ();
396
397    for ( my $i = 0; $i <= $#{$dirlist}; $i++ )
398    {
399        my $onedir = ${$dirlist}[$i];
400        my $modulesstring = $onedir->{'modules'};    # comma separated modules list
401        my $moduleslist = installer::converter::convert_stringlist_into_array(\$modulesstring, ",");
402
403        my $includedir = 0;
404
405        # iterating over all modules of this dir
406
407        for ( my $j = 0; $j <= $#{$moduleslist}; $j++ )
408        {
409            if ( $includedir ) { last; }
410            my $dirmodule = ${$moduleslist}[$j];
411            installer::remover::remove_leading_and_ending_whitespaces(\$dirmodule);
412
413            # iterating over all modules of the package
414
415            my $packagemodules = $onepackage->{'allmodules'};
416
417            for ( my $k = 0; $k <= $#{$packagemodules}; $k++ )
418            {
419                my $packagemodule = ${$packagemodules}[$k];
420
421                if ( $dirmodule eq $packagemodule )
422                {
423                    $includedir = 1;
424                    last;
425                }
426            }
427        }
428
429        if ( $includedir )
430        {
431            push(@newdirlist, $onedir);
432        }
433    }
434
435    return \@newdirlist;
436}
437
438#####################################################################
439# Resolving all variables in the packagename.
440#####################################################################
441
442sub resolve_packagevariables
443{
444    my ($packagenameref, $variableshashref, $make_lowercase) = @_;
445
446    my $key;
447
448    # Special handling for dictionaries
449    if ( $$packagenameref =~ /-dict-/ )
450    {
451        if (exists($variableshashref->{'DICTIONARYUNIXPRODUCTNAME'}) ) { $$packagenameref =~ s/\%UNIXPRODUCTNAME/$variableshashref->{'DICTIONARYUNIXPRODUCTNAME'}/g; }
452        if (exists($variableshashref->{'DICTIONARYBRANDPACKAGEVERSION'}) ) { $$packagenameref =~ s/\%BRANDPACKAGEVERSION/$variableshashref->{'DICTIONARYBRANDPACKAGEVERSION'}/g; }
453    }
454
455    foreach $key (keys %{$variableshashref})
456    {
457        my $value = $variableshashref->{$key};
458        if ( $make_lowercase ) { $value = lc($value); }
459        $$packagenameref =~ s/\%$key/$value/g;
460    }
461}
462
463#####################################################################
464# Resolving all variables in the packagename.
465#####################################################################
466
467sub resolve_packagevariables2
468{
469    my ($packagenameref, $variableshashref, $make_lowercase, $isdict ) = @_;
470
471    my $key;
472
473    # Special handling for dictionaries
474    if ( $isdict )
475    {
476        if (exists($variableshashref->{'DICTIONARYUNIXPRODUCTNAME'}) ) { $$packagenameref =~ s/\%UNIXPRODUCTNAME/$variableshashref->{'DICTIONARYUNIXPRODUCTNAME'}/g; }
477        if (exists($variableshashref->{'DICTIONARYBRANDPACKAGEVERSION'}) ) { $$packagenameref =~ s/\%BRANDPACKAGEVERSION/$variableshashref->{'DICTIONARYBRANDPACKAGEVERSION'}/g; }
478    }
479
480    foreach $key (keys %{$variableshashref})
481    {
482        my $value = $variableshashref->{$key};
483        if ( $make_lowercase ) { $value = lc($value); }
484        $$packagenameref =~ s/\%$key/$value/g;
485    }
486}
487
488#####################################################################
489# New packages system.
490#####################################################################
491
492##################################################################
493# Controlling the content of the packagelist
494# 1. Items in @installer::globals::packagelistitems must exist
495# 2. If a shellscript file is defined, it must exist
496##################################################################
497
498sub check_packagelist
499{
500    my ($packages) = @_;
501
502    if ( ! ( $#{$packages} > -1 )) { installer::exiter::exit_program("ERROR: No packages defined!", "check_packagelist"); }
503
504    for ( my $i = 0; $i <= $#{$packages}; $i++ )
505    {
506        my $onepackage = ${$packages}[$i];
507
508        my $element;
509
510        # checking all items that must be defined
511
512        foreach $element (@installer::globals::packagelistitems)
513        {
514            if ( ! exists($onepackage->{$element}) )
515            {
516                installer::exiter::exit_program("ERROR in package list: No value for $element !", "check_packagelist");
517            }
518        }
519
520        # checking the existence of the script file, if defined
521
522        if ( $onepackage->{'script'} )
523        {
524            my $scriptfile = $onepackage->{'script'};
525            my $gid =  $onepackage->{'module'};
526            my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfile, "" , 0);
527
528            if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find script file $scriptfile for module $gid!", "check_packagelist"); }
529
530            my $infoline = "$gid: Using script file: \"$$fileref\"!\n";
531            push( @installer::globals::logfileinfo, $infoline);
532
533            $onepackage->{'script'} = $$fileref;
534        }
535    }
536}
537
538#####################################################################
539# Reading pack info for one module from packinfo file.
540#####################################################################
541
542sub get_packinfo
543{
544    my ($gid, $filename, $packages, $onelanguage, $islanguagemodule) = @_;
545
546    my $packagelist = installer::files::read_file($filename);
547
548    my @allpackages = ();
549
550    for ( my $i = 0; $i <= $#{$packagelist}; $i++ )
551    {
552        my $line = ${$packagelist}[$i];
553
554        if ( $line =~ /^\s*\#/ ) { next; }  # this is a comment line
555
556        if ( $line =~ /^\s*Start\s*$/i )    # a new package definition
557        {
558            my %onepackage = ();
559
560            my $counter = $i + 1;
561
562            while (!( ${$packagelist}[$counter] =~ /^\s*End\s*$/i ))
563            {
564                if ( ${$packagelist}[$counter] =~ /^\s*(\S+)\s*\=\s*\"(.*)\"/ )
565                {
566                    my $key = $1;
567                    my $value = $2;
568                    $onepackage{$key} = $value;
569                }
570
571                $counter++;
572            }
573
574            $onepackage{'islanguagemodule'} = $islanguagemodule;
575            if ( $islanguagemodule )
576            {
577                $saveonelanguage = $onelanguage;
578                $saveonelanguage =~ s/_/-/g;
579                $onepackage{'language'} = $saveonelanguage;
580            }
581
582            push(@allpackages, \%onepackage);
583        }
584    }
585
586    # looking for the packinfo with the correct gid
587
588    my $foundgid = 0;
589    my $onepackage;
590    foreach $onepackage (@allpackages)
591    {
592        # Adding the language to the module gid for LanguagePacks !
593        # Making the module gid language specific: gid_Module_Root -> gir_Module_Root_pt_BR (as defined in scp2)
594        if ( $onelanguage ne "" ) { $onepackage->{'module'} = $onepackage->{'module'} . "_$onelanguage"; }
595
596        if ( $onepackage->{'module'} eq $gid )
597        {
598            # Resolving the language identifier
599            my $onekey;
600            foreach $onekey ( keys %{$onepackage} )
601            {
602                # Some keys require "-" instead of "_" for example in "en-US". All package names do not use underlines.
603                my $locallang = $onelanguage;
604                if (( $onekey eq "solarispackagename" ) ||
605                   ( $onekey eq "solarisrequires" ) ||
606                   ( $onekey eq "packagename" ) ||
607                   ( $onekey eq "requires" )) { $locallang =~ s/_/-/g; } # avoiding illegal package abbreviation
608                $onepackage->{$onekey} =~ s/\%LANGUAGESTRING/$locallang/g;
609            }
610
611            # Saving the language for the package
612            my $lang = $onelanguage;
613            $lang =~ s/_/-/g;
614            $onepackage->{'specificlanguage'} = $lang;
615
616            push(@{$packages}, $onepackage);
617            $foundgid = 1;
618            last;
619        }
620    }
621
622    if ( ! $foundgid )
623    {
624        installer::exiter::exit_program("ERROR: Could not find package info for module $gid in file \"$filename\"!", "get_packinfo");
625    }
626}
627
628#####################################################################
629# Collecting all packages from scp project.
630#####################################################################
631
632sub collectpackages
633{
634    my ( $allmodules, $languagesarrayref ) = @_;
635
636    installer::logger::include_header_into_logfile("Collecting packages:");
637
638    my @packages = ();
639    my %gid_analyzed = ();
640
641    my $onemodule;
642    foreach $onemodule ( @{$allmodules} )
643    {
644        my $packageinfo = "PackageInfo";
645        if (( $installer::globals::tab ) && ( $onemodule->{"TabPackageInfo"} )) { $packageinfo = "TabPackageInfo" }
646
647        if ( $onemodule->{$packageinfo} )   # this is a package module!
648        {
649            my $modulegid = $onemodule->{'gid'};
650
651            # Only collecting modules with correct language for language packs
652#           if ( $installer::globals::languagepack ) { if ( ! ( $modulegid =~ /_$onelanguage\s*$/ )) { next; } }
653            # Resetting language, if this is no language pack
654#           if ( ! $installer::globals::languagepack ) { $onelanguage = ""; }
655
656            my $styles = "";
657            if ( $onemodule->{'Styles'} ) { $styles = $onemodule->{'Styles'}; }
658
659            # checking modules with style LANGUAGEMODULE
660            my $islanguagemodule = 0;
661            my $onelanguage = "";
662            if ( $styles =~ /\bLANGUAGEMODULE\b/ )
663            {
664                $islanguagemodule = 1;
665                $onelanguage = $onemodule->{'Language'}; # already checked, that it is set.
666                $onelanguage =~ s/-/_/g; # pt-BR -> pt_BR in scp
667            }
668
669            # Modules in different languages are listed more than once in multilingual installation sets
670            if ( exists($gid_analyzed{$modulegid}) ) { next; }
671            $gid_analyzed{$modulegid} = 1;
672
673            my $packinfofile = $onemodule->{$packageinfo};
674
675            # The file with package information has to be found in path list
676            my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packinfofile, "" , 0);
677
678            if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $packinfofile for module $modulegid!", "collectpackages"); }
679
680            my $infoline = "$modulegid: Using packinfo: \"$$fileref\"!\n";
681            push( @installer::globals::logfileinfo, $infoline);
682
683            get_packinfo($modulegid, $$fileref, \@packages, $onelanguage, $islanguagemodule);
684        }
685    }
686
687    return \@packages;
688}
689
690#####################################################################
691# Printing packages content for debugging purposes
692#####################################################################
693
694sub log_packages_content
695{
696    my ($packages) = @_;
697
698    if ( ! ( $#{$packages} > -1 )) { installer::exiter::exit_program("ERROR: No packages defined!", "print_content"); }
699
700    installer::logger::include_header_into_logfile("Logging packages content:");
701
702    my $infoline = "";
703
704    for ( my $i = 0; $i <= $#{$packages}; $i++ )
705    {
706        my $onepackage = ${$packages}[$i];
707
708        # checking all items that must be defined
709
710        $infoline = "Package $onepackage->{'module'}\n";
711        push(@installer::globals::logfileinfo, $infoline);
712
713        my $key;
714        foreach $key (sort keys %{$onepackage})
715        {
716            if ( $key =~ /^\s*\;/ ) { next; }
717
718            if ( $key eq "allmodules" )
719            {
720                $infoline = "\t$key:\n";
721                push(@installer::globals::logfileinfo, $infoline);
722                my $onemodule;
723                foreach $onemodule ( @{$onepackage->{$key}} )
724                {
725                    $infoline = "\t\t$onemodule\n";
726                    push(@installer::globals::logfileinfo, $infoline);
727                }
728            }
729            else
730            {
731                $infoline = "\t$key: $onepackage->{$key}\n";
732                push(@installer::globals::logfileinfo, $infoline);
733            }
734        }
735
736        $infoline = "\n";
737        push(@installer::globals::logfileinfo, $infoline);
738
739    }
740}
741
742#####################################################################
743# Creating assignments from modules to destination pathes.
744# This is required for logging in fileinfo file. Otherwise
745# the complete destination file would not be known in file list.
746# Saved in %installer::globals::moduledestination
747#####################################################################
748
749sub create_module_destination_hash
750{
751    my ($packages, $allvariables) = @_;
752
753    for ( my $i = 0; $i <= $#{$packages}; $i++ )
754    {
755        my $onepackage = ${$packages}[$i];
756
757        my $defaultdestination = $onepackage->{'destpath'};
758        resolve_packagevariables(\$defaultdestination, $allvariables, 1);
759        if ( $^O =~ /darwin/i ) { $defaultdestination =~ s/\/opt\//\/Applications\//; }
760
761        foreach my $onemodule ( @{$onepackage->{'allmodules'}} )
762        {
763            $installer::globals::moduledestination{$onemodule} = $defaultdestination;
764        }
765    }
766}
767
768#####################################################################
769# Adding the default pathes into the files collector for Unixes.
770# This is necessary to know the complete destination path in
771# fileinfo log file.
772#####################################################################
773
774sub add_defaultpathes_into_filescollector
775{
776    my ($allfiles) = @_;
777
778    for ( my $i = 0; $i <= $#{$allfiles}; $i++ )
779    {
780        my $onefile = ${$allfiles}[$i];
781
782        if ( ! $onefile->{'destination'} ) { installer::exiter::exit_program("ERROR: No destination found at file $onefile->{'gid'}!", "add_defaultpathes_into_filescollector"); }
783        my $destination = $onefile->{'destination'};
784
785        if ( ! $onefile->{'modules'} ) { installer::exiter::exit_program("ERROR: No modules found at file $onefile->{'gid'}!", "add_defaultpathes_into_filescollector"); }
786        my $module = $onefile->{'modules'};
787        # If modules contains a list of modules, only taking the first one.
788        if ( $module =~ /^\s*(.*?)\,/ ) { $module = $1; }
789
790        if ( ! exists($installer::globals::moduledestination{$module}) ) { installer::exiter::exit_program("ERROR: No default destination path found for module $module!", "add_defaultpathes_into_filescollector"); }
791        my $defaultpath = $installer::globals::moduledestination{$module};
792        $defaultpath =~ s/\/\s*$//; # removing ending slashes
793        my $fulldestpath = $defaultpath . $installer::globals::separator . $destination;
794
795        $onefile->{'fulldestpath'} = $fulldestpath;
796    }
797}
798
799#####################################################################
800# Creating list of cabinet files from packages
801#####################################################################
802
803sub prepare_cabinet_files
804{
805    my ($packages, $allvariables) = @_;
806
807    if ( ! ( $#{$packages} > -1 )) { installer::exiter::exit_program("ERROR: No packages defined!", "print_content"); }
808
809    installer::logger::include_header_into_logfile("Preparing cabinet files:");
810
811    my $infoline = "";
812
813    for ( my $i = 0; $i <= $#{$packages}; $i++ )
814    {
815        my $onepackage = ${$packages}[$i];
816
817        my $cabinetfile = "$onepackage->{'packagename'}\.cab";
818
819        resolve_packagevariables(\$cabinetfile, $allvariables, 0);
820
821        $installer::globals::allcabinets{$cabinetfile} = 1;
822
823        # checking all items that must be defined
824
825        $infoline = "Package $onepackage->{'module'}\n";
826        push(@installer::globals::logfileinfo, $infoline);
827
828        # Assigning the cab file to the module and also to all corresponding sub modules
829
830        my $onemodule;
831        foreach $onemodule ( @{$onepackage->{'allmodules'}} )
832        {
833            if ( ! exists($installer::globals::allcabinetassigns{$onemodule}) )
834            {
835                $installer::globals::allcabinetassigns{$onemodule} = $cabinetfile;
836            }
837            else
838            {
839                my $infoline = "Warning: Already existing assignment: $onemodule : $installer::globals::allcabinetassigns{$onemodule}\n";
840                push(@installer::globals::logfileinfo, $infoline);
841                $infoline = "Ignoring further assignment: $onemodule : $cabinetfile\n";
842                push(@installer::globals::logfileinfo, $infoline);
843            }
844        }
845    }
846}
847
848#####################################################################
849# Logging assignments of cabinet files
850#####################################################################
851
852sub log_cabinet_assignments
853{
854    installer::logger::include_header_into_logfile("Logging cabinet files:");
855
856    my $infoline = "List of cabinet files:\n";
857    push(@installer::globals::logfileinfo, $infoline);
858
859    my $key;
860    foreach $key ( sort keys %installer::globals::allcabinets ) { push(@installer::globals::logfileinfo, "\t$key\n"); }
861
862    $infoline = "\nList of assignments from modules to cabinet files:\n";
863    push(@installer::globals::logfileinfo, $infoline);
864
865    foreach $key ( sort keys %installer::globals::allcabinetassigns ) { push(@installer::globals::logfileinfo, "\t$key : $installer::globals::allcabinetassigns{$key}\n"); }
866}
867
8681;
869