xref: /AOO41X/main/solenv/bin/modules/installer/javainstaller.pm (revision fe22d2cfc602815794415026f1317bd625db6f83) !
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
23package installer::javainstaller;
24
25use Cwd;
26use installer::exiter;
27use installer::files;
28use installer::globals;
29use installer::languages;
30use installer::pathanalyzer;
31use installer::scriptitems;
32use installer::systemactions;
33use installer::worker;
34use installer::logger;
35
36##############################################################
37# Returning a specific language string from the block
38# of all translations
39##############################################################
40
41sub get_language_string_from_language_block
42{
43    my ($language_block, $language, $oldstring) = @_;
44
45    my $newstring = "";
46
47    for ( my $i = 0; $i <= $#{$language_block}; $i++ )
48    {
49        if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
50        {
51            $newstring = $1;
52            last;
53        }
54    }
55
56    if ( $newstring eq "" )
57    {
58        $language = "en-US";    # defaulting to english
59
60        for ( my $i = 0; $i <= $#{$language_block}; $i++ )
61        {
62            if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
63            {
64                $newstring = $1;
65                last;
66            }
67        }
68    }
69
70    return $newstring;
71}
72
73##############################################################
74# Returning the complete block in all languages
75# for a specified string
76##############################################################
77
78sub get_language_block_from_language_file
79{
80    my ($searchstring, $languagefile) = @_;
81
82    my @language_block = ();
83
84    for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
85    {
86        if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
87        {
88            my $counter = $i;
89
90            push(@language_block, ${$languagefile}[$counter]);
91            $counter++;
92
93            while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
94            {
95                push(@language_block, ${$languagefile}[$counter]);
96                $counter++;
97            }
98
99            last;
100        }
101    }
102
103    return \@language_block;
104}
105
106#######################################################
107# Searching for the module name and description in the
108# modules collector
109#######################################################
110
111sub get_module_name_description
112{
113    my ($modulesarrayref, $onelanguage, $gid, $type) = @_;
114
115    my $found = 0;
116
117    my $newstring = "";
118
119    for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
120    {
121        my $onemodule = ${$modulesarrayref}[$i];
122
123        if ( $onemodule->{'gid'} eq $gid )
124        {
125            my $typestring = $type . " " . "(" . $onelanguage . ")";
126            if ( $onemodule->{$typestring} ) { $newstring = $onemodule->{$typestring}; }
127            $found = 1;
128        }
129
130        if ( $found ) { last; }
131    }
132
133    # defaulting to english
134
135    if ( ! $found )
136    {
137        my $defaultlanguage = "en-US";
138
139        for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
140        {
141            my $onemodule = ${$modulesarrayref}[$i];
142
143            if ( $onemodule->{'gid'} eq $gid )
144            {
145                my $typestring = $type . " " . "(" . $defaultlanguage . ")";
146                if ( $onemodule->{$typestring} ) { $newstring = $onemodule->{$typestring}; }
147                $found = 1;
148            }
149
150            if ( $found ) { last; }
151        }
152    }
153
154    return $newstring;
155}
156
157#######################################################
158# Setting the productname and productversion
159#######################################################
160
161sub set_productname_and_productversion
162{
163    my ($templatefile, $variableshashref) = @_;
164
165    $installer::logger::Lang->print("\n");
166    $installer::logger::Lang->print("Setting product name and product version in Java template file\n");
167
168    my $productname = $variableshashref->{'PRODUCTNAME'};
169    my $productversion = $variableshashref->{'PRODUCTVERSION'};
170
171    for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
172    {
173        ${$templatefile}[$i] =~ s/\{PRODUCTNAME\}/$productname/g;
174        ${$templatefile}[$i] =~ s/\{PRODUCTVERSION\}/$productversion/g;
175    }
176
177    $infoline = "End of: Setting product name and product version in Java template file\n\n";
178    $installer::logger::Lang->print($infoline);
179}
180
181#######################################################
182# Setting the localized Module name and description
183#######################################################
184
185sub set_component_name_and_description
186{
187    my ($templatefile, $modulesarrayref, $onelanguage) = @_;
188
189    $installer::logger::Lang->print("\n");
190    $installer::logger::Lang->print("Setting component names and description in Java template file\n");
191
192    for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
193    {
194        # OOO_gid_Module_Prg_Wrt_Name
195        # OOO_gid_Module_Prg_Wrt_Description
196
197        my $oneline = ${$templatefile}[$i];
198        my $oldstring = "";
199        my $gid = "";
200        my $type = "";
201
202        if ( $oneline =~ /\b(OOO_gid_\w+)\b/ )
203        {
204            $oldstring = $1;
205
206            $infoline = "Found: $oldstring\n";
207            $installer::logger::Lang->print($infoline);
208
209            if ( $oldstring =~ /^\s*OOO_(gid_\w+)_(\w+?)\s*$/ )
210            {
211                $gid = $1;
212                $type = $2;
213            }
214
215            my $newstring = get_module_name_description($modulesarrayref, $onelanguage, $gid, $type);
216
217            $infoline = "\tReplacing (language $onelanguage): OLDSTRING: $oldstring NEWSTRING $newstring\n";
218            $installer::logger::Lang->print($infoline);
219
220            ${$templatefile}[$i] =~ s/$oldstring/$newstring/;   # always substitute, even if $newstring eq ""
221        }
222    }
223
224    $infoline = "End of: Setting component names and description in Java template file\n\n";
225    $installer::logger::Lang->print($infoline);
226}
227
228#######################################################
229# Translating the Java file
230#######################################################
231
232sub translate_javafile
233{
234    my ($templatefile, $languagefile, $onelanguage) = @_;
235
236    for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
237    {
238        my @allstrings = ();
239
240        my $oneline = ${$templatefile}[$i];
241
242        while ( $oneline =~ /\b(OOO_\w+)\b/ )
243        {
244            my $replacestring = $1;
245            push(@allstrings, $replacestring);
246            $oneline =~ s/$replacestring//;
247        }
248
249        my $oldstring;
250
251        foreach $oldstring (@allstrings)
252        {
253            my $language_block = get_language_block_from_language_file($oldstring, $languagefile);
254            my $newstring = get_language_string_from_language_block($language_block, $onelanguage, $oldstring);
255
256            $newstring =~ s/\"/\\\"/g;  # masquerading the "
257            $newstring =~ s/\\\\\"/\\\"/g;  # unmasquerading if \" was converted to \\" (because " was already masked)
258
259            # if (!( $newstring eq "" )) { ${$idtfile}[$i] =~ s/$oldstring/$newstring/; }
260            ${$templatefile}[$i] =~ s/$oldstring/$newstring/;   # always substitute, even if $newstring eq ""
261        }
262    }
263}
264
265###########################################################
266# Returning the license file name for a defined language
267###########################################################
268
269sub get_licensefilesource
270{
271    my ($language, $includepatharrayref) = @_;
272
273    my $licensefilename = "LICENSE_" . $language;
274
275    my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $includepatharrayref, 0);
276    if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "get_licensefilesource"); }
277
278    my $infoline = "Found licensefile $licensefilename: $$licenseref \n";
279    $installer::logger::Lang->print($infoline);
280
281    return $$licenseref;
282}
283
284#######################################################
285# Converting the license string into the
286# Java specific encoding.
287#######################################################
288
289sub convert_licenstring
290{
291    my ($licensefile, $includepatharrayref, $javadir, $onelanguage) = @_;
292
293    my $licensedir = $javadir . $installer::globals::separator . "license";
294    installer::systemactions::create_directory($licensedir);
295
296    # saving the original license file
297
298    my $licensefilename = $licensedir . $installer::globals::separator . "licensefile.txt";
299    installer::files::save_file($licensefilename, $licensefile);
300
301    # creating the ulf file from the license file
302
303    $licensefilename = $licensedir . $installer::globals::separator . "licensefile.ulf";
304    my @licensearray = ();
305
306    my $section = "\[TRANSLATE\]\n";
307    push(@licensearray, $section);
308
309    for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
310    {
311        my $oneline = ${$licensefile}[$i];
312
313        if ($i == 0) { $oneline =~ s/^\s*\�\�\�//; }
314
315        $oneline =~ s/\s*$//;
316        $oneline =~ s/\"/\\\"/g;    # masquerading the "
317        $oneline =~ s/\'/\\\'/g;    # masquerading the '
318
319        $oneline =~ s/\$\{/\{/g;    # replacement of variables, only {PRODUCTNAME}, not ${PRODUCTNAME}
320
321        my $ulfstring = $onelanguage . " = " . "\"" . $oneline . "\"\n";
322        push(@licensearray, $ulfstring);
323    }
324
325    installer::files::save_file($licensefilename, \@licensearray);
326
327    # converting the ulf file to the jlf file with ulfconv
328
329    @licensearray = ();
330
331    my $converter = "ulfconv";
332
333    my $converterref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$converter, $includepatharrayref, 0);
334    if ($$converterref eq "") { installer::exiter::exit_program("ERROR: Could not find converter $converter!", "convert_licenstring"); }
335
336    my $infoline = "Found converter file $converter: $$converterref \n";
337    $installer::logger::Lang->print($infoline);
338
339    my $systemcall = "$$converterref $licensefilename |";
340    open (CONV, "$systemcall");
341    @licensearray = <CONV>;
342    close (CONV);
343
344    $licensefilename = $licensedir . $installer::globals::separator . "licensefile.jlf";
345    installer::files::save_file($licensefilename, \@licensearray);
346
347    # creating the license string from the jlf file
348
349    $licensestring = "";
350
351    for ( my $i = 1; $i <= $#licensearray; $i++ )   # not the first line!
352    {
353        my $oneline = $licensearray[$i];
354        $oneline =~ s/^\s*$onelanguage\s*\=\s*\"//;
355        $oneline =~ s/\"\s*$//;
356        $licensestring = $licensestring . $oneline . "\\n";
357    }
358
359    $infoline = "Systemcall: $systemcall\n";
360    $installer::logger::Lang->print($infoline);
361
362    if ( $licensestring eq "" )
363    {
364        $infoline = "ERROR: Could not convert $licensefilename !\n";
365        $installer::logger::Lang->print($infoline);
366    }
367
368    return $licensestring;
369}
370
371#######################################################
372# Adding the license file into the java file
373# In the template java file there are two
374# occurences of INSTALLSDK_GUI_LICENSE
375# and INSTALLSDK_CONSOLE_LICENSE
376#######################################################
377
378sub add_license_file_into_javafile
379{
380    my ( $templatefile, $licensefile, $includepatharrayref, $javadir, $onelanguage ) = @_;
381
382    my $licensestring = convert_licenstring($licensefile, $includepatharrayref, $javadir, $onelanguage);
383
384    # saving the licensestring in an ulf file
385    # converting the file using "ulfconv license.ulf"
386    # including the new string into the java file
387
388    for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
389    {
390        ${$templatefile}[$i] =~ s/INSTALLSDK_GUI_LICENSE/$licensestring/;
391        ${$templatefile}[$i] =~ s/INSTALLSDK_CONSOLE_LICENSE/$licensestring/;
392    }
393}
394
395#######################################################
396# Executing one system call
397#######################################################
398
399sub make_systemcall
400{
401    my ( $systemcall, $logreturn ) = @_;
402
403    my @returns = ();
404
405    $installer::logger::Info->printf("... %s ...\n", $systemcall);
406
407    open (REG, "$systemcall");
408    while (<REG>) {push(@returns, $_); }
409    close (REG);
410
411    my $returnvalue = $?;   # $? contains the return value of the systemcall
412
413    my $infoline = "Systemcall: $systemcall\n";
414    $installer::logger::Lang->print($infoline);
415
416    if ( $logreturn )
417    {
418        foreach my $line (@returns)
419        {
420            $installer::logger::Lang->printf($line);
421        }
422    }
423
424    if ($returnvalue)
425    {
426        $infoline = "ERROR: $systemcall\n";
427        $installer::logger::Lang->print($infoline);
428        $error_occured = 1;
429    }
430    else
431    {
432        $infoline = "SUCCESS: $systemcall\n";
433        $installer::logger::Lang->print($infoline);
434    }
435
436    return \@returns;
437}
438
439#######################################################
440# Setting the class path for the Installer SDK
441#######################################################
442
443sub set_classpath_for_install_sdk
444{
445    my ( $directory ) = @_;
446
447    my $installsdk = "";
448    my $solarVersion = "";
449    my $inPath = "";
450    my $updMinorExt = "";
451
452    if ( defined( $ENV{ 'SOLARVERSION' } ) ) { $solarVersion =  $ENV{'SOLARVERSION'}; }
453    else { installer::exiter::exit_program("ERROR: Environment variable \"SOLARVERSION\" not set!", "set_classpath_for_install_sdk"); }
454
455    if ( defined( $ENV{ 'INPATH' } ) ) { $inPath =  $ENV{'INPATH'}; }
456    else { installer::exiter::exit_program("ERROR: Environment variable \"INPATH\" not set!", "set_classpath_for_install_sdk"); }
457
458    if ( defined( $ENV{ 'UPDMINOREXT' } ) ) { $updMinorExt =  $ENV{'UPDMINOREXT'}; }
459
460    $installsdk = $solarVersion .  $installer::globals::separator . $inPath . $installer::globals::separator . "bin" . $updMinorExt;
461    $installsdk = $installsdk . $installer::globals::separator . "javainstaller";
462
463    if ( $ENV{'INSTALLSDK_SOURCE'} ) { $installsdk = $ENV{'INSTALLSDK_SOURCE'}; }   # overriding the Install SDK with INSTALLSDK_SOURCE
464
465    # The variable CLASSPATH has to contain:
466    # $installsdk/classes:$installsdk/classes/setupsdk.jar:
467    # $installsdk/classes/parser.jar:$installsdk/classes/jaxp.jar:
468    # $installsdk/classes/ldapjdk.jar:$directory
469
470    my @additional_classpath = ();
471    push(@additional_classpath, "$installsdk\/classes");
472    push(@additional_classpath, "$installsdk\/installsdk.jar");
473    push(@additional_classpath, "$installsdk\/classes\/parser.jar");
474    push(@additional_classpath, "$installsdk\/classes\/jaxp.jar");
475    push(@additional_classpath, "$directory");
476
477    my $newclasspathstring = "";
478    my $oldclasspathstring = "";
479    if ( $ENV{'CLASSPATH'} ) { $oldclasspathstring = $ENV{'CLASSPATH'}; }
480    else { $oldclasspathstring = "\."; }
481
482    for ( my $i = 0; $i <= $#additional_classpath; $i++ )
483    {
484        $newclasspathstring = $newclasspathstring . $additional_classpath[$i] . ":";
485    }
486
487    $newclasspathstring = $newclasspathstring . $oldclasspathstring;
488
489    $ENV{'CLASSPATH'} = $newclasspathstring;
490
491    my $infoline = "Setting CLASSPATH to $ENV{'CLASSPATH'}\n";
492    $installer::logger::Lang->print($infoline);
493}
494
495#######################################################
496# Setting the class file name in the Java locale file
497#######################################################
498
499sub set_classfilename
500{
501    my ($templatefile, $classfilename, $searchstring) = @_;
502
503    for ( my $j = 0; $j <= $#{$templatefile}; $j++ )
504    {
505        if ( ${$templatefile}[$j] =~ /\Q$searchstring\E/ )
506        {
507            ${$templatefile}[$j] =~ s/$searchstring/$classfilename/;
508            last;
509        }
510    }
511}
512
513#######################################################
514# Substituting one variable in the xml file
515#######################################################
516
517sub replace_one_variable
518{
519    my ($xmlfile, $variable, $searchstring) = @_;
520
521    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
522    {
523        ${$xmlfile}[$i] =~ s/\$\{$searchstring\}/$variable/g;
524    }
525}
526
527#######################################################
528# Substituting the variables in the xml file
529#######################################################
530
531sub substitute_variables
532{
533    my ($xmlfile, $variableshashref) = @_;
534
535    my $key;
536
537    foreach $key (keys %{$variableshashref})
538    {
539        my $value = $variableshashref->{$key};
540        replace_one_variable($xmlfile, $value, $key);
541    }
542}
543
544##########################################################
545# Finding the line number in xml file of a special
546# component
547##########################################################
548
549sub find_component_line
550{
551    my ($xmlfile, $componentname) = @_;
552
553    my $linenumber = 0;
554
555    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
556    {
557        if ( ${$xmlfile}[$i] =~ /name\s*\=\'\s*$componentname/ )
558        {
559            $linenumber = $i;
560            last;
561        }
562    }
563
564    return $linenumber;
565}
566
567##########################################################
568# Removing one package from the xml file
569##########################################################
570
571sub remove_package
572{
573    my ($xmlfile, $packagename) = @_;
574
575    my $searchstring = $packagename;
576    if ( $searchstring =~ /\-(\S+?)\s*$/ ) { $searchstring = $1; } # "SUNW%PRODUCTNAME-mailcap" -> "mailcap"
577
578    my $packagestring = "";
579    my $namestring = "";
580    my $infoline = "";
581
582    if ( $installer::globals::issolarispkgbuild )
583    {
584        $packagestring = "\<pkgunit";
585        $namestring = "pkgName";
586    }
587    elsif ( $installer::globals::islinuxrpmbuild )
588    {
589        $packagestring = "\<rpmunit";
590        $namestring = "rpmUniqueName";
591    }
592
593    my $removed_packge = 0;
594
595    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
596    {
597        if ( ${$xmlfile}[$i] =~ /^\s*\Q$packagestring\E/ )
598        {
599            # this is a package, but is it the correct one?
600
601            my $do_delete = 0;
602            my $linecounter = 1;
603            my $startline = $i+1;
604            my $line = ${$xmlfile}[$startline];
605            if (($line =~ /^\s*\Q$namestring\E\s*\=/) && ($line =~ /\-\Q$searchstring\E/)) { $do_delete = 1; }
606
607            # but not deleting fonts package in language packs
608            if ( $line =~ /-ONELANGUAGE-/ ) { $do_delete = 0; }
609
610            my $endcounter = 0;
611
612            while ((!( $line =~ /\/\>/ )) && ( $startline <= $#{$xmlfile} ))
613            {
614                $linecounter++;
615                $startline++;
616                $line = ${$xmlfile}[$startline];
617                if (($line =~ /^\s*\Q$namestring\E\s*\=/) && ($line =~ /\-\Q$searchstring\E/)) { $do_delete = 1; }
618            }
619
620            $linecounter = $linecounter + 1;
621
622            if ( $do_delete )
623            {
624                my $infoline = "\tReally removing package $packagename from xml file.\n";
625                $installer::logger::Lang->print($infoline);
626                splice(@{$xmlfile},$i, $linecounter);   # removing $linecounter lines, beginning in line $i
627                $removed_packge = 1;
628                last;
629            }
630        }
631    }
632
633    if ( $removed_packge )
634    {
635        $infoline = "Package $packagename successfully removed from xml file.\n";
636        $installer::logger::Lang->print($infoline);
637    }
638    else
639    {
640        $infoline = "Did not find package $packagename in xml file.\n";
641        $installer::logger::Lang->print($infoline);
642    }
643
644}
645
646##########################################################
647# Removing one component from the xml file
648##########################################################
649
650sub remove_component
651{
652    my ($xmlfile, $componentname) = @_;
653
654    my @removed_lines = ();
655
656    push(@removed_lines, "\n");
657
658    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
659    {
660        if ( ${$xmlfile}[$i] =~ /name\s*\=\'\s*$componentname/ )
661        {
662            # Counting the lines till the second "</component>"
663
664            push(@removed_lines, ${$xmlfile}[$i]);
665            my $linecounter = 1;
666            my $startline = $i+1;
667            my $line = ${$xmlfile}[$startline];
668            push(@removed_lines, $line);
669            my $endcounter = 0;
670
671            while ((!( $line =~ /^\s*\<\/component\>\s*$/ )) && ( $startline <= $#{$xmlfile} ))
672            {
673                $linecounter++;
674                $startline++;
675                $line = ${$xmlfile}[$startline];
676                push(@removed_lines, $line);
677            }
678
679            $linecounter = $linecounter + 2;     # last line and following empty line
680
681            splice(@{$xmlfile},$i, $linecounter);   # removing $linecounter lines, beginning in line $i
682            last;
683        }
684    }
685
686    return \@removed_lines;
687}
688
689##########################################################
690# If this is an installation set without language packs
691# the language pack module can be removed
692##########################################################
693
694sub remove_languagepack_from_xmlfile
695{
696    my ($xmlfile) = @_;
697
698    # Component begins with "<component selected="true" name='module_languagepacks' componentVersion="${PRODUCTVERSION}">"
699    # and ends with "</component>" (the second "</component>" !)
700
701    remove_component($xmlfile, "languagepack_DEFAULT");
702    remove_component($xmlfile, "languagepack_ONELANGUAGE");
703    remove_component($xmlfile, "module_languagepacks");
704}
705
706##########################################################
707# Duplicating a component
708##########################################################
709
710sub duplicate_component
711{
712    my ( $arrayref ) = @_;
713
714    @newarray = ();
715
716    for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
717    {
718        push(@newarray, ${$arrayref}[$i]);
719    }
720
721    return \@newarray;
722}
723
724##########################################################
725# Including a component into the xml file
726# at a specified line
727##########################################################
728
729sub include_component_at_specific_line
730{
731    my ($xmlfile, $unit, $line) = @_;
732
733    splice(@{$xmlfile},$line, 0, @{$unit});
734}
735
736##########################################################
737# Font packages do not exist for all languages.
738##########################################################
739
740sub remove_font_package_from_unit
741{
742    my ( $unitcopy, $onelanguage ) = @_;
743
744    my $searchstring = "-fonts";
745
746    my $packagestring = "";
747    my $namestring = "";
748
749    if ( $installer::globals::issolarispkgbuild )
750    {
751        $packagestring = "\<pkgunit";
752        $namestring = "pkgName";
753    }
754    elsif ( $installer::globals::islinuxrpmbuild )
755    {
756        $packagestring = "\<rpmunit";
757        $namestring = "rpmUniqueName";
758    }
759
760    for ( my $i = 0; $i <= $#{$unitcopy}; $i++ )
761    {
762        if ( ${$unitcopy}[$i] =~ /^\s*\Q$packagestring\E/ )
763        {
764            # this is a package, but is it the correct one?
765
766            my $do_delete = 0;
767            my $linecounter = 1;
768            my $startline = $i+1;
769            my $line = ${$unitcopy}[$startline];
770            if (($line =~ /^\s*\Q$namestring\E\s*\=/) && ($line =~ /\Q$searchstring\E/)) { $do_delete = 1; }
771
772            my $endcounter = 0;
773
774            while ((!( $line =~ /\/\>/ )) && ( $startline <= $#{$unitcopy} ))
775            {
776                $linecounter++;
777                $startline++;
778                $line = ${$unitcopy}[$startline];
779                if (($line =~ /^\s*\Q$namestring\E\s*\=/) && ($line =~ /\Q$searchstring\E/)) { $do_delete = 1; }
780            }
781
782            $linecounter = $linecounter + 1;
783
784            if ( $do_delete )
785            {
786                splice(@{$unitcopy},$i, $linecounter);  # removing $linecounter lines, beginning in line $i
787                last;
788            }
789        }
790    }
791}
792
793##########################################################
794# If this is an installation set with language packs,
795# modules for each language pack have to be created
796# dynamically
797##########################################################
798
799sub duplicate_languagepack_in_xmlfile
800{
801    my ($xmlfile, $languagesarrayref) = @_;
802
803    my $unit = remove_component($xmlfile, "languagepack_ONELANGUAGE");
804    my $startline = find_component_line($xmlfile, "module_languagepacks");
805    my $infoline = "";
806    $startline = $startline + 1;
807
808    for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
809    {
810        my $onelanguage = ${$languagesarrayref}[$i];
811        my $unitcopy = duplicate_component($unit);
812
813        # replacing string ONELANGUAGE in the unit copy
814        for ( my $j = 0; $j <= $#{$unitcopy}; $j++ ) { ${$unitcopy}[$j] =~ s/ONELANGUAGE/$onelanguage/g; }
815
816        # including the unitcopy into the xml file
817        include_component_at_specific_line($xmlfile, $unitcopy, $startline);
818        $startline = $startline + $#{$unitcopy} + 1;
819    }
820
821    # adding the default language as language pack, too
822    $unit = remove_component($xmlfile, "languagepack_DEFAULT");
823    $startline = find_component_line($xmlfile, "module_languagepacks");
824    $startline = $startline + 1;
825
826    $onelanguage = ${$languagesarrayref}[0];
827    $unitcopy = duplicate_component($unit);
828
829    # replacing string DEFAULT in the unit copy
830    for ( my $j = 0; $j <= $#{$unitcopy}; $j++ ) { ${$unitcopy}[$j] =~ s/DEFAULT/$onelanguage/g; }
831
832    # including the unitcopy into the xml file
833    include_component_at_specific_line($xmlfile, $unitcopy, $startline);
834    $startline = $startline + $#{$unitcopy} + 1;
835}
836
837#######################################################
838# Removing empty packages from xml file. The names
839# are stored in @installer::globals::emptypackages
840#######################################################
841
842sub remove_empty_packages_in_xmlfile
843{
844    my ($xmlfile) = @_;
845
846    for ( my $i = 0; $i <= $#installer::globals::emptypackages; $i++ )
847    {
848        my $packagename = $installer::globals::emptypackages[$i];
849        my $infoline = "Try to remove package $packagename from xml file.\n";
850        $installer::logger::Lang->print($infoline);
851        remove_package($xmlfile, $packagename);
852    }
853}
854
855#######################################################
856# Preparing the language packs in the xml file
857#######################################################
858
859sub prepare_language_pack_in_xmlfile
860{
861    my ($xmlfile, $languagesarrayref) = @_;
862
863    # if ( ! $installer::globals::is_unix_multi )
864    # {
865    #   remove_languagepack_from_xmlfile($xmlfile);
866    # }
867    # else
868    # {
869        duplicate_languagepack_in_xmlfile($xmlfile, $languagesarrayref);
870    # }
871
872}
873
874#######################################################
875# Returning a rpm unit from a xml file
876#######################################################
877
878sub get_rpm_unit_from_xmlfile
879{
880    my ($rpmname, $xmlfile) = @_;
881
882    my $infoline = "Searching for $rpmname in xml file.\n";
883    $installer::logger::Lang->print($infoline);
884
885    my @rpmunit = ();
886    my $includeline = 0;
887    my $record = 0;
888    my $foundrpm = 0;
889
890    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
891    {
892        my $oneline = ${$xmlfile}[$i];
893
894        if ( $oneline =~ /^\s*\<rpmunit/ ) { $record = 1; }
895
896        if ( $record ) { push(@rpmunit, $oneline); }
897
898        if ( $oneline =~ /^\s*rpmUniqueName\s*=\s*\"\Q$rpmname\E\"\s*$/ ) { $foundrpm = 1; }
899
900        if (( $record ) && ( $oneline =~ /\/\>\s*$/ )) { $record = 0; }
901
902        if (( ! $foundrpm ) && ( ! $record )) { @rpmunit = (); }
903
904        if (( $foundrpm ) && ( ! $record )) { $includeline = $i + 1; }
905
906        if (( $foundrpm ) && ( ! $record )) { last; }
907    }
908
909    if ( ! $foundrpm ) { installer::exiter::exit_program("ERROR: Did not find rpmunit $rpmname in xml file!", "get_rpm_unit_from_xmlfile"); }
910
911    $infoline = "Found $rpmname in xml file. Returning block lines: $#rpmunit + 1. Includeline: $includeline \n";
912    $installer::logger::Lang->print($infoline);
913
914    return (\@rpmunit, $includeline);
915}
916
917#######################################################
918# Exchanging package names in xml file
919#######################################################
920
921sub exchange_name_in_rpmunit
922{
923    my ($rpmunit, $oldpackagename, $newpackagename) = @_;
924
925    for ( my $i = 0; $i <= $#{$rpmunit}; $i++ )
926    {
927        ${$rpmunit}[$i] =~ s/$oldpackagename/$newpackagename/;
928    }
929}
930
931#######################################################
932# Preparing link RPMs in the xml file
933#######################################################
934
935sub prepare_linkrpm_in_xmlfile
936{
937    my ($xmlfile, $rpmlist) = @_;
938
939    for ( my $i = 0; $i <= $#{$rpmlist}; $i++ )
940    {
941        my $oldpackagename = "";
942        my $newpackagename = "";
943
944        my $rpmline = ${$rpmlist}[$i];
945
946        my $infoline = "Preparing link/patch RPM: $rpmline\n";
947        $installer::logger::Lang->print($infoline);
948
949        if ( $rpmline =~ /^\s*(\S.*?\S)\s+(\S.*?\S)\s*$/ )
950        {
951            $oldpackagename = $1;
952            $newpackagename = $2;
953        }
954
955        my ($rpmunit, $includeline) = get_rpm_unit_from_xmlfile($oldpackagename, $xmlfile);
956        exchange_name_in_rpmunit($rpmunit, $oldpackagename, $newpackagename);
957        include_component_at_specific_line($xmlfile, $rpmunit, $includeline);
958    }
959}
960
961#######################################################################
962# Removing w4w filter module from xml file for Solaris x86 and Linux
963#######################################################################
964
965sub remove_w4w_from_xmlfile
966{
967    my ($xmlfile) = @_;
968
969    # Component begins with "<component selected='true' name='gid_Module_Prg_Wrt_Flt_W4w' componentVersion="8">"
970    # and ends with "</component>"
971
972    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
973    {
974        if ( ${$xmlfile}[$i] =~ /name\s*\=\'\s*gid_Module_Prg_Wrt_Flt_W4w/ )
975        {
976            # Counting the lines till "</component>"
977
978            my $linecounter = 1;
979            my $startline = $i+1;
980            my $line = ${$xmlfile}[$startline];
981
982            while ((!( $line =~ /^\s*\<\/component\>\s*$/ )) && ( $startline <= $#{$xmlfile} ))
983            {
984                $linecounter++;
985                $startline++;
986                $line = ${$xmlfile}[$startline];
987            }
988
989            $linecounter = $linecounter + 2;     # last line and following empty line
990
991            splice(@{$xmlfile},$i, $linecounter);   # removing $linecounter lines, beginning in line $i
992            last;
993        }
994    }
995}
996
997#######################################################################
998# Removing module from xml file, if not defined in scp
999#######################################################################
1000
1001sub remove_scpgid_from_xmlfile
1002{
1003    my ($xmlfile, $scpgid) = @_;
1004
1005    # Component begins with "<component selected='true' name='$scpgid' componentVersion="8">"
1006    # and ends with "</component>"
1007
1008    my $successfully_removed = 0;
1009
1010    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1011    {
1012        if ( ${$xmlfile}[$i] =~ /name\s*\=\'\s*\Q$scpgid\E/ )
1013        {
1014            # Counting the lines till "</component>"
1015
1016            my $linecounter = 1;
1017            my $startline = $i+1;
1018            my $line = ${$xmlfile}[$startline];
1019
1020            while ((!( $line =~ /^\s*\<\/component\>\s*$/ )) && ( $startline <= $#{$xmlfile} ))
1021            {
1022                $linecounter++;
1023                $startline++;
1024                $line = ${$xmlfile}[$startline];
1025            }
1026
1027            $linecounter = $linecounter + 2;     # last line and following empty line
1028
1029            splice(@{$xmlfile},$i, $linecounter);   # removing $linecounter lines, beginning in line $i
1030            $successfully_removed = 1;
1031            last;
1032        }
1033    }
1034
1035    my $infoline = "";
1036    if ($successfully_removed)
1037    {
1038        $infoline = "Module $scpgid successfully removed from xml file.\n";
1039        $installer::logger::Lang->print($infoline);
1040    }
1041    else
1042    {
1043        $infoline = "Module $scpgid not found in xml file (no problem).\n";
1044        $installer::logger::Lang->print($infoline);
1045    }
1046}
1047
1048#######################################################################
1049# Special mechanism for removing modules for xml file, if they are
1050# not defined in scp (introduced for onlineupdate module).
1051#######################################################################
1052
1053sub remove_module_if_not_defined
1054{
1055    my ($xmlfile, $modulesarrayref, $scpgid) = @_;
1056
1057    my $infoline = "Checking existence of $scpgid in scp definition\n";
1058    $installer::logger::Lang->print($infoline);
1059
1060    my $found = 0;
1061
1062    for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
1063    {
1064        my $onemodule = ${$modulesarrayref}[$i];
1065        if ( $onemodule->{'gid'} eq $scpgid ) { $found = 1; }
1066        if ( $found ) { last; }
1067    }
1068
1069    if ( ! $found )
1070    {
1071        $infoline = "Module $scpgid not found -> Removing from xml file.\n";
1072        $installer::logger::Lang->print($infoline);
1073        remove_scpgid_from_xmlfile($xmlfile, $scpgid);
1074    }
1075}
1076
1077###########################################################
1078# Preparing the package subdirectory
1079###########################################################
1080
1081sub create_empty_packages
1082{
1083    my ( $xmlfile ) = @_;
1084
1085    if ( $installer::globals::issolarispkgbuild )
1086    {
1087        my $path = "";
1088
1089        for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1090        {
1091            if ( ${$xmlfile}[$i] =~ /pkgRelativePath\s*\=\s*\'(.*?)\'\s*$/ )
1092            {
1093                $path = $1;
1094                installer::systemactions::create_directory_structure($path);
1095                last;   # only creating one path
1096            }
1097        }
1098
1099        for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1100        {
1101            if ( ${$xmlfile}[$i] =~ /pkgName\s*\=\s*\'(.*?)\'\s*$/ )
1102            {
1103                my $pkgname = $1;
1104                if ( $path ne "" ) { $pkgname = $path . $installer::globals::separator . $pkgname; }
1105                installer::systemactions::create_directory_structure($pkgname);
1106            }
1107        }
1108    }
1109
1110    # "-novalidate" does not work for Linux RPMs
1111
1112    if ( $installer::globals::islinuxrpmbuild )
1113    {
1114        for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1115        {
1116            if ( ${$xmlfile}[$i] =~ /rpmPath\s*\=\s*\"(.*?)\"\s*$/ )
1117            {
1118                my $rpmpath = $1;
1119                my $path = "";
1120
1121                if ( $rpmpath =~ /^\s*(.*)\/(.*?)\s*$/ )
1122                {
1123                    $path = $1;
1124                }
1125
1126                if ( $path ne "" ) { installer::systemactions::create_directory_structure($path); }
1127
1128                my $systemcall = "touch $rpmpath";  # creating empty rpm
1129                system($systemcall);
1130            }
1131        }
1132    }
1133}
1134
1135###########################################################
1136# Reading the archive file name from the xml file
1137###########################################################
1138
1139sub get_archivefilename
1140{
1141    my ( $xmlfile ) = @_;
1142
1143    my $archivefilename = "";
1144
1145    for ( my $j = 0; $j <= $#{$xmlfile}; $j++ )
1146    {
1147        if ( ${$xmlfile}[$j] =~ /archiveFileName\s*=\s*\'(.*?)\'/ )
1148        {
1149            $archivefilename = $1;
1150            last;
1151        }
1152    }
1153
1154    return $archivefilename;
1155}
1156
1157#######################################################
1158# Copying the loader locally
1159#######################################################
1160
1161sub copy_setup_locally
1162{
1163    my ($includepatharrayref, $loadername, $newname) = @_;
1164
1165    my $loadernameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$loadername, $includepatharrayref, 0);
1166
1167    if ($$loadernameref eq "") { installer::exiter::exit_program("ERROR: Could not find Java loader $loadername!", "copy_setup_locally"); }
1168
1169    installer::systemactions::copy_one_file($$loadernameref, $newname);
1170    my $localcall = "chmod 775 $newname \>\/dev\/null 2\>\&1";
1171    system($localcall);
1172}
1173
1174
1175#######################################################
1176# Copying the loader into the installation set
1177#######################################################
1178
1179sub put_loader_into_installset
1180{
1181    my ($installdir, $filename) = @_;
1182
1183    my $installname = $installdir . $installer::globals::separator . $filename;
1184
1185    installer::systemactions::copy_one_file($filename, $installname);
1186
1187    my $localcall = "chmod 775 $installname \>\/dev\/null 2\>\&1";
1188    system($localcall);
1189}
1190
1191#################################################################
1192# Setting for Solaris the package names in the Java translation
1193# file. The name is used for the
1194# This name is displayed tools like prodreg.
1195# Unfortunately this name in the component is also used
1196# in the translation template file for the module name
1197# and module description translations.
1198#################################################################
1199
1200sub replace_component_name_in_java_file
1201{
1202    my ($alljavafiles, $oldname, $newname) = @_;
1203
1204    # The new name must not contain white spaces
1205
1206    $newname =~ s/ /\_/g;
1207
1208    for ( my $i = 0; $i <= $#{$alljavafiles}; $i++ )
1209    {
1210        my $javafilename = ${$alljavafiles}[$i];
1211        my $javafile = installer::files::read_file($javafilename);
1212
1213        my $oldstring = "ComponentDescription-" . $oldname;
1214        my $newstring = "ComponentDescription-" . $newname;
1215
1216        for ( my $j = 0; $j <= $#{$javafile}; $j++ ) { ${$javafile}[$j] =~ s/\b$oldstring\b/$newstring/; }
1217
1218        $oldstring = $oldname . "-install-DisplayName";
1219        $newstring = $newname . "-install-DisplayName";
1220
1221        for ( my $j = 0; $j <= $#{$javafile}; $j++ ) { ${$javafile}[$j] =~ s/\b$oldstring\b/$newstring/; }
1222
1223        $oldstring = $oldname . "-uninstall-DisplayName";
1224        $newstring = $newname . "-uninstall-DisplayName";
1225
1226        for ( my $j = 0; $j <= $#{$javafile}; $j++ ) { ${$javafile}[$j] =~ s/\b$oldstring\b/$newstring/; }
1227
1228        installer::files::save_file($javafilename, $javafile);
1229        $infoline = "Changes in Java file: $javafilename : $oldname \-\> $newname\n";
1230        $installer::logger::Lang->print($infoline);
1231    }
1232}
1233
1234#################################################################
1235# Some module names are not defined in the scp project.
1236# The names for this modules are searched in the base Java
1237# translation file.
1238#################################################################
1239
1240sub get_module_name_from_basejavafile
1241{
1242    my ($componentname, $javatemplateorigfile, $ulffile) = @_;
1243
1244    my $searchname = $componentname . "-install-DisplayName";
1245    my $modulename = "";
1246    my $replacename = "";
1247
1248    # line content: { "coremodule-install-DisplayName", "OOO_INSTALLSDK_117" },
1249
1250    for ( my $i = 0; $i <= $#{$javatemplateorigfile}; $i++ )
1251    {
1252        if ( ${$javatemplateorigfile}[$i] =~ /\"\s*\Q$searchname\E\s*\"\s*\,\s*\"\s*(.*?)\s*\"\s*\}\s*\,\s*$/ )
1253        {
1254            $replacename = $1;
1255            last;
1256        }
1257    }
1258
1259    if ( $replacename ne "" )
1260    {
1261        my $language_block = get_language_block_from_language_file($replacename, $ulffile);
1262        $modulename = get_language_string_from_language_block($language_block, "en-US", $replacename);
1263    }
1264
1265    return $modulename;
1266}
1267
1268#################################################################
1269# Setting for Solaris the package names in the xml file.
1270# This name is displayed tools like prodreg.
1271# Unfortunately this name in the component is also used
1272# in the translation template file for the module name
1273# and module description translations.
1274#################################################################
1275
1276sub replace_component_names
1277{
1278    my ($xmlfile, $templatefilename, $modulesarrayref, $javatemplateorigfile, $ulffile) = @_;
1279
1280    # path in which all java languages files are located
1281
1282    my $javafilesdir = $templatefilename;
1283    installer::pathanalyzer::get_path_from_fullqualifiedname(\$javafilesdir);
1284    my $alljavafiles = installer::systemactions::find_file_with_file_extension("java", $javafilesdir);
1285    for ( my $i = 0; $i <= $#{$alljavafiles}; $i++ ) { ${$alljavafiles}[$i] = $javafilesdir . ${$alljavafiles}[$i]; }
1286
1287    # analyzing the xml file
1288
1289    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1290    {
1291        my $newstring = "";
1292        my $componentname = "";
1293
1294        if ( ${$xmlfile}[$i] =~ /\bcomponent\b.*\bname\s*\=\'\s*(.*?)\s*\'/ )
1295        {
1296            $componentname = $1;
1297
1298            # Getting module name from the scp files in $modulesarrayref
1299
1300            my $onelanguage = "en-US";
1301            my $gid = $componentname;
1302            my $type = "Name";
1303
1304            my $modulename = "";
1305            $modulename = get_module_name_description($modulesarrayref, $onelanguage, $gid, $type);
1306
1307            if ( $modulename eq "" )
1308            {
1309                $infoline = "Info: Modulename for $gid not defined in modules collector. Looking in Java ulf file.\n";
1310                $installer::logger::Lang->print($infoline);
1311            }
1312
1313            if ( $modulename eq "" ) # the modulename can also be set in the Java ulf file
1314            {
1315                $modulename = get_module_name_from_basejavafile($componentname, $javatemplateorigfile, $ulffile);
1316            }
1317
1318            if ( $modulename ne "" )    # only do something, if the modulename was found
1319            {
1320                ${$xmlfile}[$i] =~ s/$componentname/$modulename/;
1321
1322                $infoline = "Replacement in xml file (Solaris): $componentname \-\> $modulename\n";
1323                $installer::logger::Lang->print($infoline);
1324
1325                # Replacement has to be done in all Java language files
1326                replace_component_name_in_java_file($alljavafiles, $componentname, $modulename);
1327            }
1328
1329            if ( $modulename eq "" ) # the modulename can also be set in the Java ulf file
1330            {
1331                $infoline = "WARNING: No replacement in xml file for component: $componentname\n";
1332                $installer::logger::Lang->print($infoline);
1333            }
1334        }
1335    }
1336}
1337
1338#############################################################################
1339# Collecting all packages or rpms located in the installation directory
1340#############################################################################
1341
1342sub get_all_packages_in_installdir
1343{
1344    my ($installdir, $subdir) = @_;
1345
1346    my $infoline = "";
1347
1348    my @allrpms = ();   # not needed for Solaris at the moment
1349    my $allrpms = \@allrpms;
1350
1351    $installdir =~ s/\Q$installer::globals::separator\E\s*$//;
1352    my $directory = $installdir . $installer::globals::separator . $subdir;
1353    $directory =~ s/\Q$installer::globals::separator\E\s*$//;
1354
1355    if ( $installer::globals::islinuxrpmbuild )
1356    {
1357        $allrpms = installer::systemactions::find_file_with_file_extension("rpm", $directory);
1358
1359        # collecting rpms with the complete path
1360
1361        for ( my $i = 0; $i <= $#{$allrpms}; $i++ )
1362        {
1363            ${$allrpms}[$i] = $directory . $installer::globals::separator . ${$allrpms}[$i];
1364            $infoline = "Found RPM: ${$allrpms}[$i]\n";
1365            $installer::logger::Lang->print($infoline);
1366        }
1367    }
1368
1369    return $allrpms;
1370}
1371
1372#######################################################
1373# Adding the values of the array
1374#######################################################
1375
1376sub do_sum
1377{
1378    my ( $allnumbers ) = @_;
1379
1380    my $sum = 0;
1381
1382    for ( my $i = 0; $i <= $#{$allnumbers}; $i++ )
1383    {
1384        $sum = $sum + ${$allnumbers}[$i];
1385    }
1386
1387    return $sum;
1388}
1389
1390#######################################################
1391# Setting the filesize for the RPMs in the xml file
1392#######################################################
1393
1394sub set_filesize_in_xmlfile
1395{
1396    my ($filesize, $rpmname, $xmlfile) = @_;
1397
1398    my $infoline = "";
1399    my $foundrpm = 0;
1400    my $filesizeset = 0;
1401
1402    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1403    {
1404        my $line = ${$xmlfile}[$i];
1405
1406        # searching for "rpmPath="RPMS/${UNIXPRODUCTNAME}-core01-${PACKAGEVERSION}-${PACKAGEREVISION}.i586.rpm""
1407
1408        if (( $line =~ /rpmPath\s*=/ ) && ( $line =~ /\Q$rpmname\E\"\s*$/ ))
1409        {
1410            $foundrpm = 1;
1411
1412            my $number = $i;
1413            $number++;
1414
1415            while ( ! ( ${$xmlfile}[$number] =~ /\/\>\s*$/ ))
1416            {
1417                if ( ${$xmlfile}[$number] =~ /FILESIZEPLACEHOLDER/ )
1418                {
1419                    ${$xmlfile}[$number] =~ s/FILESIZEPLACEHOLDER/$filesize/;
1420                    $filesizeset = 1;
1421                    $infoline = "Setting filesize for $rpmname : $filesize\n";
1422                    $installer::logger::Lang->print($infoline);
1423                    last;
1424                }
1425
1426                $number++;
1427            }
1428
1429            last;
1430        }
1431    }
1432
1433    if ( ! $foundrpm )
1434    {
1435        $infoline = "ERROR: Did not find $rpmname in xml file !\n";
1436        $installer::logger::Lang->print($infoline);
1437    }
1438
1439    if ( ! $filesizeset )
1440    {
1441        $infoline = "ERROR: Did not set filesize for $rpmname in xml file !\n";
1442        $installer::logger::Lang->print($infoline);
1443    }
1444}
1445
1446############################################################
1447# Collecting all rpmUniqueName in xml file.
1448############################################################
1449
1450sub collect_uniquenames_in_xmlfile
1451{
1452    my ($xmlfile) = @_;
1453
1454    my @rpmuniquenames = ();
1455
1456    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1457    {
1458        my $oneline = ${$xmlfile}[$i];
1459
1460        if ( $oneline =~ /^\s*rpmUniqueName\s*\=\s*\"(.*)\"\s*$/ )
1461        {
1462            my $rpmuniquename = $1;
1463            push(@rpmuniquenames, $rpmuniquename)
1464        }
1465    }
1466
1467    return \@rpmuniquenames;
1468}
1469
1470############################################################
1471# Searching for the corresponding rpm, that fits to
1472# the unique rpm name.
1473# Simple mechanism: The name of the rpm starts with the
1474# unique rpm name followed by a "-".
1475############################################################
1476
1477sub find_rpmname_to_uniquename
1478{
1479    my ($uniquename, $listofpackages) = @_;
1480
1481    my @all_correct_rpms = ();
1482    my $infoline = "";
1483
1484    # special handling for java RPMs, which have a very strange naming schema
1485    my $localuniquename = $uniquename;
1486    if ( $uniquename =~ /^\s*jre\-/ ) { $localuniquename = "jre"; }
1487
1488    for ( my $i = 0; $i <= $#{$listofpackages}; $i++ )
1489    {
1490        my $completerpmname = ${$listofpackages}[$i];
1491        my $rpmname = $completerpmname;
1492        installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$rpmname);
1493
1494        if ( $rpmname =~ /^\s*\Q$localuniquename\E\-\d/ ) { push(@all_correct_rpms, $rpmname); }
1495    }
1496
1497    # @all_correct_rpms has to contain exactly one value
1498
1499    if ( $#all_correct_rpms > 0 )
1500    {
1501        my $number = $#all_correct_rpms + 1;
1502        $infoline = "There are $number RPMs for the unique name \"$uniquename\" :\n";
1503        $installer::logger::Lang->print($infoline);
1504        my $allrpmstring = "";
1505        for ( my $i = 0; $i <= $#all_correct_rpms; $i++ ) { $allrpmstring = $allrpmstring . $all_correct_rpms[$i] . "\n"; }
1506        $installer::logger::Lang->print($allrpmstring);
1507        installer::exiter::exit_program("ERROR: Found $number RPMs that start with unique name \"$uniquename\". Only one allowed!", "find_rpmname_to_uniquename");
1508    }
1509
1510    if ( $#all_correct_rpms < 0 )
1511    {
1512        $infoline = "There is no rpm for the unique name \"$uniquename\"\n";
1513        $installer::logger::Lang->print($infoline);
1514        installer::exiter::exit_program("ERROR: There is no RPM that start with unique name \"$uniquename\"!", "find_rpmname_to_uniquename");
1515    }
1516
1517    if ( $#all_correct_rpms == 0 )
1518    {
1519        $infoline = "Found one rpm for the unique name \"$uniquename\" : $all_correct_rpms[0]\n";
1520        $installer::logger::Lang->print($infoline);
1521    }
1522
1523    return $all_correct_rpms[0];
1524}
1525
1526#######################################################
1527# Including the complete RPM name into the xml file
1528#######################################################
1529
1530sub set_rpmname_into_xmlfile
1531{
1532    my ($rpmname, $uniquename, $xmlfile) = @_;
1533
1534    my $foundrpm = 0;
1535    my $rpmnameset = 0;
1536
1537    for ( my $i = 0; $i <= $#{$xmlfile}; $i++ )
1538    {
1539        my $oneline = ${$xmlfile}[$i];
1540
1541        if ( $oneline =~ /^\s*rpmUniqueName\s*\=\s*\"\Q$uniquename\E\"\s*$/ )
1542        {
1543            $foundrpm = 1;
1544
1545            my $number = $i;
1546            $number++;
1547
1548            while ( ! ( ${$xmlfile}[$number] =~ /\/\>\s*$/ ))
1549            {
1550                if ( ${$xmlfile}[$number] =~ /RPMFILENAMEPLACEHOLDER/ )
1551                {
1552                    ${$xmlfile}[$number] =~ s/RPMFILENAMEPLACEHOLDER/$rpmname/;
1553                    $rpmnameset = 1;
1554                    $infoline = "Setting RPM name for $uniquename : $rpmname\n";
1555                    $installer::logger::Lang->print($infoline);
1556                    last;
1557                }
1558
1559                $number++;
1560            }
1561
1562            last;
1563        }
1564    }
1565
1566    if ( ! $foundrpm )
1567    {
1568        $infoline = "ERROR: Did not find $rpmname in xml file !\n";
1569        $installer::logger::Lang->print($infoline);
1570    }
1571
1572    if ( ! $rpmnameset )
1573    {
1574        $infoline = "ERROR: Did not set rpm name for $uniquename in xml file !\n";
1575        $installer::logger::Lang->print($infoline);
1576    }
1577
1578}
1579
1580############################################################
1581# Including the rpm path dynamically into the xml file.
1582# This is introduced, because system integration has
1583# variable PackageVersion and PackageRevision in xml file.
1584############################################################
1585
1586sub put_rpmpath_into_xmlfile
1587{
1588    my ($xmlfile, $listofpackages) = @_;
1589
1590    my $infoline = "";
1591
1592    my $alluniquenames = collect_uniquenames_in_xmlfile($xmlfile);
1593
1594    my $number = $#{$listofpackages} + 1;
1595    $infoline = "Number of packages in installation set: $number\n";
1596    $installer::logger::Lang->print($infoline);
1597    $number = $#{$alluniquenames} + 1;
1598    $infoline = "Number of unique RPM names in xml file: $number\n";
1599    $installer::logger::Lang->print($infoline);
1600
1601    $installer::logger::Lang->print("Packages in installation set:\n");
1602    for ( my $i = 0; $i <= $#{$listofpackages}; $i++ )
1603    {
1604        $installer::logger::Lang->print(${$listofpackages}[$i] . "\n");
1605    }
1606
1607    $installer::logger::Lang->print("\n");
1608    $installer::logger::Lang->print("Unique RPM names in xml file:\n");
1609    for ( my $i = 0; $i <= $#{$alluniquenames}; $i++ )
1610    {
1611        $infoline = "${$alluniquenames}[$i]\n";
1612        $installer::logger::Lang->print($infoline);
1613    }
1614
1615    if ( $#{$alluniquenames} != $#{$listofpackages} ) { installer::exiter::exit_program("ERROR: xml file contains $#{$alluniquenames} unique names, but there are $#{$listofpackages} packages in installation set!", "put_rpmpath_into_xmlfile"); }
1616
1617    for ( my $i = 0; $i <= $#{$alluniquenames}; $i++ )
1618    {
1619        my $uniquename = ${$alluniquenames}[$i];
1620        my $rpmname = find_rpmname_to_uniquename($uniquename, $listofpackages);
1621        set_rpmname_into_xmlfile($rpmname, $uniquename, $xmlfile);
1622    }
1623}
1624
1625#######################################################
1626# Including the file size of the rpms into the
1627# xml file
1628#######################################################
1629
1630sub put_filesize_into_xmlfile
1631{
1632    my ($xmlfile, $listofpackages) = @_;
1633
1634    my $infoline = "";
1635
1636    for ( my $i = 0; $i <= $#{$listofpackages}; $i++ )
1637    {
1638        my $completerpmname = ${$listofpackages}[$i];
1639        my $rpmname = $completerpmname;
1640        installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$rpmname);
1641
1642        if ( ! $installer::globals::rpmquerycommand ) { installer::exiter::exit_program("ERROR: rpm not found for querying packages!", "put_filesize_into_xmlfile"); }
1643        my $systemcall = "$installer::globals::rpmquerycommand -qp --queryformat \"\[\%\{FILESIZES\}\\n\]\" $completerpmname 2\>\&1 |";
1644        my $rpmout = make_systemcall($systemcall, 0);
1645        my $filesize = do_sum($rpmout);
1646
1647        $infoline = "Filesize $rpmname : $filesize\n";
1648        $installer::logger::Lang->print($infoline);
1649
1650        set_filesize_in_xmlfile($filesize, $rpmname, $xmlfile);
1651    }
1652}
1653
1654#######################################################
1655# Creating the java installer class file dynamically
1656#######################################################
1657
1658sub create_java_installer
1659{
1660    my ( $installdir, $newdir, $languagestringref, $languagesarrayref, $allvariableshashref, $includepatharrayref, $modulesarrayref ) = @_;
1661
1662    installer::logger::include_header_into_logfile("Creating Java installer:");
1663
1664    my $infoline = "";
1665
1666    # collecting all packages or rpms located in the installation directory
1667    my $listofpackages = get_all_packages_in_installdir($installdir, $newdir);
1668
1669    # creating the directory
1670    my $javadir = installer::systemactions::create_directories("javainstaller", $languagestringref);
1671    $javadir =~ s/\/\s*$//;
1672#   push(@installer::globals::removedirs, $javadir);
1673
1674    # copying the content from directory install_sdk into the java directory
1675
1676    my $projectroot = "";
1677    if ( $ENV{'PRJ'} ) { $projectroot = $ENV{'PRJ'}; }
1678    else { installer::exiter::exit_program("ERROR: Environment variable PRJ not set", "create_java_installer"); }
1679
1680    $projectroot =~ s/\/\s*$//;
1681    my $sourcedir = "$projectroot/inc_global/unix/install_sdk";
1682    installer::systemactions::copy_complete_directory_without_cvs($sourcedir, $javadir);
1683
1684    # determining the java template file
1685
1686    my $templatefilename = $javadir . $installer::globals::separator . "locale/resources/MyResources_template.java";
1687
1688    # Saving the content of the template file. It is used in the xml files
1689
1690    my $javatemplateorigfile = installer::files::read_file($templatefilename);
1691
1692    # determining the ulf language file
1693
1694    # my $ulffilename = "installsdk.ulf";
1695    my $ulffilename = "installsdk.jlf";
1696    $ulffilename = $installer::globals::javalanguagepath . $installer::globals::separator . $ulffilename;
1697    my $ulffile = installer::files::read_file($ulffilename);
1698
1699    $installer::logger::Lang->print("\n");
1700    $installer::logger::Lang->print("Reading ulf file: $ulffilename\n");
1701
1702    $infoline = "Translating the Java template file\n";
1703    $installer::logger::Lang->print($infoline);
1704
1705    for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1706    {
1707        my $onelanguage = ${$languagesarrayref}[$i];
1708
1709        # replacing all strings in the Java file with content of ulf files
1710
1711        my $templatefile = installer::files::read_file($templatefilename);
1712
1713        set_component_name_and_description($templatefile, $modulesarrayref, $onelanguage);
1714        translate_javafile($templatefile, $ulffile, $onelanguage);
1715
1716        # adding the license file into the Java file
1717
1718        my $licensefilesource = get_licensefilesource($onelanguage, $includepatharrayref);
1719        my $licensefile = installer::files::read_file($licensefilesource);
1720        add_license_file_into_javafile($templatefile, $licensefile, $includepatharrayref, $javadir, $onelanguage);
1721
1722        # setting productname and productversion
1723
1724        set_productname_and_productversion($templatefile, $allvariableshashref);
1725
1726        # setting the class name in the java file ( "MyResources_TEMPLATE" -> "MyResources_en" )
1727
1728        # if ( $onelanguage =~ /^\s*(\w+)\-(\w+)\s*$/ ) { $onelanguage = $1; }
1729        $onelanguage =~ s/en-US/en/;    # java file name and class name contain only "_en"
1730        $onelanguage =~ s/\-/\_/;       # "pt-BR" -> "pt_BR"
1731        my $classfilename = "MyResources_" . $onelanguage;
1732        set_classfilename($templatefile, $classfilename, "MyResources_TEMPLATE");
1733
1734        # saving the new file
1735
1736        my $newfilename = $templatefilename;
1737        $newfilename =~ s/_template\.java\s*$/_$onelanguage\.java/;
1738
1739        installer::files::save_file($newfilename, $templatefile);
1740
1741        $infoline = "Saving Java file: $newfilename\n";
1742        $installer::logger::Lang->print($infoline);
1743    }
1744
1745    # renaming one language java file to "MyResources.java"
1746
1747    my $baselanguage = installer::languages::get_default_language($languagesarrayref);
1748    $baselanguage =~ s/\-/\_/;      # "pt-BR" -> "pt_BR"
1749    $baselanguage =~ s/en_US/en/;   # java file name and class name contain only "_en"
1750    # if ( $baselanguage =~ /^\s*(\w+)\-(\w+)\s*$/ ) { $baselanguage = $1; }     # java file name and class name contain only "_en"
1751    # $baselanguage =~ s/en-US/en/;  # java file name and class name contain only "_en"
1752    my $baselanguagefilename = $javadir . $installer::globals::separator . "locale/resources/MyResources_" . $baselanguage . "\.java";
1753    my $basedestfilename = $javadir . $installer::globals::separator . "locale/resources/MyResources.java";
1754    installer::systemactions::copy_one_file($baselanguagefilename, $basedestfilename);
1755
1756    # setting the class file name also for the base class
1757
1758    my $basetemplatefile = installer::files::read_file($basedestfilename);
1759    my $oldclassfilename = $baselanguagefilename;
1760    installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$oldclassfilename);
1761    $oldclassfilename =~ s/\.java//;
1762    my $newclassfilename = $basedestfilename;
1763    installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newclassfilename);
1764    $newclassfilename =~ s/\.java//;
1765
1766    set_classfilename($basetemplatefile, $newclassfilename, $oldclassfilename);
1767
1768    installer::files::save_file($basedestfilename, $basetemplatefile);
1769
1770    $infoline = "Created base Java file: $basedestfilename\n";
1771    $installer::logger::Lang->print($infoline);
1772
1773    # deleting the template file
1774
1775    unlink($templatefilename);
1776
1777    $infoline = "Deleted template Java resource file: $templatefilename\n";
1778    $installer::logger::Lang->print($infoline);
1779
1780    # changing into Java directory
1781
1782    my $from = cwd();
1783
1784    chdir($javadir);
1785
1786    $infoline = "Changing into directory: $javadir\n";
1787    $installer::logger::Lang->print($infoline);
1788
1789    # preparing the xml file
1790
1791    my $xmlfilename = "";
1792    my $subdir = "";
1793
1794    if ( $installer::globals::issolarispkgbuild )
1795    {
1796        $xmlfilename = "pkgUnit.xml";
1797    }
1798    elsif ( $installer::globals::islinuxrpmbuild )
1799    {
1800        $xmlfilename = "rpmUnit.xml";
1801    }
1802    else
1803    {
1804        installer::exiter::exit_program("ERROR: No platform for Install SDK", "create_java_installer");
1805    }
1806
1807    # reading, editing and saving the xmlfile
1808
1809    my $xmlfile = installer::files::read_file($xmlfilename);
1810    prepare_language_pack_in_xmlfile($xmlfile, $languagesarrayref);
1811    my $xmlfilename2 = $xmlfilename . ".test2";
1812    installer::files::save_file($xmlfilename2, $xmlfile);
1813    remove_empty_packages_in_xmlfile($xmlfile);
1814    my $xmlfilename3 = $xmlfilename . ".test3";
1815    installer::files::save_file($xmlfilename3, $xmlfile);
1816    substitute_variables($xmlfile, $allvariableshashref);
1817    if (( $installer::globals::islinuxrpmbuild ) && ( $#installer::globals::linkrpms > -1 )) { prepare_linkrpm_in_xmlfile($xmlfile,\@installer::globals::linkrpms); }
1818    if ( $installer::globals::issolarisx86build || $installer::globals::islinuxbuild ) { remove_w4w_from_xmlfile($xmlfile); }
1819    remove_module_if_not_defined($xmlfile, $modulesarrayref, "gid_Module_Optional_Onlineupdate");
1820    replace_component_names($xmlfile, $templatefilename, $modulesarrayref, $javatemplateorigfile, $ulffile);
1821    my $xmlfilename4 = $xmlfilename . ".test4";
1822    installer::files::save_file($xmlfilename4, $xmlfile);
1823    if ( $installer::globals::islinuxrpmbuild ) { put_rpmpath_into_xmlfile($xmlfile, $listofpackages); }
1824    if ( $installer::globals::islinuxrpmbuild ) { put_filesize_into_xmlfile($xmlfile, $listofpackages); }
1825    installer::files::save_file($xmlfilename, $xmlfile);
1826    $infoline = "Saving xml file: $xmlfilename\n";
1827    $installer::logger::Lang->print($infoline);
1828
1829    # Setting the classpath and starting compiler
1830
1831    set_classpath_for_install_sdk($javadir);
1832
1833    # creating class files:
1834    # language class file, dialog class files, installer class file
1835
1836    my $jdkpath = "";
1837    if ( $ENV{'JDKPATH'} ) { $jdkpath = $ENV{'JDKPATH'}; }
1838
1839    my $javac = "javac";
1840    if ( $jdkpath ) { $javac = $jdkpath . $installer::globals::separator . $javac; }
1841
1842    my $systemcall = "$javac locale\/resources\/\*\.java 2\>\&1 |";
1843    make_systemcall($systemcall, 1);
1844
1845    $systemcall = "$javac com\/sun\/staroffice\/install\/\*\.java 2\>\&1 |";
1846    make_systemcall($systemcall, 1);
1847
1848    # making subdirectory creating empty packages
1849    create_empty_packages($xmlfile);
1850
1851    # Copy "jresetup" from solver locally to include it into the classfile
1852    # Copy "jresetup" from solver to installdir
1853
1854    my $setupname = "jresetup";
1855    my $newname = "setup";
1856    copy_setup_locally($includepatharrayref, $setupname, $newname);
1857
1858    my $java = "java";
1859    if ( $jdkpath ) { $java = $jdkpath . $installer::globals::separator . $java; }
1860
1861    $systemcall = "$java com.sun.setup.builder.InstallBuilder $xmlfilename -novalidate 2\>\&1 |";
1862    make_systemcall($systemcall, 1);
1863
1864    # copying the newly created classfile into the installation set
1865
1866    my $archivefilename = get_archivefilename($xmlfile);
1867    $archivefilename = $archivefilename . ".class";
1868
1869    if ( ! -f $archivefilename ) { installer::exiter::exit_program("ERROR: Could not find Java class file $archivefilename!", "create_java_installer"); }
1870
1871    installer::systemactions::copy_one_file($archivefilename, $installdir);
1872
1873    # Adding the loader into the installation set. The name of the loader is setup.
1874    put_loader_into_installset($installdir, $newname);
1875
1876    chdir($from);
1877
1878    $infoline = "Changing into directory: $from\n";
1879    $installer::logger::Lang->print($infoline);
1880}
1881
18821;
1883