Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / cli_ure / source / scripts / increment_version.pl
blob9b677b314d03aa525d949986611ca7defe1fcf0a
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2000, 2010 Oracle and/or its affiliates.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # This file is part of OpenOffice.org.
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.
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).
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.
26 #*************************************************************************
28 use warnings;
29 use strict;
30 use diagnostics;
32 sub trim;
33 sub readIncVersions($);
34 sub processLine($$);
35 sub checkName($);
36 sub incrementNewVersion($);
37 sub incrementOldVersion($);
38 sub incrementPolicyVersion($);
39 my $usage =
40 "The tool increments the minor version of assemblies and the major version of ".
41 "the respective policy files. This is only done if new uno types have been added since".
42 "the last product upate. This information is obtained from the file which is passed as ".
43 "argument changedTypes. The names in the version file must have a particular form. ".
44 "They must end on one of folling terms: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n".
45 "If no new published types habe been added then no output, argument newVersions, is written".
46 "Usage is: \n increment_version.pl oldVersions incVersions newVersions changedTypes\n\n".
47 "oldVersion: Contains name value pairs, which are used for forming the config files of ".
48 "the policy assemblies, for building the assemblies. \n\n".
49 "incVersions: File containing the names of which the versions are to be incremented. ".
50 "Every line may only contain one name. The names must exactly match those from the ".
51 "oldVersion file.\n\n".
52 "newVersions: Contains all entries from oldVersions, but the values of the names,".
53 "which occur in selection, have been incremented.\n\n".
54 "changedTypes: File that contains the information if new published types have been added ".
55 "since the last product update.\n\n" ;
57 my $sNameForm =
58 "The names must end on one of these names: NEW_VERSION, OLD_VERSION, POLICY_VERSION\n".
59 "For example, valid names are: \n".
60 "CLI_URETYPES_NEW_VERSION\nCLI_URETYPES_OLD_VERSION\nCLI_URETYPES_POLICY_VERSION\n";
62 if (scalar @ARGV < 4) {
63 print $usage;
64 exit -1;
67 -e "$ARGV[0]" or die "Error: wrong arguments. \n".$usage;
68 -e "$ARGV[1]" or die "Error: wrong arguments. \n".$usage;
69 -e "$ARGV[3]" or die "Error: wrong arguments. \n".$usage;
71 #check if new types have been added since last release.
72 #If not, then there is nothing to be done.
73 #read in oldVersions line by line and apply the increment operation
74 open TYPES, "$ARGV[3]" or die "Cannot open to $ARGV[3] $!";
76 my $newTypes;
78 #We look for the line that contains the number of new types
79 while(<TYPES>)
81 if (/New and published types/i)
83 $_ =~ /=\s*(\d+)/;
84 if ( ! defined $1)
86 print "\n###$ARGV[3] contains an invalid entry for 'New and published types'. \n\n";
87 exit -1;
89 $newTypes = $1;
93 #Check if changeTypes contained the line we are looking for
94 if (! defined $newTypes)
96 print "\n###$ARGV[3] does not contain entry about the new types ".
97 "or we are looking for the wrong string! \n\n";
98 exit -1;
101 if ( $newTypes == 0)
103 print "\nNo new UNO types since las product update.\n";
104 exit 0;
106 else
108 print "\nNew UNO types were addes since last release. The version will be increased.\n\n";
111 #read in incVersions in a list
112 my @incVersions = readIncVersions($ARGV[1]);
113 #print "@incVersions";
115 #read in oldVersions line by line and apply the increment operation
116 open OLDVERSION, "$ARGV[0]" or die "Cannot open to $ARGV[0] $!";
118 #open file we want to write to
119 open NEWVERSION, "> $ARGV[2]" or die "Cannot write to $ARGV[2] $!";
121 print NEWVERSION processLine($_, @incVersions) while(<OLDVERSION>);
123 close NEWVERSION;
124 close OLDVERSION;
126 exit 0;
128 sub processLine($$)
130 my $line = $_[0];
131 #skip empty lines
132 my $trimmed;
133 return $line if (length($trimmed = trim($line)) == 0);
134 #Skip comment symbol: #
135 return $line if ($trimmed =~ /^#/);
137 #Get the left part of '='
138 my $i = index($line, "=");
139 if( $i == -1)
141 print "Error: No '=' found in line:,: \n $line \n";
142 exit -1;
144 my $name = substr($line, 0, $i);
145 $name = trim($name);
146 #We do not check the names here because the file can contain
147 #other names, e.g. CLI_URETYPES_POLICY_ASSEMBLY
148 if (length($name) == 0) {
149 print "Wrong line in $ARGV[0]\n", $sNameForm;
150 exit -1;
152 my $value = substr($line, $i + 1);
153 $value = trim($value);
155 #Check if the entry shall be incremented, this information is in the second
156 #argument
157 my $found;
158 for(@incVersions) {
159 if ($_ eq $name) {
160 $found = 1;
161 last;
164 if ( ! defined($found)) {
165 return $line;
168 #Check if the name represents a version we need to change
169 if ($name =~ /NEW_VERSION$/)
171 $value = incrementNewVersion($value);
173 elsif ($name =~ /OLD_VERSION$/)
175 $value = incrementOldVersion($value);
177 elsif ($name =~ /POLICY_VERSION$/)
179 $value = incrementPolicyVersion($value);
181 else
183 #other name which we ignore
184 return $line;
186 return "${name}=${value}\n";
189 #The value of a new version has the form x.x.x.x
190 #We increment the third position from the left.
191 #Te argument must already be trimmed.
192 sub incrementNewVersion($)
194 my @parts = split /\./,$_[0];
195 if (scalar @parts != 4)
197 print "Error, no valid version given in $ARGV[0]\n. A 'new version' has four parts.";
198 exit -1;
200 $parts[2]++;
201 #build the version string and return
202 return "$parts[0].$parts[1].$parts[2].$parts[3]";
205 #The value of a new version has the form x.x.x.x-x.x.x.x
206 #We increment the third position of the second part.
207 #Te argument must already be trimmed.
208 sub incrementOldVersion($)
210 my @parts = split /[\.-]/,$_[0];
211 if (scalar @parts != 8)
213 print "Error, no valid version given in $ARGV[0]\n. A 'old version' has the form
214 x.x.x.x-x.x.x.x\n.";
215 exit -1;
217 $parts[6]++;
218 return "$parts[0].$parts[1].$parts[2].$parts[3]-$parts[4].$parts[5].$parts[6].$parts[7]";
219 return $_[0];
222 sub incrementPolicyVersion($)
224 my @parts = split /\./,$_[0];
225 if (scalar @parts != 4)
227 print "Error, no valid version given in $ARGV[0]\n. A 'policy version' has four parts.";
228 exit -1;
230 $parts[0]++;
231 #build the version string and return
232 return "$parts[0].$parts[1].$parts[2].$parts[3]";
236 sub readIncVersions($)
238 open INC, $_[0] or die "Could not open $_[0] $!";
239 my $arg = $_[0];
240 my @names;
242 while(<INC>)
244 chomp;
245 #Skip empty lines
246 my $line;
247 if (length($line = trim($_)) == 0) {
248 next;
250 #Skip comment symbol: #
251 if ($line =~ /^#/) {
252 next;
254 if (!checkName($line)) {
255 print "Wrong entry in file $_[0]\n", $sNameForm;
256 exit -1;
258 push @names, $line;
260 print "No entries found in $arg\n" if(scalar @names == 0);
261 return @names;
264 #The argument must already be trimmed
265 #returns 1 if ok
266 sub checkName($)
268 my $name = $_[0];
269 if ( $name !~/NEW_VERSION$|OLD_VERSION$|POLICY_VERSION$/) {
270 return 0;
272 return 1;
275 sub trim($)
277 my $string = shift;
278 $string =~ s/^\s+//;
279 $string =~ s/\s+$//;
280 return $string;