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