Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / solenv / bin / modules / par2script / check.pm
blob727cd7c832879121b00f9833268e37b64347b77c
2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package par2script::check;
21 use par2script::globals;
23 ################################
24 # Checks of the setup script
25 ################################
27 ########################################################
28 # Checking if all defined directories are needed
29 ########################################################
31 sub check_needed_directories
33 my $allfiles = $par2script::globals::definitions{'File'};
34 my $alldirs = $par2script::globals::definitions{'Directory'};
36 # checking if all defined directories are needed
38 my $dir;
39 foreach $dir ( keys %{$alldirs} )
41 # I. directory has create flag
42 if (( exists($alldirs->{$dir}->{'Styles'}) ) && ( $alldirs->{$dir}->{'Styles'} =~ /\bCREATE\b/ )) { next; }
44 # II. there is at least one file in the directory
45 my $fileinside = 0;
46 my $file;
47 foreach $file ( keys %{$allfiles} )
49 if (( $allfiles->{$file}->{'Dir'} eq $dir ) || ( $allfiles->{$file}->{'NetDir'} eq $dir ))
51 $fileinside = 1;
52 last;
55 if ( $fileinside ) { next; }
57 # III. the directory is parent for another directory
58 my $isparent = 0;
59 my $onedir;
60 foreach $onedir ( keys %{$alldirs} )
62 if ( $alldirs->{$onedir}->{'ParentID'} eq $dir )
64 $isparent = 1;
65 last;
68 if ( $isparent ) { next; }
70 # no condition is true -> directory definition is superfluous
71 my $infoline = "\tINFO: Directory definition $dir is superfluous\n";
72 # print $infoline;
73 push(@par2script::globals::logfileinfo, $infoline);
77 ##################################################
78 # Checking if the directories in the item
79 # definitions are defined.
80 ##################################################
82 sub check_directories_in_item_definitions
84 my $item;
85 foreach $item ( @par2script::globals::items_with_directories )
87 my $allitems = $par2script::globals::definitions{$item};
89 my $onegid;
90 foreach $onegid ( keys %{$allitems} )
92 if ( ! exists($allitems->{$onegid}->{'Dir'}) ) { die "\nERROR: No directory defined for item: $onegid!\n\n"; }
93 my $dir = $allitems->{$onegid}->{'Dir'};
94 if (( $dir eq "PD_PROGDIR" ) || ( $dir =~ /PREDEFINED_/ )) { next; }
96 # checking if this directoryid is defined
97 if ( ! exists($par2script::globals::definitions{'Directory'}->{$dir}) )
99 die "\nERROR: Directory $dir in item $onegid not defined!\n\n";
105 ########################################################
106 # Checking for all Items, that know their modules,
107 # whether these modules exist.
108 ########################################################
110 sub check_module_existence
112 my $item;
113 foreach $item ( @par2script::globals::items_with_moduleid )
115 my $allitems = $par2script::globals::definitions{$item};
117 my $onegid;
118 foreach $onegid ( keys %{$allitems} )
120 if ( ! exists($allitems->{$onegid}->{'ModuleID'}) ) { die "\nERROR: No ModuleID defined for item: $onegid!\n\n"; }
121 my $moduleid = $allitems->{$onegid}->{'ModuleID'};
123 # checking if this directoryid is defined
124 if ( ! exists($par2script::globals::definitions{'Module'}->{$moduleid}) )
126 die "\nERROR: ModuleID $moduleid in item $onegid not defined!\n\n";
132 ########################################################
133 # Every script has to contain exactly one root module.
134 # This module has no ParentID or an empty ParentID.
135 ########################################################
137 sub check_rootmodule
139 my $rootgid = "";
140 my $foundroot = 0;
142 my $allmodules = $par2script::globals::definitions{'Module'};
144 my $modulegid = "";
145 foreach $modulegid (keys %{$allmodules} )
147 if (( ! exists($allmodules->{$modulegid}->{'ParentID'}) ) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
149 if ( $foundroot )
151 die "\nERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).\n";
153 $rootgid = $modulegid;
154 $foundroot = 1;
158 if ( ! $foundroot )
160 die "\nERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.\n";
163 print " $rootgid\n" if $par2script::globals::verbose;
167 ########################################################
168 # File, Shortcut, Directory, Unixlink must not
169 # contain a ModuleID
170 ########################################################
172 sub check_moduleid_at_items
174 my $item;
175 foreach $item ( @par2script::globals::items_without_moduleid )
177 my $allitems = $par2script::globals::definitions{$item};
179 my $onegid;
180 foreach $onegid ( keys %{$allitems} )
182 if ( exists($allitems->{$onegid}->{'ModuleID'}) )
184 die "\nERROR: ModuleID assigned to $onegid! No module assignment to $item!\n\n";
190 ########################################################
191 # Controlling existence of multi assignments
192 ########################################################
194 sub check_multiple_assignments
196 my @multiassignments = ();
197 my $error;
199 my $topitem;
200 foreach $topitem ( keys %par2script::globals::assignedgids )
202 my $item;
203 foreach $item ( keys %{$par2script::globals::assignedgids{$topitem}} )
205 if ( $par2script::globals::assignedgids{$topitem}->{$item} > 1 )
207 $error = 1;
208 my $string = "\tGID: $item Assignments: $par2script::globals::assignedgids{$topitem}->{$item}";
209 push(@multiassignments, $string);
214 if ( $error ) { par2script::exiter::multiassignmenterror(\@multiassignments); }
217 ########################################################
218 # Check, if a defined directory has a flag CREATE
219 ########################################################
221 sub contains_create_flag
223 my ($gid) = @_;
225 my $createflag = 0;
227 if (( exists($par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'}) ) &&
228 ( $par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'} =~ /\bCREATE\b/ ))
230 $createflag = 1;
233 return $createflag;
236 ########################################################
237 # Controlling existence of definitions without
238 # any assignment
239 ########################################################
241 sub check_missing_assignments
243 # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
244 # this causes an error.
245 # Directories only have to be assigned, if they have the flag "CREATE".
247 my @missingassignments = ();
248 $error = 0;
250 my $item;
251 foreach $item ( @par2script::globals::items_assigned_at_modules )
253 my $assignedgids = $par2script::globals::assignedgids{$item};
254 my $definedgids = $par2script::globals::definitions{$item};
256 my $gid;
257 foreach $gid ( keys %{$definedgids} )
259 if ( $item eq "Directory" ) { if ( ! contains_create_flag($gid) ) { next; } }
261 if ( ! exists( $assignedgids->{$gid} ))
263 $error = 1;
264 push(@missingassignments, $gid);
269 if ( $error ) { par2script::exiter::missingassignmenterror(\@missingassignments); }
272 #############################################################
273 # Controlling if for all shortcuts with file assignment
274 # the file is defined. And for all shortcuts with
275 # shortcut assignment the shortcut has to be defined.
276 #############################################################
278 sub check_shortcut_assignments
280 my $allshortcuts = $par2script::globals::definitions{'Shortcut'};
281 my $allfiles = $par2script::globals::definitions{'File'};
283 my $shortcut;
284 foreach $shortcut ( keys %{$allshortcuts} )
286 if (( exists($allshortcuts->{$shortcut}->{'FileID'}) ) &&
287 ( ! exists($allfiles->{$allshortcuts->{$shortcut}->{'FileID'}}) ))
289 die "\nERROR: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n";
292 if (( exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
293 ( ! exists($allshortcuts->{$allshortcuts->{$shortcut}->{'ShortcutID'}}) ))
295 die "\nERROR: ShortcutID $allshortcuts->{$shortcut}->{'ShortcutID'} has no definition at shortcut $shortcut !\n";
298 if (( ! exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
299 ( ! exists($allshortcuts->{$shortcut}->{'FileID'}) ))
301 die "\nERROR: Shortcut requires assignment to \"ShortcutID\" or \"FileID\". Missing at shortcut $shortcut !\n";
306 #############################################################
307 # Controlling if for Modules and Directories, the parents
308 # are defined. If not, this can lead to a problem during
309 # script creation, because only recursively added
310 # Modules or Directories are added to the script.
311 #############################################################
313 sub check_missing_parents
315 my @parentitems = ("Module", "Directory");
316 my %rootparents = ("PREDEFINED_PROGDIR" => "1");
318 my $oneitem;
319 foreach $oneitem ( @parentitems )
321 my $alldefinitions = $par2script::globals::definitions{$oneitem};
323 my $onegid;
324 foreach $onegid ( keys %{$alldefinitions} )
326 # If there is a ParentID used, it must be defined
327 if (( exists($alldefinitions->{$onegid}->{'ParentID'}) ) &&
328 ( ! exists($alldefinitions->{$alldefinitions->{$onegid}->{'ParentID'}}) ) &&
329 ( ! exists($rootparents{$alldefinitions->{$onegid}->{'ParentID'}}) ))
331 die "\nERROR: Parent \"$alldefinitions->{$onegid}->{'ParentID'}\" at $oneitem \"$onegid\" is not defined!\n";