Merge branch 'stable-4.2'
[egit/eclipse.git] / tools / version.sh
blob0612e0442b92c747f88874b978d5e7bd15eb3388
1 #!/bin/sh
2 # Copyright (C) 2009, Google Inc.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Eclipse Public License v1.0
6 # which accompanies this distribution, and is available at
7 # http://www.eclipse.org/legal/epl-v10.html
9 # Update all pom.xml with new build number
11 # TODO(spearce) This should be converted to some sort of
12 # Java based Maven plugin so its fully portable.
18 while [ $# -gt 0 ]
20 case "$1" in
21 --snapshot=*)
22 V=$(echo "$1" | perl -pe 's/^--snapshot=//')
23 if [ -z "$V" ]
24 then
25 echo >&2 "usage: $0 --snapshot=0.n.0"
26 exit 1
28 case "$V" in
29 *-SNAPSHOT) : ;;
30 *) V=$V-SNAPSHOT ;;
31 esac
32 shift
35 --release)
36 V=$(git describe HEAD) || exit
37 shift
40 --jgit=*)
41 J=${1##--jgit=}
42 shift
46 echo >&2 "usage: $0 {--snapshot=0.n.0 | --release} [--jgit=0.n.0]"
47 exit 1
48 esac
49 done
51 case "$V" in
52 v*) V=$(echo "$V" | perl -pe s/^v//) ;;
53 '')
54 echo >&2 "usage: $0 {--snapshot=0.n.0 | --release}"
55 exit 1
56 esac
58 case "$V" in
59 *-SNAPSHOT)
60 POM_V=$V
61 OSGI_V="${V%%-SNAPSHOT}.qualifier"
63 *-[1-9]*-g[0-9a-f]*)
64 POM_V=$(echo "$V" | perl -pe 's/-(\d+-g.*)$/.$1/')
65 OSGI_V=$(perl -e '
66 $ARGV[0] =~ /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?-(\d+)-g(.*)$/;
67 my ($a, $b, $c, $p, $r) = ($1, $2, $3, $4, $5);
68 $b = '0' unless defined $b;
69 $c = '0' unless defined $c;
71 printf "%s.%s.%s.%6.6i_g%s\n", $a, $b, $c, $p, $r;
72 ' "$V")
75 POM_V=$V
76 OSGI_V=$V
78 esac
80 to_version() {
81 perl -e '
82 $ARGV[0] =~ /^(\d+(?:\.\d+(?:\.\d+)?)?)/;
83 print $1
84 ' "$1"
87 next_version() {
88 perl -e '
89 $ARGV[0] =~ /^(\d+)(?:\.(\d+)(?:\.(\d+))?)?/;
90 my ($a, $b) = ($1, $2);
91 $b = 0 unless defined $b;
92 $b++;
93 print "$a.$b.0";
94 ' "$1"
97 EGIT_V=$(to_version "$V")
98 EGIT_N=$(next_version "$EGIT_V")
100 [ -z "$J" ] && J=$V
101 JGIT_V=$(to_version "$J")
102 JGIT_N=$(next_version "$JGIT_V")
104 perl -pi~ -e '
105 s/^(Bundle-Version:\s*).*$/${1}'"$OSGI_V"'/;
106 s/(org.eclipse.egit.*;version=")[^"[(]*(")/${1}'"$EGIT_V"'${2}/;
107 s/(org.eclipse.egit.*;version="\[)[^"]*(\)")/${1}'"$EGIT_V,$EGIT_N"'${2}/;
108 s/(org.eclipse.jgit.*;version="\[)[^"]*(\)")/${1}'"$JGIT_V,$JGIT_N"'${2}/;
109 ' $(git ls-files | grep META-INF/MANIFEST.MF)
111 perl -pi~ -e '
112 if ($ARGV ne $old_argv) {
113 $seen_version = 0;
114 $old_argv = $ARGV;
116 if ($seen_version < 2) {
117 $seen_version++ if (!/<\?xml/ &&
118 s/(version=")[^"]*(")/${1}'"$OSGI_V"'${2}/);
120 s/(feature="org.eclipse.egit" version=")[^"]*(")/${1}'"$EGIT_V"'${2}/;
121 ' org.eclipse.egit.mylyn-feature/feature.xml
123 perl -pi~ -e '
124 if ($ARGV ne $old_argv) {
125 $seen_version = 0;
126 $old_argv = $ARGV;
128 if (!$seen_version) {
129 $seen_version = 1 if (!/<\?xml/ &&
130 s/(version=")[^"]*(")/${1}'"$OSGI_V"'${2}/);
132 s/(feature="org.eclipse.jgit" version=")[^"]*(")/${1}'"$JGIT_V"'${2}/;
133 ' $(git ls-files | grep feature.xml)
135 perl -pi~ -e '
136 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
137 ' org.eclipse.egit-feature/pom.xml
139 perl -pi~ -e '
140 if ($ARGV ne $old_argv) {
141 $seen_version = 0;
142 $old_argv = $ARGV;
144 if (!$seen_version) {
145 $seen_version = 1 if
146 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
148 s{<(egit-version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
149 ' pom.xml
151 perl -pi~ -e '
152 if ($ARGV ne $old_argv) {
153 $seen_version = 0;
154 $old_argv = $ARGV;
156 if ($seen_version < 2) {
157 $seen_version++ if
158 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
160 ' org.eclipse.egit.repository/pom.xml
162 perl -pi~ -e '
163 if ($ARGV ne $old_argv) {
164 $seen_version = 0;
165 $seen_version2 = 0;
166 $old_argv = $ARGV;
168 if (!$seen_version) {
169 $seen_version = 1 if
170 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
172 if ($seen_version2 < 2) {
173 $seen_version2++ if
174 s|(<version\>)([\.\d]*)(\</version\>)|${1}'$EGIT_V'${3}|;
176 ' org.eclipse.egit.ui.test/pom.xml
178 perl -pi~ -e '
179 if ($ARGV ne $old_argv) {
180 $seen_version = 0;
181 $seen_version2 = 0;
182 $old_argv = $ARGV;
184 if (!$seen_version) {
185 $seen_version = 1 if
186 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
188 if ($seen_version2 < 3) {
189 $seen_version2++ if
190 s|(<version\>)([\.\d]*)(\</version\>)|${1}'$EGIT_V'${3}|;
192 ' org.eclipse.egit.mylyn.ui.test/pom.xml
194 perl -pi~ -e '
195 if ($ARGV ne $old_argv) {
196 $seen_version = 0;
197 $old_argv = $ARGV;
199 if (!$seen_version) {
200 $seen_version = 1 if
201 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
203 s{<(jgit-version)>[^<]*</\1>}{<${1}>'"$J"'</${1}>};
204 ' $(git ls-files | grep pom.xml)
206 find . -name '*~' | xargs rm -f
207 git diff