xref: /trunk/main/solenv/bin/modules/par2script/check.pm (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
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.
14#
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).
20#
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.
25#
26#*************************************************************************
27
28package par2script::check;
29
30use par2script::globals;
31
32################################
33# Checks of the setup script
34################################
35
36########################################################
37# Checking if all defined directories are needed
38########################################################
39
40sub check_needed_directories
41{
42    my $allfiles = $par2script::globals::definitions{'File'};
43    my $alldirs = $par2script::globals::definitions{'Directory'};
44
45    # checking if all defined directories are needed
46
47    my $dir;
48    foreach $dir ( keys %{$alldirs} )
49    {
50        # I. directory has create flag
51        if (( exists($alldirs->{$dir}->{'Styles'}) ) && ( $alldirs->{$dir}->{'Styles'} =~ /\bCREATE\b/ )) { next; }
52
53        # II. there is at least one file in the directory
54        my $fileinside = 0;
55        my $file;
56        foreach $file ( keys %{$allfiles} )
57        {
58            if (( $allfiles->{$file}->{'Dir'} eq $dir ) || ( $allfiles->{$file}->{'NetDir'} eq $dir ))
59            {
60                $fileinside = 1;
61                last;
62            }
63        }
64        if ( $fileinside ) { next; }
65
66        # III. the directory is parent for another directory
67        my $isparent = 0;
68        my $onedir;
69        foreach $onedir ( keys %{$alldirs} )
70        {
71            if ( $alldirs->{$onedir}->{'ParentID'} eq $dir )
72            {
73                $isparent = 1;
74                last;
75            }
76        }
77        if ( $isparent ) { next; }
78
79        # no condition is true -> directory definition is superfluous
80        my $infoline = "\tINFO: Directory definition $dir is superfluous\n";
81        # print $infoline;
82        push(@par2script::globals::logfileinfo, $infoline);
83    }
84}
85
86##################################################
87# Checking if the directories in the item
88# definitions are defined.
89##################################################
90
91sub check_directories_in_item_definitions
92{
93    my $item;
94    foreach $item ( @par2script::globals::items_with_directories )
95    {
96        my $allitems = $par2script::globals::definitions{$item};
97
98        my $onegid;
99        foreach $onegid ( keys %{$allitems} )
100        {
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; }
104
105            # checking if this directoryid is defined
106            if ( ! exists($par2script::globals::definitions{'Directory'}->{$dir}) )
107            {
108                die "\nERROR: Directory $dir in item $onegid not defined!\n\n";
109            }
110        }
111    }
112}
113
114########################################################
115# Checking for all Items, that know their modules,
116# whether these modules exist.
117########################################################
118
119sub check_module_existence
120{
121    my $item;
122    foreach $item ( @par2script::globals::items_with_moduleid )
123    {
124        my $allitems = $par2script::globals::definitions{$item};
125
126        my $onegid;
127        foreach $onegid ( keys %{$allitems} )
128        {
129            if ( ! exists($allitems->{$onegid}->{'ModuleID'}) ) { die "\nERROR: No ModuleID defined for item: $onegid!\n\n"; }
130            my $moduleid = $allitems->{$onegid}->{'ModuleID'};
131
132            # checking if this directoryid is defined
133            if ( ! exists($par2script::globals::definitions{'Module'}->{$moduleid}) )
134            {
135                die "\nERROR: ModuleID $moduleid in item $onegid not defined!\n\n";
136            }
137        }
138    }
139}
140
141########################################################
142# Every script has to contain exactly one root module.
143# This module has no ParentID or an empty ParentID.
144########################################################
145
146sub check_rootmodule
147{
148    my $rootgid = "";
149    my $foundroot = 0;
150
151    my $allmodules = $par2script::globals::definitions{'Module'};
152
153    my $modulegid = "";
154    foreach $modulegid (keys %{$allmodules} )
155    {
156        if (( ! exists($allmodules->{$modulegid}->{'ParentID'}) ) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
157        {
158            if ( $foundroot )
159            {
160                die "\nERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).\n";
161            }
162            $rootgid = $modulegid;
163            $foundroot = 1;
164        }
165    }
166
167    if ( ! $foundroot )
168    {
169        die "\nERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.\n";
170    }
171
172    print " $rootgid\n";
173
174}
175
176########################################################
177# File, Shortcut, Directory, Unixlink must not
178# contain a ModuleID
179########################################################
180
181sub check_moduleid_at_items
182{
183    my $item;
184    foreach $item ( @par2script::globals::items_without_moduleid )
185    {
186        my $allitems = $par2script::globals::definitions{$item};
187
188        my $onegid;
189        foreach $onegid ( keys %{$allitems} )
190        {
191            if ( exists($allitems->{$onegid}->{'ModuleID'}) )
192            {
193                die "\nERROR: ModuleID assigned to $onegid! No module assignment to $item!\n\n";
194            }
195        }
196    }
197}
198
199########################################################
200# Controlling existence of multi assignments
201########################################################
202
203sub check_multiple_assignments
204{
205    my @multiassignments = ();
206    my $error;
207
208    my $topitem;
209    foreach $topitem ( keys %par2script::globals::assignedgids )
210    {
211        my $item;
212        foreach $item ( keys %{$par2script::globals::assignedgids{$topitem}} )
213        {
214            if ( $par2script::globals::assignedgids{$topitem}->{$item} > 1 )
215            {
216                $error = 1;
217                my $string = "\tGID: $item Assignments: $par2script::globals::assignedgids{$topitem}->{$item}";
218                push(@multiassignments, $string);
219            }
220        }
221    }
222
223    if ( $error ) { par2script::exiter::multiassignmenterror(\@multiassignments); }
224}
225
226########################################################
227# Check, if a defined directory has a flag CREATE
228########################################################
229
230sub contains_create_flag
231{
232    my ($gid) = @_;
233
234    my $createflag = 0;
235
236    if (( exists($par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'}) ) &&
237        ( $par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'} =~ /\bCREATE\b/ ))
238    {
239        $createflag = 1;
240    }
241
242    return $createflag;
243}
244
245########################################################
246# Controlling existence of definitions without
247# any assignment
248########################################################
249
250sub check_missing_assignments
251{
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".
255
256    my @missingassignments = ();
257    $error = 0;
258
259    my $item;
260    foreach $item ( @par2script::globals::items_assigned_at_modules )
261    {
262        my $assignedgids = $par2script::globals::assignedgids{$item};
263        my $definedgids = $par2script::globals::definitions{$item};
264
265        my $gid;
266        foreach $gid ( keys %{$definedgids} )
267        {
268            if ( $item eq "Directory" ) { if ( ! contains_create_flag($gid) ) { next; } }
269
270            if ( ! exists( $assignedgids->{$gid} ))
271            {
272                $error = 1;
273                push(@missingassignments, $gid);
274            }
275        }
276    }
277
278    if ( $error ) { par2script::exiter::missingassignmenterror(\@missingassignments); }
279}
280
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#############################################################
286
287sub check_shortcut_assignments
288{
289    my $allshortcuts = $par2script::globals::definitions{'Shortcut'};
290    my $allfiles = $par2script::globals::definitions{'File'};
291
292    my $shortcut;
293    foreach $shortcut ( keys %{$allshortcuts} )
294    {
295        if (( exists($allshortcuts->{$shortcut}->{'FileID'}) ) &&
296            ( ! exists($allfiles->{$allshortcuts->{$shortcut}->{'FileID'}}) ))
297        {
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";
300        }
301
302        if (( exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
303            ( ! exists($allshortcuts->{$allshortcuts->{$shortcut}->{'ShortcutID'}}) ))
304        {
305            die "\nERROR: ShortcutID $allshortcuts->{$shortcut}->{'ShortcutID'} has no definition at shortcut $shortcut !\n";
306        }
307
308        if (( ! exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) &&
309            ( ! exists($allshortcuts->{$shortcut}->{'FileID'}) ))
310        {
311            die "\nERROR: Shortcut requires assignment to \"ShortcutID\" or \"FileID\". Missing at shortcut $shortcut !\n";
312        }
313    }
314}
315
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#############################################################
322
323sub check_missing_parents
324{
325    my @parentitems = ("Module", "Directory");
326    my %rootparents = ("PREDEFINED_PROGDIR" => "1");
327
328    my $oneitem;
329    foreach $oneitem ( @parentitems )
330    {
331        my $alldefinitions = $par2script::globals::definitions{$oneitem};
332
333        my $onegid;
334        foreach $onegid ( keys %{$alldefinitions} )
335        {
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'}}) ))
340            {
341                die "\nERROR: Parent \"$alldefinitions->{$onegid}->{'ParentID'}\" at $oneitem \"$onegid\" is not defined!\n";
342            }
343        }
344    }
345}
346
3471;
348