1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2000, 2010 Oracle and/or its affiliates.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # This file is part of OpenOffice.org.
11 # OpenOffice.org is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Lesser General Public License version 3
13 # only, as published by the Free Software Foundation.
15 # OpenOffice.org is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Lesser General Public License version 3 for more details
19 # (a copy is included in the LICENSE file that accompanied this code).
21 # You should have received a copy of the GNU Lesser General Public License
22 # version 3 along with OpenOffice.org. If not, see
23 # <http://www.openoffice.org/license.html>
24 # for a copy of the LGPLv3 License.
26 #*************************************************************************
28 package par2script
::check
;
30 use par2script
::globals
;
32 ################################
33 # Checks of the setup script
34 ################################
36 ########################################################
37 # Checking if all defined directories are needed
38 ########################################################
40 sub check_needed_directories
42 my $allfiles = $par2script::globals
::definitions
{'File'};
43 my $alldirs = $par2script::globals
::definitions
{'Directory'};
45 # checking if all defined directories are needed
48 foreach $dir ( keys %{$alldirs} )
50 # I. directory has create flag
51 if (( exists($alldirs->{$dir}->{'Styles'}) ) && ( $alldirs->{$dir}->{'Styles'} =~ /\bCREATE\b/ )) { next; }
53 # II. there is at least one file in the directory
56 foreach $file ( keys %{$allfiles} )
58 if (( $allfiles->{$file}->{'Dir'} eq $dir ) || ( $allfiles->{$file}->{'NetDir'} eq $dir ))
64 if ( $fileinside ) { next; }
66 # III. the directory is parent for another directory
69 foreach $onedir ( keys %{$alldirs} )
71 if ( $alldirs->{$onedir}->{'ParentID'} eq $dir )
77 if ( $isparent ) { next; }
79 # no condition is true -> directory definition is superfluous
80 my $infoline = "\tINFO: Directory definition $dir is superfluous\n";
82 push(@par2script::globals
::logfileinfo
, $infoline);
86 ##################################################
87 # Checking if the directories in the item
88 # definitions are defined.
89 ##################################################
91 sub check_directories_in_item_definitions
94 foreach $item ( @par2script::globals
::items_with_directories
)
96 my $allitems = $par2script::globals
::definitions
{$item};
99 foreach $onegid ( keys %{$allitems} )
101 if ( ! exists($allitems->{$onegid}->{'Dir'}) ) { die "\nERROR: No directory defined for item: $onegid!\n\n"; }
102 my $dir = $allitems->{$onegid}->{'Dir'};
103 if (( $dir eq "PD_PROGDIR" ) || ( $dir =~ /PREDEFINED_/ )) { next; }
105 # checking if this directoryid is defined
106 if ( ! exists($par2script::globals
::definitions
{'Directory'}->{$dir}) )
108 die "\nERROR: Directory $dir in item $onegid not defined!\n\n";
114 ########################################################
115 # Checking for all Items, that know their modules,
116 # whether these modules exist.
117 ########################################################
119 sub check_module_existence
122 foreach $item ( @par2script::globals
::items_with_moduleid
)
124 my $allitems = $par2script::globals
::definitions
{$item};
127 foreach $onegid ( keys %{$allitems} )
129 if ( ! exists($allitems->{$onegid}->{'ModuleID'}) ) { die "\nERROR: No ModuleID defined for item: $onegid!\n\n"; }
130 my $moduleid = $allitems->{$onegid}->{'ModuleID'};
132 # checking if this directoryid is defined
133 if ( ! exists($par2script::globals
::definitions
{'Module'}->{$moduleid}) )
135 die "\nERROR: ModuleID $moduleid in item $onegid not defined!\n\n";
141 ########################################################
142 # Every script has to contain exactly one root module.
143 # This module has no ParentID or an empty ParentID.
144 ########################################################
151 my $allmodules = $par2script::globals
::definitions
{'Module'};
154 foreach $modulegid (keys %{$allmodules} )
156 if (( ! exists($allmodules->{$modulegid}->{'ParentID'}) ) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
160 die "\nERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).\n";
162 $rootgid = $modulegid;
169 die "\nERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.\n";
172 print " $rootgid\n" if $par2script::globals
::verbose
;
176 ########################################################
177 # File, Shortcut, Directory, Unixlink must not
179 ########################################################
181 sub check_moduleid_at_items
184 foreach $item ( @par2script::globals
::items_without_moduleid
)
186 my $allitems = $par2script::globals
::definitions
{$item};
189 foreach $onegid ( keys %{$allitems} )
191 if ( exists($allitems->{$onegid}->{'ModuleID'}) )
193 die "\nERROR: ModuleID assigned to $onegid! No module assignment to $item!\n\n";
199 ########################################################
200 # Controlling existence of multi assignments
201 ########################################################
203 sub check_multiple_assignments
205 my @multiassignments = ();
209 foreach $topitem ( keys %par2script::globals
::assignedgids
)
212 foreach $item ( keys %{$par2script::globals
::assignedgids
{$topitem}} )
214 if ( $par2script::globals
::assignedgids
{$topitem}->{$item} > 1 )
217 my $string = "\tGID: $item Assignments: $par2script::globals::assignedgids{$topitem}->{$item}";
218 push(@multiassignments, $string);
223 if ( $error ) { par2script
::exiter
::multiassignmenterror
(\
@multiassignments); }
226 ########################################################
227 # Check, if a defined directory has a flag CREATE
228 ########################################################
230 sub contains_create_flag
236 if (( exists($par2script::globals
::definitions
{'Directory'}->{$gid}->{'Styles'}) ) &&
237 ( $par2script::globals
::definitions
{'Directory'}->{$gid}->{'Styles'} =~ /\bCREATE\b/ ))
245 ########################################################
246 # Controlling existence of definitions without
248 ########################################################
250 sub check_missing_assignments
252 # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
253 # this causes an error.
254 # Directories only have to be assigned, if they have the flag "CREATE".
256 my @missingassignments = ();
260 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
262 my $assignedgids = $par2script::globals
::assignedgids
{$item};
263 my $definedgids = $par2script::globals
::definitions
{$item};
266 foreach $gid ( keys %{$definedgids} )
268 if ( $item eq "Directory" ) { if ( ! contains_create_flag
($gid) ) { next; } }
270 if ( ! exists( $assignedgids->{$gid} ))
273 push(@missingassignments, $gid);
278 if ( $error ) { par2script
::exiter
::missingassignmenterror
(\
@missingassignments); }
281 #############################################################
282 # Controlling if for all shortcuts with file assignment
283 # the file is defined. And for all shortcuts with
284 # shortcut assignment the shortcut has to be defined.
285 #############################################################
287 sub check_shortcut_assignments
289 my $allshortcuts = $par2script::globals
::definitions
{'Shortcut'};
290 my $allfiles = $par2script::globals
::definitions
{'File'};
293 foreach $shortcut ( keys %{$allshortcuts} )
295 if (( exists($allshortcuts->{$shortcut}->{'FileID'}) ) &&
296 ( ! exists($allfiles->{$allshortcuts->{$shortcut}->{'FileID'}}) ))
298 # die "\nERROR: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n";
299 print "\n\tWARNING: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n";
302 if (( exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
303 ( ! exists($allshortcuts->{$allshortcuts->{$shortcut}->{'ShortcutID'}}) ))
305 die "\nERROR: ShortcutID $allshortcuts->{$shortcut}->{'ShortcutID'} has no definition at shortcut $shortcut !\n";
308 if (( ! exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
309 ( ! exists($allshortcuts->{$shortcut}->{'FileID'}) ))
311 die "\nERROR: Shortcut requires assignment to \"ShortcutID\" or \"FileID\". Missing at shortcut $shortcut !\n";
316 #############################################################
317 # Controlling if for Modules and Directories, the parents
318 # are defined. If not, this can lead to a problem during
319 # script creation, because only recursively added
320 # Modules or Directories are added to the script.
321 #############################################################
323 sub check_missing_parents
325 my @parentitems = ("Module", "Directory");
326 my %rootparents = ("PREDEFINED_PROGDIR" => "1");
329 foreach $oneitem ( @parentitems )
331 my $alldefinitions = $par2script::globals
::definitions
{$oneitem};
334 foreach $onegid ( keys %{$alldefinitions} )
336 # If there is a ParentID used, it must be defined
337 if (( exists($alldefinitions->{$onegid}->{'ParentID'}) ) &&
338 ( ! exists($alldefinitions->{$alldefinitions->{$onegid}->{'ParentID'}}) ) &&
339 ( ! exists($rootparents{$alldefinitions->{$onegid}->{'ParentID'}}) ))
341 die "\nERROR: Parent \"$alldefinitions->{$onegid}->{'ParentID'}\" at $oneitem \"$onegid\" is not defined!\n";