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