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 .
23 sub readRedirectionValues
($);
26 "Usage is: \n clipatchconfig.pl configTemplate redirections policyConfig
28 configTemplate: The config file which is used for the policy assembly. It
29 contains place holders for the binding redirection.
31 redirections: file containing the values for oldVersion and newVersion tags
32 which are used in the BindingRedirect element of the config files.
34 policyConfig: Name of the file in which we want to write the config file.
38 if (scalar @ARGV < 3) {
44 my %redirectionValue = readRedirectionValues
($ARGV[1]);
47 #Read config file in which we will replace the versions
49 open TEMPLATE
, $ARGV[0] or die $!;
50 my $templ = <TEMPLATE
>;
52 #Open the config file we are goint to write to
53 open CONFIG
, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
55 #No substitute the place holders for oldVersion and new Version in the config template with
56 #the values obtained from the redirections file
57 for (keys %redirectionValue) {
58 $templ=~ s/\b$_\b/$redirectionValue{$_}/;
60 #Write the config file
63 #Reads the key value pairs from the files, which name must be passed in
64 #the parameter. The file contains lines of the form name=value, for example
65 #CLI_URETYPES_OLD_VERSION=1.1.0.0-1.1.1.0
66 sub readRedirectionValues
($)
68 #Read in the values for the version redirection
69 open REDIR
, $_[0] or die $!;
71 my %redirectionValues;
78 if (length($trimmed = trim
($_)) == 0) {
82 #Skip comment symbol: #
83 if ($trimmed =~ /^#/) {
87 my @lineParts = split /=/,$_;
89 #Check if we have valid name value pairs.
90 if (scalar @lineParts != 2) {
91 print "Error: Values in $ARGV[1] are not correct (Entries must have the form name=value). Invalid line: \n$_\n";
95 #Trim the strings and check if they still contain characters
96 my $name = trim
($lineParts[0]);
97 my $value = trim
($lineParts[1]);
98 if (length($name) == 0 || length($value) == 0) {
99 print "Error: Values in $ARGV[1] are not correct. Invalid line: \n$_\n";
103 #Check if we have duplicate key names
104 for (keys %redirectionValues) {
106 print "Error: Values in $ARGV[1] are not correct. The name $_ is not unique.\n";
111 $redirectionValues{$name} = $value;
113 return %redirectionValues;