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