merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / installer / servicesfile.pm
blob393802ce8d8ab6fb9772352b6cbed23c3d5e45b9
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: servicesfile.pm,v $
11 # $Revision: 1.33 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::servicesfile;
34 use Cwd;
35 use installer::converter;
36 use installer::existence;
37 use installer::exiter;
38 use installer::globals;
39 use installer::logger;
40 use installer::pathanalyzer;
41 use installer::remover;
42 use installer::scriptitems;
43 use installer::systemactions;
45 ################################################################
46 # Adding the newly created file into the files collector
47 ################################################################
49 sub add_services_sourcepath_into_filearray
51 my ( $filesarrayref, $servicesfile, $servicesname ) = @_;
53 my $found = 0;
54 my $onefile;
56 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
58 $onefile = ${$filesarrayref}[$i];
59 my $name = $onefile->{'Name'};
61 if ( $servicesname eq $name )
63 $found = 1;
64 $onefile->{'sourcepath'} = $servicesfile; # setting the sourcepath!
65 last;
69 if ( ! $found ) { installer::exiter::exit_program("ERROR: Did not find $servicesname in files collector!", "add_services_sourcepath_into_filearray"); }
73 ################################################################
74 # Generating a file url from a path
75 ################################################################
77 sub make_file_url
79 my ( $path ) = @_;
81 my $fileurl = "";
83 # removing ending slash/backslash
85 installer::remover::remove_ending_pathseparator(\$path);
87 if ($installer::globals::iswin)
89 $path =~ s/\\/\//g;
90 $fileurl = "file\:\/\/\/" . $path;
92 else
94 $fileurl = "file\:\/\/" . $path;
97 return $fileurl;
100 ################################################################
101 # Determining all sourcepath from the uno components
102 ################################################################
104 sub get_all_sourcepathes
106 my ( $filesref ) = @_;
108 my @pathes = ();
110 for ( my $i = 0; $i <= $#{$filesref}; $i++ )
112 my $onefile = ${$filesref}[$i];
113 my $path = $onefile->{'sourcepath'};
115 installer::pathanalyzer::get_path_from_fullqualifiedname(\$path);
117 if (! installer::existence::exists_in_array($path, \@pathes))
119 push(@pathes, $path);
123 return \@pathes;
126 ################################################################
127 # Registering all uno component files in the services.rdb
128 ################################################################
130 sub register_unocomponents
132 my ($allvariableshashref, $unocomponents, $regcompfileref, $servicesfile, $nativeservicesurlprefix) = @_;
134 installer::logger::include_header_into_logfile("Registering UNO components:");
136 my $error_occured = 0;
137 my $filestring = "";
138 for ( my $i = 0; $i <= $#{$unocomponents}; ++$i )
140 my $sourcepath = make_file_url(${$unocomponents}[$i]->{'sourcepath'});
141 my $urlprefix = ${$unocomponents}[$i]->{'NativeServicesURLPrefix'};
142 if (defined($urlprefix))
144 call_regcomp(
145 $regcompfileref, $servicesfile, $sourcepath, $urlprefix);
147 else
149 $filestring .= ";" unless $filestring eq "";
150 $filestring .= $sourcepath;
152 if (length($filestring) > $installer::globals::unomaxservices ||
153 ($i == $#{$unocomponents} && $filestring ne ""))
155 call_regcomp(
156 $regcompfileref, $servicesfile, $filestring,
157 $nativeservicesurlprefix);
158 $filestring = "";
162 return $error_occured;
165 sub call_regcomp
167 my ($regcompfileref, $servicesfile, $filestring, $urlprefix) = @_;
168 my @regcompoutput = ();
170 my $systemcall = "$installer::globals::wrapcmd $$regcompfileref -register -r ".fix_cygwin_path($servicesfile)." -c " . $installer::globals::quote . $filestring . $installer::globals::quote . " -wop=" . $installer::globals::quote . $urlprefix . $installer::globals::quote . " 2\>\&1 |";
172 open (REG, "$systemcall");
173 while (<REG>) {push(@regcompoutput, $_); }
174 close (REG);
176 my $returnvalue = $?; # $? contains the return value of the systemcall
178 my $infoline = "Systemcall: $systemcall\n";
179 push( @installer::globals::logfileinfo, $infoline);
181 for ( my $j = 0; $j <= $#regcompoutput; $j++ ) { push( @installer::globals::logfileinfo, "$regcompoutput[$j]"); }
183 if ($returnvalue)
185 $infoline = "ERROR: $systemcall\n";
186 push( @installer::globals::logfileinfo, $infoline);
187 $error_occured = 1;
189 else
191 $infoline = "SUCCESS: $systemcall\n";
192 push( @installer::globals::logfileinfo, $infoline);
196 ################################################################
197 # Registering all java component files in the services.rdb
198 ################################################################
200 sub register_javacomponents
202 my ($allvariableshashref, $javacomponents, $regcompfileref, $servicesfile, $regcomprdb, $javaservicesurlprefix) = @_;
204 installer::logger::include_header_into_logfile("Registering Java components:");
206 my $ridljar_ref = "ridl.jar";
207 my $ure_internal_java_dir_ref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$ridljar_ref, "", 1);
208 installer::pathanalyzer::get_path_from_fullqualifiedname($ure_internal_java_dir_ref);
209 if ( $$ure_internal_java_dir_ref eq "" ) { installer::exiter::exit_program("Could not determine URE_INTERNAL_JAVA_DIR when registering Java components!", "register_javacomponents"); }
211 my $error_occured = 0;
213 my $do_register = 1;
214 if (!( $installer::globals::solarjava )) { $do_register = 0; }
216 if ( $do_register )
218 my $filestring = "";
220 for ( my $i = 0; $i <= $#{$javacomponents}; )
222 my $sourcepath = ${$javacomponents}[$i++]->{'sourcepath'};
224 $filestring = $filestring . make_file_url($sourcepath);
226 if ( $i % $installer::globals::javamaxservices == 0 || $i > $#{$javacomponents} ) # limiting to $installer::globals::maxservices files
228 my @regcompoutput = ();
230 my $systemcall = "$installer::globals::wrapcmd $$regcompfileref -register -br ".fix_cygwin_path($regcomprdb)." -r ".fix_cygwin_path($servicesfile)." -c " . $installer::globals::quote . $filestring . $installer::globals::quote . " -l com.sun.star.loader.Java2 -wop=" . $installer::globals::quote . $javaservicesurlprefix . $installer::globals::quote ." -env:URE_INTERNAL_JAVA_DIR=" . $installer::globals::quote . make_file_url($$ure_internal_java_dir_ref) . $installer::globals::quote . " 2\>\&1 |";
232 open (REG, "$systemcall");
233 while (<REG>) {push(@regcompoutput, $_); }
234 close (REG);
236 my $returnvalue = $?; # $? contains the return value of the systemcall
238 my $infoline = "Systemcall: $systemcall\n";
239 push( @installer::globals::logfileinfo, $infoline);
241 for ( my $k = 0; $k <= $#regcompoutput; $k++ ) { push( @installer::globals::logfileinfo, "$regcompoutput[$k]"); }
243 if ($returnvalue)
245 $infoline = "ERROR: $systemcall\n";
246 $error_occured = 1;
248 else
250 $infoline = "SUCCESS: $systemcall\n";
253 push( @installer::globals::logfileinfo, $infoline);
255 $filestring = "";
257 else
259 $filestring = $filestring . ";";
264 return $error_occured;
269 ################################################################
270 # Helper routine to change cygwin (POSIX) path to DOS notation
271 # if needed
272 ################################################################
273 sub fix_cygwin_path
275 my ( $path ) = @_;
277 if ( $installer::globals::iswin eq 1 && $installer::globals::wrapcmd eq "" )
279 $path = qx{cygpath -m "$path"};
280 chomp($path);
283 return $path;
288 ################################################################
289 # Registering all uno component files in the services.rdb
290 ################################################################
291 sub get_source_path_cygwin_safe
293 my ( $name, $array, $int ) = @_;
295 my $ret = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$name, $array, $int);
296 if ( $installer::globals::iswin eq 1 )
298 if( substr( $$ret, 1,1 ) eq ":" )
300 chomp($$ret = qx{cygpath -u "$$ret"});
303 return $ret;
306 sub register_pythoncomponents
308 my ($pythoncomponents, $regcompfileref, $servicesfile,$includepatharrayref) = @_;
310 installer::logger::include_header_into_logfile("Registering python UNO components:");
312 my $error_occured = 0;
313 my $counter = 0;
315 my $systemcall = "";
317 my $allsourcepathes = get_all_sourcepathes($pythoncomponents);
319 for ( my $j = 0; $j <= $#{$allsourcepathes}; $j++ )
321 my $filestring = "";
322 my $onesourcepath = ${$allsourcepathes}[$j];
323 my $to = "";
324 my $from = cwd();
325 if ( $installer::globals::iswin ) { $from =~ s/\//\\/g; }
327 my $typesrdbname = "types.rdb";
329 # FIXME: Remove the unneeded
330 # get_source_path_cygwin_safe() -> fix_cygwin_path()
331 # when WRAPCMD is gone
332 my $typesrdbref = get_source_path_cygwin_safe($typesrdbname, $includepatharrayref, 1);
334 if ( $$typesrdbref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $typesrdbname !", "register_pythoncomponents"); }
336 my $pyunoservicesrdbname = "pyuno_services.rdb";
337 my $pyunoservicesrdbref = get_source_path_cygwin_safe($pyunoservicesrdbname, $includepatharrayref, 1);
339 if ( $$pyunoservicesrdbref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $pyunoservicesrname !", "register_pythoncomponents"); }
341 for ( my $i = 0; $i <= $#{$pythoncomponents}; $i++ )
343 my $doinclude = 1;
344 my $sourcepath = ${$pythoncomponents}[$i]->{'sourcepath'};
346 $to = $sourcepath;
347 installer::pathanalyzer::get_path_from_fullqualifiedname(\$to);
349 if (!($to eq $onesourcepath)) { $doinclude = 0; }
351 if ( $doinclude )
353 my $filename = ${$pythoncomponents}[$i]->{'Name'};
354 $filestring = $filestring . $filename . "\;";
355 $counter++;
358 if ( $counter > 0 )
360 $filestring =~ s/\;\s*$//;
361 $filestring = substr( $filestring, 0, length($filestring)-3);
362 chdir($onesourcepath);
364 my @regcompoutput = ();
366 $systemcall = "$installer::globals::wrapcmd $$regcompfileref -register"
367 . " -br " . fix_cygwin_path($$typesrdbref)
368 . " -br " . fix_cygwin_path($$pyunoservicesrdbref)
369 . " -r " . fix_cygwin_path($servicesfile)
370 . " -c vnd.openoffice.pymodule:" . $filestring . " -l com.sun.star.loader.Python 2\>\&1 |";
372 open (REG, "$systemcall");
373 while (<REG>) {push(@regcompoutput, $_); }
374 close (REG);
376 my $returnvalue = $?; # $? contains the return value of the systemcall
378 my $infoline = "Systemcall: $systemcall\n";
379 push( @installer::globals::logfileinfo, $infoline);
381 for ( my $j = 0; $j <= $#regcompoutput; $j++ ) { push( @installer::globals::logfileinfo, "$regcompoutput[$j]"); }
383 if ($returnvalue)
385 $infoline = "ERROR: $systemcall\n";
386 push( @installer::globals::logfileinfo, $infoline);
387 $error_occured = 1;
389 else
391 $infoline = "SUCCESS: $systemcall\n";
392 push( @installer::globals::logfileinfo, $infoline);
395 chdir($from);
397 $counter = 0;
398 $filestring = "";
403 return $error_occured;
406 ################################################################
407 # Iterating over all files, to find all files with the
408 # style UNO_COMPONENT. This can be libraries and jar files.
409 ################################################################
411 sub register_all_components
413 my ( $allvariableshashref, $servicesgid, $filesarrayref, $regcompfileref, $servicesfile, $regcomprdb, $includepatharrayref, $nativeservicesurlprefix, $javaservicesurlprefix ) = @_;
415 my $registererrorflag = 0;
417 my @unocomponents = ();
418 my @javacomponents = ();
419 my @pythoncomponents = ();
421 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
423 my $onefile = ${$filesarrayref}[$i];
424 my $styles = "";
425 my $regmergefile = "";
426 my $registryid = "";
428 if ( $onefile->{'RegistryID'} ) { $registryid = $onefile->{'RegistryID'}; }
430 if ( $servicesgid ne $registryid ) { next; } # only registration for the current $servicesgid
432 if ( $onefile->{'Regmergefile'} ) { $regmergefile = $onefile->{'Regmergefile'}; }
434 if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
436 if (( $styles =~ /\bUNO_COMPONENT\b/ ) && ( $regmergefile eq "" )) # regmergefiles will not be registered with regcomp
438 my $filename = $onefile->{'Name'};
440 if ( $filename =~ /\.jar\s*$/ ) # java component
442 push(@javacomponents, $onefile);
444 elsif( $filename =~ /\.py\s*$/ ) # python_component
446 push(@pythoncomponents, $onefile);
448 else # uno component
450 push(@unocomponents, $onefile);
455 $uno_error_occured = 0;
456 $java_error_occured = 0;
457 $python_error_occured = 0;
459 if ( $#unocomponents > -1 ) { $uno_error_occured = register_unocomponents($allvariableshashref, \@unocomponents, $regcompfileref, $servicesfile, $nativeservicesurlprefix); }
460 if ( $#javacomponents > -1 ) { $java_error_occured = register_javacomponents($allvariableshashref, \@javacomponents, $regcompfileref, $servicesfile, $regcomprdb, $javaservicesurlprefix); }
461 if ( $#pythoncomponents > -1 ) { $python_error_occured = register_pythoncomponents(\@pythoncomponents, $regcompfileref, $servicesfile, $includepatharrayref); }
463 if ( $uno_error_occured || $java_error_occured || $python_error_occured ) { $registererrorflag = 1; }
465 return $registererrorflag;
468 ###################################################
469 # Include the solver lib directory into
470 # the LD_LIBRARY_PATH for Unix platforms
471 ###################################################
473 sub include_libdir_into_ld_library_path
475 my ( $var, $binfile ) = @_;
477 my $ld_library_path = $binfile;
478 installer::pathanalyzer::get_path_from_fullqualifiedname(\$ld_library_path);
479 $ld_library_path =~ s/\/\s*$//; # removing ending slashes
480 $ld_library_path =~ s/\/bin\./\/lib\./;
481 $ld_library_path =~ s/\/bin\s*$/\/lib/; # when packing from flat
483 my $oldldlibrarypathstring = $ENV{$var};
484 my $new_ld_library_path = $ld_library_path;
485 if ( defined $oldldlibrarypathstring ) {
486 $new_ld_library_path = $new_ld_library_path . $installer::globals::pathseparator . $oldldlibrarypathstring;
488 if ( $ENV{'SYSTEM_MOZILLA'} && $ENV{'SYSTEM_MOZILLA'} eq "YES" &&
489 (!$ENV{'WITH_OPENLDAP'} || $ENV{'WITH_OPENLDAP'} ne "YES")) {
490 $new_ld_library_path = $new_ld_library_path . $installer::globals::pathseparator . $ENV{'MOZ_LIB'};
492 $ENV{$var} = $new_ld_library_path;
494 my $infoline = "Setting $var to $ENV{$var}\n";
495 push( @installer::globals::logfileinfo, $infoline);
498 ##################################################################
499 # Setting the needed jar files into the CLASSPATH
500 # They are needed from regcomp.
501 # The jar files are defined in @installer::globals::regcompjars
502 ##################################################################
504 sub prepare_classpath_for_java_registration
506 my ( $includepatharrayref ) = @_;
507 my $local_pathseparator = $installer::globals::pathseparator;
509 if( $^O =~ /cygwin/i )
510 { # $CLASSPATH must use DOS separator even when using cygwin's perl
511 $local_pathseparator = ';';
514 for ( my $i = 0; $i <= $#installer::globals::regcompjars; $i++ )
516 my $filename = $installer::globals::regcompjars[$i];
518 my $jarfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 1);
520 if ( $$jarfileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $filename for registering java components!", "prepare_classpath_for_java_registration"); }
522 my $oldclasspathstring = "";
523 if ( $ENV{'CLASSPATH'} ) { $oldclasspathstring = $ENV{'CLASSPATH'}; }
524 else { $oldclasspathstring = "\."; }
525 my $classpathstring = $$jarfileref . $local_pathseparator . $oldclasspathstring;
526 if ( $^O =~ /cygwin/i ) {
527 $classpathstring =~ s/\//\\/g; # guw.pl likes '\' in $PATH.
529 $ENV{'CLASSPATH'} = $classpathstring;
531 my $infoline = "Setting CLASSPATH to $ENV{'CLASSPATH'}\n";
532 push( @installer::globals::logfileinfo, $infoline);
536 ##################################################################
537 # Setting the jdk lib into the LD_LIBRARY_PATH (Unix)
538 # This is used by regcomp to register Java components.
539 # The jdk lib is defined in $installer::globals::jdklib
540 ##################################################################
542 sub add_jdklib_into_ld_library_path
544 my ($var) = @_;
545 if (defined $installer::globals::jdklib) {
546 my $oldldlibrarypathstring = $ENV{$var};
547 my $new_ld_library_path = $installer::globals::jdklib;
548 if (defined $oldldlibrarypathstring) {
549 $new_ld_library_path .=
550 $installer::globals::pathseparator . $oldldlibrarypathstring;
552 $ENV{$var} = $new_ld_library_path;
553 my $infoline = "Setting $var to $ENV{$var}\n";
554 push( @installer::globals::logfileinfo, $infoline);
558 ##################################################################
559 # Adding the libraries included in zip files into path variable
560 # (for example mozruntime.zip). This is needed to register all
561 # libraries successfully.
562 ##################################################################
564 sub add_path_to_pathvariable_directory
566 my ( $filesarrayref, $searchstring ) = @_;
568 # determining the path
570 my $path = "";
572 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
574 my $onefile = ${$filesarrayref}[$i];
575 my $sourcepath = $onefile->{'sourcepath'};
577 installer::pathanalyzer::get_path_from_fullqualifiedname(\$sourcepath);
578 installer::remover::remove_ending_pathseparator(\$sourcepath);
580 if ( $sourcepath =~ /\Q$searchstring\E\s*$/ )
582 $path = $sourcepath;
583 last;
587 # adding the path to the PATH variable
589 if ( $path ne "" )
591 my $oldpath = "";
592 if ( $ENV{'PATH'} ) { $oldpath = $ENV{'PATH'}; }
593 else { $oldpath = "\."; }
594 if ( $^O =~ /cygwin/i ) {
595 $path = qx(cygpath -u "$path");
596 chomp $path;
598 my $newpath = $path . $installer::globals::pathseparator . $oldpath;
599 $ENV{'PATH'} = $newpath;
601 my $infoline = "Setting PATH to $ENV{'PATH'}\n";
602 push( @installer::globals::logfileinfo, $infoline);
606 ##################################################################
607 # Adding the path of a specified library to the path variable
608 # (for example msvcr70.dll). This is needed to register all
609 # libraries successfully.
610 ##################################################################
612 sub add_path_to_pathvariable
614 my ( $filesarrayref, $searchstring ) = @_;
616 # determining the path
618 my $path = "";
620 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
622 my $onefile = ${$filesarrayref}[$i];
623 my $sourcepath = $onefile->{'sourcepath'};
625 if ( $sourcepath =~ /\Q$searchstring\E\s*$/ )
627 installer::pathanalyzer::get_path_from_fullqualifiedname(\$sourcepath);
628 installer::remover::remove_ending_pathseparator(\$sourcepath);
629 $path = $sourcepath;
630 last;
634 # adding the path to the PATH variable
636 if ( $path ne "" )
638 my $oldpath = "";
639 if ( $ENV{'PATH'} ) { $oldpath = $ENV{'PATH'}; }
640 else { $oldpath = "\."; }
641 if ( $^O =~ /cygwin/i ) {
642 $path = qx(cygpath -u "$path");
643 chomp $path;
645 my $newpath = $path . $installer::globals::pathseparator . $oldpath;
646 $ENV{'PATH'} = $newpath;
648 my $infoline = "Setting PATH to $ENV{'PATH'}\n";
649 push( @installer::globals::logfileinfo, $infoline);
653 ##################################################################
654 # Setting the jre path into the PATH (Windows only)
655 # This is used by regcomp.exe to register Java components.
656 # The jre path is saved in $installer::globals::jrepath
657 ##################################################################
659 sub add_jrepath_into_path
661 my $oldpath = "";
662 if ( $ENV{'PATH'} ) { $oldpath = $ENV{'PATH'}; }
663 else { $oldpath = "\."; }
665 if ( $installer::globals::jrepath ne "" )
667 my $newpath = $installer::globals::jrepath . $installer::globals::pathseparator . $oldpath;
668 $ENV{'PATH'} = $newpath;
670 my $infoline = "Setting PATH to $ENV{'PATH'}\n";
671 push( @installer::globals::logfileinfo, $infoline);
675 #######################################################################################
676 # Preparing a registry "regcomp.rdb" which regcomp can work on (types+java services).
677 # Copying the "udkapi.rdb", renaming it to "regcomp.rdb" and registering the
678 # libraries @installer::globals::regcompregisterlibs, which are javavm.uno.so
679 # and javaloader.uno.so or javavm.uno.dll and javaloader.uno.dll
680 #######################################################################################
682 sub prepare_regcomp_rdb
684 my ( $regcompfile, $servicesdir, $includepatharrayref) = @_;
686 # udkapi.rdb has to be found in the sourcepath
688 my $filename = "udkapi.rdb";
689 my $udkapirdbref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 1);
690 if ( $$udkapirdbref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $filename for creating regcomp.rdb!", "prepare_regcomp_rdb"); }
692 my $regcompfilename = "regcomp.rdb";
693 my $regcomprdb = $servicesdir . $installer::globals::separator . $regcompfilename;
695 # If there is an older version of this file, it has to be removed
696 if ( -f $regcomprdb ) { unlink($regcomprdb); }
698 installer::systemactions::copy_one_file($$udkapirdbref, $regcomprdb);
700 # now the libraries in @installer::globals::regcompregisterlibs can be registered in the "regcomp.rdb"
702 for ( my $i = 0; $i <= $#installer::globals::regcompregisterlibs; $i++ )
704 my $libfilename = $installer::globals::regcompregisterlibs[$i] . $installer::globals::libextension;
705 my $libfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$libfilename, $includepatharrayref, 1);
706 if ( $$libfileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $libfilename for creating regcomp.rdb!", "prepare_regcomp_rdb"); }
708 my $from = cwd();
709 if ( $installer::globals::iswin ) { $from =~ s/\//\\/g; }
711 my $to = $$libfileref;
712 installer::pathanalyzer::get_path_from_fullqualifiedname(\$to);
714 chdir($to);
716 my $systemcall = "$installer::globals::wrapcmd $regcompfile -register -s -r " . fix_cygwin_path($regcomprdb) . " -c $libfilename";
718 my $returnvalue = system($systemcall);
720 chdir($from);
722 my $infoline;
723 if ($returnvalue) { $infoline = "ERROR: $systemcall\n"; }
724 else { $infoline = "SUCCESS: $systemcall\n"; }
726 push( @installer::globals::logfileinfo, $infoline);
729 return $regcomprdb;
732 ################################################################
733 # Collecting all gids of the databases, that are part of
734 # the file definition
735 ################################################################
737 sub collect_all_services_gids
739 my ($filesarrayref) = @_;
741 my @databasegids = ();
742 my $error_occured = 0;
743 my @error_files = ();
745 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
747 my $onefile = ${$filesarrayref}[$i];
749 if ( $onefile->{'RegistryID'} )
751 my $databasegid = $onefile->{'RegistryID'};
752 if (! installer::existence::exists_in_array($databasegid, \@databasegids)) { push(@databasegids, $databasegid); }
754 else
756 push(@error_files, $onefile->{'gid'});
757 $error_occured = 1;
761 if ( $error_occured )
763 my $infoline = "ERROR: Style UNO_COMPONENT is set, but no RegistryID is assigned!\n";
764 push( @installer::globals::logfileinfo, $infoline);
765 print $infoline;
767 for ( my $j = 0; $j <= $#error_files; $j++ )
769 $infoline = "$error_files[$j]\n";
770 push( @installer::globals::logfileinfo, $infoline);
771 print $infoline;
774 installer::exiter::exit_program("ERROR: File defintion error.", "collect_all_services_gids");
777 return \@databasegids;
780 ######################################################################
781 # All gids in $databasegids are as RegistryID assigned to files.
782 # For all this Registry Files a definition has to exist.
783 ######################################################################
785 sub check_defintion_of_databasegids
787 my ($databasegids, $registryfiles) = @_;
789 my @registryfiles = ();
791 # First check: For all assigned Registry files, a definition of
792 # a file with flag STARREGISTRY has to exist.
794 for ( my $i = 0; $i <= $#{$databasegids}; $i++ )
796 my $onegid = ${$databasegids}[$i];
797 my $gid_defined = 0;
799 for ( my $j = 0; $j <= $#{$registryfiles}; $j++ )
801 my $registrygid = ${$registryfiles}[$j]->{'gid'};
803 if ( $onegid eq $registrygid )
805 $gid_defined = 1;
806 last;
810 if ( ! $gid_defined )
812 installer::exiter::exit_program("ERROR: Gid $onegid is assigned to file(s), but not defined!", "check_defintion_of_databasegids");
816 # Second check: If there is a file defined as StarRegistry, is a file with flag UNO_COMPONENT assigned?
818 for ( my $j = 0; $j <= $#{$registryfiles}; $j++ )
820 my $onefile = ${$registryfiles}[$j];
821 my $registrygid = $onefile->{'gid'};
823 my $gid_assigned = 0;
825 for ( my $i = 0; $i <= $#{$databasegids}; $i++ )
827 my $onegid = ${$databasegids}[$i];
829 if ( $onegid eq $registrygid )
831 $gid_assigned = 1;
832 last;
836 if ( ! $gid_assigned )
838 my $infoline = "Warning: $registrygid is defined with flag STARREGISTRY, but no file is assigned to the registry.\n";
839 push( @installer::globals::logfileinfo, $infoline);
841 else
843 push(@registryfiles, $onefile);
847 return \@registryfiles;
850 ################################################################
851 # Some files have flag UNO_COMPONENT, but are not registered
852 # with regcomp. This files use the regmerge mechanism, that
853 # is not used in this perl-file. Therefore this files
854 # have to be filtered out here.
855 ################################################################
857 sub filter_regmergefiles
859 my ($unocomponentfiles) = @_;
861 my @regcompfiles = ();
863 for ( my $i = 0; $i <= $#{$unocomponentfiles}; $i++ )
865 my $onefile = ${$unocomponentfiles}[$i];
866 my $regmergefile = "";
868 if ( $onefile->{'Regmergefile'} ) { $regmergefile = $onefile->{'Regmergefile'}; }
869 if ( $regmergefile ne "" ) { next; }
871 push(@regcompfiles, $onefile);
874 return \@regcompfiles;
877 ################################################################
878 # Setting defaults for Creating services.rdb file by registering all uno components
879 ################################################################
881 sub set_url_prefixes
883 my ( $registryfile ) = @_;
885 my $nativeservicesurlprefix = "";
886 my $javaservicesurlprefix = "";
888 if ( $registryfile->{'NativeServicesURLPrefix'} ) { $nativeservicesurlprefix = $registryfile->{'NativeServicesURLPrefix'}; }
889 else { $nativeservicesurlprefix = "vnd.sun.star.expand:\$ORIGIN/"; }
891 if ( $registryfile->{'JavaServicesURLPrefix'} ) { $javaservicesurlprefix = $registryfile->{'JavaServicesURLPrefix'}; }
892 else { $javaservicesurlprefix = "vnd.sun.star.expand:\$UNO_JAVA_COMPONENT_PATH/"; }
894 return ($nativeservicesurlprefix, $javaservicesurlprefix);
897 ################################################################
898 # Creating services.rdb file by registering all uno components
899 ################################################################
901 sub create_services_rdb
903 my ($allvariableshashref, $filesarrayref, $includepatharrayref, $languagestringref) = @_;
905 # collecting all services files
906 my $unocomponentfiles = installer::worker::collect_all_items_with_special_flag($filesarrayref, "UNO_COMPONENT");
907 $unocomponentfiles = filter_regmergefiles($unocomponentfiles);
909 if ( $#{$unocomponentfiles} > -1 ) # not empty -> at least one file with flag UNO_COMPONENT
911 my $databasegids = collect_all_services_gids($unocomponentfiles);
913 my $registryfiles = installer::worker::collect_all_items_with_special_flag($filesarrayref, "STARREGISTRY");
915 $registryfiles = check_defintion_of_databasegids($databasegids, $registryfiles);
917 # Now the creation of all files with flag STARREGISTRY can begin
919 for ( my $i = 0; $i <= $#{$registryfiles}; $i++ )
921 my $registryfile = ${$registryfiles}[$i];
923 # my $servicesname = "services.rdb";
924 my $servicesname = $registryfile->{'Name'}; # not unique!
925 my $servicesgid = $registryfile->{'gid'}; # unique
926 my $uniquedirname = $servicesgid . "_servicesrdb";
927 # my $uniquedirname = $servicesgid;
929 my ($nativeservicesurlprefix, $javaservicesurlprefix) = set_url_prefixes($registryfile);
931 installer::logger::include_header_into_logfile("Creating $servicesname ($servicesgid):");
933 # my $servicesdir = installer::systemactions::create_directories($servicesname, $languagestringref);
934 my $servicesdir = installer::systemactions::create_directories($uniquedirname, $languagestringref);
936 # if ( $^O =~ /cygwin/i )
937 # { # $servicesdir is used as a parameter for regcomp and has to be DOS style
938 # $servicesdir = qx{cygpath -d "$servicesdir"};
939 # chomp($servicesdir);
940 # $servicesdir =~ s/\\/\//g;
943 push(@installer::globals::removedirs, $servicesdir);
945 my $servicesfile = $servicesdir . $installer::globals::separator . $servicesname;
947 # If there is an older version of this file, it has to be removed
948 if ( -f $servicesfile ) { unlink($servicesfile); }
950 # if ((-f $servicesfile) && (!($installer::globals::services_rdb_created))) { $installer::globals::services_rdb_created = 1; }
951 # if ((!($installer::globals::services_rdb_created)) && $installer::globals::servicesrdb_can_be_created ) # This has to be done once
952 if ( $installer::globals::servicesrdb_can_be_created ) # This has to be done always
954 # Creating the services.rdb in directory "inprogress"
955 my $origservicesdir = $servicesdir;
956 $servicesdir = installer::systemactions::make_numbered_dir("inprogress", $servicesdir);
957 $servicesfile = $servicesdir . $installer::globals::separator . $servicesname;
959 # determining the location of the file regcomp
960 # Because the program regcomp.exe (regcomp) is used now, it has to be taken the version
961 # from the platform, this script is running. It is not important, for which platform the
962 # product is built.
964 my $searchname;
966 if ($installer::globals::isunix) { $searchname = "regcomp"; }
967 else { $searchname = "regcomp.exe"; }
969 $regcompfileref = get_source_path_cygwin_safe($searchname, $includepatharrayref, 1);
970 if ( $$regcompfileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $searchname for registering uno components!", "create_services_rdb"); }
972 # For Windows the libraries included into the mozruntime.zip have to be added to the path
973 if ($installer::globals::iswin) { add_path_to_pathvariable_directory($filesarrayref, "mozruntime_zip"); }
974 if ($installer::globals::iswin) { add_path_to_pathvariable($filesarrayref, "msvcr70.dll"); }
976 # setting the LD_LIBRARY_PATH, needed by regcomp
977 # Linux: Take care of the lock daemon. He has to be started!
978 # For windows it is necessary that "msvcp7x.dll" and "msvcr7x.dll" are included into the path !
980 my $var_library_path;
981 my $old_library_path;
982 if ( $installer::globals::isunix ) {
983 $var_library_path = $installer::globals::ismacosx ?
984 'DYLD_LIBRARY_PATH' : 'LD_LIBRARY_PATH';
985 $old_library_path = $ENV{$var_library_path};
986 include_libdir_into_ld_library_path(
987 $var_library_path, $$regcompfileref);
990 my $regcomprdb = "";
992 if ( $installer::globals::solarjava ) # this is needed to register Java components
994 prepare_classpath_for_java_registration($includepatharrayref);
996 if ( $installer::globals::isunix )
997 { add_jdklib_into_ld_library_path($var_library_path); }
998 else { add_jrepath_into_path(); }
1000 # Preparing a registry which regcomp can work on (types+java services).
1001 # Copying the "udkapi.rdb", renaming it to "regcomp.rdb" and registering the
1002 # libraries $(REGISTERLIBS_JAVA), which are javavm.uno.so and javaloader.uno.so
1003 # or javavm.uno.dll and javaloader.uno.dll
1005 $regcomprdb = prepare_regcomp_rdb($$regcompfileref, $servicesdir, $includepatharrayref);
1008 # and now iteration over all files
1010 # my $error_during_registration = register_all_components($filesarrayref, $regcompfileref, $servicesfile, $regcomprdb, $includepatharrayref);
1011 my $error_during_registration = register_all_components($allvariableshashref, $servicesgid, $unocomponentfiles, $regcompfileref, $servicesfile, $regcomprdb, $includepatharrayref, $nativeservicesurlprefix, $javaservicesurlprefix);
1013 if (defined $var_library_path) {
1014 if (defined $old_library_path) {
1015 $ENV{$var_library_path} = $old_library_path;
1016 } else {
1017 delete $ENV{$var_library_path};
1021 # Dependent from the success, the registration directory can be renamed.
1023 if ( $error_during_registration )
1025 $servicesdir = installer::systemactions::rename_string_in_directory($servicesdir, "inprogress", "witherror");
1026 push(@installer::globals::removedirs, $servicesdir);
1027 # and exiting the packaging process
1028 installer::exiter::exit_program("ERROR: Could not register all components for file $servicesname ($servicesgid)!", "create_services_rdb");
1030 else
1032 $servicesdir = installer::systemactions::rename_directory($servicesdir, $origservicesdir);
1035 $servicesfile = $servicesdir . $installer::globals::separator . $servicesname;
1037 else
1039 my $infoline;
1041 if (!($installer::globals::servicesrdb_can_be_created))
1043 $infoline = "Warning: $servicesname was not created. Build platform and compiler do not match. Build platform: $installer::globals::plat, compiler : $installer::globals::compiler\n";
1044 push( @installer::globals::logfileinfo, $infoline);
1047 if ( $installer::globals::services_rdb_created )
1049 $infoline = "Info: $servicesname was not created. $servicesfile already exists.\n";
1050 push( @installer::globals::logfileinfo, $infoline);
1053 if ((!($installer::globals::servicesrdb_can_be_created)) && (!($installer::globals::services_rdb_created)))
1055 $infoline = "ERROR: $servicesname was not created and does not exist!\n";
1056 push( @installer::globals::logfileinfo, $infoline);
1060 # Adding the new services file source path to the filearray
1061 $registryfile->{'sourcepath'} = $servicesfile; # setting the sourcepath!
1062 # add_services_sourcepath_into_filearray( $filesarrayref, $servicesfile, $servicesname );
1066 # Setting the global variable $installer::globals::services_rdb_created
1068 $installer::globals::services_rdb_created = 1;