merge the formfield patch from ooo-build
[ooovba.git] / cli_ure / source / scripts / increment_version.pl
blob0caf4e5202c04b0ad7288190f746de2ff81420a5
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: increment_version.pl,v $
11 # $Revision: 1.4 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 use warnings;
33 use strict;
34 use diagnostics;
36 sub trim;
37 sub readIncVersions($);
38 sub processLine($$);
39 sub checkName($);
40 sub incrementNewVersion($);
41 sub incrementOldVersion($);
42 sub incrementPolicyVersion($);
43 my $usage =
44 "The tool increments the minor version of assemblies and the major version of ".
45 "the respective policy files. This is only done if new uno types have been added since".
46 "the last product upate. This information is obtained from the file which is passed as ".
47 "argument changedTypes. The names in the version file must have a particular form. ".
48 "They must end on one of folling terms: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n".
49 "If no new published types habe been added then no output, argument newVersions, is written".
50 "Usage is: \n increment_version.pl oldVersions incVersions newVersions changedTypes\n\n".
51 "oldVersion: Contains name value pairs, which are used for forming the config files of ".
52 "the policy assemblies, for building the assemblies. \n\n".
53 "incVersions: File containing the names of which the versions are to be incremented. ".
54 "Every line may only contain one name. The names must exactly match those from the ".
55 "oldVersion file.\n\n".
56 "newVersions: Contains all entries from oldVersions, but the values of the names,".
57 "which occur in selection, have been incremented.\n\n".
58 "changedTypes: File that contains the information if new published types have been added ".
59 "since the last product update.\n\n" ;
61 my $sNameForm =
62 "The names must end on one of these names: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n".
63 "For example, valid names are: \n".
64 "CLI_URETYPES_NEW_VERSION\nCLI_URETYPES_OLD_VERSION\nCLI_URETYPES_POLICY_VERSION\n";
66 if (scalar @ARGV < 4) {
67 print $usage;
68 exit -1;
71 -e "$ARGV[0]" or die "Error: wrong arguments. \n".$usage;
72 -e "$ARGV[1]" or die "Error: wrong arguments. \n".$usage;
73 -e "$ARGV[3]" or die "Error: wrong arguments. \n".$usage;
75 #check if new types have been added since last release.
76 #If not, then there is nothing to be done.
77 #read in oldVersions line by line and apply the increment operation
78 open TYPES, "$ARGV[3]" or die "Cannot open to $ARGV[3] $!";
80 my $newTypes;
82 #We look for the line that contains the number of new types
83 while(<TYPES>)
85 if (/New and published types/i)
87 $_ =~ /=\s*(\d+)/;
88 if ( ! defined $1)
90 print "\n###$ARGV[3] contains an invalid entry for 'New and published types'. \n\n";
91 exit -1;
93 $newTypes = $1;
97 #Check if changeTypes contained the line we are looking for
98 if (! defined $newTypes)
100 print "\n###$ARGV[3] does not contain entry about the new types ".
101 "or we are looking for the wrong string! \n\n";
102 exit -1;
105 if ( $newTypes == 0)
107 print "\nNo new UNO types since las product update.\n";
108 exit 0;
110 else
112 print "\nNew UNO types were addes since last release. The version will be increased.\n\n";
115 #read in incVersions in a list
116 my @incVersions = readIncVersions($ARGV[1]);
117 #print "@incVersions";
119 #read in oldVersions line by line and apply the increment operation
120 open OLDVERSION, "$ARGV[0]" or die "Cannot open to $ARGV[0] $!";
122 #open file we want to write to
123 open NEWVERSION, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
125 print NEWVERSION processLine($_, @incVersions) while(<OLDVERSION>);
127 close NEWVERSION;
128 close OLDVERSION;
130 exit 0;
132 sub processLine($$)
134 my $line = $_[0];
135 #skip empty lines
136 my $trimmed;
137 return $line if (length($trimmed = trim($line)) == 0);
138 #Skip comment symbol: #
139 return $line if ($trimmed =~ /^#/);
141 #Get the left part of '='
142 my $i = index($line, "=");
143 if( $i == -1)
145 print "Error: No '=' found in line:,: \n $line \n";
146 exit -1;
148 my $name = substr($line, 0, $i);
149 $name = trim($name);
150 #We do not check the names here because the file can contain
151 #other names, e.g. CLI_URETYPES_POLICY_ASSEMBLY
152 if (length($name) == 0) {
153 print "Wrong line in $ARGV[0]\n", $sNameForm;
154 exit -1;
156 my $value = substr($line, $i + 1);
157 $value = trim($value);
159 #Check if the entry shall be incremented, this information is in the second
160 #argument
161 my $found;
162 for(@incVersions) {
163 if ($_ eq $name) {
164 $found = 1;
165 last;
168 if ( ! defined($found)) {
169 return $line;
172 #Check if the name represents a version we need to change
173 if ($name =~ /NEW_VERSION$/)
175 $value = incrementNewVersion($value);
177 elsif ($name =~ /OLD_VERSION$/)
179 $value = incrementOldVersion($value);
181 elsif ($name =~ /POLICY_VERSION$/)
183 $value = incrementPolicyVersion($value);
185 else
187 #other name which we ignore
188 return $line;
190 return "${name}=${value}\n";
193 #The value of a new version has the form x.x.x.x
194 #We increment the third position from the left.
195 #Te argument must already be trimmed.
196 sub incrementNewVersion($)
198 my @parts = split /\./,$_[0];
199 if (scalar @parts != 4)
201 print "Error, no valid version given in $ARGV[0]\n. A 'new version' has four parts.";
202 exit -1;
204 $parts[2]++;
205 #build the version string and return
206 return "$parts[0].$parts[1].$parts[2].$parts[3]";
209 #The value of a new version has the form x.x.x.x-x.x.x.x
210 #We increment the third position of the second part.
211 #Te argument must already be trimmed.
212 sub incrementOldVersion($)
214 my @parts = split /[\.-]/,$_[0];
215 if (scalar @parts != 8)
217 print "Error, no valid version given in $ARGV[0]\n. A 'old version' has the form
218 x.x.x.x-x.x.x.x\n.";
219 exit -1;
221 $parts[6]++;
222 return "$parts[0].$parts[1].$parts[2].$parts[3]-$parts[4].$parts[5].$parts[6].$parts[7]";
223 return $_[0];
226 sub incrementPolicyVersion($)
228 my @parts = split /\./,$_[0];
229 if (scalar @parts != 4)
231 print "Error, no valid version given in $ARGV[0]\n. A 'policy version' has four parts.";
232 exit -1;
234 $parts[0]++;
235 #build the version string and return
236 return "$parts[0].$parts[1].$parts[2].$parts[3]";
240 sub readIncVersions($)
242 open INC, $_[0] or die "Could not open $_[0] $!";
243 my $arg = $_[0];
244 my @names;
246 while(<INC>)
248 chomp;
249 #Skip empty lines
250 my $line;
251 if (length($line = trim($_)) == 0) {
252 next;
254 #Skip comment symbol: #
255 if ($line =~ /^#/) {
256 next;
258 if (!checkName($line)) {
259 print "Wrong entry in file $_[0]\n", $sNameForm;
260 exit -1;
262 push @names, $line;
264 print "No entries found in $arg\n" if(scalar @names == 0);
265 return @names;
268 #The argument must already be trimmed
269 #returns 1 if ok
270 sub checkName($)
272 my $name = $_[0];
273 if ( $name !~/NEW_VERSION$|OLD_VERSION$|POLICY_VERSION$/) {
274 return 0;
276 return 1;
279 sub trim($)
281 my $string = shift;
282 $string =~ s/^\s+//;
283 $string =~ s/\s+$//;
284 return $string;