update dev300-m58
[ooovba.git] / solenv / bin / modules / installer / regmerge.pm
blob5bb2169f0d834c87ac2dd17ef729f22d92154140
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: regmerge.pm,v $
11 # $Revision: 1.7 $
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::regmerge;
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 # Collecting all files with content:
47 # Regmergefile = "mydatabasepart.rdb";
48 ################################################################
50 sub collect_all_regmergefiles
52 my ($filesarrayref) = @_;
54 my @regmergefiles = ();
56 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
58 my $onefile = ${$filesarrayref}[$i];
59 if ( $onefile->{'Regmergefile'} ) { push(@regmergefiles, $onefile); }
62 return \@regmergefiles;
65 ################################################################
66 # Collecting all gids of the databases, that are part of
67 # the file definition
68 ################################################################
70 sub collect_all_database_gids
72 my ($filesarrayref) = @_;
74 my @databasegids = ();
76 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
78 my $onefile = ${$filesarrayref}[$i];
80 if ( $onefile->{'RegistryID'} )
82 my $databasegid = $onefile->{'RegistryID'};
83 if (! installer::existence::exists_in_array($databasegid, \@databasegids)) { push(@databasegids, $databasegid); }
85 else
87 installer::exiter::exit_program("ERROR: File defintion error. File :$onefile->{'gid'} without RegistryID!", "collect_all_database_gids");
91 return \@databasegids;
94 ################################################################
95 # Returning the database file from the files collector. In the
96 # future this file does not need to exist, but currently it
97 # has to exist already in the files collector.
98 ################################################################
100 sub get_database_file
102 my ($databasegid, $filesarrayref) = @_;
104 my $found = 0;
105 my $onefile;
107 for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
109 $onefile = ${$filesarrayref}[$i];
110 my $gid = $onefile->{'gid'};
112 if ( $databasegid eq $gid )
114 $found = 1;
115 last;
119 if ( ! $found ) { installer::exiter::exit_program("ERROR: Did not find StarRegistry file $databasegid!", "get_database_file"); }
121 return $onefile;
124 ################################################################
125 # The regmerge file has to be found the in include pathes
126 ################################################################
128 sub get_regmerge_file
130 my ($includepatharrayref) = @_;
132 my $searchname;
134 if ($installer::globals::isunix) { $searchname = "regcomplazy"; }
135 else { $searchname = "regcomplazy.exe"; }
137 my $regmergefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$searchname, $includepatharrayref, 1);
138 if ( $$regmergefileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $searchname for merging the StarRegistry!", "get_regmerge_file"); }
140 return $$regmergefileref;
143 ################################################################
144 # Collecting all files that are merged to one defined
145 # StarRegistry database
146 ################################################################
148 sub collect_all_files_for_one_registry
150 my ($regmergefiles, $databasegid) = @_;
152 my @regmergefiles = ();
154 for ( my $i = 0; $i <= $#{$regmergefiles}; $i++ )
156 my $onefile = ${$regmergefiles}[$i];
157 if ( $onefile->{'RegistryID'} eq $databasegid ) { push(@regmergefiles, $onefile); }
160 return \@regmergefiles;
163 ################################################################
164 # Collecting all particles from the regmerge files
165 ################################################################
167 sub collect_all_regmerge_particles
169 my ($databaseregisterfiles) = @_;
171 my @regmergeparticles = ();
173 for ( my $i = 0; $i <= $#{$databaseregisterfiles}; $i++ )
175 my $onefile = ${$databaseregisterfiles}[$i];
176 if ( $onefile->{'Regmergefile'} ) { push(@regmergeparticles, $onefile->{'Regmergefile'}); }
177 else { installer::exiter::exit_program("ERROR: Could not find entry for \"Regmergefile\" in $onefile->{'gid'}!", "collect_all_regmerge_particles"); }
180 return \@regmergeparticles;
183 ################################################################
184 # Collecting all source pathes of the regmerge particles
185 ################################################################
187 sub get_all_source_pathes
189 my ($regmergeparticles, $includepatharrayref) = @_;
191 my @regmergeparticles = ();
193 for ( my $i = 0; $i <= $#{$regmergeparticles}; $i++ )
195 my $filename = ${$regmergeparticles}[$i];
197 my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 1);
198 if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $filename for merging the StarRegistry!", "get_all_source_pathes"); }
200 push(@regmergeparticles, $$fileref);
203 return \@regmergeparticles;
206 ################################################################
207 # Merging the rdb files into the StarRegistry database
208 ################################################################
210 sub merge_files
212 my ($regmergefile, $databasefile, $registerfiles, $databasedir, $allvariableshashref) = @_;
214 my $databasesource = $databasefile->{'sourcepath'};
215 my $databasename = $databasefile->{'Name'};
216 my $databasedest = $databasedir . $installer::globals::separator . $databasename;
218 installer::systemactions::copy_one_file($databasesource, $databasedest);
219 $databasefile->{'sourcepath'} = $databasedest; # new sourcepath for the StarRegistry file
221 # One call for every merge particle. This is only possible, if there are only a few merge particles.
223 my $prefix = $databasefile->{'NativeServicesURLPrefix'};
224 # TODO: "NativeServicesURLPrefix" or "JavaServicesURLPrefix"
226 my $error_occured = 0;
228 for ( my $i = 0; $i <= $#{$registerfiles}; $i++ )
230 my $registerfile = $databasedir . $installer::globals::separator . $i . ".tmp";
231 open (IN, '<', $registerfiles->[$i]) or $error_occured = 1;
232 open (OUT, '>', $registerfile) or $error_occured = 1;
233 while (<IN>)
235 s/^ComponentName=/ComponentName=$prefix/;
236 print OUT $_ or $error_occured = 1;
238 close IN or $error_occured = 1;
239 close OUT or $error_occured = 1;
241 my $systemcall = $regmergefile . " -v " . $databasedest . " " . $registerfile . " 2\>\&1 |";
243 my @regmergeoutput = ();
245 my $var_library_path;
246 my $old_library_path;
247 if ($installer::globals::isunix) {
248 $var_library_path = $installer::globals::ismacosx ?
249 'DYLD_LIBRARY_PATH' : 'LD_LIBRARY_PATH';
250 $old_library_path = $ENV{$var_library_path};
251 installer::servicesfile::include_libdir_into_ld_library_path(
252 $var_library_path, $regmergefile);
255 open (REG, "$systemcall");
256 while (<REG>) {push(@regmergeoutput, $_); }
257 close (REG);
259 my $returnvalue = $?; # $? contains the return value of the systemcall
261 if (defined $var_library_path) {
262 if (defined $old_library_path) {
263 $ENV{$var_library_path} = $old_library_path;
264 } else {
265 delete $ENV{$var_library_path};
269 my $infoline = "Systemcall: $systemcall\n";
270 push( @installer::globals::logfileinfo, $infoline);
272 for ( my $j = 0; $j <= $#regmergeoutput; $j++ ) { push( @installer::globals::logfileinfo, "$regmergeoutput[$j]"); }
274 if ($returnvalue)
276 $infoline = "ERROR: $systemcall\n";
277 push( @installer::globals::logfileinfo, $infoline);
278 $error_occured = 1;
280 else
282 $infoline = "SUCCESS: $systemcall\n";
283 push( @installer::globals::logfileinfo, $infoline);
287 return $error_occured;
290 ################################################################
291 # Expanding the registry database files by merging rdb files
292 # into this registry database files.
293 ################################################################
295 sub merge_registration_files
297 my ($filesarrayref, $includepatharrayref, $languagestringref, $allvariableshashref) = @_;
299 installer::logger::include_header_into_logfile("Creating starregistry databases:");
301 # Test if there is something to do. At least one file has to have the content:
302 # Regmergefile = "mydatabasepart.rdb";
304 my $regmergefiles = collect_all_regmergefiles($filesarrayref);
306 if ( $#{$regmergefiles} > -1 ) # not empty -> at least one regmerge file
308 # prepare registration
310 my $regmergefile = get_regmerge_file($includepatharrayref); # searching for regmerge (regcomplazy.exe)
312 my $databasegids = collect_all_database_gids($regmergefiles);
314 # iterating over all database gids
316 my $regmergeerror = 0;
318 for ( my $i = 0; $i <= $#{$databasegids}; $i++ )
320 $databasegid = ${$databasegids}[$i];
322 # my $databasedirname = "starregistryrdb"; <- not unique!
323 my $databasedirname = $databasegid . "_rdb"; # <- unique!
324 my $databasedir = installer::systemactions::create_directories($databasedirname, $languagestringref);
325 push(@installer::globals::removedirs, $databasedir);
327 my $databasefile = get_database_file($databasegid, $filesarrayref);
328 my $databaseregisterfiles = collect_all_files_for_one_registry($regmergefiles, $databasegid);
330 if ( $#{$databaseregisterfiles} > -1 ) # not empty -> at least one regmerge file
332 my $regmergeparticles = collect_all_regmerge_particles($databaseregisterfiles);
333 $regmergeparticles = get_all_source_pathes($regmergeparticles, $includepatharrayref);
334 my $oneregmergeerror = merge_files($regmergefile, $databasefile, $regmergeparticles, $databasedir, $allvariableshashref);
335 if ($oneregmergeerror) { $regmergeerror = 1; }
339 if ( $regmergeerror ) { installer::exiter::exit_program("ERROR: regmerge !", "merge_registration_files"); }