1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: increment_version.pl,v $
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 #*************************************************************************
37 sub readIncVersions
($);
40 sub incrementNewVersion
($);
41 sub incrementOldVersion
($);
42 sub incrementPolicyVersion
($);
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" ;
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) {
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] $!";
82 #We look for the line that contains the number of new types
85 if (/New and published types/i)
90 print "\n###$ARGV[3] contains an invalid entry for 'New and published types'. \n\n";
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";
107 print "\nNo new UNO types since las product update.\n";
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
>);
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, "=");
145 print "Error: No '=' found in line:,: \n $line \n";
148 my $name = substr($line, 0, $i);
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;
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
168 if ( ! defined($found)) {
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);
187 #other name which we ignore
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.";
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
222 return "$parts[0].$parts[1].$parts[2].$parts[3]-$parts[4].$parts[5].$parts[6].$parts[7]";
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.";
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] $!";
251 if (length($line = trim
($_)) == 0) {
254 #Skip comment symbol: #
258 if (!checkName
($line)) {
259 print "Wrong entry in file $_[0]\n", $sNameForm;
264 print "No entries found in $arg\n" if(scalar @names == 0);
268 #The argument must already be trimmed
273 if ( $name !~/NEW_VERSION$|OLD_VERSION$|POLICY_VERSION$/) {