1*cdf0e10cSrcweir#************************************************************************* 2*cdf0e10cSrcweir# 3*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# This file is part of OpenOffice.org. 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir# 15*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir# 21*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir# 26*cdf0e10cSrcweir#************************************************************************* 27*cdf0e10cSrcweir 28*cdf0e10cSrcweirpackage par2script::check; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse par2script::globals; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir################################ 33*cdf0e10cSrcweir# Checks of the setup script 34*cdf0e10cSrcweir################################ 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir######################################################## 37*cdf0e10cSrcweir# Checking if all defined directories are needed 38*cdf0e10cSrcweir######################################################## 39*cdf0e10cSrcweir 40*cdf0e10cSrcweirsub check_needed_directories 41*cdf0e10cSrcweir{ 42*cdf0e10cSrcweir my $allfiles = $par2script::globals::definitions{'File'}; 43*cdf0e10cSrcweir my $alldirs = $par2script::globals::definitions{'Directory'}; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir # checking if all defined directories are needed 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir my $dir; 48*cdf0e10cSrcweir foreach $dir ( keys %{$alldirs} ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir # I. directory has create flag 51*cdf0e10cSrcweir if (( exists($alldirs->{$dir}->{'Styles'}) ) && ( $alldirs->{$dir}->{'Styles'} =~ /\bCREATE\b/ )) { next; } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir # II. there is at least one file in the directory 54*cdf0e10cSrcweir my $fileinside = 0; 55*cdf0e10cSrcweir my $file; 56*cdf0e10cSrcweir foreach $file ( keys %{$allfiles} ) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir if (( $allfiles->{$file}->{'Dir'} eq $dir ) || ( $allfiles->{$file}->{'NetDir'} eq $dir )) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir $fileinside = 1; 61*cdf0e10cSrcweir last; 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir } 64*cdf0e10cSrcweir if ( $fileinside ) { next; } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir # III. the directory is parent for another directory 67*cdf0e10cSrcweir my $isparent = 0; 68*cdf0e10cSrcweir my $onedir; 69*cdf0e10cSrcweir foreach $onedir ( keys %{$alldirs} ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir if ( $alldirs->{$onedir}->{'ParentID'} eq $dir ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir $isparent = 1; 74*cdf0e10cSrcweir last; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir if ( $isparent ) { next; } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir # no condition is true -> directory definition is superfluous 80*cdf0e10cSrcweir my $infoline = "\tINFO: Directory definition $dir is superfluous\n"; 81*cdf0e10cSrcweir # print $infoline; 82*cdf0e10cSrcweir push(@par2script::globals::logfileinfo, $infoline); 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir} 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir################################################## 87*cdf0e10cSrcweir# Checking if the directories in the item 88*cdf0e10cSrcweir# definitions are defined. 89*cdf0e10cSrcweir################################################## 90*cdf0e10cSrcweir 91*cdf0e10cSrcweirsub check_directories_in_item_definitions 92*cdf0e10cSrcweir{ 93*cdf0e10cSrcweir my $item; 94*cdf0e10cSrcweir foreach $item ( @par2script::globals::items_with_directories ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir my $allitems = $par2script::globals::definitions{$item}; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir my $onegid; 99*cdf0e10cSrcweir foreach $onegid ( keys %{$allitems} ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir if ( ! exists($allitems->{$onegid}->{'Dir'}) ) { die "\nERROR: No directory defined for item: $onegid!\n\n"; } 102*cdf0e10cSrcweir my $dir = $allitems->{$onegid}->{'Dir'}; 103*cdf0e10cSrcweir if (( $dir eq "PD_PROGDIR" ) || ( $dir =~ /PREDEFINED_/ )) { next; } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir # checking if this directoryid is defined 106*cdf0e10cSrcweir if ( ! exists($par2script::globals::definitions{'Directory'}->{$dir}) ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir die "\nERROR: Directory $dir in item $onegid not defined!\n\n"; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir} 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir######################################################## 115*cdf0e10cSrcweir# Checking for all Items, that know their modules, 116*cdf0e10cSrcweir# whether these modules exist. 117*cdf0e10cSrcweir######################################################## 118*cdf0e10cSrcweir 119*cdf0e10cSrcweirsub check_module_existence 120*cdf0e10cSrcweir{ 121*cdf0e10cSrcweir my $item; 122*cdf0e10cSrcweir foreach $item ( @par2script::globals::items_with_moduleid ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir my $allitems = $par2script::globals::definitions{$item}; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir my $onegid; 127*cdf0e10cSrcweir foreach $onegid ( keys %{$allitems} ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir if ( ! exists($allitems->{$onegid}->{'ModuleID'}) ) { die "\nERROR: No ModuleID defined for item: $onegid!\n\n"; } 130*cdf0e10cSrcweir my $moduleid = $allitems->{$onegid}->{'ModuleID'}; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir # checking if this directoryid is defined 133*cdf0e10cSrcweir if ( ! exists($par2script::globals::definitions{'Module'}->{$moduleid}) ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir die "\nERROR: ModuleID $moduleid in item $onegid not defined!\n\n"; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir} 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir######################################################## 142*cdf0e10cSrcweir# Every script has to contain exactly one root module. 143*cdf0e10cSrcweir# This module has no ParentID or an empty ParentID. 144*cdf0e10cSrcweir######################################################## 145*cdf0e10cSrcweir 146*cdf0e10cSrcweirsub check_rootmodule 147*cdf0e10cSrcweir{ 148*cdf0e10cSrcweir my $rootgid = ""; 149*cdf0e10cSrcweir my $foundroot = 0; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir my $allmodules = $par2script::globals::definitions{'Module'}; 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir my $modulegid = ""; 154*cdf0e10cSrcweir foreach $modulegid (keys %{$allmodules} ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir if (( ! exists($allmodules->{$modulegid}->{'ParentID'}) ) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" )) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir if ( $foundroot ) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir die "\nERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).\n"; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir $rootgid = $modulegid; 163*cdf0e10cSrcweir $foundroot = 1; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir if ( ! $foundroot ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir die "\nERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.\n"; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir print " $rootgid\n"; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir} 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir######################################################## 177*cdf0e10cSrcweir# File, Shortcut, Directory, Unixlink must not 178*cdf0e10cSrcweir# contain a ModuleID 179*cdf0e10cSrcweir######################################################## 180*cdf0e10cSrcweir 181*cdf0e10cSrcweirsub check_moduleid_at_items 182*cdf0e10cSrcweir{ 183*cdf0e10cSrcweir my $item; 184*cdf0e10cSrcweir foreach $item ( @par2script::globals::items_without_moduleid ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir my $allitems = $par2script::globals::definitions{$item}; 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir my $onegid; 189*cdf0e10cSrcweir foreach $onegid ( keys %{$allitems} ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir if ( exists($allitems->{$onegid}->{'ModuleID'}) ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir die "\nERROR: ModuleID assigned to $onegid! No module assignment to $item!\n\n"; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir} 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir######################################################## 200*cdf0e10cSrcweir# Controlling existence of multi assignments 201*cdf0e10cSrcweir######################################################## 202*cdf0e10cSrcweir 203*cdf0e10cSrcweirsub check_multiple_assignments 204*cdf0e10cSrcweir{ 205*cdf0e10cSrcweir my @multiassignments = (); 206*cdf0e10cSrcweir my $error; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir my $topitem; 209*cdf0e10cSrcweir foreach $topitem ( keys %par2script::globals::assignedgids ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir my $item; 212*cdf0e10cSrcweir foreach $item ( keys %{$par2script::globals::assignedgids{$topitem}} ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir if ( $par2script::globals::assignedgids{$topitem}->{$item} > 1 ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir $error = 1; 217*cdf0e10cSrcweir my $string = "\tGID: $item Assignments: $par2script::globals::assignedgids{$topitem}->{$item}"; 218*cdf0e10cSrcweir push(@multiassignments, $string); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir if ( $error ) { par2script::exiter::multiassignmenterror(\@multiassignments); } 224*cdf0e10cSrcweir} 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir######################################################## 227*cdf0e10cSrcweir# Check, if a defined directory has a flag CREATE 228*cdf0e10cSrcweir######################################################## 229*cdf0e10cSrcweir 230*cdf0e10cSrcweirsub contains_create_flag 231*cdf0e10cSrcweir{ 232*cdf0e10cSrcweir my ($gid) = @_; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir my $createflag = 0; 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir if (( exists($par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'}) ) && 237*cdf0e10cSrcweir ( $par2script::globals::definitions{'Directory'}->{$gid}->{'Styles'} =~ /\bCREATE\b/ )) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir $createflag = 1; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir return $createflag; 243*cdf0e10cSrcweir} 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir######################################################## 246*cdf0e10cSrcweir# Controlling existence of definitions without 247*cdf0e10cSrcweir# any assignment 248*cdf0e10cSrcweir######################################################## 249*cdf0e10cSrcweir 250*cdf0e10cSrcweirsub check_missing_assignments 251*cdf0e10cSrcweir{ 252*cdf0e10cSrcweir # If defined gids for "File", "Directory" or "Unixlink" are not assigned, 253*cdf0e10cSrcweir # this causes an error. 254*cdf0e10cSrcweir # Directories only have to be assigned, if they have the flag "CREATE". 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir my @missingassignments = (); 257*cdf0e10cSrcweir $error = 0; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir my $item; 260*cdf0e10cSrcweir foreach $item ( @par2script::globals::items_assigned_at_modules ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir my $assignedgids = $par2script::globals::assignedgids{$item}; 263*cdf0e10cSrcweir my $definedgids = $par2script::globals::definitions{$item}; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir my $gid; 266*cdf0e10cSrcweir foreach $gid ( keys %{$definedgids} ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir if ( $item eq "Directory" ) { if ( ! contains_create_flag($gid) ) { next; } } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir if ( ! exists( $assignedgids->{$gid} )) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir $error = 1; 273*cdf0e10cSrcweir push(@missingassignments, $gid); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if ( $error ) { par2script::exiter::missingassignmenterror(\@missingassignments); } 279*cdf0e10cSrcweir} 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir############################################################# 282*cdf0e10cSrcweir# Controlling if for all shortcuts with file assignment 283*cdf0e10cSrcweir# the file is defined. And for all shortcuts with 284*cdf0e10cSrcweir# shortcut assignment the shortcut has to be defined. 285*cdf0e10cSrcweir############################################################# 286*cdf0e10cSrcweir 287*cdf0e10cSrcweirsub check_shortcut_assignments 288*cdf0e10cSrcweir{ 289*cdf0e10cSrcweir my $allshortcuts = $par2script::globals::definitions{'Shortcut'}; 290*cdf0e10cSrcweir my $allfiles = $par2script::globals::definitions{'File'}; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir my $shortcut; 293*cdf0e10cSrcweir foreach $shortcut ( keys %{$allshortcuts} ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir if (( exists($allshortcuts->{$shortcut}->{'FileID'}) ) && 296*cdf0e10cSrcweir ( ! exists($allfiles->{$allshortcuts->{$shortcut}->{'FileID'}}) )) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir # die "\nERROR: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n"; 299*cdf0e10cSrcweir print "\n\tWARNING: FileID $allshortcuts->{$shortcut}->{'FileID'} has no definition at shortcut $shortcut !\n"; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir if (( exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) && 303*cdf0e10cSrcweir ( ! exists($allshortcuts->{$allshortcuts->{$shortcut}->{'ShortcutID'}}) )) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir die "\nERROR: ShortcutID $allshortcuts->{$shortcut}->{'ShortcutID'} has no definition at shortcut $shortcut !\n"; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir if (( ! exists($allshortcuts->{$shortcut}->{'ShortcutID'}) ) && 309*cdf0e10cSrcweir ( ! exists($allshortcuts->{$shortcut}->{'FileID'}) )) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir die "\nERROR: Shortcut requires assignment to \"ShortcutID\" or \"FileID\". Missing at shortcut $shortcut !\n"; 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir} 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir############################################################# 317*cdf0e10cSrcweir# Controlling if for Modules and Directories, the parents 318*cdf0e10cSrcweir# are defined. If not, this can lead to a problem during 319*cdf0e10cSrcweir# script creation, because only recursively added 320*cdf0e10cSrcweir# Modules or Directories are added to the script. 321*cdf0e10cSrcweir############################################################# 322*cdf0e10cSrcweir 323*cdf0e10cSrcweirsub check_missing_parents 324*cdf0e10cSrcweir{ 325*cdf0e10cSrcweir my @parentitems = ("Module", "Directory"); 326*cdf0e10cSrcweir my %rootparents = ("PREDEFINED_PROGDIR" => "1"); 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir my $oneitem; 329*cdf0e10cSrcweir foreach $oneitem ( @parentitems ) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir my $alldefinitions = $par2script::globals::definitions{$oneitem}; 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir my $onegid; 334*cdf0e10cSrcweir foreach $onegid ( keys %{$alldefinitions} ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir # If there is a ParentID used, it must be defined 337*cdf0e10cSrcweir if (( exists($alldefinitions->{$onegid}->{'ParentID'}) ) && 338*cdf0e10cSrcweir ( ! exists($alldefinitions->{$alldefinitions->{$onegid}->{'ParentID'}}) ) && 339*cdf0e10cSrcweir ( ! exists($rootparents{$alldefinitions->{$onegid}->{'ParentID'}}) )) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir die "\nERROR: Parent \"$alldefinitions->{$onegid}->{'ParentID'}\" at $oneitem \"$onegid\" is not defined!\n"; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir} 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir1; 348