1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: check.pm,v $
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 par2script
::check
;
34 use par2script
::globals
;
36 ################################
37 # Checks of the setup script
38 ################################
40 ########################################################
41 # Checking if all defined directories are needed
42 ########################################################
44 sub check_needed_directories
46 my $allfiles = $par2script::globals
::definitions
{'File'};
47 my $alldirs = $par2script::globals
::definitions
{'Directory'};
49 # checking if all defined directories are needed
52 foreach $dir ( keys %{$alldirs} )
54 # I. directory has create flag
55 if (( exists($alldirs->{$dir}->{'Styles'}) ) && ( $alldirs->{$dir}->{'Styles'} =~ /\bCREATE\b/ )) { next; }
57 # II. there is at least one file in the directory
60 foreach $file ( keys %{$allfiles} )
62 if (( $allfiles->{$file}->{'Dir'} eq $dir ) || ( $allfiles->{$file}->{'NetDir'} eq $dir ))
68 if ( $fileinside ) { next; }
70 # III. the directory is parent for another directory
73 foreach $onedir ( keys %{$alldirs} )
75 if ( $alldirs->{$onedir}->{'ParentID'} eq $dir )
81 if ( $isparent ) { next; }
83 # no condition is true -> directory definition is superfluous
84 my $infoline = "\tINFO: Directory definition $dir is superfluous\n";
86 push(@par2script::globals
::logfileinfo
, $infoline);
90 ##################################################
91 # Checking if the directories in the item
92 # definitions are defined.
93 ##################################################
95 sub check_directories_in_item_definitions
98 foreach $item ( @par2script::globals
::items_with_directories
)
100 my $allitems = $par2script::globals
::definitions
{$item};
103 foreach $onegid ( keys %{$allitems} )
105 if ( ! exists($allitems->{$onegid}->{'Dir'}) ) { die "\nERROR: No directory defined for item: $onegid!\n\n"; }
106 my $dir = $allitems->{$onegid}->{'Dir'};
107 if (( $dir eq "PD_PROGDIR" ) || ( $dir =~ /PREDEFINED_/ )) { next; }
109 # checking if this directoryid is defined
110 if ( ! exists($par2script::globals
::definitions
{'Directory'}->{$dir}) )
112 die "\nERROR: Directory $dir in item $onegid not defined!\n\n";
118 ########################################################
119 # Checking for all Items, that know their modules,
120 # whether these modules exist.
121 ########################################################
123 sub check_module_existence
126 foreach $item ( @par2script::globals
::items_with_moduleid
)
128 my $allitems = $par2script::globals
::definitions
{$item};
131 foreach $onegid ( keys %{$allitems} )
133 if ( ! exists($allitems->{$onegid}->{'ModuleID'}) ) { die "\nERROR: No ModuleID defined for item: $onegid!\n\n"; }
134 my $moduleid = $allitems->{$onegid}->{'ModuleID'};
136 # checking if this directoryid is defined
137 if ( ! exists($par2script::globals
::definitions
{'Module'}->{$moduleid}) )
139 die "\nERROR: ModuleID $moduleid in item $onegid not defined!\n\n";
145 ########################################################
146 # If the StarRegistry is not defined in the script,
147 # it has to be removed from the file definition.
148 ########################################################
150 sub check_registry_at_files
152 my %starregistrygid = ();
155 foreach $item ( keys %{$par2script::globals
::definitions
{'File'}} )
157 if (( exists($par2script::globals
::definitions
{'File'}->{$item}->{'Styles'}) ) &&
158 ( $par2script::globals
::definitions
{'File'}->{$item}->{'Styles'} =~ /\bSTARREGISTRY\b/ ))
160 $starregistrygid{$item} = 1;
164 foreach $item ( keys %{$par2script::globals
::definitions
{'File'}} )
166 if ( exists($par2script::globals
::definitions
{'File'}->{$item}->{'RegistryID'}) )
168 my $registryid = $par2script::globals
::definitions
{'File'}->{$item}->{'RegistryID'};
169 if ( ! exists($starregistrygid{$registryid}) )
171 die "\nERROR: No definition found for $registryid at file $item\n\n";
174 # if ( ! ( $par2script::globals::definitions{'File'}->{$item}->{'Styles'} =~ /\bUNO_COMPONENT\b/ ))
176 # die "\nERROR: Flag UNO_COMPONENT required for file $item\n\n";
178 # -> also possible, that Regmergefile is defined (does not require flag UNO_COMPONENT)
181 # and also vice versa
183 if (( exists($par2script::globals
::definitions
{'File'}->{$item}->{'Styles'}) ) &&
184 ( $par2script::globals
::definitions
{'File'}->{$item}->{'Styles'} =~ /\bUNO_COMPONENT\b/ ))
186 if ( ! exists($par2script::globals
::definitions
{'File'}->{$item}->{'RegistryID'}) )
188 die "\nERROR: Flag UNO_COMPONENT defined, but no file as \"RegistryID\" at file $item !\n\n";
194 ########################################################
195 # Every script has to contain exactly one root module.
196 # This module has no ParentID or an empty ParentID.
197 ########################################################
204 my $allmodules = $par2script::globals
::definitions
{'Module'};
207 foreach $modulegid (keys %{$allmodules} )
209 if (( ! exists($allmodules->{$modulegid}->{'ParentID'}) ) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
213 die "\nERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).\n";
215 $rootgid = $modulegid;
222 die "\nERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.\n";
229 ########################################################
230 # File, Shortcut, Directory, Unixlink must not
232 ########################################################
234 sub check_moduleid_at_items
237 foreach $item ( @par2script::globals
::items_without_moduleid
)
239 my $allitems = $par2script::globals
::definitions
{$item};
242 foreach $onegid ( keys %{$allitems} )
244 if ( exists($allitems->{$onegid}->{'ModuleID'}) )
246 die "\nERROR: ModuleID assigned to $onegid! No module assignment to $item!\n\n";
252 ########################################################
253 # Controlling existence of multi assignments
254 ########################################################
256 sub check_multiple_assignments
258 my @multiassignments = ();
262 foreach $topitem ( keys %par2script::globals
::assignedgids
)
265 foreach $item ( keys %{$par2script::globals
::assignedgids
{$topitem}} )
267 if ( $par2script::globals
::assignedgids
{$topitem}->{$item} > 1 )
270 my $string = "\tGID: $item Assignments: $par2script::globals::assignedgids{$topitem}->{$item}";
271 push(@multiassignments, $string);
276 if ( $error ) { par2script
::exiter
::multiassignmenterror
(\
@multiassignments); }
279 ########################################################
280 # Check, if a defined directory has a flag CREATE
281 ########################################################
283 sub contains_create_flag
289 if (( exists($par2script::globals
::definitions
{'Directory'}->{$gid}->{'Styles'}) ) &&
290 ( $par2script::globals
::definitions
{'Directory'}->{$gid}->{'Styles'} =~ /\bCREATE\b/ ))
298 ########################################################
299 # Controlling existence of definitions without
301 ########################################################
303 sub check_missing_assignments
305 # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
306 # this causes an error.
307 # Directories only have to be assigned, if they have the flag "CREATE".
309 my @missingassignments = ();
313 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
315 my $assignedgids = $par2script::globals
::assignedgids
{$item};
316 my $definedgids = $par2script::globals
::definitions
{$item};
319 foreach $gid ( keys %{$definedgids} )
321 if ( $item eq "Directory" ) { if ( ! contains_create_flag
($gid) ) { next; } }
323 if ( ! exists( $assignedgids->{$gid} ))
326 push(@missingassignments, $gid);
331 if ( $error ) { par2script
::exiter
::missingassignmenterror
(\
@missingassignments); }
334 #############################################################
335 # Controlling if for all shortcuts with file assignment
336 # the file is defined. And for all shortcuts with
337 # shortcut assignment the shortcut has to be defined.
338 #############################################################
340 sub check_shortcut_assignments
342 my $allshortcuts = $par2script::globals
::definitions
{'Shortcut'};
343 my $allfiles = $par2script::globals
::definitions
{'File'};
346 foreach $shortcut ( keys %{$allshortcuts} )
348 if (( exists($allshortcuts->{$shortcut}->{'FileID'}) ) &&
349 ( ! exists($allfiles->{$allshortcuts->{$shortcut}->{'FileID'}}) ))
351 # die "\nERROR: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n";
352 print "\n\tWARNING: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n";
355 if (( exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
356 ( ! exists($allshortcuts->{$allshortcuts->{$shortcut}->{'ShortcutID'}}) ))
358 die "\nERROR: ShortcutID $allshortcuts->{$shortcut}->{'ShortcutID'} has no definition at shortcut $shortcut !\n";
361 if (( ! exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
362 ( ! exists($allshortcuts->{$shortcut}->{'FileID'}) ))
364 die "\nERROR: Shortcut requires assignment to \"ShortcutID\" or \"FileID\". Missing at shortcut $shortcut !\n";
369 #############################################################
370 # Controlling if for Modules and Directories, the parents
371 # are defined. If not, this can lead to a problem during
372 # script creation, because only recursively added
373 # Modules or Directories are added to the script.
374 #############################################################
376 sub check_missing_parents
378 my @parentitems = ("Module", "Directory");
379 my %rootparents = ("PREDEFINED_PROGDIR" => "1");
382 foreach $oneitem ( @parentitems )
384 my $alldefinitions = $par2script::globals
::definitions
{$oneitem};
387 foreach $onegid ( keys %{$alldefinitions} )
389 # If there is a ParentID used, it must be defined
390 if (( exists($alldefinitions->{$onegid}->{'ParentID'}) ) &&
391 ( ! exists($alldefinitions->{$alldefinitions->{$onegid}->{'ParentID'}}) ) &&
392 ( ! exists($rootparents{$alldefinitions->{$onegid}->{'ParentID'}}) ))
394 die "\nERROR: Parent \"$alldefinitions->{$onegid}->{'ParentID'}\" at $oneitem \"$onegid\" is not defined!\n";