Fix build
[egit.git] / tools / version.sh
blob4c92033d88be547a79c580baa349070ccf81db3b
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) {
117 $seen_version = 1 if (!/<\?xml/ &&
118 s/(version=")[^"]*(")/${1}'"$OSGI_V"'${2}/);
120 s/(feature="org.eclipse.jgit" version=")[^"]*(")/${1}'"$JGIT_V"'${2}/;
121 ' org.eclipse.egit-feature/feature.xml
123 perl -pi -e '
124 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
125 ' org.eclipse.egit-feature/pom.xml
127 perl -pi -e '
128 if ($ARGV ne $old_argv) {
129 $seen_version = 0;
130 $old_argv = $ARGV;
132 if ($seen_version < 2) {
133 $seen_version++ if
134 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
136 ' org.eclipse.egit-updatesite/pom.xml
138 perl -pi -e '
139 if ($ARGV ne $old_argv) {
140 $seen_version = 0;
141 $old_argv = $ARGV;
143 if (!$seen_version) {
144 $seen_version = 1 if
145 s{<(version)>[^<\$]*</\1>}{<${1}>'"$POM_V"'</${1}>};
147 s{<(jgit-version)>[^<]*</\1>}{<${1}>'"$J"'</${1}>};
148 ' $(git ls-files | grep pom.xml)
150 git diff